IoT Hub Events

While the MQTT protocol underpinning the Scaleway IoT Hub has many advantages, it’s not known for being rich in error management features. But a solution to this is found in Scaleway’s Hub Events feature, which provides you with real-time error messages from your Hub. Read on to find out more.

The IoT Hub & MQTT

Scaleway’s IoT Hub is a rich and complex product, offering a wide ecosystem of services to turn connected devices into smart devices. The Hub enables secure device-to-device and device-to-cloud communication, ensuring flexible data delivery to many destinations.

The MQTT protocol underpinning the Hub has many advantages - not least that it is lightweight, reliable and keeps bandwidth low - all essential for IoT scenarios. However, MQTT is not rich in features when it comes to error management. It does not provide a standard way of reporting errors to connected clients, making debugging difficult. When a security error, for example, occurs, as your device tries to connect to the Hub, how can you know it has happened and get more information to be able to deal with it accordingly?

Hub Events

The answer lies in Scaleway’s Hub Events feature. Hub Events are messages published on your Hub to inform you of any problems or abnormalities which have occurred. Essentially, these messages represent errors that have occurred on your Hub. To receive these messages, all you need to do is to subscribe to topics, which, by default, are located under the $SCW/events prefix.

The big advantage of Hub Events is that it lets you manage errors without needing to abruptly disconnect devices. With Hub Events, you can receive notifications of errors in real time, while your devices remain connected.

Hub Event Types

Once you’ve subscribed to Hub Events, you’ll be able to access clear, explicit error messages informing you of malformed packet or network errors, security errors, custom certificate authority error messages and more. As well as the error message itself, you get information about the time the error occurred, its severity level and what type of object it appeared on. Here’s an example of a Hub Event payload triggered when a device which was configured to deny insecure connections, attempted to connect to an insecure device:

{	    "time":"2020-01-17T15:01:29Z",    "severity": "error",    "object-type": "device",    "object-id": "secured-device-id",    "msg": "mutual TLS authentication is required",    "packet":"CONNECT: dup: false qos: 0 retain: false rLength: 12"}

Not all errors are related to the devices on your Hub, some can also be related to your Hub’s Routes. For example, it may be the case that the destination of a Route, such as an Object Storage bucket, is no longer available. Similarly, a Route may fail to connect to a database, or else connect but fail to execute its query. In all of these cases, you will also receive a Hub Event, giving you more information about the nature of the problem.

To learn more about Hub Events, including example Hub Event messages and a tutorial taking you through the generation of an error and its reception on Hub Events, check out our documentation.

Diving in

It is possible to enable and disable the Hub Events from the IoT Hub page on your Scaleway console. From there you can also change the topic prefix under which Hub Events are published.

Watch this space for even more new features like Hub Events, coming soon to your IoT Hub.

Recommended articles