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.

You can implement one of the following two authentication methods through programming.
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
Please ensure the device can access this interface normally!

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 ID
bench
Integer
The ID of the console to which the device belongs.
The Console ID can be viewed on the console's Development Settings page.
Product Code
product
String
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 ID
device
Integer
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.
Timestamp
ts
11-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.
Signature
sign
32-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 Code
code
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.
Data
data
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.
hostIP address or domain name of the Broker
(It is recommended to use an IP address instead of a domain name, as DNS resolution failures may occur on many public network lines)
portPort number of the Broker
topic The topic used by the device to subscribe to and publish messages. Leave it blank, or output "key", "client", or other values.
The complete topic subscribed to by the device is: {pre}/{type}/{side}, where
{pre} is the topic prefix:
When "key" is output (or left blank), the topic is: thing/Product Code/Device Code/{type}/{side};
When "client" is output, the topic is: thing/Product Code/Device Client/{type}/{side};
When other non-empty strings are output, the topic is: [Output Value]/{type}/{side}

{type} is the message type
{side} indicates client or server: server / client
user
clientDevice Client | Client ID (must be unique for the Broker)
keyDevice Code | Username (used to log in to the Broker)
secretDevice Password (used to log in to the Broker)
Note on return values: All are strings
2. When code != 200: Return {}

Response Example: