How to generate an error and receive an event
To demonstrate the use of Hub Events, the following tutorial allows you 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.
You may need certain IAM permissions to carry out some actions described on this page. This means:
- you are the Owner of the Scaleway Organization in which the actions will be carried out, or
- you are an IAM user of the Organization, with a policy granting you the necessary permission sets
- You have an account and are logged into the Scaleway console
- You have created an IoT Hub
- You have installed
mosquitto
on your local computer
-
Click IoT Hub in the Managed Services section of the side menu. The list of your IoT Hubs displays.
-
Click the name of the IoT Hub you want to configure. The hub’s overview page displays.
-
Click Devices to display the device configuration.
-
Click Add devices in the devices tab. The Create a Device wizard displays.
-
Enter a name for the device (
logger
) and allow insecure connections. -
Click Add a Device to Hub. The devices details displays. Take a note of the Device ID:
-
Open a terminal window on your local computer and subscribe to the
$SCW/events/error/#
topic to receive the hub event:mosquitto_sub -h iot.fr-par.scw.cloud -p 1883 -i <logger-device-id> -t '$SCW/events/error/#'Note:The Endpoint
iot-fr-par.scw.cloud
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.
-
Create a second secured device, named secured device and denying insecure connections.
Note:This will be used to generate an mTLS error by using a device configured to
Deny Insecure
connections, and trying to connect with it. -
Open a second terminal on your computer and connect the secured device to your Hub, but without using any security:
mosquitto_pub -h iot.fr-par.scw.cloud -i secured-device-id -t foo/bar -m 'This wont work' -
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:{"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"}