Remote RPI system monitor

Pi 3b, works fine on Pi 4b.

Currently on Python 3.8.5

It looks like it are 2 different problems:

  • You can’t install rpi_bad_power but the script can run without it
  • For some reason you get a bad syntax on message received.

Could you try to edit the system_sensor.py file and remove the whitespace before ‘)’ so it becomes:

print (f"Message received: {message.payload.decode()}")

and then restart the service?

Same result.

EDIT SECTION
Before:

def on_message(client, userdata, message):
    print (f"Message received: {message.payload.decode()}"  )
    if(message.payload.decode() == "online"):
        send_config_message(client)

After:

def on_message(client, userdata, message):
    print (f"Message received: {message.payload.decode()}")
    if(message.payload.decode() == "online"):
        send_config_message(client)

STATUS

● system_sensors.service - System Sensor service
   Loaded: loaded (/etc/systemd/system/system_sensors.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2020-11-04 09:11:20 EST; 20s ago
  Process: 30356 ExecStart=/usr/bin/python3 /home/pi/system_sensors/src/system_sensors.py /home/pi/system_sensors/src/settings.yaml (code=exited, status=1/FAILURE)
 Main PID: 30356 (code=exited, status=1/FAILURE)
      CPU: 176ms

Nov 04 09:11:20 pihole systemd[1]: Started System Sensor service.
Nov 04 09:11:20 pihole python3[30356]:   File "/home/pi/system_sensors/src/system_sensors.py", line 95
Nov 04 09:11:20 pihole python3[30356]:     print (f"Message received: {message.payload.decode()}")
Nov 04 09:11:20 pihole python3[30356]:                                                          ^
Nov 04 09:11:20 pihole python3[30356]: SyntaxError: invalid syntax
Nov 04 09:11:20 pihole systemd[1]: system_sensors.service: Main process exited, code=exited, status=1/FAILURE
Nov 04 09:11:20 pihole systemd[1]: system_sensors.service: Unit entered failed state.
Nov 04 09:11:20 pihole systemd[1]: system_sensors.service: Failed with result 'exit-code'.

very weird there isn’t anything wrong with this syntax.
Could you send the ouput off following command
/usr/bin/python3 --version

Python 3.5.3

That mite be the problem :man_facepalming:

So I pointed it to 3.8.5, and it appears that it would work, but it’s complaining about the under_voltage sensor.

● system_sensors.service - System Sensor service
   Loaded: loaded (/etc/systemd/system/system_sensors.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2020-11-04 09:32:12 EST; 2s ago
  Process: 13039 ExecStart=/usr/local/bin/python3.8 /home/pi/system_sensors/src/system_sensors.py /home/pi/system_sensors/src/settings.yaml (code=exited, status=1/FAILU
 Main PID: 13039 (code=exited, status=1/FAILURE)
      CPU: 441ms

Nov 04 09:32:11 pihole systemd[1]: Started System Sensor service.
Nov 04 09:32:12 pihole python3.8[13039]: Traceback (most recent call last):
Nov 04 09:32:12 pihole python3.8[13039]:   File "/home/pi/system_sensors/src/system_sensors.py", line 11, in <module>
Nov 04 09:32:12 pihole python3.8[13039]:     from rpi_bad_power import new_under_voltage
Nov 04 09:32:12 pihole python3.8[13039]: ModuleNotFoundError: No module named 'rpi_bad_power'
Nov 04 09:32:12 pihole systemd[1]: system_sensors.service: Main process exited, code=exited, status=1/FAILURE
Nov 04 09:32:12 pihole systemd[1]: system_sensors.service: Unit entered failed state.
Nov 04 09:32:12 pihole systemd[1]: system_sensors.service: Failed with result 'exit-code'.

okay could you try to install it with following command:

/usr/bin/python3.8 -m pip install rpi_bad_power==0.0.3

Does it matter that it’s /usr/local/bin/python3.8?

EDITl
Tried with above but it errored out for the next requirement, looks I would need to update Python.

yeah sorry didn’t check the right path. You need to install the dependencies for the right python installation. So you did pip install -r requirements.txt. This command installed all the dependencies for python 3.5.3.
You could install the requirements for 3.8 by issuing following command:

/usr/local/bin/python3.8 -m pip install -r requirements.txt

I did, the it said paho_mqtt was missing, installed that, than it said the next requirement was missing, how do I uninstall and re-install with 3.8.5?

normally if you used the command I send above with the -r requirements.txt (in the folder where the requirements.txt file is located) all the right packages should be installed.
You could always check with following command:

python3.8 -m pip list

Error for No module named ‘_ctypes’

Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: paho-mqtt==1.5.0 in /home/pi/.local/lib/python3.8/site-packages (from -r requirements.txt (line 1)) (1.5.0)
Collecting psutil==5.6.6
  Using cached psutil-5.6.6.tar.gz (447 kB)
    ERROR: Command errored out with exit status 1:
     command: /usr/local/bin/python3.8 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-p_r1wi7m/psutil/setup.py'"'"'; __file__='"'"'/tmp/pip-install-p_r1wi7m/psutil/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-khdw_dda
         cwd: /tmp/pip-install-p_r1wi7m/psutil/
    Complete output (11 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/home/pi/.local/lib/python3.8/site-packages/setuptools/__init__.py", line 18, in <module>
        from setuptools.dist import Distribution
      File "/home/pi/.local/lib/python3.8/site-packages/setuptools/dist.py", line 32, in <module>
        from setuptools import windows_support
      File "/home/pi/.local/lib/python3.8/site-packages/setuptools/windows_support.py", line 2, in <module>
        import ctypes
      File "/usr/local/lib/python3.8/ctypes/__init__.py", line 7, in <module>
        from _ctypes import Union, Structure, Array
    ModuleNotFoundError: No module named '_ctypes'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

I think something is wrong with your python3.8 installation.
How did you install the 3.8 version?

wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tgz
tar xzvf Python-3.8.5.tgz
cd Python-3.8.5/
./configure
make
sudo make install

could you try to install following libs:

sudo apt-get install -y build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev

Re-installed Python, seems to working, but got the following?

send config message
import of apt failed!
Connected to broker

You can disable the feature check_available_updates(https://github.com/Sennevds/system_sensors/#installation)
Or if you want to know how many apt updates are available you need to install following tool python3-apt (step 4 of the installation)

Did that, as I’m following the instructions at GitHub - Sennevds/system_sensors: Logging of system sensor specific for the RPI and sending them to a MQTT broker

If I run it again I get

Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-apt is already the newest version (1.1.0~beta5).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Okay normally everything else should work you only don’t get the amount off updates available.

Does following commands work:

$ python3.8
>>> import apt

(don’t type the & and >>> this is just the python interpreter)