There is actually a little bug in the firmware 13.2s1 that prevents to detect properly the MQTT disconnection.
So, when your 4G disconnection is down for a while, the Flexy MQTT client continues to publish data and sometimes when the Internet connection comes back, the messages are not published anymore till you disconnect/reconnect the MQTT broker.
This issue will be fixed in the next firmware 14.0.
As a work-around, I have modified your script to detect the error when publishing the data and make a DISCONNECT/RECONNECT.
Code:
SETSYS PRG,"RESUMENEXT",1
MQTT "PUBLISH", "Altizon/Datonis/mqttfx/event",Data123$,1,0
MQTT "PUBLISH", "Altizon/Datonis/mqttfx/event",Data12$,1,0
ErrorReturned = GETSYS PRG,"LSTERR"
IF ErrorReturned=28 THEN //ERROR while publishing --> No connection --> Better to close and open
MQTT "CLOSE"
SETSYS PRG,"RESUMENEXT",0
GOTO CONNECTMQTT
ENDIF
Code:
Rem --- eWON start section: Cyclic Section
eWON_cyclic_section:
Rem --- eWON user (start)
Rem --- eWON user (end)
End
Rem --- eWON end section: Cyclic Section
Rem --- eWON start section: Init Section
eWON_init_section:
Rem --- eWON user (start)
SETSYS INF, "LOAD"
//SerNum$ = GETSYS INF, "SERNUM"
CONNECTMQTT:
MQTT "OPEN","mqttfx","telemetry.datonis.io"
MQTT "SETPARAM","PORT","1883"
MQTT "SETPARAM","username","2tet1tt4eb248e2t314fc964cd43bta374a6a76c"
MQTT "SETPARAM","password","2c7822fcc25ca0b549a0a199e01e87468bdee77b4bc68d931de4e072f57c0754"
//MQTT "subscribe", "Altizon/Datonis/SerNum$/httpAck", 1
MQTT "CONNECT"
PRINT "DONE"
TSET 1,5
ONTIMER 1, "GOTO T1"
ONMQTT "GOTO MqttRx"
GETSYS PRG,"EVTINFO"
END
T1:
ConnStatus% = MQTT "STATUS"
IF ConnStatus% = 5 THEN
PRINT "OKK"
b% = GETSYS PRG, "TIMESEC"
c%=b%-19800
TIMESTRING$ = Str$(c%) + "000"
Filler_Production_Current@ = Filler_Production_Counter@ - Filler_Production_Prev@
Filler_Production_Prev@ = Filler_Production_Counter@
Labeler_Production_Current@ = Labeler_Production_Counter@ - Labeler_Production_Prev@
Labeler_Production_Prev@ = Labeler_Production_Counter@
//Filler
Data123$ = "{" + '"data":' + "{" + '"Filler_Bottle_Type":' + STR$(Filler_Bottle_Type@) + ', "Filler_Operating_Mode":' + STR$(Filler_Operating_Mode@) + ","
Data123$ = Data123$ + '"Filler_Production_Counter":' + STR$(Filler_Production_Counter@) + ', "Filler_Machine_Speed":' + STR$(Filler_Machine_Speed@) + ","
Data123$ = Data123$ + '"Filler_Design_Speed":' + STR$(Filler_Design_Speed@) + ', "Filler_Bowl_Level":' + STR$(Filler_Bowl_Level@) + ","
Data123$ = Data123$ + '"Filler_Bowl_Pressure":' + STR$(Filler_Bowl_Pressure@) + ', "Filler_Product_Temperature":' + STR$(Filler_Product_Temperature@) + ","
Data123$ = Data123$ + '"job.value":' + STR$(Filler_Production_Current@) + "},"
Data123$ = Data123$ + '"thing_key": "5d2t4e8fdd",' + '"access_key": "2tet1tt4eb248e2t314fc964cd43bta374a6a76c",'
Data123$ = Data123$ + '"timestamp":' + TIMESTRING$ + "}"
//Labeler
Data12$ = "{" + '"data":' + "{"+ '"Labeler_Bottle_type":' + STR$(Labeler_Bottle_type@) + ', "Labeler_Operating_Mode":' + STR$(Labeler_Operating_Mode@) + ","
Data12$ = Data12$ + '"Labeler_Production_Counter":' + STR$(Labeler_Production_Counter@) + ', "LF0096":' + STR$(LF0096@) + ","
Data12$ = Data12$ + '"LF0269":' + STR$(LF0269@) + ', "LF0272":' + STR$(LF0272@) + ","
Data12$ = Data12$ + '"LF0310":' + STR$(LF0310@) + ', "LF1095":' + STR$(LF1095@) + ","
Data12$ = Data12$ + '"LW0032":' + STR$(LW0032@) + ', "LF1200":' + STR$(LF1200@) + ","
Data12$ = Data12$ + '"LF1193":' + STR$(LF1193@) + ', "LF1201":' + STR$(LF1201@) + ","
Data12$ = Data12$ + '"Labeler_Temperature_Motor":' + STR$(Labeler_Temperature_Motor@) +', "Labeler_Temperature_VaccumPump":' +STR$(Labeler_Temperature_VaccumPump@) + ","
Data12$ = Data12$ + '"Labeler_Current_R":' + STR$(Labeler_Current_R@) + ', "Labeler_Current_Y":' +STR$(Labeler_Current_Y@) + ","
Data12$ = Data12$ + '"Labeler_Current_B":' + STR$(Labeler_Current_B@) + ', "Labeler_Vibration_Motor":' +STR$(Labeler_Vibration_Motor@) + ","
Data12$ = Data12$ + '"Labeler_Vibration_GearBox":' + STR$(Labeler_Vibration_GearBox@) + ', "Labeler_Vibration_VaccumPump":' + STR$(Labeler_Vibration_VaccumPump@) + ","
Data12$ = Data12$ + '"job.value":' + STR$(Labeler_Production_Current@) + ', "LW0036":' + STR$(LW0036@)+ "},"
Data12$ = Data12$ + '"thing_key": "439d18551a",' + '"access_key": "2tet1tt4eb248e2t314fc964cd43bta374a6a76c",'
Data12$ = Data12$ + '"timestamp":' + TIMESTRING$ + "}"
SETSYS PRG,"RESUMENEXT",1
MQTT "PUBLISH", "Altizon/Datonis/mqttfx/event",Data123$,1,0
MQTT "PUBLISH", "Altizon/Datonis/mqttfx/event",Data12$,1,0
ErrorReturned = GETSYS PRG,"LSTERR"
IF ErrorReturned=28 THEN //ERROR while publishing --> No connection --> Better to close and open
MQTT "CLOSE"
SETSYS PRG,"RESUMENEXT",0
GOTO CONNECTMQTT
ENDIF
// PRINT "Message data = " + Data123$
// PRINT "Message data = " + Data12$
PRINT TIMESTRING$
// PRINT "OK"
ELSE
PRINT "Error : Flexy not connected"
ENDIF
END
MqttRx:
MqttReadNext:
MessageQty%=Mqtt "READ"
IF (MessageQty%>0) Then
MsgTopic$=MQTT "MsgTopic$"
MsgData$ =MQTT "MsgData$"
Print "Subscribe Message Received:"+MsgTopic$+" "+MsgData$"
GOTO MqttReadNext
ENDIF
END
//MyLable:
//data123$ =" {"Data": { "voltage": "+STR$(Test@)+", "current": "+STR$(Test1@)+" }},"thing_key": "411a6c535e","access_key": "6ec19df9df14656ce6d15c6df35b769fb67d7t1a","timestamp": 1548147234000
//PRINT "OK"
END
Rem --- eWON user (end)
End
Rem --- eWON end section: Init Section