Interface Function
If a registration interface is assigned to the device, the device will immediately send a request to this interface after being powered on, started, and successfully connected to the network. This is to obtain the address and user information required for the next step of connecting to the MQTT server.
When the device's connection to the current MQTT server is interrupted (possibly due to network disconnection or MQTT service downtime), the device will retry the connection at intervals of 5-60 seconds. If the connection fails more than 5 times, the device will re-register to obtain new MQTT address and user information.
The registration interface can provide dynamic server and user information for the device, enabling a flexible device access mechanism. This can effectively achieve load balancing and improve service availability.
After the device requests this interface, it will prioritize using the server information and user information returned by the interface to connect to the Broker, rather than the device's pre-configured information (if any).
If you are only testing and the Broker allows anonymous connections, you can skip this section.If you skip this section, do not fill in the "Registration Interface" item in the message server settings configured on the platform.
Implementation Method
This interface can be implemented through a web service on any network server that the device can access.
Any web container such as IIS, Apache, or Nginx can be used.
It can be deployed on the same server as the Broker.
Log records can be added to the interface for debugging purposes.
| Method | Description | Features |
|---|---|---|
| One Device, One Secret | Assign different usernames and passwords to different devices. | More complex implementation Higher security |
| One Product, One Secret | Assign different usernames and passwords to different products. | Simpler implementation (static passwords can be used) Moderate security |
Device Request
When the device requests the interface, it will carry the following parameters for the interface to verify its identity.
Request Protocol: HTTP; Request Method: GET.| Parameter / Name / Type | Description |
|---|---|
Console IDbenchInteger |
The ID of the console to which the device belongs. The Console ID can be viewed on the console's Development Settings page. |
Product CodeproductString |
The product code (Key) is a constant. It is the same across different devices of the same product and never changes. The Product Key can be viewed on the corresponding product details page in the console. |
Device IDdeviceInteger |
The device ID is unique on the platform. Each device has a different ID, which never changes. The Device ID is the numeric ID on the device label attached to the device casing. It can also be viewed on the corresponding device details page in the console. |
Timestampts11-digit Integer |
The time when the device initiates the request. The value of this parameter depends on the device's standard time, which is obtained by the device through the NTP interface. If the NTP interface fails to obtain the time, this value will be 0. |
Signaturesign32-character String |
To verify the validity of the request, you can use the signature.
Specific algorithm: md5(Console ID + "." + Product ID + "." + Device ID + "." + Device Password + "." + Timestamp) Among them, the first 3 parameters are the values of the GET parameters; The device password can be viewed on the device details page in the console; In scenarios such as local area networks (LANs), signature verification can be skipped. |
Interface Response
After the device initiates the request, please decide whether to allow access based on the situation.
The request is successful if and only if the "code" of the JSON object returned by the interface is 200.If the request fails, the device will continuously send requests at 5-second intervals until the request succeeds.
| Parameter / Name | Description | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Status Codecode |
1. Return 200: Return (issue) user information (Client ID, Username, Password) in the "data" field below; 2. Return non-200: Reject the request. The device will continuously send requests to this interface at 5-second intervals until 200 is returned. |
||||||||||||||
Datadata |
1. When code == 200, return the following:
All output items below are optional. If output, the device will adopt this information; if not output, the device will use the pre-configured information.
Note on return values: All are strings
2. When code != 200: Return {} |