Skip to content

Armbian

Philippe Coval edited this page Mar 4, 2020 · 14 revisions

ARMBIAN

Mozilla Webthings is a platform for controling devices. Its main purpose is to provide a solution for users to manage a smart home that will stay under their own control, this article will tell you why and how to set it up on Odroid-XU4.

Webthings

WHY ?

Since a couple of years, cloud opperated devices showed some limitations regarding reliability or privacy and other annoyances such as interoperability I will not detail for now.

Let's focus on just the privacy concern: I personnally consider that revelling (any) user's data is a problem that everyone should consider before adopting any service or deploying any devices in their environement. Those who claim that they have nothing to hide are welcome to share their credit cards numbers. So be wise and nice and responsible because your privacy policy is not just a personal thing, your choices will also affect other family members or even your guests.

Hopefuly since a couple of years some progress also in regulation domain. Europe started with GDPR which is introducting some concepts and also promoting "Privacy by Design" architectures. Since others states followed (UK, California...).

GPDR

WHO ?

It is reasonable to predict that connected devices market might change in near future.

Meanwhile, you can be ahead and adopt Mozilla IoT platform. Since dawn of its development the project was explicitly designed to avoid that your data goes to someone else's cloud.

The principe is simple, all home devices are connected to the home network, and data just stays in, nothing is going out of sight.

Without getting too depth in details, there are many IoT standards today, and probably none will be approprate to match all use cases. But there are many overlaps that could be abstracted with common technology, this is the mission of W3C the origanization known for the standardization of the world wide web (HTML/HTTP/XML...).

W3C's "Web of Things" working group (WoT) is commited to address some IoT uses cases using existing web technologies and fill the missing gap.

While some decribed WoT as the HTML for IoT, think that WoT protocols are mostly for machines than humans, technically we are talking about REST API and JSON Schemas for semantics.

WHAT ?

The webthing simplified implementation of WoT principiles is done at different levels;

  • Native Webthings devices speaks WebThings on HTTP
  • WebThings gateway can control them from a nice web application.
  • WebThings gateway's addon can translate non webthing devices or services to WebThing API.

ThingsGateway

HOW ?

SETUP

Today we will cover how can Odroid-Xu4 can be a valid single board computer for hosting WebThing gateway software which was originaly developed on reference target Raspberry Pi.

Odroid-XU4

Following instructions should also work for other Odroids with minor adaptations. If you need to pick one, may I suggest to consider to get Odroid-H2 , it should be a bit simpler to develop on x86_64 CPU architecture.

ARMBIAN

Mozilla reference image is based on Raspbian a debian-10 port for RaspberryPi, this image wont work on non Pi devices.

Hopefully the Armbian project is also providing latest debian to various ARM boards. As well as Ubuntu which is also a derivate work of debian.

Debian or Ubuntu flavor of Armbian will work on Odroid-XU4, but let's download and then dump the debian minimal image to a SD card.

On a GNU/Linux system, I used an USB SD adapter and these command lines:

lsblk # Will list your disks make sure to use the right one
disk='/dev/disk/by-id/usb-Generic-_USB3.0_CRW_-0_000000021716-0:0' # 
file "$disk" # TODO

release="Armbian_20.02.1_Odroidxu4_buster_current_5.4.19_minimal"
url="https://dl.armbian.com/odroidxu4/archive/${release}.7z"

sudo sync
sudo apt-get install curl 7zip-full time # Install those tools on debian or adapt
time curl -O "$url" # 3sec 155313070c
time 7z e -so "$release.7z" "$release.img" | sudo dd bs=4MB of="$disk"
#| 562036736 bytes (562 MB, 536 MiB) copied, 142.735 s, 3.9 MB/s 

BOOTING ODROID

Then insert the SD image on Odroid-XU4, if you have the serial port configured you should be able to view the boot log:

#| U-Boot 2017.05-armbian (Feb 17 2020 - 07:52:44 +0100) for ODROID-XU4
#|
#| CPU:   Exynos5422 @ 800 MHz
#| Model: Odroid XU4 based on EXYNOS5422
#| Board: Odroid XU4 based on EXYNOS5422
#| Type:  xu4
#| DRAM:  2 GiB
#| MMC:   EXYNOS DWMMC: 0, EXYNOS DWMMC: 1
#| MMC Device 0 ( SD ): 7.4 GiB
#| mmc_init: -5, time 4
#| *** Warning - bad CRC, using default environment
#| 
#| In:    serial
#| Out:   serial
#| Err:   serial
#| Net:   No ethernet found.
#| Press quickly 'Enter' twice to stop autoboot:  0
#| (...)

A couple of minutes later, you should be able to log as root with password "1234" and asked to setup default user:

#| Armbian 20.02.1 Buster ttySAC2 
#| odroidxu4 login: root
#| Password: 1234
#| You are required to change your password immediately (root enforced)
#| Changing password for root.
#| (current) UNIX password: 
#| Enter new UNIX password: 
#| Retype new UNIX password: 
#|   ___      _           _     _  __  ___   _ _  _   
#|  / _ \  __| |_ __ ___ (_) __| | \ \/ / | | | || |  
#| | | | |/ _` | '__/ _ \| |/ _` |  \  /| | | | || |_ 
#| | |_| | (_| | | | (_) | | (_| |  /  \| |_| |__   _|
#|  \___/ \__,_|_|  \___/|_|\__,_| /_/\_\\___/   |_|  
#|                                                    
#| Welcome to Armbian buster with Linux 5.4.19-odroidxu4
#| 
#| System load:   2.23 0.79 0.28   Up time:       1 min
#| Memory usage:  6 % of 1993MB    IP:            192.168.1.232
#| CPU temp:      32°C             
#| Usage of /:    29% of 7.1G      
#| 
#| New to Armbian? Check the documentation first: https://docs.armbian.com
#| 
#| 
#| Thank you for choosing Armbian! Support: www.armbian.com
#| 
#| Creating a new user account. Press <Ctrl-C> to abort
#| Desktop environment will not be enabled if you abort the new user creation
#| 
#| Please provide a username (eg. your forename): user
#| Trying to add user user
#| Adding user `user' ...
#| Adding new group `user' (1000) ...
#| Adding new user `user' (1000) with group `user' ...
#| Creating home directory `/home/user' ...
#| Copying files from `/etc/skel' ...
#| Enter new UNIX password: 
#| Retype new UNIX password: 
#| passwd: password updated successfully
#| Changing the user information for user
#| Enter the new value, or press ENTER for the default
#|         Full Name []: User
#|         Room Number []: 
#|         Work Phone []: 
#|         Home Phone []: 
#|         Other []: 
#| Is the information correct? [Y/n] y
#| Dear User, your account user has been created and is sudo enabled.
#| Please use this account for your daily work from now on.

Once done let's inspect system, and install a service that will help to connect remotely using SSH with the Ethernet cable plugged in.

root@odroidxu4:~# cat /etc/os-release 
#| PRETTY_NAME="Debian GNU/Linux 10 (buster)"
#| NAME="Debian GNU/Linux"
#| VERSION_ID="10"
#| VERSION="10 (buster)"
#| (...)

root@odroidxu4:~# df 
#| Filesystem     1K-blocks   Used Available Use% Mounted on
#| udev              950928      0    950928   0% /dev
#| tmpfs             204128   6592    197536   4% /run
#| /dev/mmcblk1p1   7505192 498264   6915480   7% /
#| tmpfs            1020628      0   1020628   0% /dev/shm
#| tmpfs               5120      0      5120   0% /run/lock
#| tmpfs            1020628      0   1020628   0% /sys/fs/cgroup
#| tmpfs            1020628      0   1020628   0% /tmp
#| /dev/zram0         49584    632     45368   2% /var/log
#| tmpfs             204124      0    204124   0% /run/user/0

root@odroidxu4:~# sudo apt-get update
root@odroidxu4:~# sudo apt-get install avahi-daemon
root@odroidxu4:~# reboot

Once rebooted, let's check a SSH login using multicast DSN to discover our ssh server from its hostname.

VOLATILE STORAGE:

Optionnaly you can skip or use this trick to preserve SDcard's life span. I just plugged a pair of USB sticks of 4GB each to the 2 USB3 ports of ODroid.

This extra USB mass storage will be used for swap memory and docker. once mounted as follow:

sudo=$(which sudo)

dev="/dev/disk/by-id/usb-Generic_Mass-Storage-0:0" # TODO
file "$dev"
fdisk -l $dev || lsblk # Update previous line

dev='/dev/sda' # TODO update
label="docker"
yes | ${sudo} mkfs.ext4 -L "$label" "$dev" # TODO: verify $disk variable

dev=/dev/sdb # TODO: update if needed
label="swap"
fdisk -l $dev 
yes | $sudo mkswap -L "$label" "$dev"
free
#|              total        used        free      shared  buff/cache   available
#| Mem:        2041260      107724     1759992        6592      173544     1865772
#| Swap:       1020628           0     1020628
sudo swapoff -a
free
# 
#|              total        used        free      shared  buff/cache   available
#| Mem:        2041260      106224     1761472        6592      173564     1867272
#| Swap:             0           0           0

$sudo swapon "/dev/disk/by-label/swap"
free
#|               total        used        free      shared  buff/cache   available
#| Mem:        2041260      107912     1759716        6592      173632     1865584
#| Swap:       3943420           0     3943420

Install docker to use USB disk:

sudo apt-get install docker.io time git lsb-release file
#| Need to get 55.9 MB of archives.
#| After this operation, 255 MB of additional disk space will be used.
#| Do you want to continue? [Y/n] Y
#| (...)

dev="/dev/disk/by-label/docker"
mnt="/var/lib/docker"

df -h "$mnt"
# /dev/mmcblk1p1  7.2G  1.2G  6.0G  17% /
$sudo systemctl stop docker
$sudo sync
$sudo mkdir -p "$mnt"
$sudo mount "$dev" "$mnt"
df -h "$mnt" # /dev/sda        3.7G   16M  3.5G   1% /var/lib/docker
$sudo systemctl restart docker
$sudo docker version # 18.09.7

BUILD BINARIES:

There are various way to use mozilla webthing platform, the simplest one would be to use the deb package built for Raspbian but ARMv6 version won't be optimized for our ARMv7 CPU.

So let's try to build it again on device using docker to make sure the whole process is replicable.

It was for latest release 0.11.0, so I published "webthings-gateway_0.11.0-1_armhf-debian-buster.deb" package at:

https://bintray.com/rzr/deb/webthings-gateway#files

Feel free to install this one or rebuild on device using the following steps:

sudo apt-get install docker.io time git lsb-release file
sudo apt-get install time screen
url=https://github.com/mozilla-iot/gateway-deb.git
git clone --depth 1 --recursive "${url}"
cd gateway-deb
sudo time bash ./build-docker.sh

sudo docker image ls 
#| REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
#| <none>               <none>              c0edf15b50a7        About an hour ago   122MB
#| gatewaydeb_default   latest              32e5bdf8321c        8 hours ago         843MB
#| <none>               <none>              51a23a2e7130        9 hours ago         1.04GB
#| debian               10                  3eee7456d779        3 weeks ago         92.8MB

du -hsc ./dist/*
#| 21M     ./dist/webthings-gateway_0.11.0-1_armhf-debian-buster.deb

sudo chmod -Rv 700  ./dist/webthings-gateway_*.deb
sudo apt install -y ./dist/webthings-gateway_*.deb
#| Need to get 0 B/40.5 MB of archives.
#| After this operation, 180 MB of additional disk space will be used.
#| Do you want to continue? [Y/n] Y
#| (...)

sudo reboot

WEBAPP

The most difficult part was done, we're done with command lines, now let's wear the user hat.

Let's connect to the dashboard.

Welcome page should appear:

 | Mozilla IoT
 | Welcome
 | Choose a secure web address for your gateway:
 | [subdomain].mozilla-iot.org 
 | [Email]
 | [Create]
 | [Skip]

The gateway can be registered on mozilla.org for remote management, but let's skip creating a subdomain for now, as we won't use the gateway from the Internet for our experiments.

Next page will ask to create (local) credentials:

| Welcome
| Create your first user account:
| user: [user]
| email: [user@localhost]
| password: [password]
| password: [password]
| [Next]

And we’re ready to add some webthings .

You can start filling your dashboard with Virtual Resources,

First hit the "burger menu" icon on top left, go to settings page, and then go to the addons page.

Here you can enable a "Virtual Things" adapter:

 | virtual-things-adapter 0.1.4
 | Mozilla IoT Virtual Things Adapter
 | by Mozilla IoT

Once enabled It should be listed along ThingURLAdapter on the adapters page:

 | VirtualThingsAdapter (virtual-things)
 | ThingURLAdapter (thing-url-adapter)

You can then go back to the 1st Things page (it’s the first entry in the menu):

We can start adding "things" by pressing the bottom menu.

 | Virtual On/Off Color Light
 | Color Light
 | Save

Then press "Done" at bottom.

From this point, you can decide to control a virtual lamp from the UI, and even establish some basic rules (second entry in menu) with more virtual resources.

virtual-things

ADDONS

Add radio

http://odroidxu4.local:8080/things

Radio Save Done

https://github.com/flatsiedatsie/internet-radio/blob/master/pkg/internet_radio.py

install -d -o webthings /var/run/webthings-gateway/.mozilla-iot/data/internet-radio chmod a+rwX -R /var/run/webthings-gateway/.mozilla-iot/data/internet-radio

root@odroidxu4:/etc/webthings-gateway/addons/internet-radio# ffplay -nodisp /usr/share/sounds/alsa/Front_Center.wav root@odroidxu4:/etc/webthings-gateway/addons/internet-radio# addgroup webthings audio

CONCLUSION

Mozilla's WebThings project is a good demonstration about how a service could look same to user but is opperated totally differently what you'll find today on the IoT market. Remote control is possible for a progressive web app served by the gateway itself.

In my opinion, This is much simpler and trustworthy that a closed source application you're forced to installed to get access to the devices you bought.

INDEX

Clone this wiki locally