avaldebe/PyPMS

SPS30 to mosquitto socket error

taarhaug opened this issue · 8 comments

Hei,

Using latest version of pms on ubuntu, I cannot make the mqtt connection to mosquitto 1.4.15 work:
pms -m SPS30 -n 1 -i 10 -s /dev/ttyUSB1 mqtt --mqtt-host localhost -t "test" throws no error, but I cannot subscribe to the feed.

mosquitto log indicates socket error:

1670442753: New client connected from 192.168.50.100 as test (c1, k60).
1670442769: Socket error on client test, disconnecting.

I have used pms serial and influx successfully for a long time, but for mqtt I could not get pms to work.

pms installed with pip: python3 -m pip install pypms[mqtt,influxdb]

what is the port of your local MQTT server? The CLI uses port 1883 by default.

I do not know, what is the version of the Python MQTT library? (pip show paho-mqtt)
Is that version compatible with your MQTT server?

1.6.1. I use this client for a MQTT generator that works nicely with mosquitto. I reproduced the error on a RPi running raspbian.

I have no idea what the problem could be. I just released a new version of the library and CLI, but I do not think that updating would help. BTW, what version of python and PyPMS are you using?

pypms 0.6.2, python 3.6.9 on ubuntu 18.04
pypms 0.6.2, python 3.7.3 on raspbian

Oddest thing, Topic is critical here:

I collect data and publish:
pms -m SPS30 -n 1 -i 10 -s /dev/ttyUSB1 mqtt --mqtt-host localhost --mqtt-port 1883 -t "home/dust/SPS30"

I try to collect with mosquitto:
mosquitto_sub -t "home/dust/SPS30"

This collects nothing, but this does:

mosquitto_sub -t "home/#" (or even "home/dust/#, "home/+/#")

Not sure why. I can't see Topic sent but I check that mosquitto[_sub,_pub] works as expected with Topic publish and subscribe.

Sent data looks like this:

true
PM1
sensor,unit,concentration
SPS30
μg/m3
1.107303261756897
PM2.5
sensor,unit,concentration
SPS30
μg/m3
1.7731504440307617
PM4
sensor,unit,concentration
SPS30
μg/m3
2.2605395317077637
PM10
sensor,unit,concentration
SPS30
μg/m3
2.3580174446105957
1.2040939331054688
1.5197216272354126
1.7191693782806396
1.759059190750122
false

I guess the numbers at the end are number concentrations and typical particle size. But which is which?

SDS198 seem to get a double concentration entry in the data:

true
PM100
sensor,unit,concentration
SDS198
μg/m3
7
7
false

I found the issue. The way data is sent to mqtt, you cannot expect to publish and subscribe to the same topic (like you would find in most examples). I found it by verbose subscription:

$ mosquitto_sub -v -t "#"
home/dust/SDS198/$online false
home/dust/SDS198/pm100/$type PM100
home/dust/SDS198/pm100/$properties sensor,unit,concentration
home/dust/SDS198/pm100/sensor SDS198
home/dust/SDS198/pm100/unit μg/m3
home/dust/SDS198/pm100/concentration 2
home/dust/SDS198/$online true

My apologies, I've should have read up more on MQTT before I started testing.