-
-
Notifications
You must be signed in to change notification settings - Fork 14
Raspbian
Following previous efforts to deploy iotjs on RaspberryPi 0, I am happy to announce that IoTjs 1.0 landed in Debian, and was sync’d to Raspbian for ArmHF and Ubuntu as well.
While the package is targeting the next distro release, it can be easily installed on current versions by adding a couple of config files for “APT pinning”.
If you haven’t set up Raspbian 9, just dump the current Raspbian image to SDcard (for the record I used version 2018-03-13-raspbian-stretch-lite)
Boot your Pi. To keep track of changes in /etc/, let’s install etckeeper:
sudo apt-get update
sudo apt-get install etckeeper
Upgrade current packages:
sudo apt-get upgrade
sudo apt-get dist-upgrade
Declare the current release as default source:
cat<<EOT | sudo tee /etc/apt/apt.conf.d/50raspi
APT::Default-Release "stretch";
EOT
Then add a repo file for the next release:
cat /etc/apt/sources.list | sed 's/stretch/buster/g' | sudo tee /etc/apt/sources.list.d/raspi-buster.list
Unless you want to test the upcoming release, it maybe be safer to avoid upgrading all packages yet. In other words, we prefer that only IotJs should be available from this “not yet supported” repo.
cat<<EOT | sudo tee /etc/apt/preferences.d/raspi-buster.pref
Package: *
Pin: release n=buster
Pin-Priority: -10
EOT
cat<<EOT | sudo tee /etc/apt/preferences.d/iotjs.pref
Package: iotjs
Pin: release n=buster
Pin-Priority: 1
EOT
Now iotjs 1.0-1 should appear as available for installation:
sudo apt-get update ; apt-cache search iotjs
iotjs - Javascript Framework for Internet of Things
apt-cache policy iotjs
iotjs:
Installed: (none)
Candidate: 1.0-1
Version table:
1.0-1 1
-10 http://raspbian.raspberrypi.org/raspbian buster/main armhf Packages
Let’s install it:
sudo apt-get install iotjs
man iotjs
Even if version 1.0 is limited in compared to the development branch, you can start by using the http module which is enabled by default (not https).
To illustrate this, when I investigated “air quality monitoring” for a TizenRT+IoT.js demo I found out that OpenWeatherMap is collecting and publishing “Carbon Monoxide” Data, so let’s try their REST API.
Create a file, example.js for example, that contains:
var http = require('http');
var location = '48,-1';
var datetime = 'current';
//TODO: replace with your openweathermap.org personal key
var api_key = 'fb3924bbb699b17137ab177df77c220c';
var options = {
hostname: 'api.openweathermap.org',
port: 80,
path: '/pollution/v1/co/' + location + '/' + datetime + '.json?appid=' + api_key,
};
// workaround bug
options.headers = {
host: options.hostname
}
http.request(options, function (res) {
receive(res, function (data) {
console.log(data);
});
}).end();
function receive(incoming, callback) {
var data = '';
incoming.on('data', function (chunk) {
data += chunk;
});
incoming.on('end', function () {
callback ? callback(data) : '';
});
}
And just run it:
iotjs example.js
{"time":"2018-03-27T02:24:33Z","location":{"latitude":47.3509,"longitude":-0.9081},"data":[{"precision":-4.999999987376214e-07,"pressure":1000,"value":1.5543508880000445e-07}
(...)
You can then use this to do things such as update a map or raise an alert on anything useful, or try to rebuild master branch.
Article originally published at:
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