-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIOT_GetKey.py
More file actions
36 lines (29 loc) · 786 Bytes
/
IOT_GetKey.py
File metadata and controls
36 lines (29 loc) · 786 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from socket import *
import time
HOST = 'api.heclouds.com'
PORT = 80
BUFSIZ = 1024
ADDR = (HOST, PORT)
Content="{\"value\":1}\r\n"
value = len(Content)
data = ''
data +="GET /devices/131913/datapoints?datastream_id=Speed HTTP/1.1\r\n"
data +="api-key:cTwDAEzT3a7S8K5UUO78W93v170A\r\n"
data +="Connection: close\r\n"
data +="Host:api.heclouds.com\r\n"
data +="\r\n"
databak = 0
while True:
tcpCliSock = socket(AF_INET, SOCK_STREAM)
tcpCliSock.connect(ADDR)
tcpCliSock.send(data.encode())
data1 = tcpCliSock.recv(BUFSIZ).decode()
if not data1:
break
#print (data1)
datai = int(data1[data1.find("\"value\":")+8:data1.find("\"id\":")-3])
if databak != datai:
print(datai)
databak = datai
tcpCliSock.close()
time.sleep(0.1)