hiveeyes / ds18b20-datalogger

A temperature sensor matrix with heatmap visualization for bee hive monitoring, using Raspberry Pi, Linux, Python, DS18B20, MQTT, Kotori DAQ, and Grafana.
https://community.hiveeyes.org/t/laborprotokoll-4x5-temp-matrix-mit-ds18b20/5102
GNU General Public License v3.0
1 stars 0 forks source link

name not defined due to sensor not available #7

Closed bee-mois closed 5 months ago

bee-mois commented 5 months ago

if one sensor is offline, the whole script is stopping with an error:

Traceback (most recent call last):
  File "/home/mepi/temp-matrix/temp-matrix_5x6.py", line 198, in <module>
    matrix = [[temp_ir_1_1, temp_ir_1_2, temp_ir_1_3, temp_ir_1_4, temp_ir_1_5], \
               ^^^^^^^^^^^
NameError: name 'temp_ir_1_1' is not defined. Did you mean: 'temp_ir_3_1'?

how could the script be changed so that it finishes even if one or more sensors are offline and the available values are logged?

(temp-matrix_5x6.py refers to the main script before its name change to core.py.)

bee-mois commented 5 months ago

core.py of this repo probably has the same problem. though it does not explicitly stop with an error. if stopped with strg-c it prints:

(.venv) mepi@testpi:~ $ ds18b20-datalogger 
^CTraceback (most recent call last):
  File "/home/mepi/datalogger/.venv/bin/ds18b20-datalogger", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/mepi/datalogger/.venv/lib/python3.11/site-packages/ds18b20_datalogger/cli.py", line 5, in main
    reading = read_ds18b20_sensor_matrix()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mepi/datalogger/.venv/lib/python3.11/site-packages/ds18b20_datalogger/core.py", line 149, in read_ds18b20_sensor_matrix
    tc = read_temp(folder)
         ^^^^^^^^^^^^^^^^^
  File "/home/mepi/datalogger/.venv/lib/python3.11/site-packages/ds18b20_datalogger/core.py", line 37, in read_temp
    temp = try_temp(device_file)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/mepi/datalogger/.venv/lib/python3.11/site-packages/ds18b20_datalogger/core.py", line 47, in try_temp
    lines = read_temp_raw(device_file + "/w1_slave")
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mepi/datalogger/.venv/lib/python3.11/site-packages/ds18b20_datalogger/core.py", line 29, in read_temp_raw
    lines = f.readlines()
            ^^^^^^^^^^^^^
  File "<frozen codecs>", line 319, in decode
KeyboardInterrupt
amotl commented 5 months ago

NameError: name 'temp_ir_1_1' is not defined. Did you mean: 'temp_ir_3_1'?

core.py of this repo probably has the same problem.

Regarding the error you are describing, I don't think that core.py has this problem. It has been mitigated by just defining all the variables unconditionally, like this:

https://github.com/hiveeyes/ds18b20-datalogger/blob/63e9a71afdc33072f8be18e5ef9a4e06c3a5abef/ds18b20_datalogger/core.py#L130-L135

It's all totally redundant 🙈, but it was the easiest way to fix that flaw on behalf of the current program architecture.

bee-mois commented 5 months ago

i see. so we close this. because this repo is about core.py (and not some antedescendents).