Configuring the Platform through the API

The Export MQTT Service can be used to publish data into SmartWorks IoT using the MQTT credentials and topic for each thing (see the Credentials panel of the Thing in the AnythingDB).

The Edge API is currently not synced with the Cloud API. You need to create a Thing in the AnythingDB on the Cloud first, before creating the twin at the Edge using the API client. The thingId generated on the Cloud side needs to be used when creating the Thing at the Edge.

Things

The following example can be used if the Virtual Meter driver has been installed. Replace :thingId with the actual thingId created on the Cloud.

A Virtual Meter can be created by POSTing to:

POST /things

With request body:
{
"@context": [ "https://www.w3.org/2019/wot/td/v1",
{
"swx": "https://swx.altairone.com/schemas"
}
 ],
  "@type": [
"swx:Meter", "swx:Virtual"
 ],
"id": "/things/:thingId", "title": "My Virtual Meter", "properties": { "UD_DTYPE_KWH_ODM": { "title": "UD_DTYPE_KWH_ODM",
"description": "",
"type": "number", "readOnly": true
 },
 "UD_DTYPE_KW_AVG": {
 "title": "UD_DTYPE_KW_AVG",
 "description": "",
 "type": "number",
 "minimum": 5,
 "maximum": 30,
 "readOnly": true
 },
 "dataUsagePollSecs": {
 "title": "Data Usage Poll Secs",
 "description": "",
 "type": "integer",
 "readOnly": false
 }
 }
}

Any property that is not readOnly (like dataUsagePollSecs in this example) can be “set” afterwards but using the endpoint:

PUT /things/{thingID}/properties/{property}

With request body:
{
 "{property}": {value}
}

Configure the Edge Compute Platform System for Publishing

To configure the Edge Compute Platform system for publishing, first add a message template (optional), then a client for the MQTT broker, and then a publisher using the client and template.

  1. Create a new message template by POSTing:
    POST /exports/mqtt/messageTemplates
    with a message body as follows:
    {
        "id": "",
        "title": "Data",
        "description": " Message Template for Data Publishing ",
        "template": "{\"thingId\":\"@thingID\",\"timestamp\":@timestamp,\"data\":@data,\"title\":\"@wot:title\"}"
    }
  2. Leave the id blank. The response will show the message template object with the id filled in. This id is needed as the “templateId” for the publisher.
  3. The client to connect to the MQTT broker can be created by POSTING:
    POST /exports/mqtt/clients
    with a message body as follows:
    {
      "id": "",
      "title": "My Client",
      "description": "Describes My Client",
      "connectionURL": "tcp://localhost:1883",
      "pem": "",
      "username": "myUser",
      "password": "myPassword"
    }
    
  4. Fill in the connectionURL, pem (if using SSL), username, password, and topic as required. Use the details provided on the Credentials page of the Thing in the AnythingDB.
  5. The publisher to send telemetry data to the MQTT broker as a stream can be created by POSTing:

    POST /exports/mqtt/publishers

    with a message body as follows:
    {
      "id": "",
      "title": "My Publisher",
      "description": "Describes My Publisher",
      "clientId": "{clientId}",
      "qos": 0,
      "topic": "my-topic",
      "templateId": "{messageTemplateId}",
      "messageType": "property",
      "publishTags": [
        "raw"
      ],
      "enabled": true,
      "restricted": false
    }
    
  6. Use the clientId and templateId from above. Leave the "id' for the publisher empty. The response body will have the newly generated publisherId.
  7. The message template is optional. When not used leave “templateId” blank.
  8. Map the publisher to a Thing (we used “restricted=yes”), as follows:
    POST /exports/mqtt/publishers/:publisherID/things
    with a message body as follows:
    {
    "publisherId": "",
    "thingId": ""
    }
  9. Fill in the publisherId and the thingId from the created Thing.
    Data should start showing on the Raw History section of the item as soon as it is published by the Edge.