After receiving a request from the broker to go online, user can authenticate the broker and its permissions (optional; please see the next subsection for details). After successful authentication, construct ProtocolMessage in the decode method related to custom protocol data decoder and return LOGIN as MessageType, and indicate information such as OneNET device Id, device name, device Key and product Id to which the device belongs. The gateway project provides an interface for reading broker configuration information by default (default location: /src/main/java/com/cmiot/gateway/config) and its default implementation, which is used to configure and read maps from broker information to OneNET device information.
You can configure the broker using default configuration files. By default, the broker reads its configuration from devices.conf under the default resource file path of your java project (default location: /src/main/resources/config). At the same time, the gateway project supports customized broker configuration. For this purpose, you just need to implement an interface for reading broker configuration information (default location: /src/main/java/com/cmiot/gateway/config) and annotate it as Spring Bean. Then by
you can get broker configuration.
Gateway configuration file parameters are described as follows.
Parameter | Required or not | Description |
---|---|---|
originalIdentity | Yes | An original identifier for devices, by which user can establish the mapping relations from broker to OneNET. |
productId | Yes | OneNET product ID to which broker belongs |
deviceName | Yes | OneNET device name. |
deviceId | Yes | OneNET device ID. |
deviceKey | Yes | OneNET device Key, which is used to authenticate a device on the platform side. |
The gateway project can authenticate the device and its permissions in the form of optional extensions. The directory path for the relevant interface and its default implementation in your Java project is /src/main/java/com/cmiot/gateway/security. Users can implement a strategy interface for authentication and authorization according to their own business, and annotate it as Spring Bean, which can then be obtained and used by extending the utility class ExtensionUtil.
When the Gateway interprets MessageType as LOGIN, it will send a request from the broker to actively go online. After receiving this active request, the OneNET MQTT access service will process it and return a device login success/failure response. User can implement the downlink data processing interface DownLinkHandler (default location: /src/main/java/com/cmiot/gateway/custom).
User can actively push data to devices by the pushToDevice method in DownLinkChannelHandler. It should be noted that the internal gateway data (ProtocolMessage) transmitted by the push method are not the data finally pushed to devices, and it is still necessary for the user to independently write a custom protocol encoder to convert the internal data into the data finally pushed to devices.
User can implement the business logic corresponding to MessageType in the internal data.
Note: DownLinkChannelHandler also provides a way to actively disconnect devices.