MOZILLA IOT GATEWAY ADD-ONS

[[Gateway]] can be extended using addons

Originally published at:

Connecting sensors to Mozilla’s IoT Gateway

Here is am updated post about our first Mozilla’s IoT efforts, the generic sensor adapter and specifically the gateway project which is illustrating "Web Of Things" concept to create a decentralized Internet of Things, using Web technologies.

Today we will focus on the gateway, as it is the core component of the whole framework. Version 0.7.0 was released on begining of 2019, so you can try it your own on Raspberry Pi 3 (but 1st version adapter was supporting 0.4.0 and later)

The Raspberry Pi 3 is the reference platform, but it should be possible to port to other single board computers (supporting [[GnuLinux]] like ARTIK, etc).

The post will explain how to get started and how to establish basic automation using I2C sensors and actuators on gateway’s device (without any cloud connectivity).

To get started, first install the gateway according to these straightforward instructions:

Prepare SD Card

You need to download the Raspbian based image "gateway-0.7.0.img.zip" (1GB archive) and dump it to SD card (2.6GB min TODO).


sudo apt-get install sudo wget unzip file

version="0.7.0"
url="https://github.com/mozilla-iot/gateway/releases/download/${version}/gateway-${version}.img.zip"

lsblk # Identify your sdcard adapter ie:
dev=/dev/disk/by-id/usb-Generic-TODO

sudo sync && file "$dev" && wget -O- "$url" | funzip | sudo dd of="$dev" bs=8M oflag=dsync && sync

TODO:

If you only want to use the gateway and not hack on it, you can skip this next part which enables a developer shell though SSH. However, if you do want access to a developer shell, mount the 1st partition called “boot” (you may need to replug your SD card adapter) and add a file to enable SSH:

sudo touch /media/$USER/boot/ssh
sudo umount /media/$USER/*

First boot

Next, install the SD card in your Raspberry PI 3 (Older RPis could work too, particularly if you have a wifi adapter).

When it has completed the first boot, you can check that the Avahi daemon is registering “gateway.local” using mDNS (multicast DNS)

TODO

Logging in

You should now be able to access the web server, which is running on port 8080 (earlier version used 80):

http://gateway.local/

It will redirect you to a page to configure wifi:

URL: http://gateway.local/
Welcome
Connect to a WiFi network?
FreeWifi_secure
FreeWifi
OpenBar
...
(Skip)

We can skip it for now:

URL: http://gateway.local/connecting WiFi setup skipped The gateway is now being started. Navigate to gateway.local in your web browser while connected to same network as the gateway to continue setup. Skip

After a short delay, the user should be able to reconnect to the entry page:

The gateway can be registered on mozilla.org for remote management, but we can skip this for now.

Mozilla IoT Welcome

Choose a secure web address for your gateway: .mozilla-iot.org

Please keep me updated about new features and contribution opportunities. Privacy Policy

"Skip"

Then administrator is now welcome to register new users:

URL: http://gateway.local:8080/signup/

Mozilla IoT
Welcome
Create your first user account:
user: user
email: user@localhost
password: password
password: password
Next

And we’re ready to use it:

URL: http://gateway.local:8080/things

Mozilla IoT

No devices yet. Click + to scan for available devices.

(Menu:)

Things
Rules
Floorplan
Settings
Log out

Filling dashboard

You can start filling your dashboard with Virtual Resources,

First hit the “burger menu” icon, go to "settings" page, and then go to the "addons" page.

Here you can enable a “Virtual Things” adapter:

URL: http://gateway.local:8080/settings/addons/
virtual-things-adapter 0.1.4
Mozilla IoT Virtual Things Adapter
by Mozilla IoT

Click on "Add" then it will show as "Installing..." until "Added"

Once enabled It should be listed along ThingURLAdapter on the adapters page:

URL: http://gateway.local:8080/settings/adapters
VirtualThingsAdapter (virtual-things)
ThingURLAdapter (thing-url-adapter)

You can then go back to the 1st Things page (it’s the first entry in the menu):

We can start adding “things” by pressing the bottom menu.

URL: http://gateway.local:8080/things
Virtual On/Off Color Light
Color Light
Save

Then press “Done” at bottom.

From this point, you can decide to control a virtual lamp from the UI, and even establish some basic rules (second entry in menu) with more virtual resources.

Sensing Reality

Because IoT is not about virtual worlds, let’s see how to deal with the physical world using sensors and actuators.

For sensors, there are many way to connect them to computers using analog or digital inputs on different buses. To make it easier for applications developers, this can be abstracted using W3C’s generic sensors API.

While working on IoT.js‘s modules, I made a “generic-sensors-lite” module that abstracted a couple of I2C drivers from the NPM repository. To verify the concept, I have made an adapter for Mozilla’s IoT Gateway (which is running Node.js), so I published the generic-sensors-lite NPM module first.

Before using the mozilla-iot-generic-sensors-adapter, you need to enable the I2C bus on the gateway (version 0.4.0, master has I2C enabled by default).

TODO: ssh

Settings / Developper / Enable SSH

ssh pi@gateway.local #

pi@gateway.local's password: 


sudo raspi-config
Raspberry Pi Software Configuration Tool (raspi-config)
5 Interfacing Options Configure connections to peripherals
P5 I2C Enable/Disable automatic loading of I2C kernel module
Would you like the ARM I2C interface to be enabled?
Yes
The ARM I2C interface is enabled
ls -l /dev/i2c-1
lsmod | grep i2c
i2c_dev 16384 0
i2c_bcm2835 16384 0

Of course you’ll need at least one real sensor attached to the I2C pin of the board. Today only 2 modules are supported:

You can double check if addresses are present on I2C the bus:

sudo apt-get install i2c-tools # TODO
/usr/sbin/i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- 23 -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- 77

Install mozilla-iot-generic-sensors-adapter

TODO : add

Generic Sensors 0.0.6

Until sensors adapter is officially supported by the mozilla iot gateway, you’ll need to install it on the device (and rebuild dependencies on the target) using:

url=https://github.com/rzr/mozilla-iot-generic-sensors-adapter
dir=~/.mozilla-iot/addons/generic-sensors-adapter
git clone --depth 1 -b 0.0.1 $url $dir
cd $dir
npm install

Restart gateway (or reboot)

sudo systemctl restart mozilla-iot-gateway.service
tail -F /home/pi/.mozilla-iot/log/run-app.log

Then the sensors addon can be enabled by pressing the “enable” button on the addons page:

URL: http://gateway.local:8080/settings/addons generic-sensors-adapter 0.0.1 Generic Sensors for Mozilla IoT Gateway

It will appear on the adapters page too:

URL: https://gateway.local/settings/adapters
VirtualThingsAdapter
virtual-things
ThingURLAdapter
thing-url-adapter
GenericSensorsAdapter
generic-sensors-adapter

Now we can add those sensors as new things (Save and done buttons):

URL: http://gateway.local:8080/things

Ambient Light Sensor
(Multi Level Sensor)
Save

Temperature Sensor
(Multi Level Sensor)

Color Sensor
(Custom thing)
Save

Then "Done" button

Then they will appear as:

To get value updated in the UI, they need to turned on first (try again if you find a big, and file tickets I will forward to drivers authors).

A GPIO adapter can be also used for actuators, as shown in this demo video.

If you have other sensors, check if the community has shared a JS driver, and please let me know about integrating new sensors drivers in generic-sensors-lite

MORE

ping gateway.local
ssh pi@gateway.local # Raspbian default password for pi user is "raspberry"
ssh: connect to host gateway.local port 22: Connection refused # TODO

Let’s also track local changes to /etc by installing etckeeper, and change the default password.

sudo apt-get update
sudo apt-get install etckeeper
sudo passwd pi
sudo passwd 
sudo apt-get install zile jq screen

Then install [[IoTjs]] and start implementing some webthings

RESOURCES:

LICENSE