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.
Login to your Raspberry Pi and get the code from MySensors repository (master branch):
git clone https://github.com/mysensors/MySensors.git --branch master cd MySensors
A list of options to set the gateway is available by running the command:
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:
If everything went well the file bin/mysgw will be created.
The gateway needs root privilege to run, for a list of parameters that can be used, run:
sudo ./bin/mysgw -h
The first time you run the gateway, enable the debug messages to verify that it is working:
sudo ./bin/mysgw -d
To install run:
sudo make install
This will also provide instructions for adding the gateway at each boot.
By default, the gateway is built for ethernet and it listens on port 5003:
./configure --my-gateway=ethernet --my-port=5003
To set the gateway as a client that connects to a controller, use:
./configure --my-gateway=ethernet --my-controller-url-address=YOUR-CONTROLLER-ADDRESS
./configure --my-gateway=ethernet --my-controller-ip-address=YOUR-CONTROLLER-IP
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).
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
Use the Pin No. and not the GPIO.
Raspberry Pi 2/3
Raspberry Pi 1
(*): If you are using the nrf24 PA/LNA version you need to use a 5V->3.3V regulator.
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
The following is an example of how to add LEDs for ERR/RX/TX blinking.
./configure --my-leds-err-pin=12 --my-leds-rx-pin=16 --my-leds-tx-pin=18