Skip to content

intelligentli module documentation

Johny Mattsson edited this page Jul 20, 2015 · 1 revision

###intelligentli module

#intelligentli module The intelligentli module provides an easy interface to the DiUS internal IoT platform Intelligent.li, using API v2.

intelligentli.config({server="", user="", secret=""})

####Description Configures the module. Must be called before intelligentli.post() is used. Configuration is not persisted, it is run-time state only.

####Example

intelligentli.config({
  server="api.intelligent.li",
  user="b15ad8fe20073d2f4bd2fb662cc304628463872182af5a451ee9ce47b9229623",
  secret="c37df4c40a82511602c3585f4da508ef2234d0691a67eb02d73a4f4d7a3bb99a"
})

intelligentli.post(timestamp, json_payload, callback)

####Description Posts a payload to Intelligent.li. In case of (most) errors, the callback function will be called with a string argument containing some further information. On successful posting, the callback is called with a nil argument. Errors such as bad arguments or lack of network connectivity typically result in an immediate error rather than a callback, as these are not related to the Intelligent.li service itself.

The current UTC time has to be provided in order for the encryption/negotiation to succeed. Some variation is acceptable. Typically this timestamp will come from the rtctime module.

The JSON format is specified in the Intelligent.li API docs. At a glance, the minimal is:

{
  "streams": [
    {
      "name": <node+sensor-id>,
      "data": [
        {
          "time": <utctime>,
          "value": <sample>
        }
      ]
    }
  ]
}

Using the cjson module is highly recommended over plain old string concatenation.

See also

####Example

local samplejson = cjson.encode({
  streams = {
    { name = "nodeX-temp", data = {
      { time = 1437356499, value = 26000 },
      { time = 1437356559, value = 25875 }
    },
    { name = "nodeX-foo", data = {
      { time = 1437356600, value = 0.1231 }
    }
  }
})
intelligentli.post(rtctime.get(), samplejson, function(err) print(err or "OK!") end)