0

I would like to use the rpi-rf module https://pypi.org/project/rpi-rf/ for a remote control alert system, using a PIR motion sensor as the input.

I have so far set up the PIR input and send and receive modules, and have no problem sending data packets from the terminal. Where I am running into trouble is that I cannot find any documentation on how to hardcode the RF Code that I need to send to activate a specific device so I can automate the system.

I've searched all the documentation I can find - https://github.com/milaq/rpi-rf

This is the code for the "Send" module:

#!/usr/bin/env python3

import argparse
import logging

from rpi_rf import RFDevice

logging.basicConfig(level=logging.INFO, datefmt='%Y-%m-%d %H:%M:%S',
                    format='%(asctime)-15s - [%(levelname)s] %(module)s: %(message)s',)

parser = argparse.ArgumentParser(description='Sends a decimal code via a 433/315MHz GPIO device')
parser.add_argument('code', metavar='CODE', type=int,
                    help="Decimal code to send")
parser.add_argument('-g', dest='gpio', type=int, default=17,
                    help="GPIO pin (Default: 17)")
parser.add_argument('-p', dest='pulselength', type=int, default=None,
                    help="Pulselength (Default: 350)")
parser.add_argument('-t', dest='protocol', type=int, default=None,
                    help="Protocol (Default: 1)")
parser.add_argument('-l', dest='length', type=int, default=None,
                    help="Codelength (Default: 24)")
parser.add_argument('-r', dest='repeat', type=int, default=10,
                    help="Repeat cycles (Default: 10)")
args = parser.parse_args()

rfdevice = RFDevice(args.gpio)
rfdevice.enable_tx()
rfdevice.tx_repeat = args.repeat

if args.protocol:
    protocol = args.protocol
else:
    protocol = "default"
if args.pulselength:
    pulselength = args.pulselength
else:
    pulselength = "default"
if args.length:
    length = args.length
else:
    length = "default"

logging.info(str(args.code) +
             " [protocol: " + str(protocol) +
             ", pulselength: " + str(pulselength) +
             ", length: " + str(length) +
             ", repeat: " + str(rfdevice.tx_repeat) + "]")

rfdevice.tx_code(args.code, args.protocol, args.pulselength, args.length)
rfdevice.cleanup()

Can anybody out there tell me how to hardcode the RF Code that I need to send to activate a specific device so I can automate the system?

3
  • 1
    Not Pi specific. How do I write a program is off topic.
    – joan
    Aug 4, 2021 at 6:26
  • So should go to stack overflow? Is this a hardware site? This program is specifically written for Raspberry Pi... also, Im sorry but I wasn't asking "how do I write a program". The question is how to hard code the rf-code to activate a specific device. I thought I had outlined that above when I described the problem, should I word it differently?
    – John Conor
    Aug 4, 2021 at 11:40
  • I think the Q belongs on this site, though I would ask the lib author (directly on Github) rather than random people here. @JohnConor If you got command line tools working, why didn't you use them from your code with e.g. os.system? Aug 27, 2021 at 9:07

1 Answer 1

0

Ok, figured it out... well at least a work around. Instead of trying to change the variables within the send.py script, you can use the subprocess library to execute the script when required and pass the arguments to it.

Simply by adding:

import subprocess 

subprocess.Popen(['python','send.py','-p','174','-t','1','123456'])
2
  • Good work! Please do us all a favor, and "accept" your answer when you can. We need several things here, but more un-answered questions is not one of them :) Also note that if you subsequently get an answer you like better than your own, you can "change your mind" and accept it instead. More info available in The Tour
    – Seamus
    Aug 5, 2021 at 0:33
  • 1
    Thanks Seamus! Solid Irish name, which as a Belfast native I appreciate. Will do, saying I can accept it tomorrow. Appreciate helpful direction too, which is far from the original 2 replies I received. As I continue to grow my python and rpi expertise I'll do my best to support the community.
    – John Conor
    Aug 5, 2021 at 0:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.