How to set IPaddress pingAddr (192.168.123.456) from serial Monitor

Hello Arduino users,

I trying to set pingAddr from serial Monitor.

IPAddress pingAddr(192,168,123,456); // ip address to ping.

I tried but I failed.

Any body have good idea that using serial communication send a string as 192.168.123.456.

and then set as IPAddress pingAddr(74,125,26,147); // ip address to ping.

Thanks,
Manjunath

Have you read http://forum.arduino.cc/index.php?topic=396450 ?

I would do this by putting the characters into a buffer until the size is either too large to fit an IP (in which case you discard the invalid input) or it sees a newline, then process it using strtok and atoi...

You are aware that 192.168.123.456 is not a valid IP address, right? Each number has to be 0~255...

This should let you read an address from Serial Monitor in dotted form:

IPaddress pingAddress;
pingAddress.fromString(Serial.readStringUntil('\n'));

johnwasser & DrAzzy ,

Thanking for quick and good answers and solutions for me.

DrAzzy, yes your wright ip address contains only octets, there I mention the ip address for reference only.

Even though I have some problems & doubts as I mention bellow...

  1. Now I am able to receiving "IP address" as string is fine.

But Ping is not working Its says that echo request fails.

Is it need do type cast the ip address of 4 octets to other data type?

  1. What is the data type of the pingAddr function parameters,

IPAddress pingAddr(74,125,26,147); // ip address to ping

here my task is taking 5 no: of different ip addresses from serial comm port and

I want to store 5 different IP Addresses on Arduino Eeprom.

Then I need to test ip addresses to ping.

pingAddr1 as pingAddr( ip_a_1, ip_b_1, ip_c_1, ip_d_1 );

pingAddr2 as pingAddr( ip_a_2, ip_b_2, ip_c_2, ip_d_2 );

pingAddr3 as pingAddr( ip_a_3, ip_b_3, ip_c_3, ip_d_3 );

pingAddr4 as pingAddr( ip_a_4, ip_b_4, ip_c_4, ip_d_4 );

pingAddr5 as pingAddr( ip_a_5, ip_b_5, ip_c_5, ip_d_5 );

Then How can I do?

Please help me to complete this task.

Thanks..

Manjunath

manjunathele:
2) What is the data type of the pingAddr function parameters,

IPAddress pingAddr(74,125,26,147); // ip address to ping

I would expect 'unsigned char' (a.k.a 'byte'). You have the source file: hardware/arduino/avr/cores/arduino/IPAddress.h

johnwasser,

yes your write I tried your suggestion ,

IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet)

compile done okay fine, while I doing ICMPPing ping out put on serial terminal says that Echo request failed:2 . I think that is no response.

I have done type caste each octet with uint8_t then I pass these parameters to the function IPAddress

as shown as IPAddress pingAddr( ip_a_1, ip_b_1, ip_c_1, ip_d_1 ); // ip address to ping.............

Till now no success I fail to ping. The result is no response. What can I do..

Thanks.
Manjunath

Have you checked with a PC on the same LAN to see if the device you are trying to ping will respond? Not all devices will reply to a ping request.

johnwasser,

Yes I have done ping with pc its okay,

If I declare like this its working.

uint8_t ip_a1=192,ip_b1=168,ip_c1=1,ip_d1=70;

IPAddress pingAddr(ip_a1,ip_b1,ip_c1,ip_d1); // ip address to ping.............

but from the retriving the data from eeprom not success.

For debugging purpose How can print my pingAddr() on serial port, that can I see what values it takes.

Thanks.
---- Manjunath

manjunathele:
For debugging purpose How can print my pingAddr() on serial port, that can I see what values it takes.

What happens when you try Serial.println(pingAddr);?

johnwasser,

Good day for me, my problem solved ,Thanking you johnwasser for your support.

Its clearly understood that IP address takes 4 octets as ‘byte’ in arduino flat form.

byte is only takes the value upto 256 as digits.

here is my solution: please find attachment of “Ping_ip_taken_from_serial_com”

DrAzzy,

Great day for me DrAzzy your wright, by user suggestion by use of " atoi " solved my problem.

Once again thanks for co-operation

Note: any body like me suffering for code as having same problem they can test my code.
code output may vary according to your implementation of logic.

— Manjuanath

Ping_ip_taken_from_serial_com.ino (2.71 KB)