Accéder au contenu principal

433toMQTTto433 - Bidirectional Arduino gateway between RF 433Mhz signal and MQTT


The goal of the Arduino 433toMQTTto433 is to act as a gateway between 433Mhz sensors and a MQTT broker or between the MQTT broker and 433Mhz actuators, It enables to:
  • receive MQTT data from a topic and send RF 433Mhz signal corresponding to the received MQTT data 
  • publish MQTT data to a different topic related to received 433Mhz signal 

It can be an interesting part in an home automation system so as to interface sensors and actuators with software like openhab.

The interest of putting this gateway to an arduino and not on a raspberry pi is to be able to manage security actions at arduino level (power on a siren, cut power to certain devices) following RF data received by sensors without being dependent to the PI for security related actions.


[EDIT] all infos are now centralized into the github repository take a look at it you will find up to date info about OpenMQTTGateway

You need:

  • Arduino UNO 
  • W5100 Ethernet shield 
  • 433Mhz Receiver XD RF 5V and transmitter FS1000A 

Transmitter VCC must be plugged to pin 9, signal to pin 10, Receiver signal to pin 2
Here is the schematic:


The transmitter VCC is connected to a signal PIN of the arduino so as to activate it on needs, if it was linked to permanent VCC we would not be able to receive data due tu conflicts between the receiver and the transmitter. That's why we activate the PIN9 on demand when we need to send RF data.

In real life:


Download the following libraries into your arduino environment:
Install Mosquitto to your server.

Download the code of the gateway:

The code of the gateway can be found here https://github.com/1technophile/433toMQTTto433


Modify the lines of the sketch so as to make it communicate with your mosquitto server:
  1. First line is the MAC adress of the arduino, you can put what you want as long as it respect MAC adress requirement
  2. Second line is the IP of your Mosquitto server
  3. Third line is the Arduino IP
  4. Fourth line set the port used to communicate to Mosquitto 1883 is the default one


byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0x34, 0x99 };
byte localserver[] = { 192, 168, 1, 45 };
byte ip[] = { 192, 168, 1, 23 };
PubSubClient client(localserver, 1883, callback,ethClient);

Upload the sketch to your arduino and open the serial monitor with a speed set to 9600b.
Launch or verify that you mosquitto broker is up and running

If the connexion to mosquitto is ok you should see on the serial monitor of the arduino "connected" & "subscription OK to home/MQTTto433/"
Now you can do some tests to verify that all is working as expected, here is some usefull commands to test gateway with mosquitto from the server, on your mosquitto server:
  • Subscribe to the subject for data reiception from RF signal 
mosquitto_sub -t home/433toMQTT
  • Send data by MQTT to convert it on RF signal 
mosquitto_pub -t home/MQTTto433/ -m 1315156

Arduino serial data received when publishing data by MQTT


We see that the Arduino receive the value 1315156 on the MQTT subject "MQTTto433" and send the data by RF


Enjoy!

Commentaires


  1. // Callback function header
    void callback(char* topic, byte* payload, unsigned int length);

    This line needs inserted before "//client parameters" or you will get a callback not declared error...

    RépondreSupprimer
    Réponses
    1. you are right, with the last versions of arduino IDE I got this error code corrected thanks

      Supprimer
    2. Thank You for the awesome program!! It's perfect!

      I also had to fix my Ethernet 5100 Shield with resistors (see https://forum.arduino.cc/index.php?topic=351477.30) so I could use it on a different switch. It took me a couple hours to figure that out. Now to integrate this into Home Assistant! :)

      Supprimer
    3. With pleasure, please note I have published an ESP8266 version if you are interested.

      https://1technophile.blogspot.fr/2016/09/433tomqttto433-bidirectional-esp8266.html

      Supprimer
  2. This works perfectly with Home Assistant. Here is an example of my config below. Change the payloads with your codes.

    Switch:
    - platform: mqtt
    name: "Office Fan"
    state_topic: "home/433toMQTT"
    command_topic: "home/MQTTto433/"
    payload_on: "1382147"
    payload_off: "1382156"
    optimistic: true
    retain: true

    * Note the dash is used when there is more than one Etekcity switch but I'm only sharing one.

    I published this as Partybug on the Home Assistant forums.
    https://community.home-assistant.io/t/433tomqttto433-bidirectional-arduino-gateway/5516/12

    RépondreSupprimer
    Réponses
    1. Spacing is weird on websites. The YAML config above needs two spaces before the dash. All the lines below that need 4 spaces. For a presumed second switch, copy the dash line and those below.

      Supprimer
  3. This is code - perfect work. But, how to add to this code temperature from the DHT11 sensor ? Thank's

    RépondreSupprimer
    Réponses
    1. You mean to add a DHT11 directly on the arduino board to send the temperature with MQTT protocol?

      Supprimer
  4. Réponses
    1. ok here is an example that I use:
      https://community.home-assistant.io/t/433tomqttto433-bidirectional-arduino-gateway/5516/19?u=1technophile

      Supprimer

Enregistrer un commentaire

Posts les plus consultés de ce blog

433toMQTTto433 - Bidirectional ESP8266 NodeMCU gateway between RF 433Mhz signal and MQTT

The goal  is to act as a gateway between 433Mhz sensors and a MQTT broker or between the MQTT broker and 433Mhz actuators, It enables to:
receive MQTT data from a topic and send RF 433Mhz signal corresponding to the received MQTT data publish MQTT data to a different topic related to received 433Mhz signal 
It can be an interesting part in an home automation system so as to interface sensors and actuators (wall sockets) with software like openhab.

List of compatible sensors here

The interest of putting this gateway to an ESP8266 and not on a raspberry pi is to be able to manage security actions at gateway level (power on a siren, cut power to certain devices) following RF data received by sensors without being dependent to the PI for security related actions.

[EDIT] all infos are now centralized into the github repository take a look at it you will find up to date info about OpenMQTTGateway

You need:

Software:

MosquittoArduino IDE latest version (tested ok with 1.6.10)esp8266 board added to t…

Infrared IR, 433mhz and MQTT on ESP8266 bidirectional gateway 433nIRtoMQTTto433nIR

Following discussions on the home assistant forum people gave me the idea to add Infrared communication to the 433mhz gateway. 

The goal is to act as a gateway between 433Mhz sensors, infrared remote controls and a MQTT broker or between the MQTT broker and 433Mhz actuators, infrared devices, It enables to:
receive MQTT data from a topic and send RF 433Mhz signal corresponding to the received MQTT data publish MQTT data to a different topic related to received 433Mhz signal receive MQTT data from a topic and send infrared signal corresponding to the received MQTT data publish MQTT data to a different topic related to received infrared signal 
It can be an interesting part in an home automation system so as to interface sensors and actuators (wall sockets), your tv, home cinema, hifi ... with software like openhab or home assistant.

List of compatible RF sensors here

[EDIT] all infos are now centralized into the github repository take a look at it you will find up to date info about OpenMQT…