Go Down

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


hi all,
I want to iterate through some IP addresses in Arduino code.
I only want through certain IPs, like
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()
for (int i = 0; i <=255; i++)
        byte server[] = { 192, 168, 1, i };

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]

for i in `seq 0 255`
./getHost 192.168.1.$i


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]);

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

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131