Hi guys.
I am using a Photon. Second batch. Out of the little box, left for 30mins to update.
I am using the local network to post and get some values off a local server. All works wonderful.
When everything works well, I get a breathing green light and posts to my lan every second.
But when I try to test the WiFi robustness by rebooting the router or switching the Wifi off and on again, I sometimes get a BREATHING BLUE LIGHT, at which point all code stops executing. It is unreachable, no serial debugging output or any network activity.
I understand that the breathing blue light indicates no network available, but there is no coming back from it.
I have tried the forum and there are a few posts, but none which seem to be of any help to me.
I am looking at a solid HTTPClient implementation which will not die on me.
My code:
#include "OneWire/OneWire.h"
#include "HttpClient/HttpClient.h"
#include "LiquidCrystal_I2C_Spark/LiquidCrystal_I2C_Spark.h"
#include "SparkJson/SparkJson.h"
#include "spark-dallas-temperature/spark-dallas-temperature.h"
//General device settings
String deviceName = "Photon7";
SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_THREAD(ENABLED);
//Probes - OneWire
int TempSensorPin = 2;
OneWire oneWire(TempSensorPin);
DallasTemperature sensors(&oneWire);
float lastGoodTemp = 0;
//LCD variables
LiquidCrystal_I2C *lcd;
//HTTPCLient variables used
String serverResponse = "";
HttpClient http;
http_header_t headers[] = {
// { "Content-Type", "application/json" },
// { "Accept" , "application/json" },
{ "Accept" , "*/*"},
{ NULL, NULL } // NOTE: Always terminate headers will NULL
};
http_request_t request;
http_response_t response;
String ServerPinValue1 = "0";
String ServerPinValue2 = "0";
String ServerPinValue3 = "0";
String ServerPinValue4 = "0";
//Debug variables
String wifiStatus = "";
int signalStrength = 0;
int serverResponseStatus = 0;
void setup() {
Serial.begin(9600);
pinMode(D2, INPUT); // OneWire bus
sensors.begin();
WiFi.connect();
}
void loop() {
Serial.println("");
Serial.println("---------------Beginning of loop-----------------");
readSensors();
talkToServer();
debug();
Serial.println("---------------End of loop-----------------");
delay(1000);
}
void readSensors(){
sensors.requestTemperatures();
float tempC = sensors.getTempCByIndex(0);
if(tempC>0){
if(tempC<80){
lastGoodTemp = tempC;
}
}
}
void talkToServer(){
if(WiFi.ready()){
request.hostname = "10.0.0.108";
request.port = 80;
request.path = "/PostDataAndRequestInstructions.aspx?id:" + deviceName + "|pindata:1001|temp:" + String(lastGoodTemp) + "|SignalStrength:" + String(signalStrength);
http.get(request, response, headers);
serverResponseStatus = response.status;
if(response.status==200){
serverResponse=response.body;
//Parse server returned string and get the new pin values
ServerPinValue1 = serverResponse.substring(60, 61);
ServerPinValue2 = serverResponse.substring(61, 62);
ServerPinValue3 = serverResponse.substring(62, 63);
ServerPinValue4 = serverResponse.substring(63, 64);
Serial.println("good response from server");
}else{
Serial.println("BAD response from server");
}
}
else{
Serial.println("Wifi not ready yet");
}
}
void debug(){
wifiStatus="unknown";
if(WiFi.connecting()){ wifiStatus="connecting"; }
if(WiFi.ready()){ wifiStatus="ready";}
if(WiFi.listening()){ wifiStatus="listening";}
signalStrength=WiFi.RSSI();
Serial.println("wifi :" + wifiStatus);
Serial.println("lastGoodTemp :" + String(lastGoodTemp));
Serial.println("LocalValue1 :" + ServerPinValue1;
Serial.println("LocalValue2 :" + ServerPinValue2;
Serial.println("LocalValue3 :" + ServerPinValue3;
Serial.println("LocalValue4 :" + ServerPinValue4;
Serial.println("signalStrength :" + String(signalStrength));
Serial.println("response status:" + String(serverResponseStatus));
}