Hi nice people,
after many test I did not fix my trubble.
When I try to publish a sensor data some time works some time did not.
My sketch is based on TinyGSM library and the main point are:
-*-*--*-*-*-*-*-*---*-*-*---*
boolean mqttConnect() {
SerialUSB.print("Connecting to ");
SerialUSB.print(broker);
sensor_read();
// Connect to MQTT Broker without password if is possible
//boolean status = mqtt.connect("io.adafruit.com");
// Or, if you want to authenticate MQTT:
boolean status = mqtt.connect("io.adafruit.com", "", "");
if (status == false) {
SerialUSB.println(" fail");
return false;
}
SerialUSB.println(" success");
char soil_20_str[10];
sprintf(soil_20_str,"%d", soil_voltage_meno_20);
mqtt.publish(topicghsoil20, soil_20_str);
delay(2000);
return mqtt.connected();
}
void loop() {
if ( rtc.getSeconds() == 00 ){//rtc.getMinutes() == 59 &&
//rtc.standbyMode();
if (!mqtt.connected()) {
SerialUSB.println("=== MQTT NOT CONNECTED ===");
// Reconnect every 10 seconds
uint32_t t = millis();
mqtt.loop();
if (t - lastReconnectAttempt > 10000L) {
lastReconnectAttempt = t;
if (mqttConnect()) {
lastReconnectAttempt = 0;
}
}
delay(100);
return;
}
}
}
-*-*-*-*-*-*-*-*-*-*-*-*
In the account monitor page the results shown were:
2021/02/28 10:03PM
gh-soil-20
656
2021/02/28 10:02PM
gh-soil-20
656
2021/02/28 10:01PM
gh-soil-20
656
2021/02/28 10:00PM
gh-soil-20
656
2021/02/28 9:54PM
gh-soil-20
656
2021/02/28 9:53PM
gh-soil-20
656
2021/02/28 9:52PM
gh-soil-20
656
At 9:54 the connection failed... and in the Serial monitor the code were:
21:54:05.590 -> === MQTT NOT CONNECTED ===
21:54:05.590 -> Connecting to io.adafruit.comAT+CIPRXGET=4,0
21:54:06.943 ->
21:54:06.943 -> +CIPRXGET: 4,0,0
21:54:06.989 ->
21:54:06.989 -> OK
21:54:06.989 -> AT+CIPSTATUS=0
21:54:06.989 ->
21:54:07.036 -> +CIPSTATUS: 0,0,"TCP","52.54.110.50","1883","CLOSED"
21:54:07.130 ->
21:54:07.130 -> OK
21:54:07.130 -> AT+CIPCLOSE=0,1
21:54:07.177 ->
21:54:07.177 -> +CME ERROR: operation not allowed
21:54:07.177 -> AT+CIPSSL=0
21:54:07.223 ->
21:54:07.223 -> +CME ERROR: unknown
21:54:07.223 -> AT+CIPSTART=0,"TCP","io.adafruit.com",1883
21:54:07.270 ->
21:54:07.270 -> OK
21:54:08.058 ->
21:54:08.058 -> 0, CONNECT OK
21:54:08.106 -> AT+CIPSEND=0,72
21:54:08.106 ->
21:54:08.106 -> >F
Could someone help me?
Thanks in advance.