Alguem pode me dar um help. To tantan fazer com que o ardino apague um led via comunicação com o ethernet Shield. Estou fazendo com o post: 

http://labdegaragem.com/profiles/blogs/tutorial-acendendo-um-lampad...

Fiz tentando ascender um led e não consegui pode me ajudar? Não consigo pingar o arduino e acesso  a pagina e clico nos botoes e nada é grava no comando.txt.

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0x33, 0xA2, 0x33, 0x00, 0x33, 0x7A };
byte ip[] = { 192, 168, 0, 60 };
byte server[] = { 192, 168, 0, 19 };
char temp[2];
int x=0;
int r5pin=5;
int r6pin=6;
int r7pin=7;
int r8pin=8;
int r9pin=9;
int powerOn=HIGH;
int powerOff=LOW;

EthernetClient client;

void setup() {
pinMode(r5pin,OUTPUT);
pinMode(r6pin,OUTPUT);
pinMode(r7pin,OUTPUT);
pinMode(r8pin,OUTPUT);
pinMode(r9pin,OUTPUT);
Ethernet.begin(mac, ip);
Serial.begin(9600);
delay(1000);
Serial.println("connecting...");
if (client.connect(server,80)) {
Serial.println("connected");
client.println("GET /robo.php HTTP/1.0");
client.println(); 
} else {
Serial.println("connection failed");
Serial.println();
Serial.println("disconnecting.");
client.stop();
}
}

void loop(){
if (client.connect(server,80)) {
Serial.println("connected");
client.println("GET /robo.php HTTP/1.0");
client.println();
}
do {
if (client.available()) {
char c = client.read();
temp[x]=c;
Serial.print(temp[x]);
x++;
}
}
while(x<2);
x=0;
if(temp[0]=='L' && temp[1]=='1') {
Serial.println("Liga relay1");
digitalWrite(r7pin,powerOn);
}
if(temp[0]=='L' && temp[1]=='2') {
Serial.println("Liga relay2");
digitalWrite(r7pin,powerOn);
}
if(temp[0]=='D' && temp[1]=='1') {
Serial.println("Desliga relay1");
digitalWrite(r7pin,powerOff);
}
if(temp[0]=='D' && temp[1]=='2') {
Serial.println("Desliga relay2");
digitalWrite(r7pin,powerOff);
}
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
delay(500);
}
}

Exibições: 1497

Responder esta

Respostas a este tópico

poem o codigo ai

Usei o WebeServer mesmo


#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(8090);

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}


// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}


void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
int sensorReading = analogRead(analogChannel);
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(sensorReading);
client.println("<br />");
}
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disonnected");
}
}

vm la

vc tem q saber o ip da sua rede por exemplo se for 192.168.0.1 (seu roteador)

vc tem q mudar o 192.168.1.177 por 192.168.0.177 ou seja mudar o terceiro numero

pelo da sua rede pra saber o ip da sua rede abra o cmd e digite ipconfig

dps de verificado compile o sketch e de um ping no cmd com o ip do arduino

se ele responder escreva no browser o (ip do seu arduino):8090 (ja que eh esta porta

que esta configurada) abra o serial monitor e veja se nao esta dando algum erro

obs:baixe no seu cel o app Net Scan conecte na sua rede e faça um scan 

veja se nao tem algum dispositivo com o mesmo ip (dificil mas pode acontecer)

fazendo isso tem q funcionar senao pode ter queimado alguma coisa

espero q ajude 

Poxa, então o meu Endereço de ip é do tipo 192.168.1 mesmo, já mudei o final dele com vários tipos de números, não passando de 255 e mesmo assim não vai =\, agora pouco conseguir pinga ele mas só conseguir usando o final 177 mesmo. ele ta pingando aparece no DOS que ele recebeu os 4 pacotes e a velocidade.

Quando eu abro a serial aparecer isso server is at 255.255.255.255

Será que queimei a placa de Ethernet Shield ? =\ espero que não.

Fui tentar pinga novamente e agr não estou conseguindo mais ou seja as vezes pinga e as vezes não

Mt obg pela ajuda ae mano.

Felipe, voce nao teria um swich ou um rub entre o roteador e o ehternet shield? Se tiver pode ser que nao consiga pingar.

Algumas vezes acontece isso comigo de nao conseguir pingar, cheque a conecão no RJ45.

Opá, então Angelo, tenho somente um modem que tbm é roteador com 2 saídas. Uma delas está conectada a um computador e a outra eu conectava o Shield.

Angelo:  A conexão do cabo tá certinha. =| 

Teste o cabo e aperte bem ele no ethernet shield. Te digo isso porque ja aconteceu com muitos de nao consegui se conectar por meu contato.

Já testei ele está conectado certinho, no pc pega de boas quando uso ele, as luzes  de todos os leds  da placa estão acessas menos as Rx E Tx que piscam de vez em quando.

E agr não consigo manda nenhum ping de jeito nenhum =\

Sera que o Shield tá com problema =\ ?

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço