-
Notifications
You must be signed in to change notification settings - Fork 0
Social
There is no doubt that the Web became a platform of choice for online social interactions, but it can be also used in IoT context (see Concept).
To minimize privacy concerns, the open web prefers decentralized technology or services operators and in IoT Context rely on user's controlled Gateway.
W3C published a "Activity Pub" specification, it was then implemented into Mastodon FLOSS (also GNUsocial, StatusNet ...), this is what is going to be explained.
But if you don't know about it you're welcome to join now and practice it:
To illustrate Concept, let's try to address a generic problem:
How to notify a trusted peer about a given situation ?
For example, I want to send a reminder to my neighbor that my plants should be watered when away for home.
Watch social part of the "Smart Orchid" demo:
- When a Gateway's rule monitors the moisture of plant's ground (Sensor on Extra MCU Arduino)
- When too dry rule triggers automatically a notification to user's neighbor (registered to mastodon social network)
- https://player.vimeo.com/video/279677314#web-of-things-agriculture-20180712rzr.webm
Note, here message is public for demo purposes, but it should be private for privacy concerns
Following chapters are explaining this "Social IoT" case and how to replicate the "notification" service, here demonstrated as proof of Concept.
Note, in longer term it could make sense to ship this feature into Gateway as adapter.
Originally when I discovered IoT.js's HTTPS module, I made a simple command line client to post to the Mastodon social network:
- https://github.com/rzr/mastodon-lite
- https://www.slideshare.net/SamsungOSG/easy-iot-with-javascript/10
Since It's also compatible with node, let's try the module published in NPM repo:
It can be added using npm tool:
ls package.json || npm init
npm install mastodon-lite
cd node_modules/mastodon-lite && npm test
# error: TODO: edit configuration file ~/.mastodon-lite.json
Then update the template file with your credentials:
// cat .mastodon-lite.json
{
"access_token": "[TODO: Update with app token at https://mastodon.social/settings/applications]",
"host": "mastodon.social",
"port": 443,
"api": "/api/v1",
"rejectUnauthorized": false
}
Run again it will list online activities in JSON.
Run it with a message as first argument then it will post a public message to the web:
npm test 'https://www.npmjs.com/package/mastodon-lite# #WebOfThings #MastodonLite can be used for #SocialIoT use case cc: @TizenHelper'
Message will be then visible to public (and followers notified):
For more details check explanations on how to use and setup account:
Note, If you want to use earlier GNU social instance it should work same or easy to adapt.
To run it using iotjs (or even TizenRT) it's the very same just change the 1st command from node to iotjs.
git clone https://github.com/rzr/mastodon-lite
iotjs example 'https://github.com/rzr/webthing-iotjs/wiki/Social# #WebOfThings hints for #Social #IoT using #IoTjs @Mastodon @Mozilla #WebThing cc: @TizenHelper'
Message also published:
Then it's also easy to implement a webthing actuator which post generic messages to the social media:
This webthing just broadcast a generic "value' like demonstrated earlier, on demo it worked on node but I am going to explain how to use it using IoT.js:
project='webthing-iotjs'
url="https://github.com/rzr/$project"
branch='sandbox/rzr/iotjs/devel/master'
mkdir -p "~/mozilla-iot/$project" ; cd "~/mozilla-iot/$project"
git clone --recursive --depth 1 -b "$branch" "$url" .
cat ~/.mastodon-lite.json # Insert previously created credentials file
make -C example/mastodon-thing run
It will install modules setup env run start server and reuse your credentials file created earlier:
IOTJS_EXTRA_MODULE_PATH=~/webthing-iotjs/example/mastodon-thing/../..:node_modules iotjs mastodon-thing.js
Usage:
iotjs mastodon-thing.js [port]
Try:
curl -X PUT -H 'Content-Type: application/json' --data '{"level": 42}' "http://localhost:8888/properties/level"
As suggested you can try and see posted message at:
For reference following development branch was deployed on a RaspberryPi v3 (same as Gateway or other host)
Node was used, it's very similar (note that hardcoded strings are differing):
project='webthing-node'
url="https://github.com/tizenteam/$project"
branch='sandbox/rzr/devel/demo/master'
mkdir -p "~/mozilla-iot/$project" ; cd "~/mozilla-iot/$project"
git clone --recursive --depth 1 -b "$branch" "$url" .
npm install
Then update credentials file: ~/mozilla-iot/webthing-node/.mastodon-lite and run:
NODE_PATH=. node example/mastodon-thing
Usage:
node ~/mozilla-iot/webthing-node/example/mastodon-thing [port]
Try:
curl -H "Content-Type: application/json" http://localhost:8042/properties/level
In other shell read and update the level value:
url=http://localhost:8042/properties/level
curl -H "Content-Type: application/json" $url
# {"level":0}
curl -X PUT -H 'Content-Type: application/json' --data '{"level": 42}' "$url"
Expected to be printed in node's shell:
NODE_PATH=. node example/mastodon-thing
@rzr@mastodon.social 's plants are drying (42) ! Can neighboor @TizenHelper water them ?
And message posted to the WWW:
All the magic is Gateway's "rule engine" that link the Extra MCU "Arduino Sensor" to the "Social Actuator" (to post a user message).
So you need to logically "wire" Sensor to Actuator on the Gateway dashboard, (I used <20 condition).
Watch linked video on other I2C sensors this is the same UI:
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