IOT Stack: Measuring the Heartbeat of all Devices & Computer

Installation

python3 -m pip install paho-mqtt
#!/usr/bin/python3import paho.mqtt.client as mqttMQTT_SERVER = "192.168.178.40"
MQTT_TOPIC = "/nodes/macbook/alive"
client = mqtt.Client()
client.connect(MQTT_SERVER)
client.publish(MQTT_TOPIC, 1)
docker exec -it mosquitto sh
mosquitto_sub -t /nodes/macbook/alive
1
1
1
* * * * * /usr/local/bin/python3 /Users/work/development/iot/scripts/heartbeat.py

Data Transformation: Simple Workflow

show field keys
name: alive
fieldKey fieldType
-------- ---------
value string

Data Transformation: Advanced Workflow

{
"node":"macbook",
"alive":1
}
import paho.mqtt.client as mqttMQTT_SERVER = "192.168.178.40"
MQTT_TOPIC = "/nodes"
client = mqtt.Client()
client.connect(MQTT_SERVER)
client.publish(MQTT_TOPIC, '{"node":"macbook", "alive":1}')
  1. mqtt-in: Listens to the topic /nodes, outputs a string
  2. json: Converts the inputs msg.payload from sting to JSON
  3. change: Following a best practice advice, this node transforms the input data to the desired InfluxDB output data. When new fields are added or you change filed names, you just need to modify one wokflow node. It sets the msg.payload JSON to this form:
[
{
"node": msg.payload.node,
"alive": msg.payload.alive
}
]
select * from alive
name: alive
time alive node
---- ----- ----
1629973500497658493 1 macbook

Visualization with Grafana

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sebastian

Sebastian

IT Project Manager & Developer