Traceback (most recent call last):
File "empfang.py", line 39, in <module>
gereat, sensor, temp = data.split(":")
ValueError: need more than 1 value to unpack
Code: Alles auswählen
import socket
import sys
import os
import datetime
import urllib2
import threading
import time
UDP_IP = "127.0.0.1"
UDP_PORT = 5005
Sensoren = ['10-000802d3ab2f','10-000802bd095b']#Sensoren hier eintragen -----> ['10-000802d3ab2f','Neachstersensor'] zufinden in /sys/devices/w1_bus_master1/
sensortemp = ["",""]
baseURL = "https://api.thingspeak.com/update?api_key=**********************&"
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))
def Temperatursenden():
while not stop:
if not sensortemp[1] == "":
g = urllib2.urlopen(baseURL + "&field1=%s&field2=%s" % (sensortemp[0],sensortemp[1]))
sensortemp[0] = ""
sensortemp[1] = ""
print "Sende Daten!\n"
try:
stop = False
t1 = threading.Thread(target=Temperatursenden)
t1.start()
while True:
data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
print data
gereat, sensor, temp = data.split(":")
if not temp == "85.00":
if gereat == "t":
print "\n" + str(datetime.datetime.now().strftime("%H:%M:%S %d-%m-%Y"))
print "Sensor:", sensor
print "Temperatur", temp + "\n"
if sensor == Sensoren[0]:
sensortemp[0] = temp
if sensor == Sensoren[1]:
sensortemp[1] = temp
if gereat == "h":
print "\n" + str(datetime.datetime.now().strftime("%H:%M:%S %d-%m-%Y"))
print "Sensor:", sensor
#feucht = int(temp)#<--------------- geht nicht
print "Luftfeucht", (round(feucht,2)) + "\n"
if sensor == 3:
sensortemp[2] = round(temp,2)
except (KeyboardInterrupt, SystemExit):
stop = True
sock.close