-
Notifications
You must be signed in to change notification settings - Fork 1
/
receiver.py
executable file
·72 lines (55 loc) · 1.49 KB
/
receiver.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# from __future__ import print_function
import time
from RF24 import *
import pdb
import base64
import RPi.GPIO as GPIO
import os, sys
irq_gpio_pin = None
radio = RF24(22, 0)
pipes = [0xF0F0F0F0E1, 0x7365727631]
def setup():
pdb.set_trace()
# radio.printDetails()
# radio.begin()
print ("Hallo")
pdb.set_trace()
#radio.payloadSize = 16 # len(message)
# radio.enableDynamicPayloads()
radio.setAutoAck(1)
radio.setDataRate(RF24_250KBPS) # 250kbs
radio.setPALevel(RF24_PA_MAX)
pdb.set_trace()
radio.setChannel(90)
radio.setRetries(15, 15)
radio.setCRCLength(RF24_CRC_16)
radio.openWritingPipe(pipes[1])
radio.openReadingPipe(1, pipes[0])
# radio.maskIRQ(0,0,1)
radio.startListening()
def writeToFile(received_payload):
print('Got payload size={} value="{}"'.format(radio.payloadSize, received_payload.decode('utf-8')))
# Timestamp erzeugen
utime = int(time.time())
# Hier aktuelle Zeit einfuegen
data.write("1481278800" + " " + received_payload + " \n") # % utime
data.flush()
def receive():
if radio.available():
while radio.available():
len = radio.payloadSize
receive_payload = radio.read(len)
writeToFile(receive_payload)
# Hauptprogramm:
pdb.set_trace()
print ("Hallo")
pdb.set_trace()
setup()
radio.printDetails()
data = open('datafifo', 'a+')
print("Hauptprogramm:")
while 1:
receive()
# spaeter durch interrupt ersetzten
time.sleep(1)
data.close()