forked from etrombly/RFM69
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradio2.py
executable file
·65 lines (49 loc) · 1.29 KB
/
radio2.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
#!/usr/bin/env python2
import RFM69
from RFM69registers import *
import datetime
import time
NODE=2
NET=1
KEY="1234567891011121"
TIMEOUT=3
TOSLEEP=0.1
radio = RFM69.RFM69(RF69_915MHZ, NODE, NET, True)
print "class initialized"
print "reading all registers"
results = radio.readAllRegs()
#for result in results:
# print result
print "Performing rcCalibration"
radio.rcCalibration()
print "setting high power"
radio.setHighPower(True)
print "Checking temperature"
print radio.readTemperature(0)
print "setting encryption"
radio.encrypt(KEY)
sequence=0
print "starting loop..."
while True:
msg = "I'm radio %d: %d" % (NODE, sequence)
sequence = sequence + 1
print "tx to radio 1: " + msg
if radio.sendWithRetry(1, msg, 3, 20):
print "ack recieved"
print "starting recv..."
radio.receiveBegin()
timedOut=0
while not radio.receiveDone():
timedOut+=TOSLEEP
time.sleep(TOSLEEP)
if timedOut > TIMEOUT:
print "timed out waiting for recv"
break
print "end recv..."
print " ### %s from %s RSSI:%s " % ("".join([chr(letter) for letter in radio.DATA]), radio.SENDERID, radio.RSSI)
if radio.ACKRequested():
radio.sendACK()
else:
print "ack not requested..."
print "shutting down"
radio.shutdown()