Bosch IoT Device Management - will be discontinued by mid 2024

Command and control - one-way MQTT

One-way commands are sent from a connected business solution through Bosch IoT Things and Bosch IoT Hub to a connected device. This type of command is neither confirmed nor answered by the device.

Schematic view

images/confluence/download/attachments/2014745057/command-example.png

Prerequisites

Create command subscriber

Download the server certificate for MQTT TLS encryption

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

Start and subscribe to MQTT command topic with Mosquitto MQTT client

mosquitto_sub -d -h mqtt.bosch-iot-hub.com -p 8883 -u <authId>@<tenantId> -P <your-password> --cafile ISRGRootX1.crt -k 30 -t command///req/#


Make sure you replace all parameters correctly:

  • <authId> the ID of the credential that was created during device provisioning

  • <tenantId> the ID of your tenant

  • <your-password> the password that was registered with the credential.

    Note on the password

    Use the password as you have created it during the device provisioning (credential registration) in plain text.
    Do not use it hashed or base64 encoded, when sending messages.

    The data transfer is secured by TLS encryption.

  • The -k parameter overwrites the default keep alive period. Here we set the keep alive period to 30 seconds.
    If no data flows over an open connection for longer than 30 seconds then the client will generate a PINGREQ to indicate to the server that the device is still active.

  • The -t parameter is the name of the MQTT topic to subscribe to.
    In this example the topic command///req/# is defined using the MQTT topic wildcard format, to subscribe to all possible commands.

The MQTT client is now subscribed to Bosch IoT Hub and is ready to receive commands.

Update the feature of the thing

  • Authorize with a fresh Suite OAuth token.

  • Feature resource:

    • Navigate to PUT /things/{thingId}/features.

    • Click Try it out to access the entry fields.

    • Set the thingID that was created during device provisioning.

    • Set the Request body.

      {
      "temperature": {
      "properties": {
      "configuration": {
      "target": "21.0"
      }
      }
      }
      }
    • Click Execute.

You have updated the feature of the digital twin.

This emits a twin event "twin modified" with a respective payload which is sent via Bosch IoT Hub as a command message to the device.

Receive a one-way command

You should see the command message printed out on the command line:

Client mosq/7EqsKGFb69CxB2liZu received PUBLISH (d0, q0, r0, m0, 'command///req/0240aaceac3-f08a-4fcc-aef6-076f5adc0271replies/modified', ... (692 bytes))
{
"topic":"<your.namespace>/<your-device-name>/things/twin/events/modified",
"headers": {
"correlation-id":"0aaceac3-f08a-4fcc-aef6-076f5adc0271",
"host":"things.eu-1.bosch-iot-suite.com",
"content-type":"application/vnd.eclipse.ditto+json",
"version":2
},
"path":"/features",
"value":{"temperature":{"properties":{"configuration":{"target":"21.0"}}}},
"revision":9,
"timestamp":"2019-07-24T13:11:33.632Z"
}


That shows that the device has received the command message.