RaspyRFM/apps/lacrosse.py

59 lines
1.2 KiB
Python
Raw Normal View History

2017-03-05 22:42:34 +01:00
#!/usr/bin/env python2.7
2020-01-23 21:23:04 +01:00
from raspyrfm import *
2017-03-05 22:42:34 +01:00
import sensors
from sensors import rawsensor
import sys
import time
import threading
2020-01-23 21:23:04 +01:00
if raspyrfm_test(2, RFM69):
print("Found RaspyRFM twin")
2020-01-23 21:23:04 +01:00
rfm = RaspyRFM(2, RFM69) #when using the RaspyRFM twin
elif raspyrfm_test(1, RFM69):
print("Found RaspyRFM single")
2020-01-23 21:23:04 +01:00
rfm = RaspyRFM(1, RFM69) #when using a single single 868 MHz RaspyRFM
2018-04-24 00:15:14 +02:00
else:
print("No RFM69 module found!")
2018-04-24 00:15:14 +02:00
exit()
2020-01-17 23:36:46 +01:00
2020-01-23 21:23:04 +01:00
rfm.set_params(
Freq = 868.30, #MHz center frequency
Datarate = 9.579, #kbit/s baudrate
ModulationType = rfm69.FSK, #modulation
Deviation = 30, #kHz frequency deviation
SyncPattern = [0x2d, 0xd4], #syncword
Bandwidth = 150, #kHz bandwidth
RssiThresh = -105, #dBm RSSI threshold
)
2020-01-17 23:36:46 +01:00
class BaudChanger(threading.Thread):
baud = False
def __init__(self):
threading.Thread.__init__(self)
2020-01-17 23:36:46 +01:00
def run(self):
while True:
2020-02-05 01:15:56 +01:00
time.sleep(15)
if self.baud:
2020-01-17 23:36:46 +01:00
dr = 9.579
else:
2020-01-17 23:36:46 +01:00
dr = 17.241
print "Switch baudrate to " + str(dr) + " kbit/s"
2020-01-23 21:23:04 +01:00
rfm.set_params(Datarate = dr)
self.baud = not self.baud
2017-03-05 22:42:34 +01:00
baudChanger = BaudChanger()
baudChanger.daemon = True
baudChanger.start()
2017-03-05 22:42:34 +01:00
while 1:
2020-03-23 11:27:00 +01:00
data = rfm.receive(12)
if data == None:
continue
obj = rawsensor.CreateSensor(data).GetData()
if not 'ID' in obj:
continue
2020-01-17 23:36:46 +01:00
print(obj)