Skip to content
Philippe Coval edited this page Aug 27, 2019 · 8 revisions

DOCKER

WEBTHING-IOTJS ON 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:

IOTJS ON ARTIK530 OR 710:

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

artik710

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:

ORCHESTRATION

Check Kube chapter about Kubernetes.

MISC

ARM64

Check arm64v8/node:carbon support:

LICENSE: CC-BY-SA-4.0

INDEX

Clone this wiki locally