I have temperature sensors sending data to ubidots every minute. It will work great for a couple days to weeks but it stops sending data after a while. I believe it has issues connecting to ubidots and times out or something. Anyone else have this problem? Is there any code I could implement to prevent this from happening?
Thank you.
Can you give more information about the issues you’re facing?
Maybe device name, programming language you’re using, some snippets of your code.
Hi, thank you for the reply.
I’m using a nodemcu with the arduino ide. This is the function where it sends data to ubidots.
void ubiSave_value(String value1) {
// if you get a connection, report back via serial:
int num1;
String var1 = “{“value”: " + String(value1)+”}";
num1 = var1.length();
delay(100);
if (client.connect(“things.ubidots.com”, 80)) {
Serial.println(“connected to ubidots”);
delay(300);
client.println(“POST /api/v1.6/variables/”+idvariable1+"/values HTTP/1.1");
client.println(“Content-Type: application/json”);
client.println("Content-Length: "+String(num1));
Serial.println(String(num1));
client.println(“X-Auth-Token: “+token);
client.println(“Host: things.ubidots.com\n”);
client.print(var1);
Serial.print(var1+”\n”);
}
else {
// if you didn’t get a connection to the server:
Serial.println(“ubidots connection failed”);
}
client.stop();
if (client.available()) {
char c = client.read();
Serial.print©;
}
}
I have it go to sleep for a minute and a half also.
Hi! You can use their NodeMCU library, it can save you a lot of time.
In general -for any device used- it’s a good practice to add a logic to re-connect to WiFi if the transmission fails, and an even better practice is to reset the device automatically if it fails after x number of times.
@juanda95 Thank you! I will look into that.
@aguspg I should do that. Thank you. So if it fails x number of times, how would I be able to reset the device through software?
A Google search gave me this:
void (softReset){
asm volatile (" jmp 0");
}
I remember having tried it and it worked.
See: http://forum.arduino.cc/index.php?topic=49581.0