LowPowerLab Forum

Hardware support => Projects => Topic started by: Xose on August 27, 2016, 07:19:36 AM

Title: Moteino + ESP8266-based gateway
Post by: Xose on August 27, 2016, 07:19:36 AM
I am migrating my home wireless sensor network to Moteino.

My home network is based on MQTT with Node-RED dispatching notifications to PushOver, checking if devices are alive and sending data to 3rd party services like Xively or theThings.io. Until now I had some nodes with Xbees with or without a microcontroller (Arduino Fio, Micro Pro or custom boards with ATMega328 chips). Xbees are expensive, hard to work with and most of the times you need a microcontroller to do something useful. So I wanted to change that to something more flexible and customizable.

I bought some Moteinos a while ago and it was time to put them to work. First thing I wanted a gateway that would "translate" radio packets to MQTT messages. First tests where with a Moteino and and FTDI board (don't have a Moteino USB) plugged to my home server. But it required code in the Moteino and in the server, an USB port busy and I'm trying to switch off that server anyway so I started thinking on other options.

A Raspberry pi with the same set up would be an option. Still too much hardware for the task. An then I read this: https://lowpowerlab.com/forum/projects/(update)-rfm69-library-for-esp8266-moteino-compatible!/ (https://lowpowerlab.com/forum/projects/(update)-rfm69-library-for-esp8266-moteino-compatible!/). I have been playing with ESP8266 using @igrr's Arduino Core and this post was great news. So I designed my own board and code for the gateway.

I call it the RFM69GW and it features an ESP-12 module[/b], an RFM69CW (RFM12B compatible footprint), AMS1117-3.3V regulator and reset and flash buttons in an Sick of Beige DP6037 form factor.


It uses RFM69_ATC library (with a custom wrapper). After some testing I had to do a small modification in the RFM69.cpp file, changing the SPI clock divider to SPI_CLOCK_DIV2, speeding it up 2 times.

Code: [Select]
diff --git a/RFM69.cpp b/RFM69.cpp
index a1e1eeb..ad2e30b 100644
--- a/RFM69.cpp
+++ b/RFM69.cpp
@@ -450,7 +450,7 @@ void RFM69::select() {
   // set RFM69 SPI settings
-  SPI.setClockDivider(SPI_CLOCK_DIV4); // decided to slow down from DIV2 after SPI stalling in some instances, especially visible on mega1284p when RFM69 and FLASH chip both present
+  SPI.setClockDivider(SPI_CLOCK_DIV2); // speeding it up for the ESP8266
   digitalWrite(_slaveSelectPin, LOW);

Aside from that I initialize the RFM69_ATC library passing proper values for CS and IRQ pins, like this:

Code: [Select]
#define SPI_CS                  SS
#define IS_RFM69HW              0
#define IRQ_PIN                 5
#define IRQ_NUM                 5


The first sensor that I migrated has been the door monitor. It basically uses a reed swtich and a magnet to notify when the frontdoor at home is opened. It also reports current state every minute (used as heartbeat) and the battery status every 10 messages. I've done some power consumption calculations (check blog post below) and they yield an average 22uA. I'm powering it with 3-AAA batteries so I expect it to last for years! But these are numbers on paper, real life will tell...


Details for this project and links to schematics, board layout and code can be found here:

ESP8266 based Gateway: http://tinkerman.cat/rfm69-wifi-gateway/ (http://tinkerman.cat/rfm69-wifi-gateway/)
Moteino based Door Monitor: http://tinkerman.cat/moteino-door-monitor/ (http://tinkerman.cat/moteino-door-monitor/)
Title: Re: Moteino + ESP8266-based gateway
Post by: syrinxtech on September 11, 2016, 10:45:48 AM

That's a sweet board you have there.  Great work.

I'm assuming you have another Moteino somewhere that is doing the MQTT heavy lifting?  Which library are you using for this?
Title: Re: Moteino + ESP8266-based gateway
Post by: Xose on September 11, 2016, 10:57:35 AM
It's not a Moteino, but an ESP8266 using the same RFM69 library by Felix.
The ESP8266 is responsible for bridging the RF packets to TCP over WIFI and mapping them to MQTT topics.
You can read about it in this post: http://tinkerman.cat/rfm69-wifi-gateway/ and get the code here: https://bitbucket.org/xoseperez/rfm69gw
Title: Re: Moteino + ESP8266-based gateway
Post by: syrinxtech on September 11, 2016, 11:03:33 AM
Thanks, I was just reading that page. 

Hopefully I can leverage some of the software you're using in my gateway project.  I'm not ready to be designing PCB's yet but I'm really into the code side of things.

Thanks for the great post.