RaspyRFM/lacrosse.py

61 lines
1.3 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
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()
2020-01-17 23:36:46 +01:00
2017-03-05 22:42:34 +01:00
rfm.SetParams(
2020-01-17 23:36:46 +01:00
Freq = 868.30, #MHz center frequency
Datarate = 9.579, #kbit/s baudrate
2017-03-05 22:42:34 +01:00
ModulationType = rfm69.FSK, #modulation
2020-01-17 23:36:46 +01:00
Deviation = 30, #kHz frequency deviation
2017-03-05 22:42:34 +01:00
SyncPattern = [0x2d, 0xd4], #syncword
Bandwidth = 150, #kHz bandwidth
2020-01-17 23:36:46 +01:00
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:
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"
rfm.SetParams(Datarate = dr)
self.baud = not self.baud
2017-03-05 22:42:34 +01:00
baudChanger = BaudChanger()
baudChanger.daemon = True
baudChanger.start()
print "Waiting for sensors..."
2017-03-05 22:42:34 +01:00
while 1:
data = rfm.ReceivePacket(5)
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)