The project can help you to build a RFLink Gateway useful to integrate RF devices in your preferred home automation system.
The project core component is the firmware by Stuntteam that allows sniffing and sending 433 MHz radio frequencies frames. The frames are organized according to specific IOT protocols. The RFLink firmware is developed to run on the Arduino Mega board and it uses the USB port to communicate, no other communication interface is available.
To expose the RFLink Gateway (Arduino board) through Wi-Fi rather than USB, we can use an ESP8266-01 module. It is equipped with a customized firmware based on the ESPurna that is adapted to interface the RFLink Gateway. To simplify this integration we will use a customized board containing both Arduino Mega and ESP8266. This board is produced by RobotDyn.com. The customized firmware, based on ESPurna, will be used to expose the RFLink data through a web service.
In the following, the use hardware and software are shown, as well as the steps to assemble the gateway.
The project is realized using the following hardware:
RFLink 433.92 MHz Gateway components Components for building a RFlink Gateway: a 433 MHz Transceiver from Aurel, various type headers, SMA connector and a pcb. |
Antenna SMA for 433 MHz 433 MHz antenna |
---|---|
![]() |
![]() |
MEGA+WiFi R3 ATmega2560+ESP8266, flash 32Mb, USB-TTL CH340G, Micro-USB Customized version of the classic ARDUINO MEGA R3 board. |
|
![]() |
|
- Download the rflink firmware
- Unpack the zip file and get ready to burn it
-
Set the MEGA+WiFi R3 ATmega2560+ESP8266 board dip switch to sketch upload mode. For details see the full dip switch modes.
Mode 1 2 3 4 5 6 7 8 RXD/TXD USB <-> ATmega2560 (upload sketch) --- --- ON ON --- --- --- NoUSE 0 -
Upload the rflink Gateway firmware using
avrdude -v -p atmega2560 -c stk500 -P /dev/cu.usbmodem411 -b 115200 -D -U flash:w:RFLink.cpp.hex:i -C avrdude.conf
On OSX with Arduino
/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/avrdude -v -p atmega2560 -c stk500 -P /dev/cu.usbmodem411 -b 115200 -D -U flash:w:RFLink.cpp.hex:i -C /Applications/Arduino.app/Contents/Java/hardware/tools/avr/etc/avrdude.conf
NB If necessary, replace /dev/cu.usbmodem411 with the USB port used to connect your device.
-
Clone ESPurna repository using
git clone --branch 1.13.5 https://github.com/xoseperez/espurna.git
NB In this project I use ESPurna firmware 1.13.5
-
Customize the ESPurna firmware using the code located in the folder espurna_firmware_custom_code
-
copy custom.h into the folder code/espurna/config/
-
copy robotdyn_atmega2560_esp8266.h into the folder code/espurna/libs/
-
copy robotdyn_atmega2560_esp8266.ino into the folder code/espurna/
-
in the folder code/ open the file platformio.ini, so put the following text under GENERIC OTA ENVIRONMENTS session
[env:generic-robotdyn-atmega2560-esp8266] platform = ${common.platform} framework = ${common.framework} board = ${common.board_1m} board_build.flash_mode = ${common.flash_mode} lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} build_flags = ${common.build_flags_1m0m} -DUSE_CUSTOM_H monitor_speed = ${common.monitor_speed} extra_scripts = ${common.extra_scripts}
- in the file platformio.ini, find
lib_deps =
so replaceArduinoJson
withhttps://github.com/bblanchon/ArduinoJson#v5.13.5
-
-
Go to in the folder **code/** and build the firmware using the command
./build.sh generic-robotdyn-atmega2560-esp8266
NB Depending on your environment, the build process may be interrupted due to errors. In this cases,it is necessary to satisfy the missing dependencies and rerun the build.
After the successful build, you can found the customized firmware in the folder firmware/espurna-1.13.5/
-
Set the MEGA+WiFi R3 ATmega2560+ESP8266 board dip switch to sketch upload mode
Mode 1 2 3 4 5 6 7 8 RXD/TXD USB <-> ESP8266 (upload sketch) --- --- --- --- ON ON ON NoUSE 0 -
Upload the ESPurna custom firmware using
esptool.py --port /dev/cu.wchusbserial1410 write_flash --flash_size 1MB --flash_mode dout 0x00000 espurna-1.13.6-dev-generic-robotdyn-atmega2560-esp8266.bin
-
Set the MEGA+WiFi R3 ATmega2560+ESP8266 board dip switch to cooperation mode
Mode 1 2 3 4 5 6 7 8 RXD/TXD USB <-> Mega2560 <-> ESP8266 (COM3) ON ON ON ON --- --- --- NoUSE 0 Change of connecting port between ATmega2560 and ESP8266 setting the switch to RXD0 <-> TXD0
- Connect the power adapter and configure the rflink gateway using the web interface; for more details see the ESPurna wiki page.
Home Assistant is an open source home automation platform. If you use this platform and you want to interface the RFLink Wi-Fi Gateway then you must follow some simple steps.
- Copy the folder home_assistant_rflink_nodejs_bridge into your Home Assistant system
-
Add the following line:
@reboot <script full path>/espurna_rflink_bridge.sh >/dev/null 2>&1 */5 * * * * source <user home>/.bashrc; <script full path>/espurna_rflink_bridge.sh >><user home>/espurna_rflink_bridge.log 2>&1
to crontab Home Assistant user by replacing <script full path> with the real full script path.
-
Configure the NodeJs bridge changing the file espurna_rflink_bridge.json
Attribute name Default Note port 7373 Bridge local port polling_mills 60000 RFLink Gateway polling time reset_minute 480 RFLink Gateway restart command time Attribute name Default Note protocol http ESPurna support for http host RFLink device host name or IP Address port 80 RFLink device web service port uri /api/rflink Not change, RFLink device web service uri apikey RFLink device web service api key JSON Examples:
{ "rflink" : { "protocol" : "http", "host" : "192.168.1.77", "port" : "80", "options" : { "uri": "/api/rflink", "apikey": "7EE7A415EB877244" } }, "bridge" : { "port" : "7373", "polling_mills" : 60000, "reset_minute" : 480 } }
Before use MQTT bridge you must install support library using
npm install mqtt -g
, so add to your user .bashrcexport NODE_PATH=$(npm root -g)
.Attribute name Default Note protocol mqtt ESPurna support for mqtt host MQTT server host port 1883 MQTT service port username MQTT credential password MQTT credential clientId MQTT client ID clean MQTT true, set to false to receive QoS 1 and 2 messages while offline qos MQTT QoS topic MQTT the topic to publish JSON Examples:
{ "rflink" : { "protocol" : "mqtt", "host" : "localhost", "port" : "1883", "options" : { "username" : "rflinkserialbridge", "password" : "password", "clientId" : "rflinkserialbridge", "clean" : "true", "qos": 2, "topic": "rflinkgateway" } }, "bridge" : { "port" : "7373", "polling_mills" : 60000, "reset_minute" : 480 } }
-
Configure the Home Assistant RFLink component
rflink: host: localhost port: 7373 wait_for_ack: false reconnect_interval: 60