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:
In real life:
Download the code of the gateway:
- First line is the MAC adress of the arduino, you can put what you want as long as it respect MAC adress requirement
- Second line is the IP of your Mosquitto server
- Third line is the Arduino IP
- 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/"
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
- Send data by MQTT to convert it on RF signal
Arduino serial data received when publishing data by MQTT
Enjoy!
RépondreSupprimer// 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...
you are right, with the last versions of arduino IDE I got this error code corrected thanks
SupprimerThank You for the awesome program!! It's perfect!
SupprimerI 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! :)
With pleasure, please note I have published an ESP8266 version if you are interested.
Supprimerhttps://1technophile.blogspot.fr/2016/09/433tomqttto433-bidirectional-esp8266.html
This works perfectly with Home Assistant. Here is an example of my config below. Change the payloads with your codes.
RépondreSupprimerSwitch:
- 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
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.
SupprimerThis is code - perfect work. But, how to add to this code temperature from the DHT11 sensor ? Thank's
RépondreSupprimerYou mean to add a DHT11 directly on the arduino board to send the temperature with MQTT protocol?
Supprimeryes, using your code is higher
RépondreSupprimerok here is an example that I use:
Supprimerhttps://community.home-assistant.io/t/433tomqttto433-bidirectional-arduino-gateway/5516/19?u=1technophile
Thank's
RépondreSupprimer