Skip to content
Philippe Coval edited this page Apr 26, 2019 · 41 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 (ping @TizenHelper):

Presentation

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:

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.

MASTODON-LITE:

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

mastodon-lite

USING MASTODON API

To use API you need 1st to join an instance and create an application and generate a token to be used by client,

Steps are explained on related project's README file:

USING MASTODON-LITE WITH IOTJS:

First, you need to install IotJs runtime, on supported OS (GNU/Linux, TizenRT etc) then try the example from mastodon-lite project mentionned above:

git clone https://github.com/rzr/mastodon-lite ; cd maston-lite
iotjs example
# error: TODO: edit configuration file ~/.mastodon-lite.json

Error will be fixed once 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", // TODO: update if using a different host
  "port": 443,
  "api": "/api/v1",
  "rejectUnauthorized": false
}

Run again it will list online activities in JSON format.

Run it with a message as first argument then it will post a public message to the web:

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 USING IOTJS

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:

git clone "https://github.com/rzr/mastodon-lite"
make -C mastodon-lite run
error: TODO: edit configuration file ~/.mastodon-lite.json
  "access_token": "[TODO: Update with app token …]" ...

Create an app on your mastodon instance, then you can verify:

cd mastodon-lite && iotjs example/index.js \
      "Hi @TizenHelper from #Iotjs"

Run webting server and set a level value:

make -C mastodon-lite/example/webthing run

curl -H "Content-Type: application/json" \
  -X PUT --data '{"level": 42}' \
   http://localhost:8888/properties/level

As suggested you can try and see posted message at:

Status: Released

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.

MAKING A WEBTHING ACTUATOR USING NODE

Node can used as well, 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:

For reference following development branch was deployed on a RaspberryPi v3 (same as Gateway or other host)

RULE ENGINE:

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:

mozilla-iot-gateway-sensors-20180406rzr

GATEWAY ADAPTER

This notification alert, is also adapted to Gateway as ActivityPub adapter, it can be installed as addon, from settings menu, then configure it using credetials as explained at:

Once enabled the actuator can be added from gateway's dashboard, and text property could be changed manually or by rule engine.

Related:

STATUS

RESOURCES

LICENSE

INDEX

Clone this wiki locally
You can’t perform that action at this time.