hello, again!
still we want to send OSC message without cloud connection.
it’s working(not perfectly. but at least we figure out what is the problem.) but. I want to photon working more robustiously.
let’s think about real environment. photon read sensing value, and broadcast that values via OSC.
then suddenly router is power off… then… what happen?
normally. with cloud connection(AUTOMATIC MODE), it’ll tyring reconnect to WIFI router.
but without cloud connection(SEMI_AUTOMATIC, MANUAL), it’s not working.
I tested it in many ways. but not work. check this code.
// SYSTEM_THREAD(ENABLED); // nothing help
#include "simple-OSC.h"
SYSTEM_MODE(MANUAL); // SYSTEM_MODE(SEMI_AUTOMATIC) is not different
UDP udp;
IPAddress outIP(192, 168, 100, 255); // broadcast
unsigned int outPort = 8000;
void setup() {
pinMode(D7, OUTPUT);
// Put initialization like pinMode and begin functions here.
Serial.begin(115200);
// static IP setting
// IPAddress myAddress(192, 168, 100, 101);
// IPAddress netmask(255, 255, 255, 0);
// IPAddress gateway(192, 168, 100, 1);
// IPAddress dns(192, 168, 100, 1);
// WiFi.setStaticIP(myAddress, netmask, gateway, dns);
// WiFi.useStaticIP(); // I tried with static IP setting but not helped.
WiFi.connect();
while(!WiFi.ready()){
Particle.process(); //
delay(100);
}
Particle.process(); //
if(WiFi.ready()){ // LED ON
digitalWrite(D7, HIGH);
}
udp.begin(8001);
Serial.print("local IP: \t");
Serial.println(WiFi.localIP());
}
// loop() runs over and over again, as quickly as it can execute.
void loop() {
// check ping to
Serial.println("OSC MESSAGE START!");
OSCMessage message("/nemo");
message.addFloat(1.23);
message.send(udp, outIP, outPort);
delay(500);
Serial.println("OSC MESSAGE END!");
if(WiFi.ready()){
digitalWrite(D7, HIGH);
} else {
udp.endPacket();
udp.stop();
digitalWrite(D7, LOW);
WiFi.disconnect();
// IPAddress myAddress(192, 168, 100, 101);
// IPAddress netmask(255, 255, 255, 0);
// IPAddress gateway(192, 168, 100, 1);
// IPAddress dns(192, 168, 100, 1);
// WiFi.setStaticIP(myAddress, netmask, gateway, dns);
// WiFi.useStaticIP(); // not helped either.
WiFi.off();
delay(5000);
WiFi.on();
WiFi.connect();
Serial.print("connecting");
while(WiFi.connecting()){
Serial.print("waiting connection... ");
delay(1000);
}
Serial.println();
while(!WiFi.ready()){
Particle.process();
Serial.print(".");
delay(100);
}
Serial.println();
Serial.println("WiFi fully ready.");
Particle.process();
Serial.print("PING returns : ");
Serial.println(WiFi.ping(WiFi.gatewayIP()));
Serial.println("========");
Serial.print("local IP: \t");
Serial.println(WiFi.localIP());
delay(5000);
udp.begin(8001); //
}
}
when router is off, photon’s LED is blinking green LED… and breathing. which means that photon is connected with router. but actually is not.
about 5 seconds from reconnect… ping is working. but after few seconds… check a screenshot.
I tried ping command from my macbook. I tried recoonect to router with my laptop as soon as possible. you can see photon react ping… but few seconds later it’s not.
any help? thanks in advance.