hjelev / rpi-mqtt-monitor

Raspberry Pi MQTT Monitor gathers system information and sends it to a MQTT server.
GNU General Public License v3.0
155 stars 41 forks source link

ValueError: could not convert string to float: '' #103

Closed apollo40 closed 2 months ago

apollo40 commented 3 months ago

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: ''

hjelev commented 2 months ago

what is your OS? Please run this command and show me the output: free | grep -i mem | awk 'NR == 1 {print $3/$2*100}'

apollo40 commented 2 months ago

I use:

PRETTY_NAME="Raspbian GNU/Linux 12 (bookworm)" NAME="Raspbian GNU/Linux" VERSION_ID="12" VERSION="12 (bookworm)" VERSION_CODENAME=bookworm ID=raspbian ID_LIKE=debian HOME_URL="http://www.raspbian.org/"


Enough free memory:

                 gesamt       benutzt     frei               gemns.        Puffer/Cache    verfügbar

Speicher: 3885396 388756 2849556 9500 743972 3496640

hjelev commented 2 months ago

Pls test the new version, the issue should be resolved. I think it was the fact that your system is in German and the output of the command contained Speicher instead of mem I guess this command don't return anything for you (free | grep -i mem | awk 'NR == 1 {print $3/$2*100}')

apollo40 commented 2 months ago

Hey,

i can confirm that it works now.

thx for the fix

rafalkalinski commented 2 weeks ago

Oh, now I can see why there is this hack in check_memory :-D

ChatGPT says

LC_ALL=C free | grep -i mem | awk 'NR == 1 {print $3/$2*100}'

should do the trick. Briefly checking - it works.