TimOrme / aqimon

Simple Air Quality Monitor For Raspberry Pi and the SDS011 Nova PM Sensor
MIT License
4 stars 2 forks source link

repeated IncorrectWrapperException and IncompleteReadException, UI never shows any valid data #48

Open inactivist opened 11 months ago

inactivist commented 11 months ago

Running on PI 3B armhf (32 bit), raspios bullseye

I installed using pip3 install --user aqimon

the aqimon command starts the server, but it seems there are communication errors. The UI never updates graph, shows error status, nothing ever shows in the display

Console shows the following errors:

INFO:     192.168.2.10:48250 - "GET /api/status HTTP/1.1" 200 OK
--- Logging error ---
Traceback (most recent call last):
  File "/home/aqmon/.local/lib/python3.9/site-packages/aqimon/read/novapm.py", line 55, in read
    self.reader.sleep()
  File "/home/aqmon/.local/lib/python3.9/site-packages/sds011lib/__init__.py", line 632, in sleep
    return self.base_reader.query_sleep_state()
  File "/home/aqmon/.local/lib/python3.9/site-packages/sds011lib/__init__.py", line 353, in query_sleep_state
    self._read_until_response(expected_command=Command.SET_SLEEP)
  File "/home/aqmon/.local/lib/python3.9/site-packages/sds011lib/__init__.py", line 547, in _read_until_response
    _parse_read_response(
  File "/home/aqmon/.local/lib/python3.9/site-packages/sds011lib/__init__.py", line 176, in _parse_read_response
    _verify_read_response(result)
  File "/home/aqmon/.local/lib/python3.9/site-packages/sds011lib/__init__.py", line 116, in _verify_read_response
    raise IncorrectWrapperException()
sds011lib.exceptions.IncorrectWrapperException

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/aqmon/.local/lib/python3.9/site-packages/aqimon/server.py", line 134, in read_function
    result: AqiRead = await scheduled_reader.reader.read()
  File "/home/aqmon/.local/lib/python3.9/site-packages/aqimon/read/novapm.py", line 60, in read
    self.reader.sleep()
  File "/home/aqmon/.local/lib/python3.9/site-packages/sds011lib/__init__.py", line 632, in sleep
    return self.base_reader.query_sleep_state()
  File "/home/aqmon/.local/lib/python3.9/site-packages/sds011lib/__init__.py", line 353, in query_sleep_state
    self._read_until_response(expected_command=Command.SET_SLEEP)
  File "/home/aqmon/.local/lib/python3.9/site-packages/sds011lib/__init__.py", line 563, in _read_until_response
    raise IncompleteReadException()
sds011lib.exceptions.IncompleteReadException

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.9/logging/__init__.py", line 1079, in emit
    msg = self.format(record)
  File "/usr/lib/python3.9/logging/__init__.py", line 923, in format
    return fmt.format(record)
  File "/usr/lib/python3.9/logging/__init__.py", line 659, in format
    record.message = record.getMessage()
  File "/usr/lib/python3.9/logging/__init__.py", line 363, in getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting
Call stack:
  File "/home/aqmon/.local/bin/aqimon", line 8, in <module>
    sys.exit(start())
  File "/home/aqmon/.local/lib/python3.9/site-packages/aqimon/server.py", line 250, in start
    uvicorn.run(app, host=env_config.server_host, port=env_config.server_port)
  File "/home/aqmon/.local/lib/python3.9/site-packages/uvicorn/main.py", line 568, in run
    server.run()
  File "/home/aqmon/.local/lib/python3.9/site-packages/uvicorn/server.py", line 59, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.9/asyncio/base_events.py", line 629, in run_until_complete
    self.run_forever()
  File "/usr/lib/python3.9/asyncio/base_events.py", line 596, in run_forever
    self._run_once()
  File "/usr/lib/python3.9/asyncio/base_events.py", line 1890, in _run_once
    handle._run()
  File "/usr/lib/python3.9/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/aqmon/.local/lib/python3.9/site-packages/fastapi_utils/tasks.py", line 64, in loop
    await func()  # type: ignore
  File "/home/aqmon/.local/lib/python3.9/site-packages/aqimon/server.py", line 173, in read_function
    log.exception("Failed to retrieve data from reader", e)
Message: 'Failed to retrieve data from reader'
Arguments: (IncompleteReadException(),)
INFO:     192.168.2.10:48250 - "GET /api/status HTTP/1.1" 200 OK

Device testing

I was able to use the installed SDS011lib examples shown in here to read the device directly, with no errors as far as I can tell.

Here are a couple of examples:

Session 1

Python 3.9.2 (default, Mar 12 2021, 04:06:34) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sds011lib import SDS011QueryReader
>>> reader = SDS011QueryReader('/dev/ttyUSB0')
>>> reader.set_working_period(2)
WorkingPeriodReadResponse(operation_type=<OperationType.SET_MODE: b'\x01'>, interval=2)
>>> data = reader.query()
>>> result = reader.get_working_period()
>>> print(result.interval)
2
>>> print(result)
WorkingPeriodReadResponse(operation_type=<OperationType.QUERY: b'\x00'>, interval=2)
>>> result = reader.query()
>>> result
QueryResponse(pm25=4.7, pm10=12.7, device_id=b'x-')
>>> print(result.pm25)
4.7
>>> print(result)
QueryResponse(pm25=4.7, pm10=12.7, device_id=b'x-')

Session 2

$ python
Python 3.9.2 (default, Mar 12 2021, 04:06:34) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sds011lib import SDS011QueryReader
>>> reader = SDS011QueryReader('/dev/ttyUSB0')
>>> result = reader.query()
>>> print(result)
QueryResponse(pm25=5.3, pm10=15.1, device_id=b'x-')
>>> 
KeyboardInterrupt
>>> 

I've tried increasing AQIMON_COMMAND_WAIT_TIME environment variable, no effect.

Not sure where to go from here. I'll continue investigating as time permits.

inactivist commented 11 months ago

Confirmed seeing same error using a replacement NovaPM sensor from another vendor.

Will troubleshoot on my end.

ImDroided commented 9 months ago

I have this same issue with 2 sensors one from amazon one from aliexpress. Has anyone found a solution yet?