-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
executable file
·37 lines (35 loc) · 945 Bytes
/
client.py
File metadata and controls
executable file
·37 lines (35 loc) · 945 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
import time
import datetime
import struct
import json
from RF24 import *
import RPi.GPIO as GPIO
import requests
state = {}
start = time.time()
radio = RF24(22, 0);
address=0xABCDABCD71
radio.begin();
radio.printDetails();
radio.openReadingPipe(1, address);
radio.startListening();
start = time.time()
while(True):
timeout = False
while(not radio.available()):
if time.time() - start > 3:
timeout = True
break
if timeout:
pass
else:
payload = radio.read(14)
id, count = struct.unpack("bb", payload[:2])
t0, t1, t2 = struct.unpack("fff", payload[2:])
state[id] = { "time": str(datetime.datetime.now()), "temp":[t0,t1]}
if time.time() - start > 150:
try:
start = time.time()
requests.post("https://", data = json.dumps(state), verify = False)
except Exception as e:
print(e)