Creating your own infrastructure

Data and events

The Ambient 16 outputs two kinds of information:

  1. Data: they are stored into a database every 10 seconds. Data reflect what has been sensed during the past 10 seconds.

  2. Events: events are intantaneous signals.

Let’s take a simple example to understand the difference. When the Ambient 16 detects a motion, it will send an instantaneous event, for instance to switch on a Phillips Hue lamp through IFTTT. In parallel, it will record the quantity of motion it has observed during these 10 seconds and the number of events sent.

Recording data into InfluxDB is useful for displaying graphs of measurements. It is useful for creating your own A.I. by analysing past data. Sending events is useful for instant controls and alarms.

Protocols

The Ambient 16 uses two different protocols for interracting with the outside world: InfluxDB and MQTT. Both are opensource and easy to install under many systems like Raspberry Pis or Synology NAS.

MQTT

MQTT is a well established standard for IoT messaging. Its acronym means Message Queuing Telemetry Transport. The sender of the message – the Ambient 16 - connects to a message broker. This can be the one installed on our cloud. This can be one you have installed at home on your computer or your Raspberry Pi. You can set the MQTT broker URL and its credentials from our App. The Ambient 16 will then PUBLISH message.

An application will SUBSCRIBE to messages from the MQTT broker. This can be a thrid party application or your own python application (we provide sample codes for that). When an Ambient 16 publishes a message, it will be receives by all the applications that have subscribed.

_images/mqttExplained.png

For instance, let’s imagine we have a Ambient 16 with the device UDID abc457def123. (The UDID is the unique device ID printed on the back of the sensor). You have set your sensor to send MQTT events when a motion from left to right is detected. When a motion is detected, the Ambient 16 sends the following message to the MQTT broker:

{
    "eventId":9,
    "timeOfOccurrence": 1600575151
}

The event ID is 9 (this is the code for left to right motion events. See here for all event codes). The time of occurence is the unix timestamp, standing for the time and date when the event occured. Here, 1600575151 is the timestamp for Sunday, 20 Sep 2020 04:12:31.

On the other side, an application will have subscribed to event comming from that device, by asking that every message with the topic

/abc457def123/event

The topic can be seen as a filter for receiving specific events. You could require to receive events from all your sensors by replacing the UDID with a wildcard

/*/event

In the same way, if you have parametered the Ambient 16 to send its data through MQTT, your application should subscribe to

/abc457def123/data

and it will receive a message containing all the values measured in the past 10 seconds, every 10 seconds.

InfluxDB

InfluxDB is a time series database. It stores series of measurements along the time. It is only used for data, not for event. It will keep the history of measurements. A sensor will send its data to influx every 10 seconds.

_images/influxExplained.png

For accessing the data, and application will send an HTTP request to the InfluxDB server like this one

http://www.myinfluxdbip.com:8068/query?pretty=true&u=USERNAME&p=PASSWORD&db=MYDATABASE&q='SELECT mean(calibratedValue_celcius) FROM temperature WHERE udid='abc457def123' AND time>=1600575151s AND time<=1600575100s GROUP BY time(10s) fill(linear)'

The request contains all the information need for querying the database for temperature in celcius. For more information on data access, please read this document.

Your choice

Before creating your own infrastructure, you should decide which is the best for you.

For sending data, you can choose from the following options

  1. Use our cloud InfluxDB

  2. Use your local InfluxDB

  3. Use your local InfluxDB and our cloud InfluxDB in parallel

  4. Use your local MQTT broker

  5. Use our cloud MQTT broker

For sending events you have the choice between:

  1. Use your local MQTT broker

  2. Use our cloud MQTT broker

Our cloud infrastucture has a data retention policy of 7 days and a limited number of events being transmitted every day for free plans. It has one year of retention time and full events for paid plans (see here).

Despite all the efforts and precaution we took for securing our data on our cloud and during their transmission, you might rightly think that smarthome data should stay home. We, at descampsTECHNOLOGY totally understand and we have opened our Ambient 16 such that no data need to leave your home if this is your choice

Viewing Data

Frédéric/Thibaud will describe soon how to view data.

Debugging Events

Frédéric/Thibaud will describe soon how to debug the events.