MQTT, Node-Red, and Grafana

November 10, 2024, 06:50

pipsqueeeek

Hi y'all i'm having trouble on my node-red. THe problem is I'm using my raspberry pi as my weather station while it being my web server. My raspberry pi has different types of sensors and i want my MQTT to read my python script that prints example code:
python
data = "{"
data += "\"humidity\": " + str(humiditySensorData) + ","
data += "}"

print(data)
i'm wondering which node to connect to my MQTT out my mqqt in is connected to my influxdb out.

thunder07337

You've got it all wrong. This is a network protocol that does not read scripts. The script must be executed by the Pi to which the sensors are connected. For example my weather station: I use the BME280 as a temperature sensor and an ESP8266 (for you this is the Pi) for reading. And the ESP8266 executes the script and sends the output as mqtt to the broker. My broker is my server, a raspberry Pi 4, for you it would be the raspberry Pi again. And in Node Red you forward this output, which you are already doing, you send it to the database. Conclusion: you have to run the script from the Pi and send it to the mqtt broker.

oops.se

Its quite easy to write a python script that read a MQTT topic and then send that data to a database. So you don't have to use Node-Red.