Hallo
Hab einen ds18b20 an rpi1 angeschlossen (mqtt mosquitto clients installiert) und lese den mit der python.py aus:
Spoiler anzeigen
#!/usr/bin/python
#--------------------------------------
#
# ds18b20.py
# Read DS18B20 1-wire temperature sensor
#
# Author : Matt Hawkins
# Date : 10/02/2015
#
# http://www.raspberrypi-spy.co.uk/
#
#--------------------------------------
def gettemp(id):
try:
mytemp = ''
filename = 'w1_slave'
f = open('/sys/bus/w1/devices/' + id + '/' + filename, 'r')
line = f.readline() # read 1st line
crc = line.rsplit(' ',1)
crc = crc[1].replace('\n', '')
if crc=='YES':
line = f.readline() # read 2nd line
mytemp = line.rsplit('t=',1)
else:
mytemp = 99999
f.close()
return int(mytemp[1])
except:
return 99999
if __name__ == '__main__':
# Script has been called directly
id = '28-021318f459aa'
print "Temp : " + '{:.3f}'.format(gettemp(id)/float(1000))
Jetzt möcht ich die Temperatur an rpi2 (domoticz,mqtt) senden. Probiert hab ichs mal so aber kommt in domoticz nichts an:
Spoiler anzeigen
url_json = "http://192.168.178.53:8080/json.htm?type=command&WCF_AMPERSAND¶m=udevice&idx="
cmd = url_json + str(60) + "&nvalue=0&svalue=" + str("Temp : " + '{:.3f}'.format(gettemp(id)/float(1000))) + ";0"
hf = urllib.urlopen(cmd)
print 'Uploaded to Pi: ' + cmd
print 'Response: ' + hf.read()
hf.close
Gelöst: Temp : gelöscht,kopierfehler