-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReceiveArduino.py
48 lines (38 loc) · 1.22 KB
/
ReceiveArduino.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
39
40
41
42
43
44
45
46
47
48
import RPi.GPIO as GPIO
from lib_nrf24 import NRF24
import time
import spidev
import datetime
GPIO.setmode(GPIO.BCM)
pipes = [[0xE8, 0xE8, 0xF0, 0xF0, 0xE1], [0xF0, 0xF0, 0xF0, 0xF0, 0xE1]]
radio = NRF24(GPIO, spidev.SpiDev())
radio.begin(0, 26)
radio.setPayloadSize(32)
radio.setChannel(0x74)
radio.setDataRate(NRF24.BR_250KBPS)
radio.setPALevel(NRF24.PA_MIN)
radio.setAutoAck(True)
radio.enableDynamicPayloads()
radio.enableAckPayload()
radio.openReadingPipe(1, pipes[1])
radio.printDetails()
radio.startListening()
while True:
ackPL = [1]
while not radio.available(0):
time.sleep(0.01)
receivedMessage = []
radio.read(receivedMessage, radio.getDynamicPayloadSize())
print("Received: {}".format(receivedMessage))
print("Translating the receivedMessage into unicode characters")
string = ""
for n in receivedMessage:
if (n >= 32 and n <= 126):
string += chr(n)
print("Our received message decodes to: {}".format(string))
radio.writeAckPayload(1, ackPL, len (ackPL))
print("Loaded payload reply of {}".format(ackPL))
now = datetime.datetime.now()
f= open("logs.txt", "a+")
f.write(now.strftime("%Y-%b-%d %H:%M")+" "+"{}".format(string)+"\n")
f.close()