I'm currently having an issue with my Arduino-to-ESP-to thingspeak temp monitor. It will randomly just stop uploading for seemingly no reason. All it takes is a reset of power to the ESP (unplug) and it starts working again. Sometimes it works fine for 12 hours, other just 10 minutes. For power, I have tried both the 3.3v off the Uno (yeah, I know i shouldn't) and 2 AA's. Neither seems to affect the issue.
Here is my code just in case. I am using two temp sensors, one connected to the uno, and another wireless from my sons room upstairs, sent via Serial transceivers. Any help would be great. Thanks!
#include <DallasTemperature.h>
#include <OneWire.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
#define ONE_WIRE_BUS 8
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float temp;
float jxRoom;
long prevMil = 0;
long interval = 60000;
#define SSID "myssid"
#define PASS "mypassword"
#define IP "184.106.153.149" // thingspeak.com
String GET = "GET /update?key=my_key";
void setup()
{
Serial.begin(9600);
sensors.begin();
Serial.println("AT");
delay(5000);
if(Serial.find("OK")){
connectWiFi();
}
delay(1000);
mySerial.begin(9600);
}
void loop(){
if(mySerial.available())
{
jxRoom =(mySerial.read());
}
char buf2[10];
String jTemp = dtostrf(jxRoom, 2, 0, buf2);
sensors.requestTemperatures();
float tempC = sensors.getTempCByIndex(0);
tempC = DallasTemperature::toFahrenheit(tempC);
delay(100);
char buffer[10];
String tempF = dtostrf(tempC, 4, 1, buffer);
unsigned long curMil = millis();
if(curMil - prevMil > interval)
{
prevMil = curMil;
updateTemp(tempF, jTemp);
}
// delay(60000); took this out to use the "no delay"
}
void updateTemp(String tenmpF, String jTemp){
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += IP;
cmd += "\",80";
Serial.println(cmd);
delay(2000);
if(Serial.find("Error")){
return;
}
cmd = GET + "&field2=" + tenmpF + "&field1=" + jTemp + "\r\n";
Serial.print("AT+CIPSEND=");
Serial.println(cmd.length());
if(Serial.find(">")){
Serial.print(cmd);
}
else{
Serial.println("AT+CIPCLOSE");
}
delay(100);
}
boolean connectWiFi(){
Serial.println("AT+CWMODE=1");
delay(2000);
String cmd="AT+CWJAP=\"";
cmd+=SSID;
cmd+="\",\"";
cmd+=PASS;
cmd+="\"";
Serial.println(cmd);
delay(5000);
if(Serial.find("OK")){
return true;
}
else{
return false;
}
}