RaspyRFM/apps/rcpulse.py

52 lines
1.4 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")
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-12-02 20:28:57 +01:00
if args.protocol:
proto = rcprotocols.get_protocol(args.protocol)
if proto:
parser2 = ArgumentParser()
for param in proto.params:
parser2.add_argument("-" + param[0], "--" + param[1], required=True)
params = parser2.parse_args(remainargs)
rctrx.send(args.protocol, params.__dict__, args.timebase, args.repeats)
else:
print("Unknown protocol.")
2020-11-30 19:25:11 +01:00
del rctrx
exit()
2020-01-27 02:11:10 +01:00
2020-12-02 20:28:57 +01:00
state = "on"
while True:
2020-12-02 20:28:57 +01:00
time.sleep(15)
2020-11-30 19:25:11 +01:00
2020-12-04 02:00:11 +01:00
#rctrx.send("ittristate", {"house": "A", "group": 1, "unit": 1, "command": state})
2020-12-02 20:28:57 +01:00
if (state == "on"):
state = "off"
2020-11-30 19:25:11 +01:00
else:
2020-12-02 20:28:57 +01:00
state = "on"