Today we will focus on the gateway, as it is the core component of the whole framework. Version 0.4.0 was just released, so you can try it your own on Raspberry Pi 3. The Raspberry Pi 3 is the reference platform, but it should be possible to port to other single board computers (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
lsblk # Identify your sdcard adapter ie:
wget -O- $url | funzip | sudo dd of=$disk bs=8M oflag=dsync
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/*
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)
ssh firstname.lastname@example.org # Raspbian default password for pi user is "raspberry"
Let’s also track local changes to /etc by installing etckeeper, and change the default password.
sudo apt-get install etckeeper
sudo passwd pi
You should now be able to access the web server, which is running on port 8080 (earlier version used 80):
It will redirect you to a page to configure wifi:
Connect to a WiFi network?
We can skip it for now:
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.
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.
Then administrator is now welcome to register new users:
Create your first user account:
And we’re ready to use it:
No devices yet. Click + to scan for available devices.
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:
Mozilla IoT Virtual Things Adapter
by Mozilla IoT
Once enabled It should be listed along ThingURLAdapter on the adapters page:
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.
Virtual On/Off Color Light
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.
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.
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?
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:
- BH1750: for measuring illuminance (module is about 1 or 2 USD
- BMP085: for measuring temperature, or any compatible sensor (ie: BMP180)
You can double check if addresses are present on I2C the bus:
sudo apt-get install i2c-tools
/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
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:
git clone --depth 1 -b 0.0.1 $url $dir
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:
Generic Sensors for Mozilla IoT Gateway
It will appear on the adapters page too:
Now we can add those sensors as new things (Save and done buttons):
Ambient Light Sensor
Unknown device type
Unknown device type
Then they will appear as:
- http://gateway.local:8080/things/0 (for Ambient Light Sensor)
- http://gateway.local:8080/things/1 (for Temperature Sensor)
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