From bbb679af605c932725e5efddbfa82dafbd95bad6 Mon Sep 17 00:00:00 2001 From: "S. Seegel" Date: Thu, 19 Nov 2020 21:26:59 +0100 Subject: [PATCH] add nodered support --- apps/rfmnodered.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 apps/rfmnodered.py diff --git a/apps/rfmnodered.py b/apps/rfmnodered.py new file mode 100755 index 0000000..0a3a231 --- /dev/null +++ b/apps/rfmnodered.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python2.7 + +import socket +import threading +from raspyrfm import * +import rcprotocols +import json + +srvsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +srvsock.bind(('', 1989)) +srvsock.listen(5) + +rfm = RaspyRFM(1, RFM69) +rfm.set_params( + Freq = 433.92, #MHz + Datarate = 20.0, #kbit/s + Bandwidth = 300, #kHz + SyncPattern = [], + RssiThresh = -105, #dBm + ModulationType = rfm69.OOK, + OokThreshType = 1, #peak thresh + OokPeakThreshDec = 3, + Preamble = 0, + TxPower = 13 +) + +lock = threading.Lock() + +class clientthread(threading.Thread): + def __init__(self, socket): + self.__socket = socket + threading.Thread.__init__(self) + + def run(self): + while True: + chunk = self.__socket.recv(1024) + if len(chunk) == 0: + del self.__socket + break + print(chunk) + try: + lock.acquire() + txdata = rcprotocols.encode_dict(json.loads(chunk)) + print(txdata) + rfm.set_params( + SyncPattern = [], + Datarate = 1000.0 / txdata[1] + ) + rfm.send(txdata[0] * txdata[2]) + except: + pass + lock.release() + +while True: + (client, address) = srvsock.accept() + ct = clientthread(client) + ct.daemon = True + ct.start() \ No newline at end of file