is there something wrong with this code?

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");
      }

}     
      
}
}

What is exactly the problem? You get this message:

      Serial.println("nuevo cliente");

or don't?

hi luis, yes i get that message so i guess that the server is working and the client is detected but when i push the buttons defined nothing happens.

Thanks for helping

Juan

So, you see the message "nuevo cliente".
I can't help too much, because I never used ethernet or that library, but you should add "serial.print's" to your program to try to understand what is wrong.
Maybe one after this line:

        if (client.available()){

other after:

        comando[index] = '\0';

with the command that you receive. (at the very least)

what is at the other end of this ethernet connection that you are attempting ?

On one side it is the eternet shield and the other side is connected to a linksys router.

I think that he's talking about this "10, 0, 0, 31" other end. Is very strange this IP.

Browsing in the net, I found this page:
http://projects.ottech.net/index.php/arduino/5-netio-controller-app-mit-arduino

it have a example. They are using a different port and IP, I don't know if it makes sense or not.

I don't think thats a problem, 10.0.0.1 or 192.168.1.1 are the same way of meaning that you are using private class ip's so i don't see anything wrong. but i will check the sketch provided on the example you found to see if there is something i can use, i thing i 've already saw this example but just in case i will review it again.

Thanks