RFSniffer, 433MHz receiver RPI and MQTT


(Josar) #1

I just wrote a small program which publishes the received codes from a 433Mhz receiver to a MQTT broker.

It is based on RFSniffer from ninjablocks and is best place besides RFSniffer in RPI_utils as there is a relative depency for the RCSwitch.h.

My setup has mosquitto installed on the rpi and also the MQTT binding in OpenHAB.

Using is as simple as usig the RPI_Utils. Follow the instructions from the readme or this thread help getting everything in place.

Then download the RFmqtt place it into the folder RPI_Utils, change the Makefile, and compile it.
(Follow the instruction in the Github folder.)

Then you can run the “RFmqtt”

Following the Instructions configuring the OpenHAB MQTT binding to use the default FRmqtt values.
mqtt.cfg

mymosquitto.url=tcp://localhost:1883
mymosquitto.user=admin
mymosquitto.pwd=password

setting up some items
.items

String MQTT_data "MQTT says: [%s]" {mqtt="<[mymosquitto:433MHz:state:default]"}
Switch MQTT_Remote

and something on my sitemap to see the received data.
.sitemap

Text item=MQTT_data 
Switch item= MQTT_Remote 

E viola pressing my remote i recieve the data on my sitemap.
(On my smartphone as somehow my Firefox still does not update the view, Edge does, Chrome alos doesn’t)

As i don`t know jet how to get e.g a swtich trigger when a spicific code was received, i take the route over a rule.
.rules

rule "433MHz RX"
  when
    Item MQTT_data changed
 then
    switch MQTT_data.state {
      case "1328465": MQTT_Remote.postUpdate(ON)
      case "1328468": MQTT_Remote.postUpdate(OFF)
    }
 end

If you only have one code which is send multiple times it will not trigger the rule multiple times as openhab only forwards changed statuses. At least i think so. So just reset the MQTT_data in the rule.

.rules

rule "433MHz RX"
  when
    Item MQTT_data changed
 then
    switch MQTT_data.state {
      case "1328465": MQTT_Remote.postUpdate(ON)
      case "1328468": MQTT_Remote.postUpdate(OFF)
    }
    if(MQTT_data.state.toString !="") MQTT_data.postUpdate("")
 end

Maybe this helps other people having fun with openhab.


Receiving 433mhz and send to sonoff switch
OpenHAB Exec Binding explained in detail on 433MHz radio transmitter example
(Ramy Rutu) #2

FIRST of all thanks a lot and much appreciated for your time Josar
i tried everything and nothing really change. I thing I have a problem because of the Door Sensor type I’m using ?!
here is what my files look like :

String MQTT_data "MQTT says: [%s]" {mqtt="<[mymosquitto:433MHz:state:default]"}


and my rules :

rule "433MHz RX"
  when
    Item MQTT_data received update
then
    switch MQTT_data.state {
      case "14756833": MQTT_Remote.postUpdate(ON)
      case "14756823": MQTT_Remote.postUpdate(OFF)
    }
end

my sitemaps :

sitemap home label="DoorSensor"

{
       Frame label="doorsensor"
       {
           Switch item=MQTT_Remote
           Text item=MQTT_data

       }
}

pi@raspberrypi:~/433Utils/RPi_utils $ ls
codesend  codesend.cpp  codesend.o  Makefile  README.md  RFmqtt.cpp  RFSniffer  RFSniffer.cpp  RFSniffer.o  send  send.cpp  send.o  wiringPi
pi@raspberrypi:~/433Utils/RPi_utils $


this is the door sensor I’m using : https://www.banggood.com/SONOFF-DW1-433Mhz-Door-Window-Sensor-Compatible-With-RF-Bridge-For-Smart-Home-Alarm-Security-p-1227800.html?gmcCountry=CA&currency=CAD&createTmp=1&cur_warehouse=CN&utm_source=googleshopping&utm_medium=cpc_elc&utm_content=zouzou&utm_campaign=pla-ca-elc2-pc-en&gclid=Cj0KCQiAnuDTBRDUARIsAL41eDo_otAuoYXgKRWfkFoHXfpPGJUAZfZYg8Q-OdfknEc-PqaPDN7VXuUaAiGZEALw_wcB

I checked the sensor in terminal and its working, its connected to gpio 27. I don’t have an off or on code I only have one code to receive when the door sensor magnet is not in place, code = 14756833


(Josar) #3

Do you receive data when running RFsniffer?

./RFSniffer

Do you recieve data when running RFmqtt?

./RFmqtt

If not you have to check you setup. You need the cables connected to the PI, VCC, GND and BMC27/WiringPi2.

Then did you set up Mosquitto and tried to send data from a client to a server in the commandline?

Did you set up the MQTT binding an can send something to the MQTT_data ? Can you see the MQTT binding receiving data in the log?

I miss MQTT_Remote in your items.

If this works, then you will need a rule which triggers on the command you receive.

rule "433MHz RX"
  when
    Item MQTT_data received update
then
    switch MQTT_data.state {
      case "14756833": MQTT_Remote.postUpdate(ON)
    }
end

Will the code be send in intervalls as long as it is open? Or only once?
Will the code be send when the door opens and closes?
Depending on this you will have to desing the rule.


(Ramy Rutu) #4

i do receive data when running RFSniffer

when I run RFmqtt I get this error :

pi@raspberrypi:~ $ sudo systemctl status rfmqtt.service
● rfmqtt.service - RF 433MHz to MQTT bridge
Loaded: loaded (/etc/systemd/system/rfmqtt.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2018-02-07 22:33:37 UTC; 30min ago
Main PID: 28309 (code=exited, status=203/EXEC)

Feb 07 22:33:36 raspberrypi systemd[1]: rfmqtt.service: Unit entered failed state.
Feb 07 22:33:36 raspberrypi systemd[1]: rfmqtt.service: Failed with result ‘exit-code’.
Feb 07 22:33:37 raspberrypi systemd[1]: rfmqtt.service: Service hold-off time over, scheduling
Feb 07 22:33:37 raspberrypi systemd[1]: Stopped RF 433MHz to MQTT bridge.
Feb 07 22:33:37 raspberrypi systemd[1]: rfmqtt.service: Start request repeated too quickly.
Feb 07 22:33:37 raspberrypi systemd[1]: Failed to start RF 433MHz to MQTT bridge.
Feb 07 22:33:37 raspberrypi systemd[1]: rfmqtt.service: Unit entered failed state.
Feb 07 22:33:37 raspberrypi systemd[1]: rfmqtt.service: Failed with result ‘exit-code’.
lines 1-13/13 (END)

I don’t know how to compile and when I try to use make or cmake I get this error : Makefile:7: *** missing separator (did you mean TAB instead of 8 spaces?). Stop.

MOSQUITTO its running and I have tested already using MQttfx for Windows
MQTT binding its installed

I think my compiling not done and I don’t know how and when I try to follow the steps on GitHub I get the error above when I use make


(Josar) #5

First, when you copy the makefile content make sure to have a tab instead of spaces. Then the compilation should work.

RFmqtt: ../rc-switch/RCSwitch.o RFmqtt.o
[This are no spaces it´s a tab]$(CXX) $(CXXFLAGS) $(LDFLAGS) $+ -o $@ -lwiringPi -lmosquitto

(Ramy Rutu) #7

Hey,
so I have been trying to solve my issue but I’m only getting more errors…

First : when I try to compile and install Cmake or make after going to bunch of missing librs, when I click make install I get this error here

-- Install configuration: ""
-- Up-to-date: /usr/local/doc/cmake-3.10.2/Copyright.txt
CMake Error at cmake_install.cmake:41 (file):
  file INSTALL cannot set permissions on
  "/usr/local/doc/cmake-3.10.2/Copyright.txt"


Makefile:73: recipe for target 'install' failed
make: *** [install] Error 1

``
that's after loading to 100%
than when I navigate to 433Utils/RPi_utils and than CD BUILD than 
cmake -GNinja .. i get this error 

CMake Error at CMakeLists.txt:4:
Parse error. Expected a newline, got identifier with text “set”.

– Configuring incomplete, errors occurred!

i am lost in this ... should i start again from scratch ?

here is what my files look like : 

pi@raspberrypi:~/433Utils/RPi_utils $ ls
build codesend README.md RFmqtt.o send
CMakeCache.txt codesend.cpp RFmqtt RFSniffer send.cpp
CMakeFiles codesend.o RFmqtt.cpp RFSniffer.cpp send.o
CMakeLists.txt Makefile rfmqtt.git RFSniffer.o wiringPi

pi@raspberrypi:~ $ ls
433Utils
blanktest.py
cmake-3.10.2
cmake-3.10.2.tar.gz
config.yaml
Desktop
Documents
Downloads
led.py
mosquitto
mosquitto-repo.gpg.key
motoplotlib
Music
paho.mqtt.python
pberrypi:~ $ sudo systemctl status rfmqtt.service
Pictures
Public
python_games
RandomStuff
recieve.py
rfmqtt.git
RGBREMOTE.lircd.conf
rpitx
send.py
service
SONY.lircd.conf
SourceCode
Templates
TV.lircd.conf
udo systemctl daemon-reload
Videos
wiringPi
ystemctl enable openhab2.service

(Josar) #8

@ramy_rutu please have a look at your post, i think there is something wrong with your markdown (definition of how the post should look like).

Mostly the bad format comes from copy code and then add the fences by pressing the button. Always first set the code fence and then copy the code into it.

  1. Can you download and the standart 433Utils/RPi_utils and compile with make?
  2. Can your run ./send xxx or ./RFSniffer ?
  3. Then copy the RFmqtt.cpp to the folder RPi_utils and add the additional line to the makefile.
  4. install the libraries sudo apt-get install libmosquitto-dev
  5. execute make

Please comment each of these steps and what result you get.