Bosch IoT Device Management

Telemetry example - MQTT

Via telemetry you can send messages from your device to your application. There are no acknowledgement messages whether the messages really arrive at their target.

Schematic view

images/confluence/download/attachments/2012280520/telemetry-example.png

Prerequisites

  • The mosquitto_sub command is installed. See Eclipse Mosquitto.

  • The mosquitto_pub command is installed. See Eclipse Mosquitto.

  • Download the server certificate for MQTT TLS encryption:

    curl -o ISRGRootX1.crt https://letsencrypt.org/certs/isrgrootx1.pem


At this point we assume that you went through all steps described at Getting started and have already registered a device and its thing.

{
"thingId": "<your.namespace>:<your-device-name>",
"policyId": "<your.namespace>:<your-device-name>",
"attributes": {
"manufacturer": "Robert Bosch GmbH"
}
}


Let us assume, as soon as the device is instantiated, it needs to add a featureZ.

Such a command can be sent via MQTT.

Telemetry request via MQTT


  • Send a MQTT message with Mosquitto MQTT broker:

    mosquitto_pub -d -h mqtt.bosch-iot-hub.com -p 8883 -u {auth-id}@{tenant-id} -P {secret} --cafile ISRGRootX1.crt -t telemetry -m '{"topic":"<your.namespace>/<your-device-name>/things/twin/commands/modify","path":"/features/featureZ","value":{"properties":{"temperature":5}}}'



    Make sure you set all parameters correctly:

    • {tenant-id} the ID of your tenant

    • {auth-id} the ID of the credential

    • {secret} the secret that was registered with the credential (plaintext)
      Note: Please use the plaintext password you have created during the credential registration. Do not use hashed or base64 encoded when sending messages. The data transfer is secured by TLS encryption.

  • You should then get a response like this:

    Client 477111 sending CONNECT
    Client 477111 received CONNACK
    Client 477111 sending PUBLISH (...)
    Client 477111 sending DISCONNECT


Update the thing

This part happens automatically within the Bosch IoT Things service.

Given that the thing policy allows you to apply the change, the thing is enlarged with featureZ or with the new temperature value.

Potential listeners with read permission would additionally get an event.

Request the thing

Here we want to check that Bosch IoT Things has processed the command

Additionally, the solution subscribing for events of this thing should have received an event respectively.

https://apidocs.bosch-iot-suite.com - Things HTTP API > GET /things

  • Get a new Suite token and authorize with it at the Things API docs

    images/confluence/download/attachments/2012280520/auth-things-api.png
  • Get things request to see that the change has been delivered to the thing:

    • Click Try it out.

    • Set the Id to
      <your.namespace>:<your-device-name>.

    • Click Execute.

The response might look as in the following code block.

{
"thingId": "<your.namespace>:<your-device-name>",
"policyId": "<your.namespace>:<your-device-name>",
"attributes": {
"manufacturer": "Robert Bosch GmbH"
},
"features": {
"featureZ": {
"properties": {
"temperature": 5
}
}
}
}


Congratulations,
you have just executed successfully your first twin command.