-
-
Notifications
You must be signed in to change notification settings - Fork 14
Arduino
In IoT domain Micro controllers (MCU) are very popular, because of low cost and low consumption.
Arduino boards are very popular in academics or DiY communities, then API were ported to other micro controllers than Atmel, like espresif ESP8266, ESP32 etc.
Mozilla's is supporting Arduino API for through this SDK project:
The supported language to program MCU webthings is currently C/C++.
Note that IoT.js is also targeting constrained devices (like ARTIK05x on TizenRT or STM32 on NuttX).
So to recap, MCUs can serve WebThings API for Mozilla Gateway either in native language (C/C++) or using script runtime (IotJs, uPython, enventually Lua too?) but Gateway is too resource consuming for that.
Alternatively check other non-arduino frameworks for MCU supporting IotJs.
"Smart Orchid Demo" showed a light controller and arduino moisture sensor:
A moisture sensor is just plugged on analog pin (and +5v GND, the digital pin was not used here, but it can be used for other boards without analog like RaspberryPi and use potentiometer as "hardware threshold").
Note: IotJs is not used here, only Arduino API.
Developing webthing on Arduino APIs or compatible platforms such as Espressif ESP8266 or ESP32
Once your have setup build tool, Developing is pretty straight forward, and it has been covered elsewhere:
- https://s-opensource.org/2018/06/21/webthing-iotjs/
- https://www.crowdsupply.com/anavi-technology/light-controller/updates/connecting-anavi-light-controller-to-mozilla-iot-gateway
- http://esp8266.net/
- http://esp32.net/
The RGB Lamp code is upstreamed at:
Watch video for more:
Note: IotJs is not used here, only Arduino API.
Since I shared a slightly more advanced example that handle ADC port, it was used to monitor the moisture of the ground of a plant, or any analogic sensor:
To rebuild, just use GNU make:
git clone --depth 1 --recursive https://github.com/mozilla-iot/webthing-arduino ; cd webthing-arduino
make
make -C examples/LevelSensor upload monitor
for reference a docker file has been upstreamed:
sudo=$sudo # In not configured for $USER
sudo apt-get install docker.io # Or adapt
$sudo docker build https://github.com/mozilla-iot/webthing-arduino.git
# AVR Memory Usage
# ----------------
# Device: atmega2560
# Program: 40136 bytes (15.3% Full)
# (.text + .data + .bootloader)
# Data: 1451 bytes (17.7% Full)
# (.data + .bss + .noinit)
If you prefer you can setup IDE and do the manual configuration.
Note, hardware side, I used an Arduino mega with Ethernet Shield ( same one in this IoTivity 1.2 "arduino switch" demo )
TizenRT OS is also targeting lower class devices, currently hardware support is limited to a few platforms like ARTIK05x and a few others plus QEmu.
The key feature for Javascript developers is IoT.js support, this mean code can be portable from on GNU/Linux OS to contrained devices without any rebuild effort, which is is not the case of Arduino compabible devices.
Related Upstreamed contributions:
- https://github.com/mozilla-iot/webthing-arduino/pull/8# (Released in v0.2.0)
- https://github.com/mozilla-iot/webthing-arduino/pull/23# (Released in v0.4.1)
- https://github.com/mozilla-iot/webthing-arduino/pull/24# (Merged)
- https://github.com/mozilla-iot/webthing-arduino/pull/25# (Merged)
- https://github.com/mozilla-iot/webthing-arduino/pull/26# (Merged)
For reference code was developed in this repo: (but most of it is upstreamed)
Possible open tasks:
- TODO: refactor to handle Arduino's WiFi shield too
- TODO: port iotjs to arduino/ESP and compare performance
STM32 contributions:
- https://github.com/stm32duino/STM32Ethernet/pull/17# (Merged)
- https://github.com/stm32duino/Arduino_Core_STM32/pull/401# (Merged)
- https://github.com/mozilla-iot/webthing-arduino/pull/41# (Merged)
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