I'm happy it works for you!! I think you did great, it is an interesting exercise and it shows how well a Python script can work and communicate with Node-RED via MQTT. Myself I have many such scripts using MQTT for various needs in my own system. They have been working just excellent since years. One thing we did not discuss so far is the potential using MQTT. Imagine you have a sensor in a remote place that you would like to monitor. If you use MQTT in the same way as we just did, you can instead use a MQTT broker service in the cloud. There are several such service providers offering a secure connection for MQTT, very popular in IoT applications
My intention is not to divert from the topic but another very possible way of connecting and collecting data from sensors is to use a small ESP device. I have a couple of those ESP32's and it is dead simple to make it happen. You can check out this site where I actually found a solution supporting sds011 including communication via MQTT. So that could also be a way and in that case, no Python script needed. As you can see they have solutions ready for many sensors of different kind
Now to answer your questions
-
Yes, you just change one thing in the script in line 53 (in the latest script):
sds011_thread_Event.wait(1)
for data every ten second, change to
sds011_thread_Event.wait(10)
or any other interval you prefer (just insert number of seconds to wait in between) -
Well, depends. If the sensors are compatible then it would be possible, if they communicate in the same way with the same "protocol". If the data they deliver looks different and is in different positions, the script would need to be modified. But the principle should work; having one thread reading the data and one thread for the mqtt communication
Best regards, Walter