-->
Page 1 of 1

Problem with IPAddress (help)

PostPosted: Thu Aug 17, 2017 8:36 am
by rodrigocirilo
Hello everyone.

I ask the help of my friends for a problem I'm having.
This is an application with NodeMcuonde where it is the client and will connect on a server (C # PC application).
It happens that I have to tell the IP of the server to which the client will connect, and this is placed in the code before void setup ().
Here comes the problem because I will read the eeprom to get the IP address stored there (it can be changed) I get the IP but the IPAdress does not update with the IP value and the module does not connect to the server.


Code: Select all
String ipA = "";
String ipB = "";
String ipC = "";
String ipD = "";
byte b = ipA.toInt();
byte c = ipB.toInt();
byte d = ipC.toInt();
byte e = ipD.toInt();
byte ip[] = {};
 IPAddress Servidor(ip);
 char*         rede_wifi = "rodrigo_cirilo";
 char*         senha = "rc40507090";
 
  IPAddress Servidor(ip);
  WiFiClient    Cliente;

void setup()
  {     
 Serial. begin(9600);
  EEPROM.begin(512); 
   
     for (int i = 64; i < 67; ++i)
    {
      ipA += char(EEPROM.read(i));
    }   
     Serial.print(ipA); 
     for (int i = 67; i < 70; ++i)
    {
      ipB += char(EEPROM.read(i));
    }   
     Serial.print(ipB); 
      for (int i = 70; i < 73; ++i)
    {
      ipC += char(EEPROM.read(i));
    }   
     Serial.print(ipC); 
     for (int i = 73; i < 76; ++i)
    {
      ipD += char(EEPROM.read(i));
    }   
     Serial.print(ipD);
     
byte b = ipA.toInt();
byte c = ipB.toInt();
byte d = ipC.toInt();
byte e = ipD.toInt();
byte ip[] = { b, c, d, e };
 IPAddress Servidor(ip); /// //// If I put it here it does not update with the correct value


aqui a função para buscar pelo servidor
Code: Select all void ClientRequest()
  {
    // First Make Sure You Got Disconnected
   // Cliente.stop();

        if(Cliente.connect(Servidor, PORTA))
    {
        Cliente.print (MAC); // endereço
        chave = true;
        chave1 = true;
    }
}

Re: Problem with IPAddress (help)

PostPosted: Thu Aug 17, 2017 2:50 pm
by rodrigocirilo
no one?

Re: Problem with IPAddress (help)

PostPosted: Fri Aug 18, 2017 11:00 am
by rodrigocirilo
Eu consegui solucionar, fica de exemplo para futuras consultas..

para mudar o valor do IP devo usar uma matriz e dar os valores da seguinte maneira:

server[0] = first part of ip;
server[1] = second part of ip;
server[2] = third part of ip;
server[3] = fourth part of ip;