-
-
Notifications
You must be signed in to change notification settings - Fork 14
Docker
For developer convenience previous instructions are also verified in a Docker container too:
# sudo=sudo # TODO: setup docker for user
sudo apt-get install docker.io docker-compose # Or adapt for non Debian based OS
# sudo=sudo # if docker not configured for user
$sudo docker run --net host rzrfreefr/webthing-iotjs:latest
curl http://localhost:8888/1/properties/level
{"level":8.188338644265732
Note, before of buffered output, it should take some time to display wait some minutes before it gets flushed to console, also make sure that port is not used, you can check before:
sudo lsof | grep :8888
Or rebuild from git:
project="webthing-iotjs"
url="https://github.com/rzr/${project}"
branch="master"
git clone --recursive --depth 1 -b "$branch" "$url" ; cd "$project"
time $sudo docker-compose up
Expected log (once log is flushed TODO):
Creating network "webthingiotjs_default" with the default driver
Building web
Step 1/16 : FROM debian:9
(...)
+ sudo apt-get install -y --allow-unauthenticated iotjs-snapshot=0.0+1.0+548+g44cda409-0~rzr0+1.0+635+gf5f1e5e8 iotjs=0.0+1.0+548+g44cda409-0~rzr0+1.0+635+gf5f1e5e8
(...)
Step 12/15 : RUN echo "#log: ${project}: Preparing sources" && set -x && make setup && make && make check && sync
---> Running in b69facc67b6e
+ make setup
#log: webthing-iotjs: Preparing sources
iotjs -h || echo "log: Should have printed iotjs's usage..."
Usage: iotjs [options] {FILE | FILE.js} [arguments]
(...)
---> Running in d2428c8468b8
Removing intermediate container d2428c8468b8
---> de6408a5d31f
Successfully built de6408a5d31f
Successfully tagged webthingiotjs_web:latest
Creating webthingiotjs_web_1 ...
Creating webthingiotjs_web_1 ... done
Attaching to webthingiotjs_web_1
web_1 | iotjs example/multiple-things.js
web_1 | setting new humidity level: 8.178182286316906
web_1 | setting new humidity level: 3.371208683777668
web_1 | setting new humidity level: 22.527728818490377
It is working the same as webthing-node's project.
For reference check docker file source:
- https://github.com/rzr/webthing-iotjs/blob/sandbox/rzr/iotjs/master/Dockerfile
- https://github.com/mozilla-iot/webthing-node/commits/master/Dockerfile
- https://hub.docker.com/_/debian/
Several OS are supported on this device, mine was on Fedora-24, now support moved to Ubuntu, some might also use Tizen too.
So for now we'll use Debian in a docker container mounted on external USB disk (4GB)
cat /etc/os-release # PRETTY_NAME="Fedora 24 (Twenty Four)"
sudo=sudo # Or configure your sudoers
$sudo sync
$sudo dnf install docker docker-compose screen time git etckeeper jq
screen # Press "Ctrl+a c" : to open a new terminal
$sudo systemctl stop docker
lsblk # Bottom USB slot is sda
disk="/dev/sda" # TODO: update if needed (ie: /dev/disk/by-id/usb-*)
mnt="/var/lib/docker"
$sudo mkfs.ext4 -L webthings "$disk" # TODO: verify $part variable
$sudo mkdir -p "$mnt"
$sudo mount "$disk" "$mnt"
$sudo systemctl restart docker
$sudo docker version # docker-common-1.10.3-55.gite03ddb8.fc24.armv7hl
cd "$mnt"
Then build container and start service (~500 Mb will be used):
project="webthing-iotjs"
board="artik530"
image="arm32v7/debian"
url="https://github.com/rzr/${project}"
branch="master"
git clone --recursive --depth 1 -b "$branch" "$url" && cd "$project"
sed -e "s|^FROM .*|FROM $image|g" -i Dockerfile
$sudo systemctl restart docker
time docker rm "${project}" ||:
time docker build -t "${USER}/${project}" . # <20min
time docker run -t \
--volume /sys:/sys --publish 8888:8888 --net "host" \
--name "${project}" --rm \
"${USER}/${project}" start/board/${board}
Expected log:
/usr/bin/make -C example/platform board/artik530
(...)
sudo cat /sys/kernel/debug/gpio
(...)
gpio-28 ( |sysfs ) out hi
gpio-30 ( |sysfs ) in hi
(...)
Usage: iotjs [options] {FILE | FILE.js} [arguments]
(...)
iotjs index.js artik530
log: board: artik530: Loading
(...)
curl -H "Accept: application/json" http://localhost:8888
(...)
log: board: artik530: Started
Test in an other shell:
curl http://${HOSTNAME}.local:8888 # | jq
{
"name": "ARTIK530",
"href": "/",
"@context": "https://iot.mozilla.org/schemas",
"@type": [],
"properties": {
"RedLED": {
"@type": "OnOffProperty",
"label": "On/Off: RedLED",
"type": "boolean",
"description": "Red LED on interposer board (on GPIO28)",
"href": "/properties/RedLED"
},
"BlueLED": {
"@type": "OnOffProperty",
"label": "On/Off: BlueLED",
"type": "boolean",
"description": "Blue LED on interposer board (on GPIO38)",
"href": "/properties/BlueLED"
},
"Up": {
"@type": "BooleanProperty",
"label": "On/Off: Up",
"type": "boolean",
"readOnly": true,
"description": "SW403 Button: Nearest board edge, next to red LED (on GPIO30)",
"href": "/properties/Up"
},
"Down": {
"@type": "BooleanProperty",
"label": "On/Off: Down",
"type": "boolean",
"readOnly": true,
"description": "SW404 Button: Next to blue LED (on GPIO32)",
"href": "/properties/Down"
},
"ADC0": {
"@type": "LevelProperty",
"label": "Level: ADC0",
"type": "number",
"readOnly": true,
"description": "Analog port of ARTIK05x",
"href": "/properties/ADC0"
},
"ADC1": {
"@type": "LevelProperty",
"label": "Level: ADC1",
"type": "number",
"readOnly": true,
"description": "Analog port of ARTIK05x",
"href": "/properties/ADC1"
}
},
"links": [
{
"rel": "properties",
"href": "/properties"
}
],
"description": "A web connected ARTIK530 or ARTIK720"
}
This time a new example is running, it is implenting Hardware Input/Output (GPIO) of the device itself.
Once connected to the Gateway using Gateway's thing URL adapter), user can log in the UI or WebApp and then control "on board" LEDs and monitor Sensors (Buttons & ADC).
Status: Merged upstream in webthing-node and released
Note, that we overrode the image because iotjs's snapshot is not supporting armel, but armhf or x86 etc. Debian:9 armv7l is supported and for Ubuntu you could build iotjs in container.
TODO: Check current schemas (buttons, ...):
Related links:
More info about this device:
- https://www.artik.io/
- https://www.artik.io/modules/artik-710/
- https://s-opensource.org/2017/11/29/building-iotivity-arm-artik-devices/# (TODO)
Check Kube chapter about Kubernetes.
Check arm64v8/node:carbon support:
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