pimoroni / pms5003-circuitpython

CircuitPython library for the PMS5003 particulate sensor
MIT License
2 stars 5 forks source link

Various errors from not reading streaming data promptly #4

Open kevinjwalters opened 3 years ago

kevinjwalters commented 3 years ago
  1. ChecksumMismatchError - attributable to buffer fills and truncation - covered in #3
  2. RuntimeError: buffer size must match format from PMS5003Data - attributable to buffer fills, truncation and reads half way through PMS5003 sends (on CPython these would be struct.error: unpack requires a buffer of 28 bytes - needs better exception
  3. MemoryError around frame length - attributable to buffer fills and truncation - needs sanity checking based on a general or per-frame-type maximum length constant
  4. checksum should be verified before attempting to decode data OR the frame needs to be at least long enough to allow ">HHHHHHHHHHHHHH" to parse (see point 2).
  5. check code is robust at power-up with plotters_combined.py as it appears not to be on a Feather nRF52840 Express sometimes - needs a stop/start via REPL to fix at the moment
  6. gather more data on stuck in read, alll so far are reported at line 156 which looks like frame length read - CP 6.x read(XX) looks well behaved on REPL so unlikely to be that. This could just be bogus values causing something like read(32768) which would appear to get be stuck. https://github.com/adafruit/circuitpython/issues/3876
  7. Exception from a read with a timeout is TypeError: object of type 'NoneType' has no len() - code does not accomdoate the legitimate return value of None from CircuitPython's UART's read() (same as MicroPython).

Other:

  1. PMS5003Data repr passes checksum to format but does not use it.

CircuitPython default UART rx buffer size is 64 and the frames from the PMS5003 are 32 bytes which is why problems occur less frequently than one might expect.

kevinjwalters commented 3 years ago

@Gadgetoid How do the tests work for this library? There's no mocking of pimoroni_physical_feather_pins in https://github.com/pimoroni/pms5003-circuitpython/blob/4323b7511ee2e74129e9726869cd8af35382132d/library/tests/test_setup.py#L33-L38 so it looks like it fails if it's not executed on real hardware? Do you have some way or running these tests on an actual Feather?

kevinjwalters commented 3 years ago

Reminder, client code which does not read all the data out of the serial/UART buffer immediately or just wants to be more robust will have to catch the new FrameLengthError too but #6 negates need.