Pages: [1]   Go Down
Author Topic: IP iteration  (Read 190 times)
0 Members and 1 Guest are viewing this topic.
Maine
Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
You blocked me on facebook and now youre going to die!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
#!/bin/bash
for i in `seq 0 255`
do
./getHost 192.168.1.$i
done

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46204
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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?
Logged

Pages: [1]   Go Up
Jump to: