Command and control - one-way

One-way commands are sent from a connected business solution through the 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/894252904/command-example.png

Prerequisites

Create command subscriber

Download the server certificate for MQTT TLS encryption

curl -o iothub.crt https://docs.bosch-iot-hub.com/cert/iothub.crt

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 iothub.crt -k 30 -t control/+/+/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 is to overwrite 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 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 control/+/+/req/# is defined using the MQTT topic wildcard format, to subscribe to all possible commands.

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

Update the feature of the thing

  • Authorize with a fresh Suite OAuth token.

  • Feature resource

    • PUT /things/{thingId}/features

    • Set the thingID that was created during device provisioning

    • Set the body

      {
      "temperature": {
      "properties": {
      "configuration": {
      "target": "21.0"
      }
      }
      }
      }
    • 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, 'control///req/0240aaceac3-f08a-4fcc-aef6-076f5adc0271replies/modified', ... (692 bytes))
{
"topic":"<your.namespace>/<your-device-name>/things/twin/events/modified",
"headers":{
"response-required": false,
"correlation-id":"0aaceac3-f08a-4fcc-aef6-076f5adc0271",
"host":"things.eu-1.bosch-iot-suite.com",
"content-type":"application/vnd.eclipse.ditto+json",
"source":"<authorization-subject>",
"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.

Troubleshooting

In case you have subscribed the package in December 2018 to March 2019 please re-check manually following settings:

  • The connection which is created automatically should already set at target all 4 options.
    In case your subscription does not show the target edit it respectively.

    • Live events

    • Twin events

    • Live commands

    • Live messages

  • The policy for the DEVICE should already include read messages permission.
    In case your policy does not show such an entry edit it respectively.