The MySensors Gateway
02 August 2015
In my last two blog posts about my home made sensor and relay switch I talked about using MySensors for the sensors and Domoticz to control / read these. The missing link between the sensor and Domoticz is the MySensors gateway. In this post I will show how I build and configured this gateway.
The MySensors gateway is the device that passes messages between the MySensors network and the controller. For the controller I use Domoticz as I already am quite happy with it as a central server for my home automation network. So I needed a gateway to shuttle the data between Domoticz and MySensors. I already had an Arduino Mega 2560 and a Ethernet Shield lying around. The only extra thing I needed was a NRF24L01+ radio.
For the radio I use the version with the external antenna. This increases the range of the radio considerably which means I need less repeater nodes. Most of the sensors I'll be connecting will be battery powered so the extra range is very welcome.
There are three versions of the gateway, a serial connection, mqtt broker or using an ethernet (network) connection. I don't have the Raspberry Pi running Domoticz and the gateway close enough to each other to connect via serial but I do have a network connection and I already had the ethernet shield so via ethernet was the easiest option for me.
The Arduino Mega 2560 is overkill for the gateway. The gateway will run fine on an Arduino Uno that is cheaper and smaller. If you don't already have an Arduino that you can use I'd go for the Uno. There are several options to add ethernet to the Arduino. The Ethernet Shield is by far the easiest way. The shield fits perfectly on top of the Uno or Mega.
- Arduino Uno
- or Arduino Mega256
- Arduino Ethernet Shield
- NRF24L01 with external antenna
- USB power adapter
- Power supply for the Arduino
The code for the gateway, like all the sensors I've build so far, is based on version 1.4 of MySensors. Version 1.5 has just been released and is backwards compatible. The code I have here should work with 1.5. I'll be upgrading all my nodes soon. I'll update the code when I do.
To get the Mega with Ethernet shield to work with the NRF radio I needed to change the configuration of MySensors. The pins are connected differently than mentioned in the documentation. You will need to change the following lines in the file named "RF24_config.h" that is inside the MySensors/utility library folder.
Change these lines:
- const uint8_t SOFT_SPI_MISO_PIN = 16;
- const uint8_t SOFT_SPI_MOSI_PIN = 15;
- const uint8_t SOFT_SPI_SCK_PIN = 14;
in to this:
- const uint8_t SOFT_SPI_MISO_PIN = A2;
- const uint8_t SOFT_SPI_MOSI_PIN = A1;
- const uint8_t SOFT_SPI_SCK_PIN = A0;
Next is to enable softspi. On line 28 remove the // before #define SOFTSPI.
//#define SOFTSPI // Requires library from https://github.com/greiman/DigitalIO
After you uploaded the code to the Arduino add the // to line 28 to disable softspi for your sensors and actuators.
The source code for the sketch I uploaded to my gateway is available on my Github.
I designed this case based for an Arduino Mega2560 with Ethernet Shield and the NRF24L01+ with external antenna. The .stl files for 3d printing are available on Youmagine. 3dhubs is a good alternative when you don't have your own 3d printer to get the case printed.
Building an Arduino based temperature, humidity and light sensors (Update)
Dromotica update: Local and Remote access
Dromotica update: Scene widgets
Dromotica installed 100 times
Domoticz for Android widgets update
Using Nuon smart plug with Domoticz and Razberry