hjelev / rpi-mqtt-monitor Goto Github PK
View Code? Open in Web Editor NEWRaspberry Pi MQTT Monitor gathers system information and sends it to a MQTT server.
License: GNU General Public License v3.0
Raspberry Pi MQTT Monitor gathers system information and sends it to a MQTT server.
License: GNU General Public License v3.0
Hi,
The update entity doesn't work. I'm in version 0.9.1 and it still tells me 0.8.9.
However, if I look at the information in rpi-mqtt-monitor, I am in version 0.9.1.
The update entity image is missing. If I connect to the image link, it tells me "Folder not found".
I'm using a local image in the meantime.
Is it possible to also monitor the RSSI (WiFi Signal level)?
Hi. I've installed the script on a Ubuntu 22.04 OS. The cpu temperature isn't available when I try running below cat
. Any idea why it is not displaying?? I am using a Beelink mini pc.
ser@ser:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.3 LTS
Release: 22.04
Codename: jammy
ser@ser:~$ cat /sys/class/thermal/thermal_zone*/temp 2> /dev/null | sed 's/\(.\)..$//' | tail -n 1
ser@ser:~$ cat /sys/devices/virtual/thermal/thermal_zone0*/temp 2> /dev/null | sed 's/\(.\)..$//' | tail -n 1
ser@ser:~$ sudo systemctl status rpi-mqtt-monitor.service
● rpi-mqtt-monitor.service - System Sensors Monitor
Loaded: loaded (/etc/systemd/system/rpi-mqtt-monitor.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2024-02-13 07:56:53 JST; 46min ago
Main PID: 58972 (python3)
Tasks: 4 (limit: 15302)
Memory: 22.5M
CPU: 2.542s
CGroup: /system.slice/rpi-mqtt-monitor.service
└─58972 /usr/bin/python3 /srv/git/rpi-mqtt-monitor/src/rpi-cpu2mqtt.py --service
Feb 13 07:56:53 ser systemd[1]: Started System Sensors Monitor.
The service examples in the Readme reference a service file called rpi-cpu2mqtt.service
, however the filename in the distribution seems to have been changed to rpi-mqtt-monitor.service
Examples should read
sudo cp rpi-mqtt-monitor.service /etc/systemd/system/ ; sudo systemctl enable rpi-mqtt-monitor.service
and
sudo service rpi-mqtt-monitor start ; sudo service rpi-mqtt-monitor status
respectively
Tried both manually installing and using the script. Fails to run with a divide by zero error. Thoughts?
awk: cmd. line:1: (FILENAME=- FNR=3) fatal: division by zero attempted
Traceback (most recent call last):
File "/home//rpi-cpu2mqtt.py", line 249, in
swap = check_swap()
File "/home//rpi-cpu2mqtt.py", line 51, in check_swap
swap = round(float(swap.decode("utf-8").replace(",", ".")), 1)
ValueError: could not convert string to float: ''
Linux raspberrypi4 5.19.0-1009-raspi #16-Ubuntu SMP PREEMPT Thu Nov 24 13:38:20 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux
``pi@raspberrypi4:~/rpi-mqtt-monitor/src$ /usr/bin/python3 /home/pi/rpi-mqtt-monitor/src/rpi-cpu2mqtt.py
awk: cmd. line:1: (FILENAME=- FNR=1) fatal: division by zero attempted
Traceback (most recent call last):
File "/home/pi/rpi-mqtt-monitor/src/rpi-cpu2mqtt.py", line 318, in
swap = check_swap()
File "/home/pi/rpi-mqtt-monitor/src/rpi-cpu2mqtt.py", line 71, in check_swap
swap = round(float(swap.decode("utf-8").replace(",", ".")), 1)
ValueError: could not convert string to float: ''
Hello,
i use your script with Home Assistant. It's working fine :)
But HA has a naming convention that the Hostname should not be in the Entity name.
suggestion:
provide an HA Version of your script and remove "hostname" from the Description lines.
data["name"] = hostname + " CPU Usage" ...
Thanks
Naming of MQTT Entities
https://rc.home-assistant.io/integrations/mqtt/
Warning Message in home-asssistant.log
[homeassistant.components.mqtt.mixins] MQTT entity name starts with the device name in your config {'state_topic': 'mqtt-monitor/pi-alarm/uptime_days', 'icon': 'mdi:calendar', 'name': 'pi-alarm Uptime', 'unique_id': 'pi-alarm_uptime_days', 'unit_of_measurement': 'days', 'device': {'identifiers': ['pi-alarm'], 'manufacturer': 'Raspberry Pi', 'model': 'Raspberry Pi 4 Model B Rev 1.2\x00', 'name': 'pi-alarm', 'sw_version': 'Debian GNU/Linux 12 (bookworm)\n', 'connections': []}, 'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>, 'force_update': False, 'encoding': 'utf-8', 'enabled_by_default': True, 'payload_available': 'online', 'payload_not_available': 'offline', 'qos': 0, 'availability_mode': 'latest'}, this is not expected. Please correct your configuration. The device name prefix will be stripped off the entity name and becomes 'Uptime'
Is it possible to send various (MQTT) messages from Home Assistant back to the Pi?
I don't know if it is because I use FR locales but check_cpu_load won't work as it should.
Uptime returns 0,91 instead of 0.91
To fix it, change line 27 from this :
cpu_load = p.split("average:")[1].split(",")[0].replace(' ', '')
to that to change "," in "." :
cpu_load = p.split("average:")[1].split(", ")[0].replace(' ', '').replace(',', '.')
When I change the config, I need to stop and start the service. It would be nice, if the config is reloaded on each run.
Hi, thanks for a fantastic tool. I realise it's pretty much static data, but it would be great if the monitor were able to send the ipv4 and/or ipv6 address of the pi via MQTT.
Hello
Thanks for the good tool, I was able to run it on my TV box running Armbian.
But I had to make an edit because not all processors have vendor information in them; receiving the manufactory fails with an error.
Could you add a check for this situation or provide an alternative option for obtaining data, for example, use model name instead of vendor.
Below is the error trace:
Traceback (most recent call last):
File "/root/rpi-mqtt-monitor/src/rpi-cpu2mqtt.py", line 711, in
gather_and_send_info()
File "/root/rpi-mqtt-monitor/src/rpi-cpu2mqtt.py", line 617, in gather_and_send_info
print_measured_values(cpu_load, cpu_temp, used_space, voltage, sys_clock_speed, swap, memory, uptime_days, uptime_seconds, wifi_signal, wifi_signal_dbm, rpi5_fan_speed)
File "/root/rpi-mqtt-monitor/src/rpi-cpu2mqtt.py", line 205, in print_measured_values
""".format(config.version, check_model_name(), get_manufacturer(), get_os(), hostname, get_network_ip(), get_mac_address())
^^^^^^^^^^^^^^^^^^
File "/root/rpi-mqtt-monitor/src/rpi-cpu2mqtt.py", line 143, in get_manufacturer
pretty_name = pretty_name.split(':')[1].replace('\n', '')
~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
Hello, I use rpi as NAS and have raid0 array. How should I modify the .py script to display (or add mqtt message for) external storage?
/dev/md0 on /RAID3T
Thanks, Jan
Would it be possible to have a switch similar to the power off but only turn off/on the display. I am currently using the shell command 'xset -display :0 dpms force off' or 'xset -display :0 dpms force on'.
The mqtt option would avoid the ssh authentication issue.
I am trying to automate the touchscreen connected to the pi.
Thank you
Hi whats the swap?
A shutdown button that can shutdown the RPi on demand.
Simular to #29 but for shutdown.
Hello
Im running RPi4 with Ubuntu fpr RPI and this is the error I
m getting. Any idea what is wrong?
ubuntu@ubuntu:~/rpimonitor$ /usr/bin/python3.8 rpi-cpu2mqtt.py
/bin/sh: 1: vcgencmd: not found
Traceback (most recent call last):
File "rpi-cpu2mqtt.py", line 198, in
cpu_temp = check_cpu_temp()
File "rpi-cpu2mqtt.py", line 54, in check_cpu_temp
cpu_temp = str(p).replace('\n', ' ').replace('\r', '').split("=")[1].split("'")[0]
I'm running Alpine on my Raspi 5, it's free
command doesn't support the "total" option -t
. When using the Memory or Swap reporting, the script fails with the following error
BusyBox v1.36.1 (2023-11-07 18:53:09 UTC) multi-call binary.
Usage: free [-bkmgh]
Display free and used memory
Traceback (most recent call last):
File "/home/markus/rpi-mqtt-monitor/src/rpi-cpu2mqtt.py", line 712, in <module>
gather_and_send_info()
File "/home/markus/rpi-mqtt-monitor/src/rpi-cpu2mqtt.py", line 612, in gather_and_send_info
cpu_load, cpu_temp, used_space, voltage, sys_clock_speed, swap, memory, uptime_days, uptime_seconds, wifi_signal, wifi_signal_dbm, rpi5_fan_speed = collect_monitored_values()
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/markus/rpi-mqtt-monitor/src/rpi-cpu2mqtt.py", line 595, in collect_monitored_values
memory = check_memory()
^^^^^^^^^^^^^^
File "/home/markus/rpi-mqtt-monitor/src/rpi-cpu2mqtt.py", line 86, in check_memory
memory = round(float(memory.decode("utf-8").replace(",", ".")))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: could not convert string to float: ''
Here's an example output of free
as-is:
total used free shared buff/cache available
Mem: 8132632 5525592 156444 292000 2450596 2232356
Swap: 0 0 0
I can get it to work when removing the -t
and filtering by Mem
:
free | grep -i mem | awk 'NR == 1 {print $3/$2*100}'
For Swap, I also get the same issue as #11 (Division by Zero).
A binary sensor that shows if the git repository is up to date.
I'm searching my logs and so many clients have random names generated by not using clientID, it would be good to be able to fix it so I can parse logs better.
Can I suggest changing uptime, to a last boot timestamp. That way Home Assistant will automatically set the time formatting.
Like this:
Mqtt auto discovery parameters :
{
"name": "Last Boot",
"state_topic": "xxxx",
"device_class": "timestamp",
"value_template": "{{ as_datetime(value) }}",
"unique_id": "xxxx",
etc,
etc
}
}
I get the following error:
(foobar) pi@meteotux:~/rpi-mqtt-monitor $ python3 /home/pi/rpi-mqtt-monitor/src/rpi-cpu2mqtt.py -d
:: rpi-mqtt-monitor
Version: 0.8.9
:: Device Information
Model Name: Raspberry Pi 4 Model B Rev 1.2
Manufacturer: Raspberry Pi
OS: Debian GNU/Linux 12 (bookworm)
Hostname: meteotux
IP Address: 192.168.1.182
MAC Address: DC-A6-32-6B-18-84
Update Check Interval: 3600 seconds
:: Measured values
CPU Load: 12.0 %
CPU Temp: 57 °C
Used Space: 56 %
Voltage: False V
CPU Clock Speed: False MHz
Swap: False %
Memory: 16 %
Uptime: 0 days
Wifi Signal: False %
Wifi Signal dBm: False
RPI5 Fan Speed: False RPM
Update Available: {"installed_ver": "0.8.9", "new_ver": "0.8.9"}
/home/pi/rpi-mqtt-monitor/src/rpi-cpu2mqtt.py:398: DeprecationWarning: Callback API version 1 is deprecated, update to latest version
client = paho.Client(client_id="rpi-mqtt-monitor-" + hostname + str(int(time.time())))
MQTT error: failed to receive on socket: [Errno 104] Connection reset by peer
Any help to this?
And also this makes no sense:
Update Available: {"installed_ver": "0.8.9", "new_ver": "0.8.9"}
When i try to let the the rpi-cpu2mqqt.py run i get the following error:
Traceback (most recent call last):
File "/root/rpi-mqtt-monitor/src/rpi-cpu2mqtt.py", line 730, in
gather_and_send_info()
File "/root/rpi-mqtt-monitor/src/rpi-cpu2mqtt.py", line 630, in gather_and_send_info
cpu_load, cpu_temp, used_space, voltage, sys_clock_speed, swap, memory, uptime_days, uptime_seconds, wifi_signal, wifi_signal_dbm, rpi5_fan_speed = collect_monitored_values()
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/rpi-mqtt-monitor/src/rpi-cpu2mqtt.py", line 613, in collect_monitored_values
memory = check_memory()
^^^^^^^^^^^^^^
File "/root/rpi-mqtt-monitor/src/rpi-cpu2mqtt.py", line 84, in check_memory
memory = round(float(memory.decode("utf-8").replace(",", ".")))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: could not convert string to float: ''
Use last will to implement a connectivity sensor.
https://eclipse.dev/paho/files/paho.mqtt.python/html/client.html#paho.mqtt.client.Client.will_set
Hi
It would be nice to be able to use the HA API instead of MQTT to avoid the need to expose MQTT port for remote use ;)
That lib should make it quite easy to implement (https://pypi.org/project/HomeAssistant-API/) I guess :)
Thanks
Vincèn
A restart button that can restart the RPi on demand.
Hi,thanks for your job,i'd like (if possible) to have PIR sensor value (connected in GPIO) via mqtt...
When i try to let the the rpi-cpu2mqqt.py run i get the following error:
Traceback (most recent call last):
File "/root/rpi-mqtt-monitor/src/rpi-cpu2mqtt.py", line 730, in
gather_and_send_info()
File "/root/rpi-mqtt-monitor/src/rpi-cpu2mqtt.py", line 630, in gather_and_send_info
cpu_load, cpu_temp, used_space, voltage, sys_clock_speed, swap, memory, uptime_days, uptime_seconds, wifi_signal, wifi_signal_dbm, rpi5_fan_speed = collect_monitored_values()
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/rpi-mqtt-monitor/src/rpi-cpu2mqtt.py", line 613, in collect_monitored_values
memory = check_memory()
^^^^^^^^^^^^^^
File "/root/rpi-mqtt-monitor/src/rpi-cpu2mqtt.py", line 84, in check_memory
memory = round(float(memory.decode("utf-8").replace(",", ".")))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: could not convert string to float: ''
A update entity that makes use of #28 to display when there are changes and enabled a remote update.
Thanks for your job 😊
if I understand correctly rpi sends data every 5 minutes... is it possible to decrease the time?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.