Pre-installed application - preparation for sending values via MQTT

The values obtained from the sensor and the count are regularly published to the MQTT broker of the ALSO IoT Platform. An MQTT broker and a message for the dispatch of the values are configured for this. An event that is regularly triggered by an interval timer will dispatch the messages. Further events will trigger the message dispatch with each change of the digital input and Modbus communication states.

Configuration of the MQTT broker and the message

Menu MessagesMQTT → edit mqttBrkr1 - ALSO_AllThingsTalk_IoT ()

The MQTT broker of the ALSO IoT Platform is configured here. The placeholder YOUR_DEVICE_TOKEN for the User name must be replaced by the individual Device token copied from the ALSO IoT Platform.

en app mqtt broker 1

Menu MessagesMQTT → edit mqttMsg1 - Push_Values ()

A message with a series of data points is transmitted to ALSO’s MQTT broker using the topic device/YOUR_DEVICE_ID/state. The placeholder YOUR_DEVICE_ID between the two dashes in the topic must be replaced by the individual Device ID copied from the ALSO IoT Platform.

en app mqtt message 1

MQTT message in detail:
{
"temperature": {"value": $(flag1),"at":"$(TIMESTAMP_ISO8601)"},
"humidity": {"value": $(flag2),"at":"$(TIMESTAMP_ISO8601)"},
"counter": {"value": $(flag3),"at":"$(TIMESTAMP_ISO8601)"},
"serialnumber": {"value": "$(SERIALNUMBER)","at":"$(TIMESTAMP_ISO8601)"},
"uptime": {"value": "$(UPTIME)","at":"$(TIMESTAMP_ISO8601)"},
"wan_state": {"value": "$(statusDp1)","at":"$(TIMESTAMP_ISO8601)"},
"wan_duration": {"value": $(statusDp2),"at":"$(TIMESTAMP_ISO8601)"},
"eth1_link": {"value": "$(statusDp3)","at":"$(TIMESTAMP_ISO8601)"},
"eth2_link": {"value": "$(statusDp4)","at":"$(TIMESTAMP_ISO8601)"},
"cellular_state": {"value": "$(statusDp5)","at":"$(TIMESTAMP_ISO8601)"},
"cellular_operator": {"value": $(statusDp6),"at":"$(TIMESTAMP_ISO8601)"},
"cellular_network": {"value": "$(statusDp7)","at":"$(TIMESTAMP_ISO8601)"},
"cellular_signal": {"value": $(statusDp8),"at":"$(TIMESTAMP_ISO8601)"},
"cellular_cellid": {"value": "$(statusDp9)","at":"$(TIMESTAMP_ISO8601)"},
"cellular_locid": {"value": "$(statusDp10)","at":"$(TIMESTAMP_ISO8601)"},
"cellular_temperature": {"value": $(statusDp11),"at":"$(TIMESTAMP_ISO8601)"},
"cellular_sigind": {"value": $(statusDp12),"at":"$(TIMESTAMP_ISO8601)"},
"com_statusmodbus": {"value": $(flag5),"at":"$(TIMESTAMP_ISO8601)"},
"digital_input1": {"value": $(input1),"at":"$(TIMESTAMP_ISO8601)"},
"digital_input2": {"value": $(input2),"at":"$(TIMESTAMP_ISO8601)"}
}
Using above topic permits to send multiple values in one MQTT message to the ALSO IoT Platform as key/value pairs in a JSON structure. The technical description of ALSO┬┤s MQTT Interface is available here.

The first line of the message for example transmits the value of flag1 and a timestamp with the identifier temperature. flag1 contains the computed temperature value from the Modbus sensor (refer to ALU configuration).

flag1 is a unique internal designation for the flag, which has been allocated with the respective temperature value. It is also possible to adopt to other cloud platforms using different structures such as CSV or just plain values.
$(TIMESTAMP_ISO8601) is a fix variable for the timestamp of the router here that will be inserted into the topic automatically. For further information to this, refer to the online help of the icom Data Suite under Inserting values in messages.

Configuration of the message dispatch

Menu Data pointsTimer → edit Send_Interval ()

A timer of the type Interval is added here, which expires (triggers) every five minutes.

en app mqtt timer 1

The following fours events are added with these event/action combinations:

  • Cloud_TX_Cyclic_Values: timer1 - Send_Interval expires → message mqttMsg1 - Push_Values will be sent

  • Cloud_TX_Change_Input1: input1 - Counter_Direction changes → message mqttMsg1 - Push_Values will be sent

  • Cloud_TX_Change_Input2: input2 - Counter_Reset changes → message mqttMsg1 - Push_Values will be sent

  • Cloud_TX_Change_ComState_Modbus: flag5 - COM_Status_Modbus changes → message mqttMsg1 - Push_Values will be sent

en app mqtt event 1

en app mqtt event 2

en app mqtt event 3

en app mqtt event 4