Building a Raspberry Pi Gateway

created by hek , updated by Marcelo Aquino

Raspberry Pi is a small computer that uses very little power (2-3 watts). It has all the horsepower necessary to serve as a cloud-enabled all-in-one Controller.

Several controllers available here can run directly on the RPi. E.g. OpenHAB and PiDome.

Install and Build

Login to your Raspberry Pi and get the code from MySensors repository:

git clone https://github.com/mysensors/MySensors.git
cd MySensors

A list of options to set the gateway is available by running the command:

./configure --help

Other customizations can be made by editing the file example_linux/mysgw.cpp.

In options that requires a pin number, use the Raspberry Pi physical pin number and not the GPIO numbers.

To build, run:

make

If everything went well the file bin/mysgw will be created.

To get a list of parameters that can be used to pass to the gateway, run:

./bin/mysgw -h

The following command runs the gateway as root with debug enabled:

sudo ./bin/mysgw -d

If you wish to install:

sudo make install

The last command will provide instructions for your system on how to start the gateway on every boot.

Serial gateway

If for some reason you can't use the GPIO pins of the Raspberry Pi, you could connect the radio to a arduino with the GatewaySerial sketch and feed the pi through a serial port:

./configure --my-gateway=serial --my-serial-port=/dev/ttyACM0 --my-serial-baudrate=115200

To know the right value for the serial port, dmesg can give you some hint.

If you are running a controller on the Raspberry Pi that doesn't support communication with the gateway through ethernet, you can use a virtual serial port:

./configure --my-gateway=serial --my-serial-is-pty --my-serial-pty=/dev/ttyMySensorsGateway

For some controllers a more recognisable name needs to be used: e.g. /dev/ttyUSB020 (check if this is free).

MQTT

The following is an example of how to build a MQTT gateway:

./configure --my-gateway=mqtt --my-controller-ip-address=127.0.0.1 --my-mqtt-publish-topic-prefix=mysensors-out --my-mqtt-subscribe-topic-prefix=mysensors-in --my-mqtt-client-id=mygateway1

Wiring

Use the Pin No. and not the GPIO.

Raspberry Pi 2/3

Raspberry Pi 1

NRF24L01+ Radio

Raspberry NRF24L01+ Color
GND GND Black
5VReg -> 3.3V VCC Red
22 CE Orange
24 CSN/CS Yellow
23 SCK Green
19 MOSI Blue
21 MISO Violet
15 (Optional) IRQ Gray

RFM69 Radio

Raspberry RFM69 Color
GND GND Black
3.3V VCC Red
x NSS Yellow
x SCK Green
x MOSI Blue
x MISO Violet
x DI00 Gray
ANA Antenna

Obs: RFM69 is not yet supported.

Improving throughput for nrf24

Normally the gateway asks the nrf24 module if a new radio message is available and then sleep a few milliseconds before asking again. This is necessary to avoid high CPU usage. During the gateway sleeping period, the module will still listen for new messages, but if multiple messages arrive, it won't take all.

There is another method were the interrupt pin from the nrf24 modules is used to inform when a new message arrives and it's immediately added to a queue for further processing. To use this method connect the interrupt pin from the nrf24 module to your Raspberry Pi (check the wiring part for more details) and use the "--my-rf24-irq-pin=PIN" option to build the gateway.

In the following example, the interrupt pin is connected to the Raspberry Pi pin 15:

./configure --my-transport=nrf24 --my-rf24-irq-pin=15

Information LEDs

The following is an example of how to add LEDs for ERR/RX/TX blinking.

Raspberry Led Color
12 ERR Red
16 RX Yellow
18 TX Green
./configure --my-leds-err-pin=12 --my-leds-rx-pin=16 --my-leds-tx-pin=18

Shopping Guide

10pcs NRF24L01+ 2.4GHz Wireless Transceiver
This is what enables your sensors to communicate wirelessly across a nominal range of 60 meters.
2252 available - $9.99   Buy
In stock - $7.75   Buy
Raspberry Pi 2 with 1GB RAM
The new quad core version .
727 available - $68.54   Buy
In stock - $36.80   Buy
Raspberry Pi Model B+ 512MB
The Raspberry Pi is a low cost, credit-card sized computer.
35 available - $59.95   Buy
In stock - $29.99   Buy

Comments