This is the new version of my old website. You can find the old website here: old.dl2sba.com. If you miss any information or you find bugs, please let me know by E-Mail

My MQTT server also has some basic systems management capabilities - means the MQTT server can emit the following data to the MQTT broker:

  • CPU temperature
  • Power supply temperature
  • Average CPU load
  • Uptime of server

CPU temperature

The CPU temperature is read from the internal CPU sensor and published to the MQTT broker with this simple script:

mosquitto_pub -h 127.0.0.1 -q 1 -u xxxxx -P yyyy \
-t "dl2sba.de/sensorData/40000/3" \
-m `cat /sys/class/thermal/thermal_zone0/temp | awk -F" " '{ print $1 }'`

The script ist called on a regulare base via cron.

Power supply temperature

A simple 1-wire sensor DS18B20 is attached to the one wire bus. The temperature is read by the follwoing script:

#!/usr/bin/python
# -*- coding: utf-8 -*-
#
#       aus             http://www.netzmafia.de/skripten/hardware/RasPi/Projekt-Onewire/index.html
#                       http://www.python-kurs.eu/os_modul_shell.php
#
# Import der Module
import sys
import os

# Fuer jeden 1-Wire Slave aktuelle Temperatur ausgeben
# 1-wire Slave Datei lesen
file = open('/sys/bus/w1/devices/28-0000074bd9e4/w1_slave')
filecontent = file.read()
file.close()

# Temperaturwerte auslesen und konvertieren
stringvalue = filecontent.split("\n")[1].split(" ")[9]
temperature = float(stringvalue[2:]) / 1000
user  = "xxxx"
passw = "yyyy"
host  = "127.0.0.1"
topic = "dl2sba.de/sensorData/40000/10"
command = "mosquitto_pub -h " + host + " -q 1 -u " + user + " -P " + passw + " -t '" + topic + "' -m " + str(temperature)
os.system(command>

 which sends the temperature to the defined topic. The script ist called on a regulare base via cron.

Average CPU load

mosquitto_pub -h 127.0.0.1 -q 1 -u xxxx -P yyyy \
-t "dl2sba.de/sensorData/40000/2" \
-m ` top -b -n2 -d1 | grep "Cpu(s)" | \
sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | \
awk '{print 100 - $1}' | tail -n1`

 The script ist called on a regulare base via cron.

Uptime of server

mosquitto_pub -h 127.0.0.1 -q 1 -u xxxx -P yyyy\
-t "dl2sba.de/sensorData/40000/1" \
-m `cat /proc/uptime | \
awk -F" " '{ print $1 }'`

 The script ist called on a regulare base via cron.

(c) Dietmar Krause, DL2SBA 2026 Impressum Datenschutz
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Marketing
Set of techniques which have for object the commercial strategy and in particular the market study.
Quantcast
Save