Git Product home page Git Product logo

rpi-rf's Introduction

rpi-rf

Introduction

Python module for sending and receiving 433/315MHz LPD/SRD signals with generic low-cost GPIO RF modules on a Raspberry Pi.

Protocol and base logic ported ported from rc-switch.

Supported hardware

Most generic 433/315MHz capable modules (cost: ~2€) connected via GPIO to a Raspberry Pi.

433modules

Compatibility

Generic RF outlets and most 433/315MHz switches (cost: ~15€/3pcs).

rfoutlet

Chipsets:

  • SC5262 / SC5272
  • HX2262 / HX2272
  • PT2262 / PT2272
  • EV1527 / RT1527 / FP1527 / HS1527

For a full list of compatible devices and chipsets see the rc-switch Wiki

Dependencies

RPi.GPIO

Installation

On your Raspberry Pi, install the rpi_rf module via pip.

Python 3:

# apt-get install python3-pip
# pip3 install rpi-rf

Wiring diagram (example)

Raspberry Pi 1/2(B+):

                   RPI GPIO HEADER
              ____________
             |        ____|__
             |       |    |  |
             |     01|  . x  |02
             |       |  . x__|________       RX
             |       |  . x__|______  |   ________
             |       |  . .  |      | |  |        |
   TX        |   ____|__x .  |      | |__|VCC     |
 _______     |  |  __|__x .  |      |    |        |
|       |    |  | |  |  x____|______|____|DATA    |
|    GND|____|__| |  |  . .  |      |    |        |
|       |    |    |  |  . .  |      |    |DATA    |
|    VCC|____|    |  |  . .  |      |    |        |
|       |         |  |  . .  |      |____|GND     |
|   DATA|_________|  |  . .  |           |________|
|_______|            |  . .  |
                     |  . .  |
                     |  . .  |
                     |  . .  |
                     |  . .  |
                     |  . .  |
                     |  . .  |
                   39|  . .  |40
                     |_______|

TX:
   GND > PIN 09 (GND)
   VCC > PIN 02 (5V)
  DATA > PIN 11 (GPIO17)

RX:
   VCC > PIN 04 (5V)
  DATA > PIN 13 (GPIO27)
   GND > PIN 06 (GND)

Usage

See scripts (rpi-rf_send, rpi-rf_receive) which are also shipped as cmdline tools.

Open Source

rpi-rf's People

Contributors

escoand avatar giuseppeg88 avatar milaq avatar n8henrie avatar nhorvath avatar turbulator avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rpi-rf's Issues

Error in the code?

Im trying to run the receive code with the exact arguments as this video https://www.youtube.com/watch?v=Xe5Bj_N4Crw however it is coming up with an error saying too many arguments are given.
image

I tried taking the main bit of code out and substituting values in and the same error occurred
image

Method and parameter documentation

Hi, I'm trying out FreeBSD on my RPI and I'm reading over the code so I can figure out how to integrate https://github.com/evadot/fbsd_gpio_py since it also looks good and is for doing GPIO on FreeBSD. As someone who is trying to understand the 433mhz protocol through reading the code, it would be easier to have documentation about certain methods and objects.

For example, what is the self.gpio in the RFDevice class? Is that just an integer specifying the pin number? Also, an overview of what the code is doing at a high level. The code looks quite good, I'm just trying to understand it.

Is this compatible with Pi 3?

Hi,

Having some issues using this with Home Assistant, just would like to rule out if it could be that I am using a Pi 3, opposed to the Pi 2 this was originally made for. Any help would be appreciated, thanks!

Decoder to extract RF codes

I was struggling to get my Nexa and Telldus devices to be red using the receive command so I used another @jderehag/rpi-rfsniffer library to extract the raw timings from each button press. I created a small "decoder" to analyze these RFSniffer dumps so that the decimal codes can be used in rpi-rf and Home Assistant. Thought it might be of interested to you and others. Feel free to close this issue if it is irrelevant or if you want to move the info somewhere else.

https://github.com/Swiftwork/rfsniffer-decoder

Kind regards

Issue with Make command

Hi all, I have encountered an error whilst trying to run RFSniffer using the "make" command. I've never edited anything in the RFSniffer.cpp script so it is left in the default settings.

My error message:

g++ -DRPI   -c -o RFSniffer.o RFSniffer.cpp
RFSniffer.cpp:18:16: error: expected constructor, destructor, or type conversion before ‘(’ token
 pullUpDnControl(PIN, PUD_OFF);
                ^
<builtin>: recipe for target 'RFSniffer.o' failed
make: *** [RFSniffer.o] Error 1

Some help on what this exactly means would be greatly appreciated! I'm so close to getting it to sniff my codes that this is frustrating!

Need your help/advice

Hi, I try to understand if I can control my rf celling fan with custom RF.

That my original remote control photo.
https://imgur.com/CEoLZVQ
https://imgur.com/T56YgOf
https://imgur.com/SxH5Pi0
https://imgur.com/llVVZNF
https://imgur.com/bip5JLB
https://imgur.com/6ZEjZ5q
https://imgur.com/ef3P9B8

How I plug my stuff
https://github.com/metabsd/personal_remote_fan/blob/master/photo/schemadebranchement.png

I try with RFSniffer and I see nothing appear. I also try with rpi-rf_receive and I see couple signal.

2018-06-25 22:19:14 - [INFO] rpi-rf_receive: Listening for codes on GPIO 27
2018-06-25 22:20:57 - [INFO] rpi-rf_receive: 16 [pulselength 138, protocol 3]
2018-06-25 22:23:27 - [INFO] rpi-rf_receive: 1610612736 [pulselength 984, protocol 2]

Thank you in advance!

Code not repeating but periodic

Hi,
I've got a case where the code seems to be repeating, i.e.

2019-11-24 15:46:16 - [INFO] rpi-rf_receive: Listening for codes on GPIO 27                                            
2019-11-24 15:46:34 - [INFO] rpi-rf_receive: 1152112 [pulselength 722, protocol 2]                                     
2019-11-24 15:46:35 - [INFO] rpi-rf_receive: 1692592 [pulselength 725, protocol 2]                                     
2019-11-24 15:46:35 - [INFO] rpi-rf_receive: 2066224 [pulselength 724, protocol 2]                                     
2019-11-24 15:46:36 - [INFO] rpi-rf_receive: 1708096 [pulselength 719, protocol 2]                                     
2019-11-24 15:46:37 - [INFO] rpi-rf_receive: 1152112 [pulselength 724, protocol 2]                                     
2019-11-24 15:46:37 - [INFO] rpi-rf_receive: 1692592 [pulselength 723, protocol 2]                                     
2019-11-24 15:46:38 - [INFO] rpi-rf_receive: 2066224 [pulselength 725, protocol 2]                                     
2019-11-24 15:46:38 - [INFO] rpi-rf_receive: 1708096 [pulselength 723, protocol 2]                                     
2019-11-24 15:46:39 - [INFO] rpi-rf_receive: 1152112 [pulselength 724, protocol 2]

Each time I press a button on the remote, a (repeating) code occurs. None of them work. Any idea how to proceed? I cloned current master and installed via setup.py

receiving completely random stuff, nothing frommy remotes

nothing seems to relate to any button presses, i can press the same button 20 times 2 cm next to the receiver and i get nothing for multiple times, or nothing at all, or 2 complete random things..

what am i doing wrong?

2018-03-03 04:39:00 - [INFO] rpi-rf_receive: 8 [pulselength 2252, protocol 2]
2018-03-03 04:39:30 - [INFO] rpi-rf_receive: 2048 [pulselength 1545, protocol 4]
2018-03-03 04:41:18 - [INFO] rpi-rf_receive: 16 [pulselength 2419, protocol 4]
2018-03-03 04:41:55 - [INFO] rpi-rf_receive: 64 [pulselength 1521, protocol 4]
2018-03-03 04:42:37 - [INFO] rpi-rf_receive: 33 [pulselength 182, protocol 1]
2018-03-03 04:43:00 - [INFO] rpi-rf_receive: 8 [pulselength 2538, protocol 2]
2018-03-03 04:43:15 - [INFO] rpi-rf_receive: 64 [pulselength 842, protocol 2]
2018-03-03 04:44:31 - [INFO] rpi-rf_receive: 128 [pulselength 850, protocol 1]
2018-03-03 04:46:46 - [INFO] rpi-rf_receive: 1073741826 [pulselength 1203, protocol 1]
2018-03-03 04:47:37 - [INFO] rpi-rf_receive: 64 [pulselength 1638, protocol 4]
2018-03-03 04:47:43 - [INFO] rpi-rf_receive: 1 [pulselength 988, protocol 2]
2018-03-03 04:47:46 - [INFO] rpi-rf_receive: 2048 [pulselength 1045, protocol 4]
2018-03-03 04:48:20 - [INFO] rpi-rf_receive: 2 [pulselength 374, protocol 3]
2018-03-03 04:49:01 - [INFO] rpi-rf_receive: 16 [pulselength 905, protocol 2]
2018-03-03 04:49:01 - [INFO] rpi-rf_receive: 16 [pulselength 1492, protocol 4]
2018-03-03 04:49:46 - [INFO] rpi-rf_receive: 1 [pulselength 1140, protocol 2]
2018-03-03 04:49:46 - [INFO] rpi-rf_receive: 8 [pulselength 148, protocol 3]
2018-03-03 04:51:16 - [INFO] rpi-rf_receive: 1 [pulselength 1594, protocol 4]

Sendig not possible

Sending code was not possible for me as long as I changed the delay fom 1000000 to 1000000.0000 to make the result of the divison a float value, which is used to call time.sleep().
Hope this hint is helpful :-)
Cheers, Mike.
B.t.w.: Great job porting this to python, thanks a lot :-)

Something really wrong with send script?

Something really wrong with send script, tried

python3 Send.py -p 1 -t 1 1111111

/usr/local/lib/python3.5/dist-packages/rpi_rf/rpi_rf.py:77: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(self.gpio, GPIO.OUT)
2019-04-04 19:57:37 - [INFO] Send: 1111111 [protocol: 1, pulselength: 1, length: default, repeat: 10]
Traceback (most recent call last):
File "Send.py", line 49, in
rfdevice.tx_code(args.code, args.protocol, args.pulselength, args.length)
TypeError: tx_code() takes from 2 to 4 positional arguments but 5 were given

Not only does send script not handle cleanup on error correctly, as noted with the warning above, but the send script fails completely. Please fix your code.

Why no voltage divider on wiring diagram?

Everywhere I read that if you power these RF Rx devices with 5V then it is critical to divide the voltage down on the Rx data pin to 3.3V before connecting it to a RPi GPIO input pin otherwise you risk damaging the RPi.

However, the wiring diagram on the main README does not show this? The Rx data pin (potentially at 5V) is connected directly to the GPIO input (max should be 3.3V) so presumably at risk of damaging it?

Reading results not interpretable and always different

I'm using this library to listen to my remote, but I can't get a single code, the output is always different:

(this is a long press)

2019-12-19 23:17:34 - [INFO] receive: Listening for codes on GPIO 27
2019-12-19 23:17:39 - [INFO] receive: 992 [pulselength 454, protocol 3]
2019-12-19 23:17:44 - [INFO] receive: 512 [pulselength 375, protocol 1]
2019-12-19 23:17:44 - [INFO] receive: 64 [pulselength 384, protocol 1]
2019-12-19 23:17:44 - [INFO] receive: 256 [pulselength 379, protocol 1]
2019-12-19 23:17:44 - [INFO] receive: 128 [pulselength 376, protocol 1]
2019-12-19 23:17:44 - [INFO] receive: 64 [pulselength 379, protocol 1]
2019-12-19 23:17:44 - [INFO] receive: 512 [pulselength 1180, protocol 2]
2019-12-19 23:17:44 - [INFO] receive: 514 [pulselength 382, protocol 1]
2019-12-19 23:17:44 - [INFO] receive: 128 [pulselength 380, protocol 1]
2019-12-19 23:17:45 - [INFO] receive: 1540 [pulselength 380, protocol 1]
2019-12-19 23:17:45 - [INFO] receive: 1990 [pulselength 380, protocol 1]
2019-12-19 23:17:45 - [INFO] receive: 2082 [pulselength 381, protocol 1]
2019-12-19 23:17:45 - [INFO] receive: 4 [pulselength 530, protocol 1]
2019-12-19 23:17:45 - [INFO] receive: 1152 [pulselength 381, protocol 1]
2019-12-19 23:17:45 - [INFO] receive: 130 [pulselength 380, protocol 1]
2019-12-19 23:17:45 - [INFO] receive: 2 [pulselength 378, protocol 1]
2019-12-19 23:17:45 - [INFO] receive: 256 [pulselength 380, protocol 1]
2019-12-19 23:17:45 - [INFO] receive: 64 [pulselength 1323, protocol 2]
2019-12-19 23:17:45 - [INFO] receive: 32 [pulselength 381, protocol 1]
2019-12-19 23:17:46 - [INFO] receive: 512 [pulselength 1187, protocol 2]
2019-12-19 23:17:46 - [INFO] receive: 1088 [pulselength 382, protocol 1]
2019-12-19 23:17:46 - [INFO] receive: 221 [pulselength 384, protocol 1]
2019-12-19 23:17:46 - [INFO] receive: 4096 [pulselength 2069, protocol 4]
2019-12-19 23:17:46 - [INFO] receive: 4 [pulselength 382, protocol 1]
2019-12-19 23:17:46 - [INFO] receive: 1 [pulselength 1214, protocol 2]
2019-12-19 23:17:47 - [INFO] receive: 2 [pulselength 389, protocol 1]
2019-12-19 23:17:47 - [INFO] receive: 546 [pulselength 383, protocol 1]
2019-12-19 23:17:47 - [INFO] receive: 1280 [pulselength 382, protocol 1]
2019-12-19 23:17:47 - [INFO] receive: 8 [pulselength 391, protocol 1]
2019-12-19 23:17:47 - [INFO] receive: 256 [pulselength 382, protocol 1]
2019-12-19 23:17:47 - [INFO] receive: 1024 [pulselength 382, protocol 1]
2019-12-19 23:17:48 - [INFO] receive: 384 [pulselength 382, protocol 1]
2019-12-19 23:17:48 - [INFO] receive: 2048 [pulselength 382, protocol 1]
2019-12-19 23:17:48 - [INFO] receive: 32 [pulselength 386, protocol 1]
2019-12-19 23:17:48 - [INFO] receive: 1152 [pulselength 381, protocol 1]
2019-12-19 23:17:48 - [INFO] receive: 4 [pulselength 383, protocol 1]
2019-12-19 23:17:48 - [INFO] receive: 642 [pulselength 385, protocol 1]
2019-12-19 23:17:48 - [INFO] receive: 512 [pulselength 384, protocol 1]
2019-12-19 23:17:49 - [INFO] receive: 512 [pulselength 383, protocol 1]
2019-12-19 23:17:49 - [INFO] receive: 1 [pulselength 1977, protocol 4]
2019-12-19 23:17:49 - [INFO] receive: 576 [pulselength 168, protocol 3]
2019-12-19 23:17:49 - [INFO] receive: 2 [pulselength 1197, protocol 2]
2019-12-19 23:17:49 - [INFO] receive: 226 [pulselength 381, protocol 1]
2019-12-19 23:17:49 - [INFO] receive: 804 [pulselength 378, protocol 1]
2019-12-19 23:17:49 - [INFO] receive: 256 [pulselength 397, protocol 1]
2019-12-19 23:17:49 - [INFO] receive: 64 [pulselength 437, protocol 1]
2019-12-19 23:17:49 - [INFO] receive: 2 [pulselength 382, protocol 1]
2019-12-19 23:17:49 - [INFO] receive: 2084 [pulselength 384, protocol 1]
2019-12-19 23:17:50 - [INFO] receive: 128 [pulselength 384, protocol 1]
2019-12-19 23:17:50 - [INFO] receive: 256 [pulselength 384, protocol 1]
2019-12-19 23:17:50 - [INFO] receive: 4 [pulselength 384, protocol 1]
2019-12-19 23:17:50 - [INFO] receive: 128 [pulselength 393, protocol 1]
2019-12-19 23:17:50 - [INFO] receive: 1284 [pulselength 384, protocol 1]
2019-12-19 23:17:50 - [INFO] receive: 64 [pulselength 385, protocol 1]
2019-12-19 23:17:50 - [INFO] receive: 258 [pulselength 384, protocol 1]
2019-12-19 23:17:50 - [INFO] receive: 512 [pulselength 386, protocol 1]
2019-12-19 23:17:50 - [INFO] receive: 1092 [pulselength 384, protocol 1]
2019-12-19 23:17:50 - [INFO] receive: 8 [pulselength 848, protocol 5]
2019-12-19 23:17:50 - [INFO] receive: 4 [pulselength 378, protocol 1]
2019-12-19 23:17:51 - [INFO] receive: 1058 [pulselength 386, protocol 1]
2019-12-19 23:17:51 - [INFO] receive: 770 [pulselength 380, protocol 1]
2019-12-19 23:17:51 - [INFO] receive: 256 [pulselength 385, protocol 1]
2019-12-19 23:17:51 - [INFO] receive: 768 [pulselength 392, protocol 1]
2019-12-19 23:17:51 - [INFO] receive: 64 [pulselength 385, protocol 1]
2019-12-19 23:17:51 - [INFO] receive: 64 [pulselength 385, protocol 1]
2019-12-19 23:17:51 - [INFO] receive: 584 [pulselength 384, protocol 1]
2019-12-19 23:17:51 - [INFO] receive: 64 [pulselength 385, protocol 1]
2019-12-19 23:17:51 - [INFO] receive: 2 [pulselength 384, protocol 1]
2019-12-19 23:17:51 - [INFO] receive: 5 [pulselength 167, protocol 3]
2019-12-19 23:17:52 - [INFO] receive: 4 [pulselength 389, protocol 1]
2019-12-19 23:17:52 - [INFO] receive: 8 [pulselength 852, protocol 5]
2019-12-19 23:17:52 - [INFO] receive: 1284 [pulselength 385, protocol 1]
2019-12-19 23:17:52 - [INFO] receive: 128 [pulselength 386, protocol 1]
2019-12-19 23:17:52 - [INFO] receive: 546 [pulselength 402, protocol 1]
2019-12-19 23:17:52 - [INFO] receive: 576 [pulselength 381, protocol 1]
2019-12-19 23:17:52 - [INFO] receive: 34 [pulselength 378, protocol 1]
2019-12-19 23:17:52 - [INFO] receive: 64 [pulselength 968, protocol 5]
2019-12-19 23:17:53 - [INFO] receive: 256 [pulselength 383, protocol 1]
2019-12-19 23:17:53 - [INFO] receive: 770 [pulselength 380, protocol 1]
2019-12-19 23:17:54 - [INFO] receive: 8 [pulselength 382, protocol 1]
2019-12-19 23:17:54 - [INFO] receive: 64 [pulselength 186, protocol 3]
2019-12-19 23:17:54 - [INFO] receive: 32 [pulselength 403, protocol 1]
2019-12-19 23:17:54 - [INFO] receive: 192 [pulselength 386, protocol 1]
2019-12-19 23:17:54 - [INFO] receive: 512 [pulselength 167, protocol 3]
2019-12-19 23:17:54 - [INFO] receive: 66 [pulselength 385, protocol 1]
2019-12-19 23:17:54 - [INFO] receive: 64 [pulselength 855, protocol 5]
2019-12-19 23:17:54 - [INFO] receive: 256 [pulselength 386, protocol 1]
2019-12-19 23:17:54 - [INFO] receive: 64 [pulselength 383, protocol 1]
2019-12-19 23:17:55 - [INFO] receive: 512 [pulselength 1191, protocol 2]
2019-12-19 23:17:55 - [INFO] receive: 1024 [pulselength 387, protocol 1]
2019-12-19 23:17:55 - [INFO] receive: 128 [pulselength 1998, protocol 4]
2019-12-19 23:17:55 - [INFO] receive: 16 [pulselength 932, protocol 5]
2019-12-19 23:17:55 - [INFO] receive: 1024 [pulselength 386, protocol 1]
2019-12-19 23:17:55 - [INFO] receive: 1536 [pulselength 385, protocol 1]
2019-12-19 23:17:55 - [INFO] receive: 1280 [pulselength 386, protocol 1]
2019-12-19 23:17:55 - [INFO] receive: 1568 [pulselength 387, protocol 1]
2019-12-19 23:17:56 - [INFO] receive: 32 [pulselength 382, protocol 1]
2019-12-19 23:17:56 - [INFO] receive: 832 [pulselength 381, protocol 1]
2019-12-19 23:17:57 - [INFO] receive: 512 [pulselength 382, protocol 1]
2019-12-19 23:17:57 - [INFO] receive: 1024 [pulselength 380, protocol 1]
2019-12-19 23:17:57 - [INFO] receive: 32 [pulselength 385, protocol 1]
2019-12-19 23:17:57 - [INFO] receive: 1540 [pulselength 383, protocol 1]
2019-12-19 23:17:57 - [INFO] receive: 34 [pulselength 384, protocol 1]
2019-12-19 23:17:58 - [INFO] receive: 10 [pulselength 386, protocol 1]
2019-12-19 23:17:58 - [INFO] receive: 770 [pulselength 385, protocol 1]
2019-12-19 23:17:58 - [INFO] receive: 64 [pulselength 415, protocol 1]
2019-12-19 23:17:58 - [INFO] receive: 1024 [pulselength 386, protocol 1]
2019-12-19 23:17:58 - [INFO] receive: 832 [pulselength 386, protocol 1]
2019-12-19 23:17:58 - [INFO] receive: 1024 [pulselength 387, protocol 1]
2019-12-19 23:17:58 - [INFO] receive: 1056 [pulselength 387, protocol 1]
2019-12-19 23:17:58 - [INFO] receive: 46 [pulselength 387, protocol 1]
2019-12-19 23:17:58 - [INFO] receive: 64 [pulselength 387, protocol 1]
2019-12-19 23:17:58 - [INFO] receive: 32 [pulselength 857, protocol 5]
2019-12-19 23:17:59 - [INFO] receive: 4 [pulselength 386, protocol 1]
2019-12-19 23:17:59 - [INFO] receive: 256 [pulselength 856, protocol 5]
2019-12-19 23:17:59 - [INFO] receive: 256 [pulselength 170, protocol 3]
2019-12-19 23:17:59 - [INFO] receive: 512 [pulselength 387, protocol 1]
2019-12-19 23:17:59 - [INFO] receive: 10 [pulselength 387, protocol 1]
2019-12-19 23:17:59 - [INFO] receive: 64 [pulselength 386, protocol 1]
2019-12-19 23:17:59 - [INFO] receive: 128 [pulselength 166, protocol 3]

With RFSniffer included with 433Utils I don't get anything, empty results.

How do I interpret these answers?

Can't start at boot up

What is the way to start the 3rd script at boot up. I used "crontab" but it is not working

Long range advice

Need your help/advice

Hi, I am still a bit of a noob with python and have managed to get the rpi-rf_receive.py to work.
So i have edited it as follows.
But I am having trouble working out how to add a debounce function.

#!/usr/bin/env python3

import argparse
import signal
import sys
import time
import logging
#from threading import Timer

from rpi_rf import RFDevice

rfdevice = None
debounce = 10

# pylint: disable=unused-argument
def exithandler(signal, frame):
    rfdevice.cleanup()
    sys.exit(0)

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='Receives a decimal code via a 433/315MHz GPIO device')
parser.add_argument('-g', dest='gpio', type=int, default=27,
                    help="GPIO pin (Default: 27)")
args = parser.parse_args()

signal.signal(signal.SIGINT, exithandler)
rfdevice = RFDevice(args.gpio)
rfdevice.enable_rx()
timestamp = None
now = time.time()-debounce
#logging.info("Listening for codes on GPIO " + str(args.gpio))
print(timestamp)
while True:
    if rfdevice.rx_code_timestamp != timestamp:
        timestamp = rfdevice.rx_code_timestamp
        print(timestamp)
        if ((str(rfdevice.rx_code) == '3764961')):
            print("yay")

#        logging.info(str(rfdevice.rx_code) +
#                     " [pulselength " + str(rfdevice.rx_pulselength) +
#                     ", protocol " + str(rfdevice.rx_proto) + "]")
    time.sleep(0.01)
rfdevice.cleanup()

The output if i keep the remote button down is

172923606303
yay
172923698146
yay
172923790101

What format are the numbers from line 38 print(timestamp) ???
I made some changes that did not work below.

#!/usr/bin/env python3

import argparse
import signal
import sys
import time
import logging
#from threading import Timer

from rpi_rf import RFDevice
#print(RFDevice)
rfdevice = None
debounce = 100000000000


#t = time.localtime()
#current_time = time.time()
#print(current_time)

# pylint: disable=unused-argument
def exithandler(signal, frame):
    rfdevice.cleanup()
    sys.exit(0)

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='Receives a decimal code via a 433/315MHz GPIO device')
parser.add_argument('-g', dest='gpio', type=int, default=27,
                    help="GPIO pin (Default: 27)")
args = parser.parse_args()

signal.signal(signal.SIGINT, exithandler)
rfdevice = RFDevice(args.gpio)
rfdevice.enable_rx()
timestamp = None
oldtime = time.time()
#print(oldtime)
#logging.info("Listening for codes on GPIO " + str(args.gpio))
#print(timestamp)
#start_time = time.time()


while True:
    if rfdevice.rx_code_timestamp != timestamp:
        timestamp = rfdevice.rx_code_timestamp
        print(timestamp)
        print(debounce)
#        print(rfdevice.rx_code_timestamp)
        if timestamp <= debounce:
            if ((str(rfdevice.rx_code) == '3764961')):
                print("yay")

#        logging.info(str(rfdevice.rx_code) +
#                     " [pulselength " + str(rfdevice.rx_pulselength) +
#                     ", protocol " + str(rfdevice.rx_proto) + "]")
    time.sleep(0.01)
rfdevice.cleanup()

There must be a way to display "yay" only once and ignore or sleep but in a thread the rest of the duplicate inputs.
Or if It is easier to make it respond to long press differently to short press.
Well any way can someone help me get the code right please.
Thanks in advance

send error

python3.6 rpi-rf_send 123456
/usr/local/lib/python3.6/site-packages/rpi_rf/rpi_rf.py:77: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(self.gpio, GPIO.OUT)
2018-08-23 09:53:36 - [INFO] rpi-rf_send: 123456 [protocol: default, pulselength: default, length: default, repeat: 10]
Traceback (most recent call last):
File "rpi-rf_send", line 49, in
rfdevice.tx_code(args.code, args.protocol, args.pulselength, args.length)
TypeError: tx_code() takes from 2 to 4 positional arguments but 5 were given

function's arguments mismatch

it happens when installing via 'pip3 install rpi-rf',

in module rpi_rf.py, function tx_code takes only 3 arguments. (different from the latest code version here)
while rpi-rf_send.py sends to the function 4 arguments (the arg.length does not exist in rpi_rf.py if installing with pip3 install rpi-rf)

SYSFS?

Could this theoretically be built with SYSFS? That would remove the dependency on RPi.GPIO.

Projector screen

Greeting,
Thanks for all the support you give us. My question is I’m trying to control projector motor but I’m getting to many codes I tried all of them none was controlling my projector screen .I’m stuck

Providing Code to Parameter

I am obviously a noob but when passing the sniffed rf code as a string (see below) I get the following error:

parser.add_argument('4543795', metavar='CODE', type=int,
help="Decimal code to send")

Error: 'the following arguments are required CODE"

What am I doing incorrectly?

RPI 3B+

Sending is not working on 3B+, i made sure the hardware is fine by using the same Tx with a 2B, with (code ver 0.9.6).
But neither version 0.9.6 nor 0.9.7 are transmitting for 3B+
Receive works fine.

Python 2.7 compatibility fix

i am using this module on Libreelec on RPI3. The lightweight system behind KODI has only python 2.7. I sneak for a while and found solution to run this library on this older python. problem is int vs float:

line 176
self._sleep((highpulses * self.tx_pulselength) / 1000000)

update:
self._sleep((float(highpulses) * self.tx_pulselength) / 1000000)

the same fix on line 178.

problem: python 2.7 result of this calculations is always 0. the results should be for example 0.00035. without float is unreal.

worker for me to send commands.

Lots of noise versus 433Utils version...

I'm trying to run the Raspberry Pi GPIO RF Switch component on home-assistant but when trying to use rpi-rf_recieve, I get lots of noise when pressing down the remote button...

pi@raspberrypi:~ $ sudo rpi-rf_receive
2016-12-31 16:50:06 - [INFO] rpi-rf_receive: 505568 [pulselength 79, protocol 3]
2016-12-31 16:50:06 - [INFO] rpi-rf_receive: 243428 [pulselength 80, protocol 3]
2016-12-31 16:50:06 - [INFO] rpi-rf_receive: 131136 [pulselength 398, protocol 5]
2016-12-31 16:50:06 - [INFO] rpi-rf_receive: 521967 [pulselength 81, protocol 3]
2016-12-31 16:50:06 - [INFO] rpi-rf_receive: 505568 [pulselength 80, protocol 3]
2016-12-31 16:50:06 - [INFO] rpi-rf_receive: 131072 [pulselength 411, protocol 5]
2016-12-31 16:50:06 - [INFO] rpi-rf_receive: 15 [pulselength 80, protocol 3]
2016-12-31 16:50:06 - [INFO] rpi-rf_receive: 505568 [pulselength 79, protocol 3]

Here's what I get with RFSniffer included with 433Utils...

pi@raspberrypi:~/433Utils/RPi_utils $ sudo ./RFSniffer
Received 4543804
Received 4543804
Received 4543804
Received 4543804
Received 4543804
Received 4543804
Received 4543804

Likewise when sending the code via rpi-rf_send nothing happens, but it works with 433Utils send command.

Any help would be greatly appreciated!

Long key press help / advice

Hi I've been trying all sorts of different approaches to be able to differentiate between a long key press and a short one. I can't seem to be able to get it right as in working like i want.
This is the code i'm trying at the moment.

#!/usr/bin/env python3
import time
from rpi_rf import RFDevice
rfdevice = None
rfdevice = RFDevice(gpio=27)
rfdevice.enable_rx()
big_button = 3764961
rfdevice.rx_callback(gpio=27)
timestamp = None
# timestamp2 = time.perf_counter()
def rfff():
    print(str(rfdevice.rx_code) + " [pulselength " + str(rfdevice.rx_pulselength) +", protocol " + str(rfdevice.rx_proto) + "]")

while True:
    
#    rfff()
    if rfdevice.rx_code_timestamp != timestamp:
        timestamp = rfdevice.rx_code_timestamp
        command = (str(rfdevice.rx_code))
        t = time.time()
        if command == '3764961':
            print("yay")
            timestamp2 = time.perf_counter()
            elapsed =  timestamp - timestamp2
            time_taken = round(time.time() - t, 2) #rounding the long decimal float
            print(time_taken,'seconds')


#            print("elapsed" ,  elapsed)

    #    print("time" ,  timestamp)
    #    if ((str(rfdevice.rx_code) == '3764961')):
#            timestamp2 = rfdevice.rx_code_timestamp
    #        print("time 2" ,  timestamp2)
    #        elapsed =  timestamp - timestamp2
    #        print("elapsed" ,  elapsed)
    #        print(str(rfdevice.rx_code))

    time.sleep(0.50)

But the output is not helping

yay
0.0 seconds
yay
0.0 seconds

Why is it showing 0.0 ??
I want it to do something when Long hey press is detected
and something else when short key is pressed

Help with protocol difference

Everything is working on my RPI!
I get answers like:
6144 [pulselength 414, protocol 1]
or
6034319 [pulselength 204, protocol 3]

but on my Arduino with the same receiver, I only get things
from protocol 1 and 2.

does anyone know the difference between 1 2 vs 3?

thanks

send.py disables other remote controls

Hi

I encountered an issue with the python send script, described below. My workaround works for me. Nevertheless, you may consider to modify the script.

Cheers

Al_

Problem statement:
After successfully installing and testing a cheap, no-name 433 MHz sender (attached to RPi 3, raspbian / stretch) to switch a relais, several completely independent hand-held remote controls (for the garage door and for blinds) stopped working.

Identifying the issue:

  • After a fresh RPi reboot, the hand-held remote controls function properly.
  • Once I have sent a command to the relais using the python send script, the hand-held remote controls permanently no longer function (failure confirmed over more than 24 hours)
  • If I unplug the signal pin (in my case gpio 27), the hand-held remote controls again function correctly. Same if I unplug the power from the 433 MHz sender.

I expect that the 433 MHz sender continuously sends noise interfering with other remote controls using the same frequency. I further expect that this happens because the python send script leaves gpio 27 on '1' or undefined (in which case it may fluctuate between '0' and '1' in the absence of a pull-down resistor)

Workaround:
I wrap the call to the python send script in the bash script shown below. This solves the issue for me.

#!/bin/bash

#  -g GPIO         GPIO pin (Default: 17)
#  -p PULSELENGTH  Pulselength (Default: 350)
#  -t PROTOCOL     Protocol (Default: 1)

declare -r -i gpio=27

echo "executing as $( whoami )"

[ -d "/sys/class/gpio/gpio${gpio}" ] && echo ${gpio} > /sys/class/gpio/unexport && echo "unexported ${gpio} to /sys/class/gpio/"

~/send_433MHz.py -g ${gpio} -p 318 -t 1 $1

# it seems that the GPIO pin and/or the 433 MHz sender is not properly closed
# --> force GPIO pin to 0 (hoping that it is the pin, not the sender itself)
[ -d "/sys/class/gpio/gpio${gpio}" ] || echo ${gpio} > /sys/class/gpio/export && echo "exported ${gpio} to /sys/class/gpio/"
sleep 3s   # something, possibly udev rule, takes time to set the owner:group on /sys/class/gpio/gpio${gpio}/*
ls -lA /sys/class/gpio/gpio${gpio}/direction
echo "out" > /sys/class/gpio/gpio${gpio}/direction
ls -lA /sys/class/gpio/gpio${gpio}/value
echo 0 > /sys/class/gpio/gpio${gpio}/value

Suggestion
To modify the python script and force the signal gpio pin to '0' before ending the script.

Misleading var names and log messages GPIO mode

In various parts of the code the lib uses the label gpio

# rpi-rf_receive
logging.info("Listening for codes on GPIO " + str(args.gpio))
# rpi_rf.py
class RFDevice:
    def __init__(self, ...):
        #...
        _LOGGER.debug("Using GPIO " + str(gpio))

but actually in the code of RFDevice it sets the GPIO in mode BCM

GPIO.setmode(GPIO.BCM)

This is kind of misleading.

receive codes seem incorrect

Hello,
I'm new to rpi-rf and RF. I am trying to figure out how to print out the correct codes. Perhaps I just don't understand how to use the library.

Here is what I am sending:
python3.6 rpi-rf_send.py 2048 -p 771 -t 5

Here are some of the responses I am getting:
2018-08-22 17:54:36 - [INFO] rpi-rf_receive: 6 [pulselength 770, protocol 5]
2018-08-22 17:54:36 - [INFO] rpi-rf_receive: 1 [pulselength 805, protocol 5]
2018-08-22 17:54:40 - [INFO] rpi-rf_receive: 64 [pulselength 1963, protocol 4]

Why is the receive displaying different random responses than what I am sending?

I would like to be able to do something like this on the receive side:
if code == 123:
do something
elif code == 456:
do something else
else:
do something amazing

I haven't quite figured out how to get "code" on the receiving end.

Thanks.

Aleko sliding gate keyfob signal analysis for new protocol

hope someone can use this info to create a new protocol or help me create one for Aleko keyfobs. these have a HCS301
Aleko sliding gate key fob signal analysis:
50% signal preamble = 390us ~ 400us each step = Te (matches specs of HCS301)
total preamble = 9055us (a 23Te 50% cycle wave) (23Te=9200us per spec)
total low after preamble = 3960us (a 10Te pause) (10Te = 10*400 = 4000 per spec)
zero = 2 highs, 1 low (1te each step)
one = 1 high, 2 lows (1te each step)

Some traces using piscope(ignore last bit for now since its to mark repeats):
101011111000011111110100100010101110111011100000101111101010010011<-has noise error
000111010111111100100011011010111110111011111000101111101010010011
000111010111111100100011011010111110111011111000101111101010010011

The leyend I used below doesn't sync on here, but maybe you can copy and paste to Spyder or Notepad to see the 1:1 correspontace of the 1's and 0's to the *,s,b,S etc markings
my rental house keyfob:
button A
100001010000000000110111001110011110111011111000101111100110010011
100001010000000000110111001110011110111011111000101111101010010011
100001010000000000110111001110011110111011111000101111101010010011
button B
010111000010101110011010110011011110111011111000101111101010001011
010111000010101110011010110011011110111011111000101111101010001011
********************************ssssssssssssssssssssssssssssbbbbSS
*-encrypted bits
s-serial code
b-button
SS-status

same rental house keyfob again(d= delta, s= same as before):
button A
010110110010111100110011001101111110111011111000101111101010010011
100001010000000000110111001110011110111011111000101111101010010011<-previous run
dddddddddddddddddddddddddddddddsssssssssssssssssssssssssssssssssss
button B
100010010000111100010100010011111110111011111000101111101010001011
010111000010101110011010110011011110111011111000101111101010001011<-previous run
dddddddddddddddddddddddddddddddsssssssssssssssssssssssssssssssssss

seems like the encrypted portion ends in a 1 each time

button C
111100111010110110010000010000101110111011111000101111101010001111
111100111010110110010000010000101110111011111000101111101010001111
********************************ssssssssssssssssssssssssssssbbbbSS
button D
100011111011011000000011101101111110111011111000101111101010000111
100011111011011000110111101101111110111011111000101111101010000111
********************************ssssssssssssssssssssssssssssbbbbSS

buttons A to D
0100
0010
0011
0001

the last two bits are for battery low in voltage and code repeated
it seems that when you press the button it always repeats the same
code until you depress it. Vlow is 0 at 6.6volts 1 at 13v.
Confirmed that code repeat is 0 the first message, 1 the rest of the
repeats.

Reduce CPU usage

Hi there!
Is there way to reduce CPU usage on rpi zero since receive script use about 50%-75% cpu power?
I want to use rf receiver script on a battery powered project so cpu usage is important for me.
Playing with sleep time in the main loop does not helps a lot for me :(
cpu

RPI 4 installation not working

I am unable to install this library like usual using pip3 install rpi-rf.
Everything was updated via apt-get prior to installation.

System:
HASSIO
Raspberry Pi 4
python3 --version: Python 3.8.8

➜ ~ pip3 install rpi-rf
Collecting rpi-rf
Using cached rpi_rf-0.9.7-py3-none-any.whl (7.4 kB)
Collecting RPi.GPIO
Using cached RPi.GPIO-0.7.0.tar.gz (30 kB)
Using legacy 'setup.py install' for RPi.GPIO, since package 'wheel' is not installed.
Installing collected packages: RPi.GPIO, rpi-rf
Running setup.py install for RPi.GPIO ... error
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-izinf4wv/rpi-gpio_5bd48e3eebb8478784dbc3c77164ece7/setup.py'"'"'; file='"'"'/tmp/pip-install-izinf4wv/rpi-gpio_5bd48e3eebb8478784dbc3c77164ece7/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record /tmp/pip-record-e7_x1af0/install-record.txt --single-version-externally-managed --compile --install-headers /usr/include/python3.8/RPi.GPIO
cwd: /tmp/pip-install-izinf4wv/rpi-gpio_5bd48e3eebb8478784dbc3c77164ece7/
Complete output (19 lines):
running install
running build
running build_py
creating build
creating build/lib.linux-aarch64-3.8
creating build/lib.linux-aarch64-3.8/RPi
copying RPi/init.py -> build/lib.linux-aarch64-3.8/RPi
creating build/lib.linux-aarch64-3.8/RPi/GPIO
copying RPi/GPIO/init.py -> build/lib.linux-aarch64-3.8/RPi/GPIO
running build_ext
building 'RPi._GPIO' extension
creating build/temp.linux-aarch64-3.8
creating build/temp.linux-aarch64-3.8/source
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -g -fno-semantic-interposition -g -fno-semantic-interposition -g -fno-semantic-interposition -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/usr/include/python3.8 -c source/py_gpio.c -o build/temp.linux-aarch64-3.8/source/py_gpio.o
source/py_gpio.c:23:10: fatal error: Python.h: No such file or directory
23 | #include "Python.h"
| ^~~~~~~~~~
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-izinf4wv/rpi-gpio_5bd48e3eebb8478784dbc3c77164ece7/setup.py'"'"'; file='"'"'/tmp/pip-install-izinf4wv/rpi-gpio_5bd48e3eebb8478784dbc3c77164ece7/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record /tmp/pip-record-e7_x1af0/install-record.txt --single-version-externally-managed --compile --install-headers /usr/include/python3.8/RPi.GPIO Check the logs for full command output.

Not receiving from any RF remote

Hey everyone,
So my last project was to do what is described on this brush bruh automation video(albeit with rf shades instead of plugs):
https://www.youtube.com/watch?v=5UUazFbK-Hg&t
However, when I get to "sniffing" the codes from my rf remote, it doesn't really work. I press the button on my controller while running the rfrx.py/RFSniffer/rpi-rf_receive(Sniffs on GPIO 27) script and nothing happens, it does record some random codes, but they're not the ones being sent from my remote
When I deploy codes from my transmitter, however, it does seem to be receiving them on the rfrx.py/RFSniffer/rpi-rf_receive script, which leads me to believe it's working properly.
http://imgur.com/a/DnfgD
This is how I have the pi wired:
http://imgur.com/a/mTQHE
and one of the controllers I'm trying to emulate:
http://imgur.com/a/f87PL
I've already tried everything I could think so without much success, so if anyone has any guidance I'd appreciate it!
Also just realized that if I send through the transmitter a code 10 digits long, it won't show on the receiving side

Using rpi-rf with OrangePI

HI everybody,

Could I use this python package rpi-rf with an Orange Pi, because Orange Pi works with raspbian, and other SO that are compatible with Raspberry.

Is there another Python Module to use in OrangePi which be able to read the rf433 Mhz.

I appreciate your help

Max number of bits sent?

Hi,

The sniffer detects a 10-digit (essentially, 32 bit) code coming from my remote. I have tried sending this signal over the transmitter to no avail. I suspect this is due to the tx_code method defined for the RFDevice class.

Specifically, I suspect the problem lies within line 105, wich reads:

rawcode = format(code, '#0{}b'.format(self.tx_length + 2))[2:]

tx_length gets a value of 24 by default. Which I think means the binary code transmitted is limited to 24 bits (not enough to transmit my code).

Before I make any experimentation (partly due to the fact that I don't have acces to my Raspberry Pi at the moment) I wanted to ask if this makes any sense and if changing the default value of tx_length to something greater will help my cause.

Thanks in advance!

Wiring diagram

Hi Milaq,

could you please provide a wiring diagram, how to set things up?
Would make it a lot easier for us.
Thank you,
Ted

Problems when running within a docker container

I have problems with send and/or receive within a docker container. There seems to be some kind of timing problem.

First I tried to receive the original remote:

# rpi-rf_receive
2018-01-23 22:35:28 - [INFO] rpi-rf_receive: 3045422 [pulselength 102, protocol 3]

And then I tried to send and receive the same code by myself:

# rpi-rf_send -t 3 -p 102 3045422
2018-01-23 22:39:42 - [INFO] rpi-rf_send: 3045422 [protocol: 3, pulselength: 102]
# rpi-rf_receive
2018-01-23 22:39:17 - [INFO] rpi-rf_receive: 3045422 [pulselength 530, protocol 5]

Is there any similar problem known? How can I identify and send the correct pulselength?

Doesn't work in RPi1

I have a Raspberry Pi 1 Model B.

I tried to send codes via codesend from https://github.com/ninjablocks/433Utils and it works.
If I try to do the exact same thing (same GPIO, protocol, pulselength, and code) it doesn't.

Can't tell why. Maybe RPi.GPIO is broken, but I don't think so.

Chris

Support for C.H.I.P.

Hi,

First of all, great library! I use it to control my porch light through a component in Home Assitant. I recently migrated my setup from a RPi to a C.H.I.P. and noticed that this package does not work anymore. This because RPi.GPIO of course only works on a RPi. However there is a (almost) drop-in replacement for this dependency called CHIP_IO. The only method that CHIP_IO seems to lack is GPIO.setmode.

With this patch a got the library working on the C.H.I.P.:

diff --git a/rpi_rf/rpi_rf.py b/rpi_rf/rpi_rf.py
index 3949169..72c1e70 100644
--- a/rpi_rf/rpi_rf.py
+++ b/rpi_rf/rpi_rf.py
@@ -6,7 +6,10 @@ import logging
 import time
 from collections import namedtuple

-from RPi import GPIO
+try:
+    from RPi import GPIO
+except:
+    from CHIP_IO import GPIO

 MAX_CHANGES = 67

@@ -54,8 +57,11 @@ class RFDevice:
         self.rx_proto = None
         self.rx_bitlength = None
         self.rx_pulselength = None
-
-        GPIO.setmode(GPIO.BCM)
+        # the method 'setmode' is not available in CHIP_IO.GPIO
+        try:
+            GPIO.setmode(GPIO.BCM)
+        except:
+            pass
         _LOGGER.debug("Using GPIO " + str(gpio))

     def cleanup(self):

If you are willing to add support for C.H.I.P. I could make a PR out of this patch.

Cheers!

RPI 3B installation not working

I am unable to install this library like usual using pip3 install rpi-rf.
Everything was updated via apt-get prior to installation.

System:
Raspberry Pi 3B
python3 --version: Python 3.4.2

Error:

pip3 install rpi-rf
Collecting rpi-rf
  Using cached https://files.pythonhosted.org/packages/e8/b4/092c00607f8e12670c0ac8cb9d4ec495952726105cc36c879825151630bf/rpi_rf-0.9.7-py3-none-any.whl
Collecting RPi.GPIO (from rpi-rf)
  Using cached https://files.pythonhosted.org/packages/af/2f/407b6e4cc8a0bdf434825a160bba1807991886b63cce16a5f1a6e1f24cdf/RPi.GPIO-0.6.5.tar.gz
Building wheels for collected packages: RPi.GPIO
  Running setup.py bdist_wheel for RPi.GPIO ... error
  Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-l9zpqsk3/RPi.GPIO/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-gjlff0r9 --python-tag cp34:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-armv7l-3.4
  creating build/lib.linux-armv7l-3.4/RPi
  copying RPi/__init__.py -> build/lib.linux-armv7l-3.4/RPi
  creating build/lib.linux-armv7l-3.4/RPi/GPIO
  copying RPi/GPIO/__init__.py -> build/lib.linux-armv7l-3.4/RPi/GPIO
  running build_ext
  building 'RPi._GPIO' extension
  creating build/temp.linux-armv7l-3.4
  creating build/temp.linux-armv7l-3.4/source
  arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.4m -c source/py_gpio.c -o build/temp.linux-armv7l-3.4/source/py_gpio.o
  source/py_gpio.c:23:20: fatal error: Python.h: No such file or directory
   #include "Python.h"
                      ^
  compilation terminated.
  error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for RPi.GPIO
  Running setup.py clean for RPi.GPIO
Failed to build RPi.GPIO
Installing collected packages: RPi.GPIO, rpi-rf
  Running setup.py install for RPi.GPIO ... error
    Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-l9zpqsk3/RPi.GPIO/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-y94z120n/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-armv7l-3.4
    creating build/lib.linux-armv7l-3.4/RPi
    copying RPi/__init__.py -> build/lib.linux-armv7l-3.4/RPi
    creating build/lib.linux-armv7l-3.4/RPi/GPIO
    copying RPi/GPIO/__init__.py -> build/lib.linux-armv7l-3.4/RPi/GPIO
    running build_ext
    building 'RPi._GPIO' extension
    creating build/temp.linux-armv7l-3.4
    creating build/temp.linux-armv7l-3.4/source
    arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.4m -c source/py_gpio.c -o build/temp.linux-armv7l-3.4/source/py_gpio.o
    source/py_gpio.c:23:20: fatal error: Python.h: No such file or directory
     #include "Python.h"
                        ^
    compilation terminated.
    error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-l9zpqsk3/RPi.GPIO/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-y94z120n/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-l9zpqsk3/RPi.GPIO/

Add support for pigpio

The pigpio library/daemon uses the DMA controller for very accurate hardware-based pin sampling and timestamping. This allows very exact reception (and probably also transmission, but I didn't look at that yet), unlike the GPIO-callbacks used now. Pigpio uses a daemon written in C that talks to the hardware, and exposes an interface using a TCP socket or FIFO/pipe, of which the former is used by a python wrapper they also provide.

I did a very quick implementation of RX, which seems to work well. Here's what I get with the unmodified library:

2017-05-08 16:12:22 - [INFO] rpi-rf_receive: 5326161 [pulselength 321, protocol 1]
2017-05-08 16:12:22 - [INFO] rpi-rf_receive: 5326161 [pulselength 320, protocol 1]
2017-05-08 16:12:22 - [INFO] rpi-rf_receive: 5326161 [pulselength 320, protocol 1]
2017-05-08 16:12:22 - [INFO] rpi-rf_receive: 5326161 [pulselength 319, protocol 1]

Here's what I get when using the unmodified library with apt-get update (or something similar with a moderate load) running in the background:

2017-05-08 16:16:42 - [INFO] rpi-rf_receive: 12288 [pulselength 706, protocol 5]
2017-05-08 16:16:42 - [INFO] rpi-rf_receive: 5326161 [pulselength 321, protocol 1]
2017-05-08 16:16:42 - [INFO] rpi-rf_receive: 8320 [pulselength 647, protocol 5]
2017-05-08 16:16:43 - [INFO] rpi-rf_receive: 5326161 [pulselength 323, protocol 1]
2017-05-08 16:16:43 - [INFO] rpi-rf_receive: 5326161 [pulselength 140, protocol 3]
2017-05-08 16:16:43 - [INFO] rpi-rf_receive: 5326161 [pulselength 327, protocol 1]
2017-05-08 16:16:43 - [INFO] rpi-rf_receive: 5326161 [pulselength 325, protocol 1]
2017-05-08 16:16:43 - [INFO] rpi-rf_receive: 8192 [pulselength 1652, protocol 4]
2017-05-08 16:16:43 - [INFO] rpi-rf_receive: 5326161 [pulselength 321, protocol 1]

When some big wget is running in the background (so lots of USB activity, I suspect), I get random output when not sending anything, and pretty much the same when sending something.

When using pigpio, the output is flawless, even with apt-get or wget running (though with wget, the output is delayed, probably because there's two different processes involved). I think this change would also solve #4.

I've attached my current patch below, to use it make sure to install pigpio first (there's a python3-pigpio Debian package) and run the daemon using pigpiod -g -l (-g: run in foreground, -l: local connections only).

This is just a prototype patch, to properly implement this the low-level I/O code should be separated from the decoding code so you can have multiple I/O backends (which makes this related to #3).

diff --git a/rpi_rf/rpi_rf.py b/rpi_rf/rpi_rf.py
index 3949169..bf65c43 100644
--- a/rpi_rf/rpi_rf.py
+++ b/rpi_rf/rpi_rf.py
@@ -6,7 +6,8 @@ import logging
 import time
 from collections import namedtuple

-from RPi import GPIO
+#from RPi import GPIO
+import pigpio

 MAX_CHANGES = 67

@@ -48,6 +49,7 @@ class RFDevice:
         self._rx_last_timestamp = 0
         self._rx_change_count = 0
         self._rx_repeat_count = 0
+        self._rx_handler = None
         # successful RX values
         self.rx_code = None
         self.rx_code_timestamp = None
@@ -55,7 +57,8 @@ class RFDevice:
         self.rx_bitlength = None
         self.rx_pulselength = None

-        GPIO.setmode(GPIO.BCM)
+        self.pigpio = pigpio.pi()
+
         _LOGGER.debug("Using GPIO " + str(gpio))

     def cleanup(self):
@@ -65,7 +68,6 @@ class RFDevice:
         if self.rx_enabled:
             self.disable_rx()
         _LOGGER.debug("Cleanup")
-        GPIO.cleanup()

     def enable_tx(self):
         """Enable TX, set up GPIO."""
@@ -164,24 +166,25 @@ class RFDevice:
             return False
         if not self.rx_enabled:
             self.rx_enabled = True
-            GPIO.setup(self.gpio, GPIO.IN)
-            GPIO.add_event_detect(self.gpio, GPIO.BOTH)
-            GPIO.add_event_callback(self.gpio, self.rx_callback)
+            self.pigpio.set_mode(self.gpio, pigpio.INPUT)
+            def callback(gpio, level, tick):
+                self.rx_callback(tick)
+            self._rx_handler = self.pigpio.callback(self.gpio, pigpio.EITHER_EDGE, callback)
             _LOGGER.debug("RX enabled")
         return True

     def disable_rx(self):
         """Disable RX, remove GPIO event detection."""
         if self.rx_enabled:
-            GPIO.remove_event_detect(self.gpio)
+            self._rx_handler.cancel();
+            self._rx_handler = None
             self.rx_enabled = False
             _LOGGER.debug("RX disabled")
         return True

     # pylint: disable=unused-argument
-    def rx_callback(self, gpio):
+    def rx_callback(self, timestamp):
         """RX callback for GPIO event detection. Handle basic signal detection."""
-        timestamp = int(time.perf_counter() * 1000000)
         duration = timestamp - self._rx_last_timestamp

         if duration > 5000:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.