Add semantic to the Node-RED msg payload with JSON-LD

Posted on Updated on

In the NODE-Red ecosystem, many nodes are built and published.
When someone creates a node that produces geo coordinates (this is an example), and another a node that consumes geo coordinates, it is very important that these two nodes can be linked together in NODE-Red. To achieve that, the former should produce a payload that the latter can read.

Using JSON or msg is not enough:

{
 "latitude" : "40.75",
 "longitude" : "73.98"
 }

Also consider another example:

{
"temperature" : "40"
}

What does it refer to? degrees Celsius or Fahrenheit?

We must agree on the content of the JSON object in the payload.

TheThingBox choice

In the ThingBox project (theThingbox.io) we decided to use JSON-LD to format the payload.

JSON-LD allows to uniquely define the content of a JSON object.

{
 "@type" : "http://schema.org/GeoCoordinates",
 "http://schema.org/latitude" : "40.75",
 "http://schema.org/longitude" : "73.98"
 }

When a node finds an object containing:

"@type" : "http://schema.org/GeoCoordinates"

then the semantic of the object is uniquely defined.

The members are also uniquely defined.

The previous object can be “compacted” by factoring paths into a context:

{
 "@context": "http://schema.org",
 "@type": "GeoCoordinates",
 "latitude": "40.75",
 "longitude": "73.98"
 }

Many objects are already defined in schema.org.
Find more about JSON-LD at http://json-ld.org  and use it in Nodes!

Advertisements

3 thoughts on “Add semantic to the Node-RED msg payload with JSON-LD

    David Janes (@dpjanes) said:
    August 6, 2014 at 11:27 pm

    Let’s talk! I’ve been working on this for the last 18 months or so
    http://www.slideshare.net/dpjanes/iotdb-semantic-metadata-for-the-internet-of-things

    You’ll note (e.g.) that with the temperature above it’s a little more difficult to get a pointer to “temperature in degrees fahrenheit”. I think I’ve got all that solved.

    {
    “@type” : “https://iotdb.org/iotdb/models/geo-coordinates”,
    “@context”: “https://iotdb.org/iotdb/models/geo-coordinates”,
    “latitude” : “40.75”,
    “longitude” : “73.98”
    }

    Maybe more importantly, we’ve defined a vocabulary also for semantic control of objects, e.g. “turn this on” – and open source Node libraries to work with all of this.

    fundatrix responded:
    August 11, 2014 at 8:16 am

    Very interesting. Add links when it can help.

    David Janes (@dpjanes) said:
    August 11, 2014 at 9:06 pm

    I’ll be playing with the ThingBox soon and see how I can fit in IOTDB. A great place to start with our stuff is here: https://iotdb.org/docs/node/getting-started

    Code-wise Node-IOTDB fits into the ecosystem where Node-Red does, wiring components together, but using programming rather than a visual tool. Here’s a simple example of wiring a switch to a light.

    var iotdb = require("iotdb")
    var iot = iotdb.iot()
    
    var contacts = iot.connect("SmartThingsContact")
    var lights = iot.connect("HueLight")
        
    contacts.on(':open', function(thing, open_attribute, is_open) {
        lights.set(':color', is_open ? 'red' : 'green')
    })
    

    And a lot lot more:
    https://iotdb.org/social/imadeit/tagged/IOTDB

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s