-
-
Notifications
You must be signed in to change notification settings - Fork 14
Armbian
Mozilla Webthings is a platform for controling devices, the original goal was to provide a solution for users to manage a smart home on their own control.
Since couple of years ago, cloud opperated devices showed some limitations regarding reliability or privacy. Personnally I consider that revelling user's data is a problem that everyone should consider, actually in Europe regulation is also promoting "Privacy By design" architecture.
This mozilla IoT project is a good demonstration about how a service could look same to user but is opperated totally differently than what you'll find on the IoT market.
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, one of them are results of "Web of Things" working group (WoT).
W3C the origanization in charge of standardization of the world wide web, is also commited to address some IoT uses cases using existing web technologies.
While some decribed WoT as the HTML for IoT, think that WoT protocols are mostly for computers than humans, technically we are talking about REST API and JSON Schemas for semantics.
The webthing implementation of WoT principiles is done at different levels;
- Native Webthings devices speaks WebThings on HTTP
- WebThings gateway can control them
- WebThings gateway's addon can translate non webthing devices or services to WebThing API.
Today we will cover how can Odroid-Xu4 can be a good board for hosting WebThing gateway software which was originaly developed on reference target Raspberry Pi.
https://hacks.mozilla.org/files/2019/04/mozilla_webthings_wordmark-500x168.png
disk='/dev/disk/by-id/usb-Generic-_USB3.0_CRW_-0_000000021716-0:0' # TODO
release="Armbian_20.02.1_Odroidxu4_buster_current_5.4.19_minimal"
url="https://dl.armbian.com/odroidxu4/archive/${release}.7z"
sudo sync
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
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
(...)
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.
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
sudo apt-get update
sudo apt-get install avahi-daemon
ssh [email protected]
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
sudo apt-get install time screen
url=https://github.com/mozilla-iot/gateway-deb.git
git clone --depth 1 --recursive "${url}"
cd gateway-deb
time bash ./build-docker.sh
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
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
reboot
Alternatively:
. /etc/os-release
image="${NAME,,}:${VERSION_ID}" # or debian:latest ...
sed -e "s|^FROM [^ ]*|FROM $image|g" -i Dockerfile
script
time $sudo docker build -t webthings-gateway-deb .
Sending build context to Docker daemon 562.2kB
Step 1/18 : FROM ubuntu:18.04 as webthings-gateway-builder
18.04: Pulling from library/ubuntu
(...)
time $sudo docker build -t webthings-gateway-deb .
(...)
dpkg-buildpackage: info: full upload (original source is included)
+ cd ..
++ ls webthings-gateway_0.11.0-1_armhf.deb
+ _deb=webthings-gateway_0.11.0-1_armhf.deb
++ lsb_release -is
++ tr '[A-Z]' '[a-z]'
++ lsb_release -cs
++ tr '[A-Z]' '[a-z]'
+ _renamed=webthings-gateway_0.11.0-1_armhf-ubuntu-bionic.deb
+ mv webthings-gateway_0.11.0-1_armhf.deb webthings-gateway_0.11.0-1_armhf-ubuntu-bionic.deb
+ ln -s webthings-gateway_0.11.0-1_armhf-ubuntu-bionic.deb webthings-gateway.deb
+ echo ''
+ echo 'Done building: webthings-gateway_0.11.0-1_armhf-ubuntu-bionic.deb'
Done building: webthings-gateway_0.11.0-1_armhf-ubuntu-bionic.deb
+ sync
Removing intermediate container a08e79d08892
---> 95c126961d48
Successfully built 95c126961d48
Successfully tagged gateway-deb:latest # TODO
real 76m18.885s
user 0m4.366s
sys 0m1.483s
docker image ls
gatewaydeb_default latest 32e5bdf8321c 8 hours ago 843MB
project=webthings-gateway
dir=/usr/local/opt/${project}/dist
repository=webthings-gateway-deb
tag="latest"
image="$repository:$tag"
#docker commit "$image" "$repository"
container=$(docker create "$image")
# ad10b93f6b19801a958021ee60808eca376c15b25d4036a9ce52ea8cae88180c
mkdir -p tmp/output
docker cp "$container:$dir/" ../
sudo apt-get install docker-compose # 1.21.0-3
time docker-compose up
#| Creating network "gatewaydeb_default" with the default driver
#| Building default
#| Step 1/18 : FROM ubuntu:18.04 as webthings-gateway-builder
#| 18.04: Pulling from library/ubuntu
#| (...)
#|
apt-get remove webthings-gateway docker.io
sudo apt install --install-recommends ./dist/webthings-gateway_*.deb
N: Download is performed unsandboxed as root as file '/root/dist/webthings-gateway_0.11.0-1_armhf-debian-buster.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)
sudo chmod -Rv 700 /var/cache/apt/archives/partial/
reboot
Welcome
Create your first user account:
user
email
password
password
## ADDONS ##
https://odroid.com/dokuwiki/doku.php?id=en:xu4_hardware#expansion_connectors
remote.sh [email protected]
apt-get install alsa-utils
https://github.com/mozilla-iot/gateway-deb/pull/9
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
Check Concept page for overview, Gateway to get started, IotJs page to install runtime to build webthing as explained in Home page.
For further experiments check Social and Sensor, or Extra parts like WebApp (for Tizen or PWA) or MCU info about running on other microcontrollers not supported by TizenRT.
While Home focus mostly on using iotjs to build webthings (on GNU/Linux or TizenRT for ARTIK05X devices).
This document is still in draft state, but reviews are always welcome, if you try to replicate it and stuck on missing instructions I would appreciate that you file issues or even better make pull request (just edit in github) that insert "TODO marks" in following chapters, like:
- TODO: please explain more this chapter and then remove this TODO line
Community contributions are welcome at:
Support is also possible, ask in:
- https://github.com/rzr/webthing-iotjs
- irc://irc.mozilla.org/#iot
WARNING: Developement branches could break over time.
Instead of maintaining "quick and dirty" demo code, I decided to split demo in smaller independents parts (which can reused) and I am upstreaming the most I can.
Then support can be done on mainline branches (or released versions).
Note that, Upstreaming can be a slow process, so snapshots links will remain until 100% of code is upstreamed.
Licence:
Reference documentation is at:
-
Concept:
- Demo Concept and Architecture
-
Gateway:
- Getting started with Mozilla IoT gateway
-
IotJs:
- Install IoT.js needed to run webthings
-
Home:
- Welcome page to build WebThings using IotJs
-
Social:
- Notification service using Mastodon FLOSS
-
TizenRT:
- webthing-iotjs on ARTIK05x
-
Sensor: and Actuator
- Physical interactions
-
Extra hints:
- Docker: About running in container
- MCU: About microcontrollers (not supported by TizenRT)
- WebApp: Alternate browser (Tizen and PWA)
- GnuLinux: Article about Edison and other
- Raspbian: Article about RaspberryPi
- Arduino: Alt For atmel or Esprissif boards
- DigitalTwins : WiP experiments
- TODO: Work in progress