danjperron wrote:P.D: How could I agree a code, like the next, to DHT22.py?
Sorry be more specific i can't figure it out what you mean?
....to my domotic center, using it url API KEY.
Same thing here ??????
What is you domotic center? Which protocol are you using ?
Could you use MQTT because with MQTT is simple.
something similar to
Code: Select all
import paho.mqtt.client as paho
#give a name to you client
client = paho.Client('RaspberryPi2')
#connect to the MQTT server
client.connect('10.11.12.192')
#publish your data using a specific topic that you choose.
client.publish('RF_DATA/DHT22_1/Temp',sensor.temperature())
client.publish('RF_DATA/DHT22_1/Hum',sensor.humidity())
Sorry, you have the reason. I didn´t give you enough information.
My domotic center is Jeedom (
http://jeedom.fr/), based in other Rpi inside my LAN.
I need to send the humidity and temperature information since other Rpi where is connected the DHT11.
The URL API HTTP protocol, can you see here:
https://jeedom.fr/doc_api.php
I modified your script to send the humidity and temperature information to mi domotic center (Jeedom in other Rpi with ip: 192.168.1.20)
Code: Select all
if __name__ == "__main__":
# Ajout pour Jeedom
import urllib
def Jeedom(id, value):
base = "https://192.168.1.20/core/api/jeeApi.php?api="
key = " xxxx"
type = "virtual"
req = base + key + "&type=" + type + "&id=" + str(id) + "&value=" + str(value)
urllib.urlopen(req)
# print "Req Virtuel : " + req
# fin
import time
import pigpio
import DHT22
# Intervals of about 2 seconds or less will eventually hang the DHT22.
# INTERVAL=3
pi = pigpio.pi()
s = DHT22.sensor(pi, 22, LED=None, power=None,DHT11=True)
# r = 0
# next_reading = time.time()
#while True:
# r += 1
# s.trigger()
# time.sleep(0.2)
# print("{} {} {} {:3.2f} {} {} {} {}".format(
# r, s.humidity(), s.temperature(), s.staleness(),
# s.bad_checksum(), s.short_message(), s.missing_message(),
# s.sensor_resets()))
id = 1035
value = s.temperature()
Jeedom(id,value)
# id2 = 1036
# value2 = s.humidity()
# Jeedom(id2,value2)
# next_reading += INTERVAL
# time.sleep(next_reading-time.time()) # Overall INTERVAL second polling.
s.cancel()
pi.stop()
Now when I execute the script I didn´t receive report....
do you know what´s the problem?