So below is an example to try, hope it does, I could not test the actual usb communication
First you have to install the paho mqtt client for Python3. Like this
sudo pip3 install paho-mqtt
Next put the script in your directory (/home/pi) and change extension from .txt to .py
Import the flow to your Node-RED, deploy
Start the script via the "Start script" button. I made it so the exec nodes runs the script visible on your monitor screen or vnc view. If this does not work we will get an error message
Abort the script via the "Abort script" button
Heartbeat checks will start automatically and is sent once per minute
Hopefully it works, I moved the usb communication to a separate thread
You should now see data coming into NR in the debug view
[{"id":"76342fda.61ba7","type":"exec","z":"44db0721.1c8138","command":"export DISPLAY=:0 && lxterminal -e python3 /home/pi/sds011.py","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":570,"y":180,"wires":[[],[],[]]},{"id":"cb8849f3.036878","type":"inject","z":"44db0721.1c8138","name":"Start script","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":160,"y":180,"wires":[["76342fda.61ba7"]]},{"id":"260e8f38.3f615","type":"mqtt out","z":"44db0721.1c8138","name":"","topic":"sds011/abort","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"397bfe63.7d8242","x":400,"y":510,"wires":[]},{"id":"3fb86da5.3e02e2","type":"inject","z":"44db0721.1c8138","name":"Abort script","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"abort","payloadType":"str","x":170,"y":510,"wires":[["260e8f38.3f615"]]},{"id":"634dd6c6.21d108","type":"inject","z":"44db0721.1c8138","name":"Heartbeat check","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Are you alive?","payloadType":"str","x":190,"y":450,"wires":[["2dbd1fb6.009ef"]]},{"id":"2dbd1fb6.009ef","type":"mqtt out","z":"44db0721.1c8138","name":"","topic":"sds011/heartbeat_check","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"397bfe63.7d8242","x":440,"y":450,"wires":[]},{"id":"7f2b6c64.37d954","type":"mqtt in","z":"44db0721.1c8138","name":"","topic":"sds011/heartbeat_response","qos":"2","datatype":"auto","broker":"397bfe63.7d8242","nl":false,"rap":false,"x":220,"y":390,"wires":[["ad4c3c00.0776b8","38edfbd5.dc9ca4"]]},{"id":"ad4c3c00.0776b8","type":"debug","z":"44db0721.1c8138","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":810,"y":390,"wires":[]},{"id":"38edfbd5.dc9ca4","type":"trigger","z":"44db0721.1c8138","name":"","op1":"","op2":"Script is restarting","op1type":"nul","op2type":"str","duration":"5","extend":true,"overrideDelay":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":600,"y":260,"wires":[["76342fda.61ba7","ad4c3c00.0776b8","cf3eecb5.6f8d9"]]},{"id":"cf3eecb5.6f8d9","type":"switch","z":"44db0721.1c8138","name":"","property":"payload","propertyType":"msg","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":600,"y":330,"wires":[["38edfbd5.dc9ca4"]]},{"id":"37b069c1.c685d6","type":"debug","z":"44db0721.1c8138","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":400,"y":600,"wires":[]},{"id":"84ee7b81.3236d8","type":"mqtt in","z":"44db0721.1c8138","name":"","topic":"sds011/data","qos":"2","datatype":"auto","broker":"397bfe63.7d8242","nl":false,"rap":true,"rh":0,"x":170,"y":600,"wires":[["37b069c1.c685d6"]]},{"id":"397bfe63.7d8242","type":"mqtt-broker","name":"","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]
sds011.txt (2.3 KB)