Skip to content
Philippe Coval edited this page Jan 29, 2020 · 40 revisions

IOTJS

INTRODUCTION:

IoT.js is an Internet of Things plaform built on Jerryscript javascript engine.

For up to date information check upstream links:

This page will explain how to install iotjs runtime to run webthing-iotjs project on contrainted devices.

Javascript4IoT

As IoT.js tries to mimic Node.js, this Webthing library wants to stay aligned to webthing-node (designed for Node.js) too, so webthing-node was forked into webthing-iotjs and then adapted for IoT.js runtime.

It can run on many devices such as regular Linux system but maybe not your favorite MCU other MCU/MPU target to consider is ARTIK05x, as shown at end of demo, you could try to compare to Arduino, but I wouldn't dare.

ARTIK05x are running full featured OS, called TizenRT, don't confuse with Linux based Tizen, this one has a different kernel and is targeting lower class architectures.

One key feature of TizenRT is "native javascript" support, using JerryScript in IoT.js runtime.

JerryscriptIoTjs

INSTALL IOTJS FOR WEBTHING-IOTJS

Only snapshot version is currently supported, if using GNU/Linux rebuild it from scratch or install snapshot debian packages:

INSTALL IOTJS ON DEBIAN AND DERIVED:

Even if iotjs-1.0 landed in debian (and derived: Ubuntu, Raspbian):

We'll use a snapshot version ( to enable all features in full profile )

Install deb using script:

curl https://raw.githubusercontent.com/rzr/iotjs-express/master/extra/tools/iotjs/setup.sh | bash -x -e

Alternatively, the snapshot package can be installed from community repo:

To avoid rebuilding let's add a third party source and install snapshot package (that would eventually "downgrade" iotjs to unreleased version):

sudo sync
sudo apt-get update -y
sudo apt-get install -y base-files gnupg

package=iotjs
cat /etc/os-release && . /etc/os-release
distro="${ID}_${VERSION_ID}"
[ "debian" != "${ID}" ] || distro="${distro}.0"
[ "debian_10.0" != "$distro" ] || distro="${ID}_${VERSION_ID}"
distro=$(echo "${distro}" | sed 's/.*/\u&/')
[ "ubuntu" != "${ID}" ] || distro="x${distro}"
url="http://download.opensuse.org/repositories/home:/rzrfreefr:/snapshot/${distro}"
file="/etc/apt/sources.list.d/home:rzrfreefr:snapshot.list"
curl -s ${url}/Release.key | gpg --with-fingerprint
curl ${url}/Release.key | sudo apt-key add -v -
echo "deb [allow-insecure=yes] $url /" | sudo tee "${file}"
curl "$url/Release.key" | sudo apt-key add -
sudo apt-get update -y
apt-cache show ${package}
apt-cache show ${package}-snapshot
version=$(apt-cache show "$package-snapshot" | grep 'Version:' | cut -d' ' -f2 | sort -n | head -n1 || echo 0)
sudo apt-get install -y --allow-downgrades --allow-unauthenticated \
  ${package}-snapshot="$version" ${package}="$version"
dpkg -s ${package} # Should print a 0.0* version

This above snipped was tested on:

  • debian-10: amd64
  • ubuntu-19.0
  • raspbian-10: armhf

Note that snapshots packages' versions are in 0.0.* form, because we don't want to upgrade automatically released versions of iotjs if previously installed.

Alternatively snapshot package that can be installed from community repo:

INSTALL IOTJS ON UBUNTU:

Even if iotjs-1.0 landed in Ubuntu:

To do this, just paste those lines into terminal (one per one to make sure):

sudo sync
sudo apt-get update -y

sudo apt-get install -y \
  gnupg base-files sed sudo dpkg debianutils coreutils apt etckeeper

cat /etc/os-release && . /etc/os-release
distro="${ID}_${VERSION_ID}"
[ "debian" != "${ID}" ] || distro="${distro}.0"
distro=$(echo "${distro}" | sed 's/.*/\u&/')
[ "ubuntu" != "${ID}" ] || distro="x${distro}"
url="http://download.opensuse.org/repositories/home:/rzrfreefr:/snapshot/${distro}"
file="/etc/apt/sources.list.d/home:rzrfreefr:snapshot.list"
curl -s ${url}/Release.key | gpg --with-fingerprint
curl ${url}/Release.key | sudo apt-key add -v -
echo "deb [allow-insecure=yes] $url /" | sudo tee "${file}"
sudo apt-get clean ; sudo apt-get update -y

apt-cache search --full iotjs
version=$(apt-cache show "iotjs-snapshot" \
 | grep 'Version:' | cut -d' ' -f2 | sort -n | head -n1 || echo 0)

sudo apt-get install -y --allow-unauthenticated \
 iotjs-snapshot="${version}" iotjs="${version}"

dpkg -s iotjs # Should print a 0.0* version
which iotjs
iotjs -h

TODO: solve this issue:

"Release: The following signatures were invalid:" 
"W: GPG error: http://download.opensuse.org/repositories/home:/"

INSTALL IOTJS ON RASPBERRY PI:

INSTALL IOTJS ON RASPBIAN 10:

Raspbian is a fork of Debian GnuLunix OS recompiled for RaspberryPi

Even if iotjs-1.0 landed in Raspbian:

We will install IoT.js snapshot package like we did for GnuLinux Debian but using this repository as source:

Precompiled package can be installed to system using those commands:

sudo sync
sudo apt-get update -y

sudo apt-get install -y gnupg base-files sed sudo dpkg debianutils coreutils apt etckeeper

cat /etc/os-release && . /etc/os-release
distro="${ID}_${VERSION_ID}"
[ "debian" != "${ID}" ] || distro="${distro}.0"
[ "debian_10.0" != "$distro" ] || distro="${ID}_${VERSION_ID}"
distro=$(echo "${distro}" | sed 's/.*/\u&/')
[ "ubuntu" != "${ID}" ] || distro="x${distro}"
url="http://download.opensuse.org/repositories/home:/rzrfreefr:/snapshot/${distro}"
file="/etc/apt/sources.list.d/home:rzrfreefr:snapshot.list"
curl -s ${url}/Release.key | gpg --with-fingerprint
curl ${url}/Release.key | sudo apt-key add -v -
echo "deb [allow-insecure=yes] $url /" | sudo tee "${file}"
sudo apt-get clean ; sudo apt-get update -y

apt-cache search --full iotjs
version=$(apt-cache show "iotjs-snapshot" \
 | grep 'Version:' | cut -d' ' -f2 | sort -n | head -n1 || echo 0)

sudo apt-get install -y --allow-unauthenticated \
 iotjs-snapshot="${version}" iotjs="${version}"

dpkg -s iotjs # Should print a 0.0* version
which iotjs
iotjs -h

INSTALL IOTJS ON RASPBIAN 9:

Precompiled package can be installed to system using those commands:

url='https://dl.bintray.com/rzr/raspbian-9-armhf'
package="iotjs"
source="/etc/apt/sources.list.d/bintray-rzr-raspbian-9-armhf.list"
sudo sync || su
echo "deb [allow-insecure=yes] $url raspbian main" | sudo tee "$source"
sudo apt-get update -y
apt-cache search ${package}
version=$(apt-cache show "$package" | grep 'Version:' | cut -d' ' -f2 | sort -n | head -n1 || echo 0)
sudo apt-get install -y --allow-downgrades --allow-unauthenticated \
  ${package}-snapshot="$version" ${package}="$version"
dpkg -s iotjs # Should print a 0.0* version (e.g: 0.0+1.0+515+g060bbdd6-0~rzr0+1.0+546+gad1de281)

/usr/bin/iotjs
# Usage: iotjs [options] {script | script.js} [arguments]

Note: Raspbian 8 or earlier are not supported so you need to setup Raspbian 9 or later. Download raspbian 9 image (Raspbian Stretch Lite) at:

HARDWARE SUPPORT

IoT.js reference hardware is RaspberryPi (on Raspbian OS), but it can be easily adapted to other boards:

USE 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) see Home page.

USE IOTJS ON INTEL EDISON:

You can also try IoT.js on Intel Edison (x86) using Jubilinux (a community Debian port) and install deb for x86 (32bits) as explained in privious debian package.

More details are explained in GnuLinux page inspired from this blog post:

USE IOTJS ON TIZENRT FOR ARTIK05x

Check TizenRT page for detailed instructions to deploy IoT.js on ARTIK05x devices.

USE IOTJS

Once installed, you can check if IoT.js is properly installed using this simple onliner script:

cat example.js
console.log(process);

iotjs example.js

It will just log some environment info:

{
  "env": {
    "HOME": "/home/rzr",
    "IOTJS_PATH": "",
    "IOTJS_ENV": "",
    "IOTJS_EXTRA_MODULE_PATH": "",
    "IOTJS_WORKING_DIR_PATH": ""
  },
  "builtin_modules": {
    "adc": true,
// (...)
}

NEXT:

Once you have verified IoT.js, then you can try to run WebThings as explained in the Home page.

If looking for a simpler module check:

EXTRA TIPS:

For extra logging:

iotjs/src/iotjs_debuglog.c

void iotjs_debuglog_init(void) {
#if defined(__NUTTX__)
  dbglevel = "2";
#endif

Porting tips:

for (var arg in process.argv) {
  arg = process.argv[arg];
}

STATUS AND TODO:

RESOURCES:

LICENSE: CC-BY-SA-4.0

INDEX

Clone this wiki locally