eclipse-mosquitto / mosquitto

Eclipse Mosquitto - An open source MQTT broker
https://mosquitto.org
Other
9.08k stars 2.39k forks source link

HOW TO SEND MY DHT11 DATA USING mosquitto_pub -m #2316

Closed Nawi98 closed 3 years ago

Nawi98 commented 3 years ago

Hello @jacmet @ketan hope u re doing good I am running mosquitto version 1.6.9 on my Raspberry PI 4 and want to retrieve my DHT11 data using the command: mosquitto_pub -m messageValue I am using the python code below to retrieve the DHT11 value (the output is on the ssh terminal) but don't know yet how to redirect it into the "messageValue" variable.

Because that is the demo's aim

#!/usr/bin/python
import sys
import Adafruit_DHT

while True:

    humidity, temperature = Adafruit_DHT.read_retry(11, 4)

    print 'Temp: {0:0.1f} C  Humidity: {1:0.1f} %'.format(temperature, humidity)

Could u please help me

Cheers.

Daedaluz commented 3 years ago

try retrieve_dht_data.py | mosquitto_pub -t "dht11" -l your script does a never ending loop, printing the results from the read. mosquitto_pub can send messages for each line with the -l option.

you might want to put in some sleep somewhere to avoid flooding.

Nawi98 commented 3 years ago

Hello @Daedaluz Thx for ur reactivity Sir. Finally here is what the link I used (see application source code) : https://thingsboard.io/docs/samples/raspberry/temperature/ Regards.

Daedaluz commented 3 years ago

please, close if there is nothing else =)