Wednesday, 21 March 2018

Orange Pi MySensors Gateway

After several stability issues with my home automation controller I have decided to separate things across different devices. My latest (and soon to be superseded) setup is an Amlogic S905x Android TV Box running Armbian with Home Assistant, samba, Node-Red, mosquitto and Pi-Hole. I've had the device crash a few times due to random kernel Out Of Memory (OOM) issues, which required a power cycle to fix, eventually resulting in a corrupt SD card... :( The solution: a dedicated Orange Pi Zero (with overlayfs) for core functions and the TV box for Home Assistant and Node-Red.

I have been using a Arduino Nano based MySensors gateway which also presented some stability issues. After power up the /dev/ttyUSB0 device didn't always come up automatically. Soldering the TEST pin on the FT232 seemed to do the trick, but it's an annoying thing when half the light switches around my house stop working and then I lose Wife Acceptance Factor. This post briefly explains the steps required to install it on an Orange Pi Zero.

I tried to use the mainline kernel, and even after enabling SPI, etc. it just didn't want to talk. With the legacy version I simply installed the overlayroot package to make everything read-only when I was done setting up for maximum robustness. I installed the watchdog package too.
The rest of the tutorial is the same. For convenience this is my configure line and the commands:

git clone cd MySensors

./configure --spi-spidev-device=/dev/spidev1.0 --my-transport=nrf24 --my-rf24-ce-pin=2 --my-rf24-cs-pin=13 --my-rf24-irq-pin=10 --my-gateway=mqtt --my-controller-ip-address= --my-mqtt-user=*** --my-mqtt-password=*** --my-mqtt-publish-topic-prefix=mysensors-out --my-mqtt-subscribe-topic-prefix=mysensors-in --my-mqtt-client-id=mygateway1 --soc=H3

sudo make install
sudo mysgw 
sudo systemctl start mysgw
sudo systemctl enable mysgw

Now that it's all installed and "working" software-wise, set up the hardware according to the tutorial. You can see a photo of mine below. I have opted to solder everything for long-term reliability.

I also installed Node-Red, which works perfectly on overlayfs (just not deploying new flows that persist across reboots). I use the Node-Red on this device to simply convert the MySensors messages which use their serial protocol into something more applicable for my light switches, etc. It's easy enough to update every now and then when I install new things. Here's the gist of it:

Hybrid ESP8266+UNO Energy Measurement

To complement my home automation system I needed to add a multi-channel power measurement system to my DB board. I figured four channels is ...