Sunday, 8 July 2018

OpenWRT Mosquitto Gateway

After setting up my Armbian based Mosquitto gateway and having it run for a few months I wasn't happy with the stability. The Orange Pi Zero with read-only OverlayFS, etc. just didn't seem to work 100% and sometimes on reboot mosquitto didn't come up, etc. I tried DietPI, which is really great, but it doesn't support a read-only mode out of the box.

The solution (I hope) is OpenWRT! I couldn't find a version for my OrangePI Zero, although I suspect that any AllWinner H3 based version would work. I did have a Cubieboard2 with a nice 3D printed enclosure lying around though. I also have a laptop drive addition to the enclosure which I can use for CCTV and storage intensive tasks.

The benefit of OpenWRT (or LEDE) is that it's designed to be read only and super robust. It's no good for a router to crash after sudden power outages... I downloaded the squashfs version (I don't have time to waste on ext4 stability). This post lists the details to get it installed and running.

Installing and Customization

I opted to use the latest stable version, 17.0.1.4, for the sunxi target: https://downloads.lede-project.org/releases download the squashfs version: direct link. I suggest using the latest stable version that's available when you read this.

I had no luck using Etcher but I suspect the issue was related to the default network settings and not Ethcher (see later). Instead I dd'd the image after extracting it:

sudo dd if=./lede.img of=/dev/sdb

Make sure that you replace the input file with the image you downloaded and the output file with the SD card (check with sudo fdisk -l)

If you eject the SD now and put it in the Cubieboard it will boot but unfortuately the default IP is status and is 192.168.1.1 with login root and no password. If you have another device on your network with this IP you have three options:

1. Connect the board to a computer directly. Set the computer static IP to 192.168.1.2. Login and make the board some other static IP or use DHCP.
2. Use a 3.3V serial to USB and edit the network config at /etc/config/network and set a proper IP then reboot.
3. Mount the SD card and edit the file with your computer (do this just after dd'ing the card).

Now you should be able to access the web UI. Set up a password, etc. Over SSH or from the web UI I ran the following to get mosquitto up and running:

opkg update
opkg install nano
opkg install wget
opkg install mosquitto
opkg install mosquitto-client

You have to run the update command after a reboot as the files seem to get cleared to save flash space (clever).

In addition, I plan to use the board to save files from my CCTV cameras. Samba is pretty heavy weight and FTP is lightweight. Performance is no issue on the Cubieboard and the camera's support both so I'm installing both. I'll use samba to access the files from Windoze, etc. and FTP to write from the cameras.

opkg install vsftpd
opkg install luci-app-samba

It seems that samba comes with a nice web config with luci! Sweet! FTP needs a little bit of manual config though... I'll be using the SATA port for the hard drive but you can use USB too. See the official guide for USB.

opkg install kmod-fs-ext4
opkg install block-mount
opkg install e2fsprogs 
opkg install luci-app-hd-idle
opkg install kmod-ata-sunxi
opkg install hdparm

Before continuing, first reboot the system to ensure everything is saved and working.

Check this tutorial for sharing via samba and this for FTP. I set up guest access to my CCTV share which is a directory on the shared drive. I made this directory readable and writable by anyone suing chmod 777 ./cctv otherwise I would have to set up users.

Add this the the bottom of /etc/vsftpd.conf so that files are created with 777 permissions:

local_root=/mnt/data/cctv (or whatever your mount is)
local_umask=0000

A couple of other useful features:

1. Enable a heartbeat "flashing" LED so that you know at a glance that the system is up and running.
2. Set up a fsck on the mounts just to keep the clean (in the mount points settings).
3. Use the following mount options: rw,async,relatime,lazytime

Lets hope the mosquitto gateway is rock solid now!



No comments:

Post a Comment

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 ...