RaspyRFM/lacrosse.py

97 lines
2.2 KiB
Python
Raw Normal View History

2017-03-05 22:42:34 +01:00
#!/usr/bin/env python2.7
from rfm69 import Rfm69
import rfm69
import sensors
from sensors import rawsensor
import sys
import time
import threading
2017-03-05 22:42:34 +01:00
2018-04-24 00:15:14 +02:00
if Rfm69.Test(1):
print("Found RaspyRFM twin")
2018-04-24 00:15:14 +02:00
rfm = Rfm69(1, 24) #when using the RaspyRFM twin
elif Rfm69.Test(0):
print("Found RaspyRFM single")
2018-04-24 00:15:14 +02:00
rfm = Rfm69() #when using a single single 868 MHz RaspyRFM
else:
print("No RFM69 module found!")
2018-04-24 00:15:14 +02:00
exit()
2017-03-05 22:42:34 +01:00
rfm.SetParams(
Freq = 868.310, #MHz center frequency
2017-03-05 22:42:34 +01:00
Datarate = 9.579, #17.241, #kbit/s baudrate
ModulationType = rfm69.FSK, #modulation
Deviation = 20, #90 kHz frequency deviation
2017-03-05 22:42:34 +01:00
SyncPattern = [0x2d, 0xd4], #syncword
Bandwidth = 150, #kHz bandwidth
RssiThresh = -100, #-100 dB RSSI threshold
)
class BaudChanger(threading.Thread):
baud = False
def __init__(self):
threading.Thread.__init__(self)
def run(self):
while True:
time.sleep(15)
print "Change"
if self.baud:
rfm.SetParams(Datarate = 9.579)
else:
rfm.SetParams(Datarate = 17.241)
self.baud = not self.baud
2017-03-05 22:42:34 +01:00
data = []
baudChanger = BaudChanger()
baudChanger.daemon = True
baudChanger.start()
#rfm.start()
#0x9f 0x6 0x5 0x32 0x32 0x0 0x0
#0x90 0x2 0x16 0x50 0xf 0x0 0x0
#0x9e 0x5 0x93 0x37 0x81 0x0 0x0
#0x9e 0x5 0x92 0x37 0x75 0x0 0x0
#0x93 0x45 0x84 0xb2 0xb5 0x9e 0x4d
#0x97 0x6 0x10 0x33 0x6 0x4f 0xb4
#0x9f 0x85 0x91 0x39 0x9 0x82 0x1b
#Frame error!
#0x6b 0x43 0xcd 0x16 0x21 0xe 0xe
#0xfc 0x9e 0x21 0x40 0x4e 0x47 0xca
#0x6f 0x85 0xaf 0x9 0x4c 0xa1 0xcc
#0x93 0x4 0xdd 0xff 0x61 0xc 0x15
#0x6a 0x83 0xd1 0x33 0x34 0x8f 0x44
#0x60 0x81 0xbd 0x6b 0x85 0xa1 0xcc
#0x6f 0x85 0xaf 0x8 0x7d 0xa1 0xcc
#0xda 0xc9 0xba 0x71 0xb5 0x58 0xd5
#0x61 0x82 0x2a 0x6e 0xc2 0xa1 0xcc
#0x6f 0x85 0xaf 0x8 0x7d 0xa1 0xcc
#0xf8 0x50 0x55 0x3f 0xee 0xbb 0x8d
#0x33 0xa0 0xd8 0x5a 0xf6 0x8 0x91
#0x60 0x81 0xbd 0x6b 0x85 0xa1 0xcc
def whitening(data, init):
lfsr = init
for i in range(len(data)):
data[i] = data[i] ^ (lfsr & 0xFF)
for j in range(8):
if ((lfsr >> 5) ^ lfsr) & 0x01 != 0:
lfsr |= 1<<9
lfsr >>= 1
print "Waiting for sensors..."
2017-03-05 22:42:34 +01:00
while 1:
data = rfm.ReceivePacket(5)
if data == None:
print("NO DATA")
continue
obj = rawsensor.CreateSensor(data).GetData()
if not 'ID' in obj:
continue
print(data)
print(obj)