Go Down

Topic: IP iteration (Read 249 times) previous topic - next topic

conradin

hi all,
I want to iterate through some IP addresses in Arduino code.
I only want through certain IPs, like 192.168.1.0-255
But I dont know how to combine an iterator with a string, and then provide that  to a varable that can be processed as an IP address.

here is some code to try and do what i want:
Code: [Select]

void setup()
{
Serial.begin(9600);
for (int i = 0; i <=255; i++)
    {
        byte server[] = { 192, 168, 1, i };
        Serial.println(server);
     }
}

void loop(){} //do nothing.


but that overloads the println function, and the compiler says its ambiguous.
Evidently println doesnt take bytes. Is there typecasting or typedef conversions I could do?
anyone have some insight I can borrow?

in Bash scripting what I would do is:
Code: [Select]

#!/bin/bash
for i in `seq 0 255`
do
./getHost 192.168.1.$i
done


PaulS

The problem is that you expect Serial.println() to take an array of bytes and convert it to something meaningful. It doesn't know how to convert the array of bytes to something that means something to you.

You could use something like this:

Code: [Select]
char ipBuf[16];
sprintf(ipBuf, "%d.%d.%d.%d", server[0], server[1], server[2], server[3]);
Serial.println(ipBuf);


But, I don't think that printing the array is the only thing you want to do with it. What else are you intending to do with the array?

Go Up