-
-
Notifications
You must be signed in to change notification settings - Fork 14
IotJs
IoT.js is an Internet of Things plaform built on Jerryscript javascript engine.
For up to date information check upstream links:
- http://www.iotjs.net/
- http://jerryscript.net/
- https://github.com/samsung/iotjs
- https://github.com/samsung/iotjs/wiki
This page will explain how to install iotjs runtime to run webthing-iotjs project on contrainted devices.
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.
Only snapshot version is currently supported, if using GNU/Linux rebuild it from scratch or install snapshot debian packages:
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:
- https://software.opensuse.org//download.html?project=home%3Arzrfreefr%3Asnapshot&package=iotjs
- https://build.opensuse.org/package/show/home:rzrfreefr:snapshot/iotjs
- http://download.opensuse.org/repositories/home:/rzrfreefr:/snapshot/Debian_9.0/
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:
- https://software.opensuse.org//download.html?project=home%3Arzrfreefr%3Asnapshot&package=iotjs-snapshot
- https://software.opensuse.org//download.html?project=home%3Arzrfreefr%3Asnapshot&package=iotjs
- https://build.opensuse.org/package/show/home:rzrfreefr:snapshot/iotjs
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:/"
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
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:
- https://www.raspberrypi.org/downloads/raspbian/
- http://director.downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2018-10-11/2018-10-09-raspbian-stretch-lite.zip
IoT.js reference hardware is RaspberryPi (on Raspbian OS), but it can be easily adapted to other boards:
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.
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:
Check TizenRT page for detailed instructions to deploy IoT.js on ARTIK05x devices.
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,
// (...)
}
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:
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];
}
- Update IoT.js in TizenRT
- https://github.com/Samsung/iotjs/pull/1780# (Status: Closed)
- https://github.com/jerryscript-project/iotjs-modules/pull/3# (Status: Open)
- https://github.com/Samsung/TizenRT/pull/2z009# (Status: Merged)
- https://github.com/the-benchmarker/web-frameworks/issues/1643# (Status: Closed)
- https://github.com/pando-project/iotjs/blob/master/docs/api/IoT.js-API-reference.md#
- http://www.sosconhistory.net/2017/pdf/day2_1150_3.pdf#
- https://groups.io/g/iotjs-dev#
- <https://github.com/pando-project/iotjs/wiki/Logging-IoT.js-execution#
- https://wiki.tizen.org/images/8/85/02-IoTjs_Modules.pdf#
- http://events17.linuxfoundation.org/sites/events/files/slides/openiot-summit-2016-iotjs.pdf
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