RaspyRFM/apps/rcpulse.py

45 lines
1.2 KiB
Python
Raw Normal View History

#!/usr/bin/env python2.7
2020-01-27 02:11:10 +01:00
from raspyrfm import *
import sys
import time
from argparse import ArgumentParser
2020-01-27 02:11:10 +01:00
import wave, struct
2020-02-05 01:15:56 +01:00
import threading
import rcprotocols
parser = ArgumentParser()
parser.add_argument("-t", "--timebase", type=int, help=u"timebase in \u03bcs")
parser.add_argument("-r", "--repeats", type=int, help=u"number of repetitions")
2020-01-27 02:11:10 +01:00
parser.add_argument("-m", "--module", type=int, metavar="1-4", help=u"RaspyRFM module 1-4", default=1)
parser.add_argument("-f", "--frequency", type=float, help=u"frequency in MHz", default=433.92)
2020-02-05 01:15:56 +01:00
parser.add_argument("-p", "--protocol", help=u"Protocol for sending")
2020-01-27 02:11:10 +01:00
parser.add_argument("-w", "--write", help=u"write wavefile")
2020-02-05 01:15:56 +01:00
args, remainargs = parser.parse_known_args()
2020-11-30 19:25:11 +01:00
def rxcb(dec, train):
for p in dec:
print(p)
if len(dec) == 0:
print(train)
2020-02-05 01:15:56 +01:00
if not raspyrfm_test(args.module, RFM69):
print("Error! RaspyRFM not found")
exit()
2020-11-30 19:25:11 +01:00
rctrx = rcprotocols.RcTransceiver(args.module, args.frequency, rxcb)
2020-11-30 19:25:11 +01:00
if len(remainargs) > 0:
rctrx.send_args(args.protocol, remainargs, args.timebase, args.repeats)
del rctrx
exit()
2020-01-27 02:11:10 +01:00
2020-11-30 19:25:11 +01:00
state = 1
while True:
2020-11-30 19:25:11 +01:00
time.sleep(10)
rctrx.send_dict({"protocol": "ittristate", "house": "A", "unit": 1, "state": state})
if (state == 1):
state = 0
else:
state = 1