Connect Command sending IoT Application

Prepare Hono Client to send Command messages

A connected business application is able to send commands to connected devices of the Bosch IoT Hub. Commands can either be one-way commands or request/response commands. In this example, we will use a simple command line client from the Eclipse Hono project that allows to interactively send commands to devices using the console.

  1. Make sure all required tools mentioned in the Prerequisites chapter are installed for your platform.

  2. Get the Eclipse Hono 0.9 Command Line Client

  3. Execute the Eclipse Hono command example:

    Linux:

    java -jar hono-cli-<version>-exec.jar \
    --hono.client.host=messaging.bosch-iot-hub.com \
    --hono.client.port=5671 \
    --hono.client.tlsEnabled=true \
    --hono.client.username={messaging-username} \
    --hono.client.password={messaging-password} \
    --tenant.id={tenant-id} \
    --device.id={device-id} \
    --spring.profiles.active=command
    

    Windows:

    java -jar hono-cli-<version>-exec.jar --hono.client.host=messaging.bosch-iot-hub.com --hono.client.port=5671 --hono.client.tlsEnabled=true --hono.client.username={messaging-username} --hono.client.password={messaging-password} --tenant.id={tenant-id} --device.id={device-id} --spring.profiles.active=command
    

    Make sure you replace all parameters correctly:

    • {messaging-username} the messaging username of your tenant
    • {messaging-password} the messaging password of your tenant
    • {tenant-id} the ID of your tenant
    • {device-id} the ID of your device
  4. Once the command sender application is ready it will prompt for a command on the console. Please be patient, as it can take up to 10 seconds for the sender to become ready.

  5. The example sender is now ready to send commands.

Send a one-way command to a client

To send a one-way command to a device follow the on-screen instructions. An example invocation looks as follows:

>>>>>>>>> Enter name of command for device [{tenant-id}:{device-id}] (prefix with 'ow:' to send one-way command):
ow:sayGreeting
>>>>>>>>> Enter command payload:
{"greeting" : "Hi, How are you?"}
>>>>>>>>> Enter content type:
application/json

17:19:51.895 [vert.x-eventloop-thread-0] INFO  org.eclipse.hono.cli.Commander - Command sent to device... [request will timeout in 60 seconds]

>>>>>>>>> Enter name of command for device [{tenant-id}:{device-id}] (prefix with 'ow:' to send one-way command):
  • As this is a one-way command, the client will directly prompt for the next command after it was sent.

Send a request/response command to a client

To send a request/response command to a device follow the on-screen instructions. An example invocation looks as follows:

>>>>>>>>> Enter name of command for device [{tenant-id}:{device-id}] (prefix with 'ow:' to send one-way command):
sayGreeting
>>>>>>>>> Enter command payload:
{"greeting" : "Hi, How are you?"}
>>>>>>>>> Enter content type:
application/json

16:33:20.968 [vert.x-eventloop-thread-0] INFO  org.eclipse.hono.cli.Commander - Command sent to device... [request will timeout in 60 seconds]
16:33:36.455 [vert.x-eventloop-thread-0] INFO  org.eclipse.hono.cli.Commander - Received Command response : {"greetingDurationInSec": 23}
  • Once the command was sent, the client will wait for a response of the device for a configurable amount of time.
  • Once the response was received it is displayed in the console. If no answer is received in time an error message will be displayed.