Service de DataChunk - Spoony 1.5

Introduction

Spoony integrate a service able to push datapoint information (ex: Power measurements) to a remote Http server in the form of JSON data.

This service allows the device to send information to the server, without need for complex network configuration, as the device connect itself to the remote server and use w3c standards protocols and data format.

In typical applications, the remote server is available through Internet connection, but using a server on the local network is also possible.

In most case, the server will simply receive data from the device and store it in a database, but other scenarios are possible according to user requirements.

4.1 Raw JSON data

4.2 Compressed JSON data

JSON data is compressed before being sent over HTTP.

Spoony use a specific compression algorithm based on LZSS adapted to constrained devices. Embedded (and server-side) compression and decompression library comes from the Open-Source project heatshrink (https://github.com/atomicobject/heatshrink). This compression algorithm use two parameters which must be known for compression and decompression: window and lookahead.

Compressed JSON data is sent to the remote server with following header:

DotVision offers free of charge the Source code used for parsing and decompression of compressed data, included in the sample Open-Source server (see paragraph 5).

Compression allow for network bandwidth reduction and reduced data usage, and is particularly suited for use over 3G/4G networks, or any other kind of pay per use network infrastructure.

While still being compliant with w3c standards, this mode of operation requires a proprietary server-side decompression algorithm.

5. Server implementation

Following are some guidelines regarding the server implementation:

Server MUST accept HTTP POST requests.

Server MUST answer 200 OK to POST request if received data is valid. If response is not sent, or if response is different from 200 OK, Spoony will retry to send the same DataChunk until his internal buffer overflow.

Server MUST answer within 2s.

Server SHOULD verify that source device is authorized to publish data and SHOULD ignore data coming from unknown or unauthorized devices.

Server SHOULD verify incoming data and validate it against the provided JSON schema before handling data.

Server SHOULD accept both compressed and raw JSON data.

DotVision can provide customers with a sample server implementation in the form of an Open-Source Microsoft® IIS Http Handler (IIS 7.0 or newer), storing data into an InfluxDb database.

Heatshrink .NET C# wrapper in form of compression/decompression Stream and utility functions

.NET C# front-end for receiving both compressed and uncompressed data transparently from devices.

.NET C# IIS Sample handler for DataChunk Requests.

.NET C# IIS Sample handler for Ping Request (used for device discovery and diagnostic and described in another document).

Both handlers store received data to a specified InfluxDb Database (v0.13) but can be adapted easily to send received data to any kind of database.

Provided source code can be used free of charge by customers to receive data from DotVision devices.

6. Device Configuration

Device is configured using xml files stored on the embedded MicroSD card.

Following files allow configuration of the DataChunkWebPushService:

File: system\services\Device\ODM\ODMDataChunk\serviceSettings.xml

<configuration>

<settings>

<add key="sourceAutomationService" value="Automation"/>

<add key="samplingPeriod" value="1"/>

<add key="chunkPoolSize" value="15"/>

<add key="datapoint" value="ade7758/FREQ"/>

<add key="datapoint" value="ade7758/VRMSA"/>

<add key="datapoint" value="ade7758/VRMSB"/>

<add key="datapoint" value="ade7758/VRMSC"/>

<add key="datapoint" value="ade7758/IRMSA"/>

<add key="datapoint" value="ade7758/IRMSB"/>

<add key="datapoint" value="ade7758/IRMSC"/>

</settings>

</configuration>

This file contains the Sample Period (Parameter “samplingPeriod”, expressed in seconds, value here is 1s), and the list of the datapoints being sampled. Here the following datapoints will be sampled and sent to the remote server:

This file contains the address of the target server (Parameter “uri”). Given address can include an optional port number.

The parameter “shrink”, when set to “true”, enable compression of JSON data as described in paragraph 4.2. If parameter is omitted or set to false, Raw (uncompressed) JSON data is sent directly to the server.

File: system\services\Device\serviceSettings.xml

<configuration version="1.0">

<!-- Service manager part -->

<settings>

<add key="rootPath" value="system/services/device"/>

<add key="fileName" value="serviceSettings.xml"/>

</settings>

<!-- Device declaration -->

<device>

<serialNumber>123456789</serialNumber>

<location>48.8566140,2.3522220,0.0</location><!--PARIS-->

<friendlyName>SpoonyDotVision-VirtualDevice</friendlyName>

<firmwareVersion>1.5.23</firmwareVersion>

<model>

<manufacturer>DotVision</manufacturer>

<manufacturerUrl>dotvision.com</manufacturerUrl>

<name>spoony</name>

<number>1.5</number>

<url/>

<presentationUrl/>

</model>

</device>

<services>

<service>

<type>NtpClient_t</type>

<name>Ntp</name>

<startMode group="2">automatic</startMode>

</service>

[ . . . ]

<service>

<type>ODMService_t</type>

<name>ODM</name>

<startMode group="3">automatic</startMode>

</service>

<service>

<type>CsvLogService_t</type>

<name>CsvLog</name>

<startMode group="3">manual</startMode>

</service>

</services>

</configuration>

Service “ODM” must be declared and configured with automatic startMode in order to be started when the device starts.

7. Available datapoints

These datapoints are available in Spoony Automation service and can be sampled.