forked from CitoyensCapteurs/CitizenWatt-Base
-
Notifications
You must be signed in to change notification settings - Fork 2
/
receive.py
38 lines (30 loc) · 824 Bytes
/
receive.py
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
37
38
#!/usr/bin/env python3
from RF24 import *
# file storing data
filename = '/tmp/sensor.log'
# TODO : read from config file
pipes = [0xE7E7E7E7E7, 0xE056D446D0]
radio = RF24(22, 0)
radio.begin()
radio.setRetries(15, 15)
radio.setDataRate(RF24_250KBPS)
radio.setAutoAck(1)
radio.setPALevel(RF24_PA_MIN)
radio.setCRCLength(RF24_CRC_8)
radio.openReadingPipe(1, pipes[1])
# for debug
# radio.printDetails()
while True:
radio.startListening()
pipe = [0]
while not radio.available():
continue
size = radio.getDynamicPayloadSize()
receive_payload = radio.read(size)
# for debug
# print(size, ''.join('{:02x}'.format(x) for x in receive_payload))
# print(receive_payload)
# print('')
FileTemp = open(filename, 'wb')
FileTemp.write(receive_payload)
FileTemp.close()