How to pass information into a custom data type

First off, I apologize if I'm not using the right C / C++ nomenclature. It's just what was able to stick with me.

I'm trying to use the newly redesigned ICMPPing.h to ping an address that I put in from a keypad. The information is available as a string ("192.168.1.100") or as a byte array ([192],[168],[1],[100]). In the example given, there is this line:

IPAddress pingAddr(192,168,1,100);

I tried reading through the header file and I think it's a little-endian uint32_t data type. I've tried a number of items, but I seem to have the most promise with something like this:

IPAddress pingAddr(NewIP[0], NewIP[1], NewIP[2], NewIP[3]);

However, I get this error:

error: expected unqualified-id before numeric constant

How can I pass manual data to this header?

Second post in this section...

Read this before posting a programming question

  1. Getting help on the forum
    Post your complete sketch (program code)! If you don't you waste time while people ask you to do that.

If your sketch is large, attach it to your reply (under Additional Options). Otherwise, please use
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags.

Sorry. I've attached the code rather than inlined it because of the size.

KeypadPing2.ino (10.5 KB)

Update:
I have figured out how to put information into the "IPAddress" class. I had to convert it to an integer, using a "union" statement:

union ArrayToInteger {
  byte array[4];
  uint32_t integer;
};

followed by:

  ArrayToInteger converter;
  converter.array[0] = NewIP[0] ; 
  converter.array[1] = NewIP[1] ; 
  converter.array[2] = NewIP[2] ; 
  converter.array[3] = NewIP[3] ;

So, the good news is that part works. It also takes keypad input, which is better. However, I still get the following error:

In file included from C:\Program Files (x86)\Arduino\libraries\ICMPPing/ICMPPing.h:12,
                 from KeypadPing3.ino:16:
C:\Program Files (x86)\Arduino\libraries\Ethernet/utility/w5100.h:98: error: expected unqualified-id before numeric constant

The lines of code that actually do the pinging are copied & pasted from the example, so I know they work.

KeypadPing3.ino (7.61 KB)

KeypadPing3.ino:5:20: warning: Keypad.h: No such file or directory
KeypadPing3.ino:16:22: warning: ICMPPing.h: No such file or directory

Links to libraries?

While not related to the error, this:

ArrayToInteger converter; //Create a converter

  converter.array[0] = NewIP[0] ; //save something to each byte in the array
  converter.array[1] = NewIP[1] ; //save something to each byte in the array
  converter.array[2] = NewIP[2] ; //save something to each byte in the array
  converter.array[3] = NewIP[3] ; //save something to each byte in the array

IPAddress pingAddr(converter.integer);

Could be written as:

ArrayToInteger converter  = {{NewIP[0] ,NewIP[1] ,NewIP[2] ,NewIP[3] }}; //Create a converter
IPAddress pingAddr(converter.integer);

Or even just:
IPAddress pingAddr(NewIP); // "IPAddress::IPAddress(const uint8_t *address)"

Original announcement: http://forum.arduino.cc/index.php/topic,161155.0.html

Github repository: GitHub - BlakeFoster/Arduino-Ping: ICMP ping library for the Arduino

And I need to stop posting after 2200. I keep forgetting stuff. :slight_smile:

I will test this in a few hours. My whole codebase is a mess, and I'm sure it would give any proper programmer fits. But, if it's ugly and works, it's not so ugly. :wink:

KeypadPing3.ino:5:20: warning: Keypad.h: No such file or directory

Link to library?

http://playground.arduino.cc/uploads/Code/keypad.zip

I also figured out what I did wrong. At one point I created a byte array for the IP address, but it didn't work. When I changed it to an int array, it passed the information successfully.

FTPMonster:
I also figured out what I did wrong.

You no longer need help with this?