Suggest an edit

How to generate an error and receive an event

Reviewed on 27 December 2023Published on 05 June 2021

To demonstrate the use of hub Events, the following tutorial allows you to generate an error, and shows you how to receive this error.

For more information about hub Events, you can check out the IoT Hub Events documentation.

Before you start

To complete the actions presented below, you must have:

  • A Scaleway account logged into the console
  • Owner status or IAM permissions allowing you to perform actions in the intended Organization
  • Created an IoT Hub
  • Installed mosquitto on your local computer
  1. Click IoT Hub in the Managed Services section of the side menu. The list of your IoT Hubs displays.

  2. Click the name of the IoT Hub you want to configure. The hub’s overview page displays.

  3. Click Devices to display the device configuration.

  4. Click Add devices in the devices tab. The Create a device wizard displays.

  5. Enter a name for the device (logger) and allow insecure connections.

  6. Click Add device to hub. The device’s details displays. Take a note of the device ID:

  7. Open a terminal window on your local computer and subscribe to the $SCW/events/error/# topic to receive the hub event:

    mosquitto_sub -h -p 1883 -i <logger-device-id> -t '$SCW/events/error/#'

    The Endpoint may vary, you find your endpoint on the hub’s network page.

    The command above contains the following elements:

    • -h: The endpoint or host of your IoT Hub. You require it to communicate with your hub.
    • -i: The device ID of your device. You can retrieve it from the Devices section of your hub.
    • -t: The thread to send your message to.
      • -m: The message containing the information you want to transmit.
  8. Create a second secured device, named secured device and denying insecure connections.


    This will be used to generate an mTLS error by using a device configured to Deny Insecure connections, and trying to connect with it.

  9. Open a second terminal on your computer and connect the secured device to your hub, but without using any security:

    mosquitto_pub -h -i secured-device-id -t foo/bar -m 'This wont work'
  10. Go back to the first terminal. The logger device will then receive a message having a topic that looks like $SCW/events/error/device/<secured-device-id>, and following payload:

    "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"
See also
How to create a routeHow to understand event messages
Docs APIScaleway consoleDedibox consoleScaleway LearningScaleway.comPricingBlogCarreer
© 2023-2024 – Scaleway