Skip to content
Philippe Coval edited this page Aug 24, 2018 · 42 revisions

SOCIAL WEB OF THINGS

INTRODUCTION:

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:

DEMO:

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 Arduino)
  • When too dry rule triggers automatically a notification to user's neighbor (registered to mastodon social network)

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.

MASTODON-LITE:

Originally when I discovered IoT.js's HTTPS module, I made a simple command line client to post to the Mastodon social network:

USING MASTODON-LITE WITH NODE:

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.

USING MASTODON-LITE WITH IOTJS:

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:

MAKING A WEBTHING ACTUATOR

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:

RULE ENGINE:

All the magic is Gateway's "rule engine" that link the Extra "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:

mozilla-iot-gateway-sensors-20180406rzr

LICENSE

INDEX

Clone this wiki locally