Rflink with mqtt V2 : enhanced and minimized
Some years ago, I built a custom shield for an arduino mega running Rflink. The purpose was to provide Rflink MQTT messages over ethernet. I recently built a new version which is more compact and with additional features.
I replaced the arduino nano by a Wemos D1 mini (esp8266). I also used an arduino mega pro, which is smaller than the orignal one. The 433Mhz hardware has been changed to by SRX 882 and STX882 as the provide a better range than RXB6 and XD-FST FS1000A.
- Provides Rflink messages as json encoded payload over MQTT (like previous version)
- OTA updates of the Wemos D1 mini
- Leds indicators for Wifi, Mqtt, message in, message out and http connections
- Simple http interface to view Rflink and Mqtt messages
EDIT on 03.01.2023 : The First version was using SoftwareSerial on D1 and D2 to communicate with RFlink. But at 57600 bauds, from time to time some serial characters were lost and / or trashed. So I updated the code and the hardware to use SoftwareSerial for serial debugging and the hardware serial port is now used for the Rflink communication through D7 and D8 (using the swap() functionn). I updated the text of this post, but not the photos.
The updated source code is available on github : https://github.com/jit06/RflinkToJsonMqtt
The new 3d enclosure can be found on Thingiverse : https://www.thingiverse.com/thing:5415688
- Arduino mega Pro : rflink works only on Mega hardware
- Wemos D1 mini : any esp8266 should do the trick
- SRX882 and STX882 kit with antennas : any other combinaison supported by Rflink will work
- Multicolor LEDs breadboard found on ebay
- Some wires / solder / soldering iron
|SRX882||Arduino Mega Pro||Comments|
|VCC||3v3||power for SRX882|
|Data||D19||as seen on rflink instructions|
|STX882||Arduino Mega Pro||Comments|
|VCC||3v3||linked with SRX882|
|GND||GND||linked with SRX882|
|Data||D14||as seen on rflink instructions|
|Wemos D1 mini||Arduino Mega Pro||Comments|
|5V||Voltage regulator pin||see below|
|D7||TX||serial connection (EDIT – was connected to D1 in the previous version)|
|D8||RX||serial connection (EDIT – was connected to D2 in the previous version)|
|Wemos D1 mini||Leds breadboard||Comments|
|D0||Led 1 – blue||Wifi signal : blink while trying to connect, stay on if connected|
|D1||Led 2 – green||Mqtt server connection : blink while trying to connect, stay on if connected (was connected to D5 in the previous version)|
|D2||Led 3 – Yellow||Blink when RF message is received (EDIT – was connected to D6 in the previous version)|
|D5||Led 4 – orange||Blink when RF order is sent|
|D6||Led 5 – Red||Stay on if there is at least one HTTP client. Blink while updating esp8266 through OTA (EDIT – was connected to D8 in the previous version)|
No real complexity here : I mainly followed the rflink documentation and put in common some VCC and GND connections. Through, note that the ESP8266 is powered via one of the Arduino Pro voltage regulator. The Wemos D1 accepts to be powered through the 5v pin only if the voltage is between 4.3 and 4.6v.
Wiring ground and vcc in common for SRX 882 + STX882 :
Wiring the two RF modules to the Arduino board
Adding leds module to Wemos D1 mini and wiring to Arduino as a Serial reader / writer. Basicaly, the Wemos use the hardware serial interface swapped on D7 and D8 (EDIT – in the previous version, it was using SoftwareSerial on D1 and D2) to communicate with the standard serial pins of the Arduino Mega
3D printed enclosure
The enclosure I made have been printed on a Anycubic I3 Mega in PLA. It tooks around 2 hours. The sources of the model (Freecad 0.19) are available on Thingiverse together the STL files.
The enclosure is a bit tight so everything can be fixed without any skrew, by simply pushing it gently:
The original code as been modified in several ways :
- Adapted to run on ESP8266 with Wifi instead of Ethernet shield
- Added Leds handling
- HTTP server to show RF activity using websocket connections
- OTA update from Arduino IDE
- Refactored the main sketch to separate functionnalities in different files
The source code is available on my github and can be compiled with Arduino IDE (check Readme.md to install the dependencies).
Usage Example with OpenHab 3
Since the previous article in 2017, I upgraded from Openhab 2 to OpenHab 3 which has a new way to handle messages.
Here is 2 examples of how I use my rflink2mqtt gateway.
Using Oregon OS-THGR228-N-THGR122
- Create a channel with mqtt state topic : “rflink/Oregon_TempHygro/2DD1” (your ID will be different)
- Create an item for each properties, link them to the channel, use JSONPATH profile with the following expression :
- $.BAT for battery status
- $.HUM for humidity
- $.TEMP for temperature
Controlling a Chacon IO switch
- Create a channel configured like the following :
- MQTT state Topic : empty
- MQTT Command Topic : “rflink/Order”
- Custom On/Open Value : “10;NewKaku;0000800;1;ON;” (your id will be different)
- Custom Off/Closed Value: “10;NewKaku;0000800;1;OFF;” (your id will be different)
- Link a switch Item to your channel
As you can see, the gateway allows to write rflink orders directly to mqtt channel “rflink/Order” : the string is passed to Rflink.