Install Armbian and configure it for a MQTT broker on Orange Pi Zero single board computer
Some time ago I was attempting to install the Mosquitto MQTT broker software on an old router with OpenWrt firmware. I no longer think that is the best option for a self-hosted MQTT broker with the advent of single board computers (SBC) like Raspberry Pi and Orange Pi. To my surprise, the Orange Pi Zero board (with quad core 1 GHz CPU and 256 MB RAM) requires less power to run than an old router (300 MHz single core CPU and 64 MB RAM).
With sufficient processing capabilities, the SBC can run more than the MQTT broker. I’m thinking of turning this Orange Pi board into a Home Automation Gateway which manages local devices and makes data available in a web interface. There is plenty of software support for what I want (I’m thinking of Node-RED with a web-based dashboard). Another good candidate is Raspberry Pi, but because it does not have wired network port (Zero version), I chose Orange Pi.
If you take a look at my old posts about Mosquitto on OpenWrt router, you will see I came with a complex configuration. That is exactly I want to get on Orange Pi too. The server should listen for connections on three ports: a port for unsecured connections used only by local network devices, a PSK secured port for some remote clients and a TLS secured port mainly for Internet access. The unsecured port and PSK secured port will be blocked by a firewall, thus not accessible from outside of LAN.
I got an Orange Pi Zero and a 32 GB SD Card. I also got some heatsinks advertised as Raspberry Pi compatible. I placed one on the AllWinner SoC since it usually gets to 50 degrees Celsius. Besides these, I also got a LM2596 voltage converter that I adjusted for precise 5 V output. I will use it to power the SBC from a 12 V supply. I have in mind getting a battery backup 12 V power supply, that’s why I want 12 V compatibility.
Orange Pi Zero SBC, the SD card and power module
I opted to install Armbian on Orange Pi. There are actually two versions, one uses Ubuntu software repositories, while the other uses Debian repos. They are named after the Ubuntu/Debian version they are using. My choice was Armbian Buster, configured for Debian software.
After downloading and extracting firmware image (with 7-Zip) I get an IMG file. This can be burned to SD card using Rufus on Windows or with dd
on Linux (after a quick format of the card). Obviously, a card reader is required for this step. Once it is done, the SD card may be inserted in the unpowered Orange Pi.
Write Armbian to SD card using Rufus
Further on, connect it with an Ethernet cable and apply power on USB port or using the power pins from the existing headers. By default, it will obtain the IP address from existing DHCP server, and we need to find it to be able to connect to the SBC. First option would be to log in to the router management page and look at DHCP clients list. All routers which provide DHCP server will display this information somewhere in the management interface. Second option is to use a network scanner. Even your phone connected to WiFi, with Ping Tools app should be able to detect LAN clients.
Find Orange Pi IP in router management page
If you can’t find IP address, you’ll have to use the serial port. If it doesn’t appear as a client in LAN, make sure the green LED on Orange Pi is on as an indication it has successfully booted from SD. A serial port is available over the USB port (you can power Orange Pi from a USB port on your computer and have access to the serial port ttyGS0
). There is also a 3-pin header serial port on the board, next to Ethernet connector (3.3 V voltage levels), which requires a USB-Serial adapter such as CH340 or FT232. Any of these may be used. If you are able to log in, the IP address will be displayed on the welcome screen.
For the rest of this guide, I will assume everything went right and you know the IP of Orange Pi. On both Windows Powershell and Linux terminal, you should be able to connect using ssh root@orange_pi_ip
. Accept connection with yes
and you should see the welcome screen after you input the root password which is 1234
. As an alternative, one may use PuTTY to connect over SSH.
Unless you are using the serial port method with your own USB-Serial adapter, any other connection to Armbian terminal will be reset upon reboot. So, if you want to see bootloader output, you need a serial port adapter.
First SSH connection to Orange Pi Armbian
You can’t go further until you change this password to something better. Follow instructions and enter twice the new root password. Then you are asked to select default shell (I choose bash
) and create your user account. Follow prompts and enter username, password and full name. Your account will be created and since it is sudo enabled this is what you should use from now on. Timezone will be automatically detected and locales will be generated. After this process is completed, I highly recommend disconnecting from this root session and reconnecting using your account. Type exit
and you should be disconnected (or close terminal/PuTTY window).
Switched from root to user account
On the new session, log in with your username and password. It is time to complete network configuration. Let’s run sudo armbian-config
(enter your user password when prompted).
There are two approaches. You may leave default network configuration on Orange Pi and configure the router DHCP server to always assign the same IP to the SBC. Or, as I prefer, configure Orange Pi with fixed (static) IP in the same subnet as the router, but outside of the range of DHCP allowable addresses (i.e., I have my router set to assign IP addresses from 192.168.1.11 to 192.168.1.254 and I will set Orange Pi board to static 192.168.1.4 since this one cannot be already assigned by DHCP server). Go to Network
, IP
, eth0
and change to Static
. Make required edits, then hit Tab and select OK
.
Configure wired network witj static IP on Armbian
After you hit Enter, you will lose SSH connection. You have to log in again on the new IP address. Disconnect and reconnect Ethernet cable if you can’t connect on the new IP, but avoid cutting power to Orange Pi. Launch armbian-config
again. Go to Personal
section and edit settings if needed (timezone could have been automatically detected, I choose to set the keyboard layout back to US and I changed hostname to something else). This is an optional step, but you can go to System
and enable Avahi
(multicast DNS). With this, if there is a running web interface on Armbian, it can be accessed from LAN at the address: hostname.local:port
(where mDNS is supported).
Before installing software, I like to have DNS servers set to 8.8.8.8
and 8.8.4.4
. To do this, we must edit a file with the following command:
sudo nano /etc/systemd/resolved.conf
Make sure to un-comment and edit the following lines:
[Resolve] DNS=8.8.8.8 2001:4860:4860::8888 FallbackDNS=8.8.4.4 2001:4860:4860::8844 #Domains= #LLMNR=yes #MulticastDNS=yes
Press Ctrl+O, then Enter and Ctrl+X and reboot. Once you are able to reconnect, let’s update software and install Mosquitto broker.
sudo apt update && sudo apt upgrade sudo apt install mosquitto mosquitto-clients
The server is up and running with the default configuration.
Mosquitto is running on Armbian
In the next post I will complete the configuration of Mosquitto. And by the way, I mentioned reboot during this guide. Do not cut power to Orange Pi to shut it down or reboot it. Use terminal commands sudo poweroff
and sudo reboot
. When the board's green LED is back on, reconnect over SSH.
I wasted soo much time with this Chinese crap, all the OrangePIs are simply crap! I have had a bunch but I keep trying to get it to work, WIFI keeps crapping out, MQTT connection is closed errors for no reason, even with direct ETH0 connection still crapy. sometimes you can ping it sometimes not. I even went as far in my C++ linux daemon code to detect when the network is down (for whatever reason) and try to issue commands to restart the network (using at least 3 different methods) all wind up worhtless.....dont waste you time. I am learning a boatload!
ReplyDeleteThe Orange Pi board shown in the photo of this post has been running 24/7 for a couple of years without any problems. The filesystem even survived to multiple sudden power outages. I eventually replaced it with a mini PC because I needed more resources.
DeleteI do use Orange Pi boards without issues. On newer models I use Linux images provided by them instead of Armbian and everything is running smoothly.