Hi, everyone!
I’m working on a Spark Core project in which I’m trying to have a core connect to a local server’s socket, send one byte to identify itself, and receive 3 bytes at a time for the purpose of setting some RGB LEDs. The server sends these bytes in a group, but these groups will come anywhere from 1 second to fifteen minutes in between.
I’ve ironed out the initial server connection; the core powers on, connects to the socket, and happily receives data, displaying that data as color values on attached RGB LEDs.
The problem is coming back from a dropped connection. This first version of error-checking failed to reconnect to our local server socket, but we could still flash it using the Spark Cloud:
void attemptConnection(){
if (client.connect(server, 7890))
{
rainbow(5);
client.write(29);
digitalWrite(D7, HIGH); //Onboard LED turn on
}
}
void loop() {
(Other code)
if (!client.connected()) {
//client.stop();
//setup();
attemptConnection();
}
}
Assuming that perhaps a dropped wifi connection wouldn’t trigger a client.connected() issue, I tried a higher-level approach. Unfortunately, when it drops it sticks the core into a green-flash mode:
if (!Spark.connected()){
client.stop();
Spark.disconnect();
Spark.connect();
attemptConnection();
}
I wouldn’t be surprised if there’s something simple I’m missing… Any idea what it is?