-->
Page 1 of 1

Problem with IP addresses -- Solved

PostPosted: Thu Nov 01, 2018 8:09 am
by rudy
IPAddress myip = (192, 168, 100, 110); instead should have been
IPAddress myip (192, 168, 100, 110); without the =

=====================Original Post===================================
I'm having a problem IP address assignment. I am not doing anything different than I have done before but it seems that it isn't working the way I thought it should.

Code: Select allIPAddress myip = (192, 168, 100, 110);
Serial.println("IP address entered as: IPAddress myip = (192, 168, 100, 110)");

Serial.print("IP address in IPAddress format: ");
Serial.println(myip);

Serial.print("Octet by octet, (myip[x]);: ");
Serial.print(myip[0]);
Serial.print(".");
Serial.print(myip[1]);
Serial.print(".");
Serial.print(myip[2]);
Serial.print(".");
Serial.println(myip[3]);


And the output is the following.

Code: Select allIP address entered as: IPAddress myip = (192, 168, 100, 110)
IP address in IPAddress format: 110.0.0.0
Octet by octet, (myip[x]);: 110.0.0.0


I'm glad to see the 110 but all the rest is wrong. Can anyone explain to me what is wrong with this?

Re: Problem with IP addresses

PostPosted: Thu Nov 01, 2018 8:20 am
by martinayotte
Serial.println(myip);

should be :
Code: Select allSerial.println(myip.toString());

Re: Problem with IP addresses

PostPosted: Thu Nov 01, 2018 11:16 am
by rudy
That didn't change the output. I think the real problem is not in the printing, but the initial save of the IP. When each byte is being printed out with this
Code: Select allSerial.print("Octet by octet, (myip[x]);: ");
Serial.print(myip[0]);
Serial.print(".");
Serial.print(myip[1]);
Serial.print(".");
Serial.print(myip[2]);
Serial.print(".");
Serial.println(myip[3]);
Serial.println();


The values are also wrong. I get printed out 110.0.0.0 and it should be 110.100.168.192

This really isn't a printing issue for me. The real problem is that I am using the saved IP as a destination for a UDP packet send. And it wasn't getting to my computer's IP.

Code: Select allIPAddress RelayIP = (192, 168, 100, 110);

    Udp.beginPacket(RelayIP, 5000);     // RelayIP, ComputerIP, whatever
    Udp.write(replyPacket);
    Udp.endPacket();


I wasn't getting anything to the computer, the packet wasn't showing up with Wireshark. I think it was blocked by my router (not sure) because the destination IP was 0.0.0.110

Re: Problem with IP addresses -- Solved

PostPosted: Thu Nov 01, 2018 9:05 pm
by rudy
Solved

IPAddress myip = (192, 168, 100, 110); instead should have been
IPAddress myip (192, 168, 100, 110); without the =