这个是我在代码里面根据那LED程序改的,有人能帮我下不
#!/usr/bin/python3
import socket
import time
import json
#must be modified===
DEVICEID='2508'
APIKEY='18a424b7b'
#modify end=========
host="www.bigiot.net"
port=8181
#connect bigiot
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.settimeout(0)
while True:
try:
s.connect((host,port))
break
except:
print('waiting for connect bigiot.net...')
time.sleep(2)
#check in bigiot
checkinBytes=bytes('{\"M\":\"checkin\",\"ID\":\"'+DEVICEID+'\",\"K\":\"'+APIKEY+'\"}\n',encoding='utf8')
s.sendall(checkinBytes)
#keep online with bigiot function
data=b''
flag=1
t=time.time()
def keepOnline(t):
if time.time()-t>40:
s.sendall(b'{\"M\":\"status\"}\n')
print('check status')
return time.time()
else:
return t
#say something to other device function
def say(s,id,content):
sayBytes=bytes('{\"M\":\"say\",\"ID\":\"'+id+'\",\"C\":\"'+content+'\"}\n',encoding='utf8')
s.sendall(sayBytes)
#deal with message coming in
def process(msg,s,checkinBytes):
msg=json.loads(msg)
if msg['M'] == 'connected':
s.sendall(checkinBytes)
if msg['M'] == 'login':
say(s,msg['ID'],'Welcome! Your public ID is '+msg['ID'])
if msg['M'] == 'say':
say(s,msg['ID'],'You have send to me:{'+msg['C']+'}')
#for key in msg:
#print(key,msg[key])
#print('msg',type(msg))
#main while
while True:
try:
d=s.recv(1)
flag=True
except:
flag=False
time.sleep(1)
t = keepOnline(t)
if flag:
if d!=b'\n':
data+=d
else:
#get cpu temp
file = open("/sys/class/thermal/thermal_zone0/temp")
temp = float(file.read())/1000
file.close
sendmessage={"M":"update","ID":"2508","V":{"2383":"temp"}}
s.sendall(b'{\"sendmessage\"}\n')
data=b''