RaspyRFM/apps/rcpulsegw.py

48 lines
1 KiB
Python
Raw Normal View History

#!/usr/bin/env python
2020-11-19 21:26:59 +01:00
from raspyrfm import *
import rcprotocols
import json
2020-11-21 01:03:14 +01:00
from argparse import ArgumentParser
2020-12-29 00:18:03 +01:00
import apiserver
import time
2020-11-21 01:03:14 +01:00
parser = ArgumentParser()
parser.add_argument("-m", "--module", type=int, metavar="1-4", help=u"RaspyRFM module 1-4", default=1)
2020-11-30 19:25:11 +01:00
parser.add_argument("-f", "--frequency", type=float, help=u"frequency in MHz", default=433.92)
2020-12-02 20:28:57 +01:00
args = parser.parse_args()
2020-11-19 21:26:59 +01:00
2020-12-29 00:18:03 +01:00
def rccb(dec, train):
payload = None
if dec is None:
payload = {"raw": train}
else:
if len(dec) > 0:
payload = {"decode": dec, "raw": train}
if payload is not None:
print("RX", payload)
2020-12-29 00:18:03 +01:00
try:
apisrv.send(payload)
except:
pass
2020-11-30 19:25:11 +01:00
if not raspyrfm_test(args.module, RFM69):
print("Error! RaspyRFM not found")
exit()
2020-12-29 00:18:03 +01:00
rctrx = rcprotocols.RcTransceiver(args.module, args.frequency, rccb)
2020-11-19 21:26:59 +01:00
2020-12-29 00:18:03 +01:00
def apicb(data):
print("TX", data)
try:
rctrx.send(data["protocol"], data["params"])
except:
pass
2020-12-29 00:18:03 +01:00
apisrv = apiserver.ApiServer(1989, apicb)
2020-11-19 21:26:59 +01:00
while True:
2020-12-29 00:18:03 +01:00
time.sleep(1)