How can I modify this code to publish my Photon’s ip once every ten seconds?
void setup() {
Serial.begin(9600);
while(!Serial.available()) Particle.process();
// Prints out the local IP over Serial.
Serial.println(WiFi.localIP());
}
How can I modify this code to publish my Photon’s ip once every ten seconds?
void setup() {
Serial.begin(9600);
while(!Serial.available()) Particle.process();
// Prints out the local IP over Serial.
Serial.println(WiFi.localIP());
}
how about trying something like this:
IPaddress myLocalIP = WiFi.localIP();
char message[64] = ""
sprintf(message, "My Local IP= %d:%d:%d:%d", myLocalIP[0],, myLocalIP[1], myLocalIP[2], myLocalIP[3]);
Particle.publish("myLocalIP", message);
I got some errors
test.cpp:1:1: error: ‘IPaddress’ does not name a type
^
test.cpp:3:1: error: expected ‘,’ or ‘;’ before ‘sprintf’
^
test.cpp:4:1: error: ‘Particle’ does not name a type
#line 1
^
make[1]: *** […/build/target/user/platform-6test.o] Error 1
make: *** [user] Error 2
Flash unsuccessful.
a few typos…
IPAddress myLocalIP = WiFi.localIP();
char message[64] = "";
sprintf(message, "My Local IP= %d:%d:%d:%d", myLocalIP[0], myLocalIP[1], myLocalIP[2], myLocalIP[3]);
Particle.publish("myLocalIP", message);
There are a still some more
test.cpp:3:10: error: expected constructor, destructor, or type conversion before ‘(’ token
^
test.cpp:4:3: error: ‘Particle’ does not name a type
#line 1
^
make[1]: *** […/build/target/user/platform-6test.o] Error 1
make: *** [user] Error 2
Error: Could not compile. Please review your code.
compiled fine for me:
int lastUpdate = 0;
void setup()
{
}
void loop()
{
if(millis() - lastUpdate > 10000UL) // 10 seconds
{
IPAddress myLocalIP = WiFi.localIP();
char message[64] = "";
sprintf(message, "My Local IP= %d:%d:%d:%d", myLocalIP[0], myLocalIP[1], myLocalIP[2], myLocalIP[3]);
Particle.publish("myLocalIP", message);
lastUpdate = millis();
}
}
It worked for me now. Thanks you are awesome!