I'm using a Maduino Zero 4G SIM7600Maduino Zero 4G SIM7600
device to upload data from 28 sensors to a ThingSpeak IoT server. It works well for a few hours, then stops uploading the data. Sometimes it starts again after an inconsistent amount of time (an hour or two), sometimes it doesn't.
I can confirm that it's only the SIM7600SIM7600
and/or Thingspeak functions that are failing, as the serial monitor demonstrates the other I2C related operations on the Arduino board are still working fine even when the server uploads fail.
void setup(){
SerialUSB.begin(115200);
SerialUSB.println("Serial initialized");
Serial1.begin(115200);
Wire.begin();
pinMode(LTE_PWRKEY_PIN, OUTPUT);
digitalWrite(LTE_RESET_PIN, LOW);
delay(100);
digitalWrite(LTE_PWRKEY_PIN, HIGH);
delay(2000);
digitalWrite(LTE_PWRKEY_PIN, LOW);
pinMode(LTE_FLIGHT_PIN, OUTPUT);
digitalWrite(LTE_FLIGHT_PIN, LOW);//Normal Mode
delay(5000);
sendData("AT+CCID", 3000, DEBUG);
sendData("AT+CREG?", 3000, DEBUG);
sendData("AT+CGATT=1", 1000, DEBUG);
sendData("AT+CGACT=1,1", 1000, DEBUG);
sendData("AT+CGDCONT=1,\"IP\",\"sp.mb.com\"", 1000, DEBUG);
delay(5000);
}
void loop(){
getData();
//Sensors 0-6
http_str = "AT+HTTPPARA=\"URL\",\"https://api.thingspeak.com/update?api_key=" + Apikey1 + "&field1=" + (String)hallData[0] + "&field2=" + (String)hallData[1] + "&field3=" + (String)hallData[2] + "&field4=" + (String)hallData[3] + "&field5=" + (String)hallData[4] + "&field6=" + (String)hallData[5] + "&field7=" + (String)hallData[6] + "\"\r\n";
SerialUSB.print("Sent to Channel 1: ");
SerialUSB.println(http_str);
sendData("AT+HTTPINIT\r\n", 2000, DEBUG);
sendData(http_str, 2000, DEBUG);
sendData("AT+HTTPACTION=1\r\n", 3000, DEBUG);
sendData("AT+HTTPTERM\r\n", 3000, DEBUG);
//Sensors 7-13
http_str = "AT+HTTPPARA=\"URL\",\"https://api.thingspeak.com/update?api_key=" + Apikey2 + "&field1=" + (String)hallData[7] + "&field2=" + (String)hallData[8] + "&field3=" + (String)hallData[9] + "&field4=" + (String)hallData[10] + "&field5=" + (String)hallData[11] + "&field6=" + (String)hallData[12] + "&field7=" + (String)hallData[13] + "\"\r\n";
SerialUSB.print("Sent to Channel 2: ");
SerialUSB.println(http_str);
sendData("AT+HTTPINIT\r\n", 2000, DEBUG);
sendData(http_str, 2000, DEBUG);
sendData("AT+HTTPACTION=1\r\n", 3000, DEBUG);
sendData("AT+HTTPTERM\r\n", 3000, DEBUG);
//Sensors 14-20
http_str = "AT+HTTPPARA=\"URL\",\"https://api.thingspeak.com/update?api_key=" + Apikey3 + "&field1=" + (String)hallData[14] + "&field2=" + (String)hallData[15] + "&field3=" + (String)hallData[16] + "&field4=" + (String)hallData[17] + "&field5=" + (String)hallData[18] + "&field6=" + (String)hallData[19] + "&field7=" + (String)hallData[20] + "\"\r\n";
SerialUSB.print("Sent to Channel 3: ");
SerialUSB.println(http_str);
sendData("AT+HTTPINIT\r\n", 2000, DEBUG);
sendData(http_str, 2000, DEBUG);
sendData("AT+HTTPACTION=1\r\n", 3000, DEBUG);
sendData("AT+HTTPTERM\r\n", 3000, DEBUG);
//Sensors 21-27
http_str = "AT+HTTPPARA=\"URL\",\"https://api.thingspeak.com/update?api_key=" + Apikey4 + "&field1=" + (String)hallData[21] + "&field2=" + (String)hallData[22] + "&field3=" + (String)hallData[23] + "&field4=" + (String)hallData[24] + "&field5=" + (String)hallData[25] + "&field6=" + (String)hallData[26] + "&field7=" + (String)hallData[27] + "\"\r\n";
SerialUSB.print("Sent to Channel 4: ");
SerialUSB.println(http_str);
sendData("AT+HTTPINIT\r\n", 2000, DEBUG);
sendData(http_str, 2000, DEBUG);
sendData("AT+HTTPACTION=1\r\n", 3000, DEBUG);
sendData("AT+HTTPTERM\r\n", 3000, DEBUG);
}
String sendData(String command, const int timeout, boolean debug){
String response = "";
Serial1.println(command);
long int time = millis();
while ( (time + timeout) > millis()){
while (Serial1.available()){
char c = Serial1.read();
response += c;
}
}
if (debug){
SerialUSB.print(response);
}
return response;
}
void setup(){
SerialUSB.begin(115200);
SerialUSB.println("Serial initialized");
Serial1.begin(115200);
Wire.begin();
pinMode(LTE_PWRKEY_PIN, OUTPUT);
digitalWrite(LTE_RESET_PIN, LOW);
delay(100);
digitalWrite(LTE_PWRKEY_PIN, HIGH);
delay(2000);
digitalWrite(LTE_PWRKEY_PIN, LOW);
pinMode(LTE_FLIGHT_PIN, OUTPUT);
digitalWrite(LTE_FLIGHT_PIN, LOW);//Normal Mode
delay(5000);
sendData("AT+CCID", 3000, DEBUG);
sendData("AT+CREG?", 3000, DEBUG);
sendData("AT+CGATT=1", 1000, DEBUG);
sendData("AT+CGACT=1,1", 1000, DEBUG);
sendData("AT+CGDCONT=1,\"IP\",\"sp.mb.com\"", 1000, DEBUG);
delay(5000);
}
void loop(){
getData();
//Sensors 0-6
http_str = "AT+HTTPPARA=\"URL\",\"https://api.thingspeak.com/update?api_key=" + Apikey1 + "&field1=" + (String)hallData[0] + "&field2=" + (String)hallData[1] + "&field3=" + (String)hallData[2] + "&field4=" + (String)hallData[3] + "&field5=" + (String)hallData[4] + "&field6=" + (String)hallData[5] + "&field7=" + (String)hallData[6] + "\"\r\n";
SerialUSB.print("Sent to Channel 1: ");
SerialUSB.println(http_str);
sendData("AT+HTTPINIT\r\n", 2000, DEBUG);
sendData(http_str, 2000, DEBUG);
sendData("AT+HTTPACTION=1\r\n", 3000, DEBUG);
sendData("AT+HTTPTERM\r\n", 3000, DEBUG);
//Sensors 7-13
http_str = "AT+HTTPPARA=\"URL\",\"https://api.thingspeak.com/update?api_key=" + Apikey2 + "&field1=" + (String)hallData[7] + "&field2=" + (String)hallData[8] + "&field3=" + (String)hallData[9] + "&field4=" + (String)hallData[10] + "&field5=" + (String)hallData[11] + "&field6=" + (String)hallData[12] + "&field7=" + (String)hallData[13] + "\"\r\n";
SerialUSB.print("Sent to Channel 2: ");
SerialUSB.println(http_str);
sendData("AT+HTTPINIT\r\n", 2000, DEBUG);
sendData(http_str, 2000, DEBUG);
sendData("AT+HTTPACTION=1\r\n", 3000, DEBUG);
sendData("AT+HTTPTERM\r\n", 3000, DEBUG);
//Sensors 14-20
http_str = "AT+HTTPPARA=\"URL\",\"https://api.thingspeak.com/update?api_key=" + Apikey3 + "&field1=" + (String)hallData[14] + "&field2=" + (String)hallData[15] + "&field3=" + (String)hallData[16] + "&field4=" + (String)hallData[17] + "&field5=" + (String)hallData[18] + "&field6=" + (String)hallData[19] + "&field7=" + (String)hallData[20] + "\"\r\n";
SerialUSB.print("Sent to Channel 3: ");
SerialUSB.println(http_str);
sendData("AT+HTTPINIT\r\n", 2000, DEBUG);
sendData(http_str, 2000, DEBUG);
sendData("AT+HTTPACTION=1\r\n", 3000, DEBUG);
sendData("AT+HTTPTERM\r\n", 3000, DEBUG);
//Sensors 21-27
http_str = "AT+HTTPPARA=\"URL\",\"https://api.thingspeak.com/update?api_key=" + Apikey4 + "&field1=" + (String)hallData[21] + "&field2=" + (String)hallData[22] + "&field3=" + (String)hallData[23] + "&field4=" + (String)hallData[24] + "&field5=" + (String)hallData[25] + "&field6=" + (String)hallData[26] + "&field7=" + (String)hallData[27] + "\"\r\n";
SerialUSB.print("Sent to Channel 4: ");
SerialUSB.println(http_str);
sendData("AT+HTTPINIT\r\n", 2000, DEBUG);
sendData(http_str, 2000, DEBUG);
sendData("AT+HTTPACTION=1\r\n", 3000, DEBUG);
sendData("AT+HTTPTERM\r\n", 3000, DEBUG);
}
String sendData(String command, const int timeout, boolean debug){
String response = "";
Serial1.println(command);
long int time = millis();
while ( (time + timeout) > millis()){
while (Serial1.available()){
char c = Serial1.read();
response += c;
}
}
if (debug){
SerialUSB.print(response);
}
return response;
}