I have a little code which is using the HTU21D temperature and humidity sensor and in every 10 seconds sends its reading to my web server using the httpclient and for troubleshooting purposes also prints out the values to serial.
This runs reliably on Photon, I have instances which are running for weeks now with no problem.
Yesterday I have received my Electron, so I activated it and flashed the exact same code to the Electron and it works - for about a minute or 2 and then it stops. After it stops, on serial no new messages sent, my server doesn’t see any http requests coming in either, but the Electron is still breathing blue showing it is connected (build.particle.io also shows the device connected).
When I press the MODE button quickly to see the wireless coverage (green flashes), nothing happens, no green flashes, which makes me think that the whole firmware froze (if that even possible)?
I have to keep the MODE button pressed for 3 seconds to get to listening mode and then reboot and then the whole thing starts from the beginning, works for a minute or two and then freezes…
Sure, here it comes the code.
Interestingly it ‘unfroze’ - it started running again. So the serial was showing the printed values for the first 2 minutes, then nothing for about 30 and after that it is showing values again for 10 minutes or so and then froze again.
// This #include statement was automatically added by the Particle IDE.
#include "HTU21D/HTU21D.h"
#include "application.h"
#include "HttpClient/HttpClient.h"
HTU21D htu = HTU21D();
/**
* Declaring the variables.
*/
unsigned int nextTime = 0; // Next time to contact the server
HttpClient http;
// Headers currently need to be set at init, useful for API keys etc.
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;
void setup() {
Serial.begin(9600);
while(! htu.begin()){
Serial.println("HTU21D not found");
delay(1000);
}
}
void loop() {
if (nextTime > millis()) {
return;
}
Serial.println();
Serial.println("Application>\tStart of Loop.");
// Request path and body can be set at runtime or at setup.
//request.hostname = "sef.io";
request.hostname = "159.2.1.1";
request.port = 80;
//htu.readHumidity();
//htu.readTemperature();
request.path = "/intake/WULO8ZD?temperature=" + String(htu.readTemperature()) + "&humidity=" + String(htu.readHumidity());
//request.path = "/intake/2WYN039?temperature=71";
Serial.println(request.path);
// The library also supports sending a body with your request:
//request.body = "{\"key\":\"value\"}";
// Get request
http.get(request, response, headers);
Serial.print("Application>\tResponse status: ");
Serial.println(response.status);
Serial.print("Application>\tHTTP Response Body: ");
Serial.println(response.body);
nextTime = millis() + 10000;
}