{solved} Best way to store data?

I'm trying to set up a way to ping a whole subnet's worth of IP addresses, using ICMPPing (attached), and then later on display the results on an LCD. I know I'm going to need an array of some kind, but I'm wondering what would work best. A few modifiers:

  • I'm using an Arduino Mega, so I have some room to work.
  • I don't know exactly how many IP addresses will be in the array. I'm willing to hard-code it to a max of 256 if need be.
  • The address lengths can vary from as small as 7 to as large as 15 characters.
  • I'm passing a 4-position byte array for the IP address (one for each octet). If I can still use that, that's great, but if I need to convert it to another type, that's fine as well.

I don't have any code yet, because I'm trying to wrap my brain around the whole array thing. What would be best way to do this?

Arduino-Ping-master.zip (7.1 KB)

If I get it right,
You only need to convert the IP addresses at the moment that you intend to display them. So, you may store the numbers in 4 byte format (what about IPV6?). So theoretically there is no real limit.
4 bytes with 256 addresses would generate 1K size array max.
once you start to display it on an LCD, you can convert it send it to the display and use the same storage for the next IP address. Once it is transferred to the LCD, the variables used to generate the text version of the IP address can be reused again.

Since the addresses are contiguous you can use a bitmap to store a flag (present/not present) for each address. That will take up 32 bytes for a 256-entry bitmap.

nicoverduin:
If I get it right,
You only need to convert the IP addresses at the moment that you intend to display them. So, you may store the numbers in 4 byte format (what about IPV6?). So theoretically there is no real limit.
4 bytes with 256 addresses would generate 1K size array max.
once you start to display it on an LCD, you can convert it send it to the display and use the same storage for the next IP address. Once it is transferred to the LCD, the variables used to generate the text version of the IP address can be reused again.

Answers:
IPv6: I'm just happy that the reason I'm building this are actually using IP. :slight_smile: If ICMPPing and the W5100 would support v6, I'll add it. But that's for the future.
For the display & use same storage: I found a function that will scroll through an array, and display array and array [i+1] until you press a button, and then it will increment i and display array and array[i+1] until it's completed. Because of that, I need to keep however many IP addresses it finds.

johnwasser:
Since the addresses are contiguous you can use a bitmap to store a flag (present/not present) for each address. That will take up 32 bytes for a 256-entry bitmap.

Well, they might not be. I might be getting something like:
192.168.100.1
192.168.100.10
192.168.100.50
192.168.100.101

and because of that randomness I was thinking of just putting it into its own array.

I think I was overthinking it. I went with a two-dimensional array, and used sprintf to put the information into a form that I could use. That seemed to work.

Presumably they will all be on the same network prefix (192.168.100 in your case it would seem). In which case you only need a 1 by n byte array to store the address for each sensor.

Well, they might not be. I might be getting something like:

They are contiguous in the sense that the ones you are pinging are all in the 192.168.100.xxx set. There are only 356 possibilities in that range. Using 32 bytes, and bitSet (0 means not answering; 1 means yes, I'm here), you can store all the data in just 32 bytes.