Hi i am testing an arduino mega with an ethernet module and a relay module to turn on and off a lamp using netio app. But i can't make it work, when i test it using serial monitor the ip shown is 10.0.0.31 so the ip address is correctly assigned so it seems that there must be something else that is not working. Thanks in advance for any help.
This is the sketch:
#include <SPI.h>
#include <Ethernet.h>
#define BUFFER 20
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(10, 0, 0, 31);
EthernetServer servidorArduino(1000);
int index = 0;
char comando[BUFFER];
int relayA = 22;
int relay2 = 24;
int relay3 = 26;
int relay4 = 28;
int relay5 = 30;
int relay6 = 32;
int relay7 = 34;
int relay8 = 36;
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
}
Ethernet.begin(mac, ip);
servidorArduino.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
pinMode(relayA, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
pinMode(relay5, OUTPUT);
pinMode(relay6, OUTPUT);
pinMode(relay7, OUTPUT);
pinMode(relay8, OUTPUT);
pinMode(relayA, HIGH);
pinMode(relay2, LOW);
pinMode(relay3, LOW);
pinMode(relay4, LOW);
pinMode(relay5, LOW);
pinMode(relay6, LOW);
pinMode(relay7, LOW);
pinMode(relay8, LOW);
}
void loop()
{
EthernetClient client = servidorArduino.available();
if (client) {
Serial.println("nuevo cliente");
while (client.connected()) {
if (client.available()){
char caracter = client.read();
if (caracter !='\n') {
comando[index] = caracter;
index++;
if (index >= BUFFER) index = BUFFER -1;
continue;
}
comando[index] = '\0';
}
if (strstr(comando, "on")) {
digitalWrite (relayA, HIGH);
client.print("OK");
}
if (strstr(comando, "off")) {
digitalWrite (relayA, LOW);
client.print("OK");
}
}
}
}