PMS5003 output as Python Dictionary

Hello, folks.
I have been using the PMS5003 for a while now with ESP8266. I have a Raspberry Pi 3B+ deployed in my basement that has been collecting temperature and humidity readings for me for a couple of years now, so I figured rather than use yet another ESP8266, I’d try to get the PMS5003 working on the Pi. I ordered a PIM477 breakout board and that made things much easier to deal with (THANK YOU!). I also found the Python package pms5003, which had things up and working for me in short order.
I am able to get the values as a tuple, or the ugly “raw_data”, but neither of these show the label for the value.
Tuple:
(0, 0, 0, 0, 0, 0, 16, 4, 0, 0, 0, 0, 4608, 209)
Raw_data:
{‘raw_data’: bytearray(b’\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x12\x00\x00\xc7’), ‘data’: (0, 0, 0, 0, 0, 0, 8, 2, 0, 0, 0, 0, 4608, 199), ‘checksum’: 199}

What I am having difficulty with is accessing the readings as a dictionary. Reading this at github makes it seem like this should be possible, but I am just not seeing how to get this accomplished. I would like to pull this dictionary apart and reassemble it as json so that I can send it to my MQTT broker with the temp and humidity data as I am currently doing.

I did eventually find this guy’s gist at github, and while it does show how to access each of the readings individually, it doesn’t list them as key:value pairs as a dictionary would.

Does anyone know how to get at this “get_all_pm” method? I am running version 0.0.5.

  • get_all_pm - Returns all PM measurements as a list of dicts that contain the values and tags associated with measurements

Thank you in advance.

Does anyone know how to get at this “get_all_pm” method? I am running version 0.0.5.

That’s in the commit they proposed for the module. You can download that full module from that person’s Github repo.

I think the last time I needed to do this I just parsed the text which the Pimoroni library returned, but yeah, it’s a bit strange that there isn’t a straightforward way to access each value.

1 Like