Skip to content

Latest commit

 

History

History
35 lines (30 loc) · 2.03 KB

README.md

File metadata and controls

35 lines (30 loc) · 2.03 KB

SETUP ECLIPSE DITTO FOR AIWATCH PROJECT

Utilities

You can find:

  • [highly recommended] Eclipse Ditto v 2.4 documentation here to understand the operations carried out below but also to understand how to do other operations.
  • Eclipse Ditto repository here.
  • Examples of using Eclipse Ditto here.

BASIC OPERATIONS TO DO

  1. Open a new terminal and go in AI_WATCH_B1/ditto_kafka/commands
  2. Create a new policy
curl -X PUT 'http://localhost:8080/api/2/policies/aiwatch:policy' -u 'ditto:ditto' -H 'Content-Type: application/json' -d @policy.json
  1. Create a new digital twin
curl -X PUT 'http://localhost:8080/api/2/things/digitaltwin:Laboratorio_Corridoio' -u 'ditto:ditto' -H 'Content-Type: application/json' -d @digitaltwin.json
  1. Create a new kafka connection source from user "nginx:ditto" (A1 Module - Tracker)
curl -X POST 'http://localhost:8080/devops/piggyback/connectivity?timeout=10' -u 'devops:foobar' -H 'Content-Type: application/json' -d @create_connectionSource.json
  1. Create a new kafka connection target to user "ditto:observer" (Software streaming anomaly detector)
curl -X POST 'http://localhost:8080/devops/piggyback/connectivity?timeout=10' -u 'devops:foobar' -H 'Content-Type: application/json' -d @create_connectionTarget.json

Javascript Mapping Functions used

Below is shown on several lines the mapping function "mapToDittoProtocolMsg()" in javascript of the file connectionSource.json

function mapToDittoProtocolMsg(headers, textPayload, bytePayload, contentType) {
const jsonString = String.fromCharCode.apply(null, new Uint8Array(bytePayload));
const jsonData = JSON.parse(jsonString);
const thingId = jsonData.thingId.split(':');
const value = {
coordinates: {
properties: {
}
}
};
Object.assign(value['coordinates'][['properties']], jsonData);
return Ditto.buildDittoProtocolMsg(thingId[0], thingId[1], 'things', 'twin', 'commands', 'modify', '/features', headers, value);
}

Below is shown on several lines the mapping function "mapFromDittoProtocolMsg()" in javascript of the file connectionTarget.json

function mapFromDittoProtocolMsg(namespace, id, group, channel, criterion, action, path, dittoHeaders, value, status, extra) {
let jsonPayload = value.coordinates.properties;
let textPayload = JSON.stringify(jsonPayload);
let bytePayload = null;
let contentType = 'text/plain; charset=UTF-8';
return Ditto.buildExternalMsg(dittoHeaders, textPayload, bytePayload, contentType);
}