Event example - MQTT
Via events you can send messages from your device to your application.
The Bosch IoT Hub service will guarantee the delivery of the message to the Things service. This means, if the connection between Hub and Things is broken, the message will be queued in the Hub internal messaging infrastructure and will be delivered to Things as soon as the connection is established again, then Bosch IoT Things sends an acknowledgement about receiving the message to Bosch IoT Hub.
The Things service will inform all solutions with read permission on the affected thing.
Schematic view
Use cases for events
Events should be the communication pattern of choice if reliability is crucial for your business or functional requirements.
Due to the involved overhead for assured delivery and reliable processing and queuing, this approach has drawbacks considering latency and throughput.
A typical example for event messages is a fire alarm. This type of incident will happen only very rarely. But if it happens, it’s absolutely crucial that the message is sent and processed successfully.
Prerequisites
At this point we assume that you went through all steps described at Getting started and have already registered a device and its thing.
The mosquitto_sub command is installed. See Eclipse Mosquitto.
The mosquitto_pub command is installed. See Eclipse Mosquitto.
You have downloaded the server certificate for MQTT TLS encryption
curl -o ISRGRootX1.crt https:
//letsencrypt.org/certs/isrgrootx1.pem
Event request
To send event messages the following example command can be used:
mosquitto_pub -d -h mqtt.bosch-iot-hub.com -p
8883
-u {auth-id}@{tenant-id} -P {secret} --cafile ISRGRootX1.crt -t event \
-m
"{\"topic\":\"<your.namespace>/<your-device-name>/things/twin/events/modified"
,\
"path\":\"/features/featureZ/properties/temperature\",\"value\":5}"
-q
1
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.
After Bosch IoT Hub has received the message from the device, it sends back an acknowledgement to the device.
After Bosch IoT Things has processed the request, it sends the acknowledgement to the Hub service.
You should then get a response like this:
Client
477111
sending CONNECT
Client
477111
received CONNACK
Client
477111
sending PUBLISH (...)
Client
477111
sending DISCONNECT