Analysis of the docking process of the telecommunications Internet of Things open platform for NB-IoT

The interconnection process of the telecom IoT open platform is shown in the following figure:

1. Create APP application

Log in to SP Portal (https://180.101.147.135:8843), the docking test environment of China Telecom's Internet of Things open platform, and the initial password needs to be changed for the first login.

Select [Application Management] -> [Application] and click "+Create Application" in the upper right corner.

The parameter settings of a typical NB-IoT application can refer to the following settings:

Industry:

Utilities (NB-IoT)

Associated API package:

Basic API Package and Utility (NB-IoT) API Package

Platform capabilities:

rule engine

Data storage time:

When the data storage time is exceeded, the application will no longer be able to obtain the reported data.

SMS server:

The user can realize the close contact with the engineer through the short message server. The server can choose one of the servers already supported by the platform, or a third-party server.

Mail Server:

Enables users to communicate closely with engineers through the mail server. The server can choose one of the servers already supported by the platform, or a third-party server.

CA certificate:

The certificate issued by the server when the third-party application connects to China Telecom's Internet of Things open platform through HTTPS is used for identity identification and electronic information encryption to achieve two-way authentication. Certificate files are limited to PEM format files no larger than 1M. When the third-party application connects to the China Telecom IoT Open Platform through HTTP, it is not necessary to upload the CA certificate.

2. Set NB-IoT parameters

Click the created application and set the NB-IoT parameters.

Currently, the platform supports setting the following three modes:

PSM mode:

power saving mode, power saving mode. There is no requirement for downlink service delay. For downlink service messages, it can wait for the device to send uplink data to enter the connection state before sending it, which can further save terminal power consumption. Such as smart water meters.

DRX mode:

discontinuous reception, discontinuous reception mode. The requirement for downlink service delay is high. It can be considered that the device is always online and the message can be sent immediately. Such as street lights.

eDRX mode:

Extended idle mode DRX, extended discontinuous reception mode. The extended mode of DRX has higher requirements on downlink service delay, and can send or buffer messages immediately according to system configuration. Such as smart wearable devices.

When the power saving mode is set to PSM mode, ACTIVE TIMER can not be set without any effect; when the power saving mode is set to eDRX mode, the eDRX cycle setting needs to be consistent with that on the network side, please contact the support personnel of China Telecom IoT Open Platform Get parameter configuration data.

The parameter settings here should be consistent with those on the network side. The parameter settings are only configured in the China Telecom Internet of Things open platform, and will not be configured in the network or devices.

3. Define the device model

Profile defines the device model in two ways:

Method 1: Create a Profile file online from the Portal

Method 2: Refer to "China Telecom Internet of Things Open Platform_Device Capability Description File Profile Development Guide" to create a profile offline

The device model means that China Telecom's IoT open platform supports the registration of new device models and supports the management of device models. Device models include: product, device template and service template.

The product is a specific instance composed of device template, manufacturer, model, protocol, etc. SP Portal supports users to customize products according to their needs (mobile oneNET follows a set of standards, which is simpler but less flexible than the telecom platform). The device template defines the basic characteristics and capabilities of the device through the device service. A device template is composed of multiple service templates. SP Portal supports users to use preset device templates, and also supports users to customize device templates according to their needs. Service templates define device capabilities, including attributes, commands, events, and more. SP Portal supports users to use preset service templates, and also supports users to customize service templates according to their needs.

3.1. Define the product equipment model

The device model defines what service capabilities a type of device has, what attributes each service has (that is, what fields are in the reported data), what commands are there, and the parameters of the commands. Each manufacturer must define the device model of its own product before accessing NB-IoT.

Let's use an example to introduce how to define a product device model:

For example:

The manufacturing information of a certain product equipment is as follows:

Manufacturer ID: ChinaTelecom
Manufacturer Name: ChinaTelecom
Device Type: SmartDevice
Device Model: NBIoTDevice
This device has three service capabilities:

They are Brightness, Temperature and Electricity respectively.

Among them, the brightness (Brightness) service has a brightness attribute and a command method for setting the attribute value;

Temperature (Temperature) service has a temperature (temperature) attribute and a method command to set the temperature;

Electricity has four attributes, namely: voltage (votage), current value of electric power (current), frequency (frequency) and power factor (powerfactor).

Next, set the device capability to the platform in the SP portal:

3.2. New service template

Use a browser to log in to the SP Portal; click on the left side to open the "Device Management" page; click the "Model" drop-down option, click "Service Template" to open the "Service Template" page; click "+Add" in the upper right corner of the interface Service template button". For example, add the Temperature service.

3.3. New service attribute

Take the temperature service as an example. This service has an attribute temperature (temperature), which is now added. Click on the temperature service you just added.

Click Attribute, click Add Attribute, and the Add Attribute page will pop up. Set the following parameters according to the actual situation.

Name: attribute name, which is unique to the system.
Attribute type: including int, long, decimal, string, DateTime, jsonObject.
Min, Max, Step, Unit: Appears only when the attribute type is int, long and decimal.
Length: Appears only when the selected attribute type is string, jsonObject or DateTime.
Access Mode: The mode in which the attribute can be accessed.
Required: Whether the attribute is required.


3.4. New service command

Take the temperature service as an example. This service has a command, namely a command to set the temperature (SET_TEMPERATURE). Now add this service command. Click the newly added temperature service, click "Command", click "Add Command", and the "Add Command" page will pop up.

3.5. New device template

Use a browser to log in to SP Portal; click on the left side to open the "Device Management" page; click the "Model" drop-down option, select "About Model" to open the "About Model" page; click "Custom Device Template" to open the The Device Templates page. Click Add Device Template in the upper right corner, and the Add Device Template page will pop up. Set the following parameters according to the actual situation:

Device Template: The name of the device template, which is unique to the system, fill in SmartDevice here.
Description (optional): Description of the device template.


3.6. Add custom products

Use a browser to log in to the SP Portal; click on the left side to open the "Device Management" page; click the "Model" drop-down option, select "About Model" to open the "About Model" page; click "Custom Product" to open the " Products" page. Click the "Add Device" button in the upper right corner, and the "Add Device Product" page will pop up. Set the following parameters according to the actual situation:

Device Type: The device type to which the product belongs. As an example, fill in the device template name in section 3.6 here.
Model: The model to which the product belongs.
Vendor ID: The vendor ID to which the product belongs.
Vendor: The name of the vendor to which the product belongs.
Protocol: The type of protocol the product belongs to. NB-IoT currently only has two protocols, CoAP and LWM2M, please choose the access protocol correctly.
Click "Click to upload file" to upload a product image.
(Optional) Description: The product description content.


Click to complete the custom device product creation.

After the device is created, the service item in the device product model is still empty, and the two created services, Temperature and Electricity, need to be added.

In addition, you need to add the preset service brightness (Brightness).

Click the created device product, click "Add Service" in the service list, open the "Add Service Type" page, and select the service capability to be added. Click and you're done.

To add a service to a product:

3.7, write profile file

For method 2, use the "China Telecom Internet of Things Open Platform_Device Capability Description File Profile Development Guide" to create a Profile file offline and then import it to the China Telecom Internet of Things Open Platform.

The composition of the model profile file package:

The profile folder contains two JSON files, devicetype-capability and devicetype-display;

The devicetype-capability describes the manufacturerId (manufacturer ID), manufacturerName (manufacturer name), model (device model), protocolType (protocol type), deviceType (device type), and serviceTypeCapabilities (service capabilities) of the device.

The service folder mainly describes the service capabilities mentioned in the serviceTypeCapabilities field in the devicetype-capability file of the profile folder, and describes each capability:

3.8. Upload profile file

The path of the upload profile file function menu is:

Device Management>Model>Import Model

4. Develop codec plug-ins and install them

4.1. Develop codec plug-ins

The device model is an abstract model of the device, which abstracts the function of the device into a service. For the codec library plug-in, it defines the output of the decode interface and the input format of the encode interface. For codec plug-in development, please refer to the "China Telecom Internet of Things Open Platform V100R001C30 Codec Library Development and Upgrade Guide" document.

4.1.1, codec plug-in quality inspection

The quality inspection of the codec plug-in is a key step to check whether the codec can be used normally. Please refer to the instructions of the codec plug-in inspection tool for operation.

Tool download address: http://www.tianyiiot.com/attchment/174/ China Telecom Internet of Things Open Platform codec plug-in detection tool.zip

4.2. Offline signing of the plug-in package

After the codec plug-in is developed, the plug-in package needs to be signed before being installed on the platform. At this time, you need to download the offline signature tool and perform the signature operation. The operation steps are as follows:

Click the icon on the left to open the management page.
Click "Tools" in the left navigation bar, and click "Download" in the right area to download the offline signature tool.
Find the compressed package "signtool.zip" in the download path, and select "Extract to signtool\" in the right-click menu to decompress it to the folder "signtool".
 Go to the signtool folder and run "signtool.exe". The operation interface is as follows.


4.2. Generate a digital signature public-private key pair

Select the signature algorithm according to the actual situation.
Two signature algorithms are currently provided:
ECDSA_256K1+SHA256
RSA2048+SHA256
Set the "private key encryption password".
Password complexity description:
The length of the password must be at least 6 characters.
The password must contain a combination of at least two of the following characters:
at least one lowercase letter,
at least one uppercase letter,
at least one number,
and at least one special character: `~!@#$%^&*( )-_=+\|[{}];:'",<.>/? and space
Click "Generate public-private key", select the directory to save in the pop-up window, and click "OK"
. View the generated public and private key files in the saved directory.
Public key file: public.pem
Private key file: private.pem
2 Digitally sign the software package.
The offline signature tool can only digitally sign compressed packages in .zip format .In
the "Digital Signature for Software Package" area, click "Import Private Key File", select the private key file generated in step 5.3, and click "Open".
In the pop-up dialog box, enter the password set in step 2, Click "OK".
In the "Packages that require digital signature" area, select the software package that needs to be digitally signed. Click "Open".
Click "Digital Signature".
After the signature is successful, it will be generated in the directory where the original software package is located Signed package named 'XXX_signed.XXX'.
Package signature verification
In the Package Signature Verification area, click Import Public Key File, select the public key file generated in Step 5.3, and click Open.
In the Software package requiring signature verification area, select the signed software package named XXX_signed.XXX generated in step 6. Click Open.
Click Verify Software Signature.
If the verification is successful, a "Signature verification successful!" prompt box will pop up.
If the verification fails, a "signature verification exception!" prompt box will pop up.
4.3. Upload the public key and signed plug-in package

The codec plug-in can dynamically add a codec library, so that when a new device is connected, it only needs to dynamically import the corresponding codec library to the platform to be compatible with the newly added device.

Please send the public key and signed plug-in package to the support staff of China Telecom IoT Open Platform, and China Telecom will complete the upload configuration of the public key and signed plug-in package.

5. Device access platform

5.1. Login application

When an application accesses the China Telecom IoT Open Platform, it must first log in, and obtain an access token (accessToken) after successful login. The appId and secret in the message in this step are the information obtained in the "Create APP Application" step.

Example message:

Method:POST
request:(非JSON格式)
https://server:port/iocm/app/sec/v1.1.0/login
Content-Type:application/x-www-form-urlencoded
Body: 
 
appId=******&secret=******
 
response:
Status Code: 200 OK
Content-Type: application/json
Body: 
{
    "accessToken": "*******",
    "tokenType": "*******",
    "expiresIn": "*******",
    "refreshToken": "*******",
    "scope": "*******"
}
5.2、订阅

In order to receive the data reported by the device, NA needs to subscribe to the notification message from the China Telecom IoT Open Platform.

Subscribe to device data reporting notifications:

POST  https://server:port/iocm/app/sub/v1.1.0/subscribe 
Header:
app_key: ******
Authorization:Bearer ******
Content-Type:application/json
Body:
{
    "notifyType": "deviceDataChanged",
    "callbackurl": "https://183.4.11.104:9999/"
}
5.3、注册设备

5.3.1. Register with application server device

All devices must be registered with the Northbound before they are allowed to connect to the platform.

By registering the device, the platform will assign a unique identifier deviceId to each device, and the subsequent application will use the deviceId to specify the device when operating the device. In addition, the psk parameter is also returned (if the user does not specify the psk parameter, the platform will randomly assign a parameter). When binding the southbound device, if the DTLS encrypted channel is used between the device and the platform, this parameter must be used, please save it. DeviceId can also be used to find devices on the SP portal.

Method:POST
request:
https://server:port/iocm/app/reg/v1.1.0/devices
Header:
app_key: ******"
Authorization:Bearer ******
Content-Type:application/json
Body: 
{     "verifyCode":"447769804451095", "nodeId":"447769804451095", "psk": "12345678",     "timeout":0 } response: Status Code: 201 CREATED Content-Type: application/json Body:  {     "deviceId": "*******",     "verifyCode": "*******",     "psk": "12345678",     "timeout":0 5.3.2. No application server device registration}















In the case of no application server, the manufacturer can use the device simulator to simulate the registration of the device. It is convenient for manufacturers to carry out joint debugging and development.

Tool download address: http://www.tianyiiot.com/attchment/173/China Telecom Internet of Things Open Platform Northbound API Debugging Tool-_GUI_APPDemo-master.zip

IP: 180.101.147.89, Port: 8743

Device Registration Tool Login:

Fill in the device Node ID and other information, and register, where the Node ID is the unique coded ID of the device, and the Verify Code is the same as the Node ID; fill in the Time Out parameter, please fill in according to the device transmission situation (if instant transmission, please fill in "0") , device registration:

After successful registration, you can see the device:

5.4. Set device information

This step is to set information such as the manufacturer, model, and device type of the device to the platform. The platform needs this information during processing:

Method:PUT
request:
https://server:port/iocm/app/dm/v1.1.0/devices/{deviceId}
Header:
app_key: ******
Authorization:Bearer ******
Content-Type:application/json
Body: 
{
"manufacturerId": "****",
" manufacturerName ": "****",
    "deviceType": "****",
    "protocolType": " CoAP",
    "model": "****"
}
response:
Status Code: 200 OK
5.5、设备接入

Access port and protocol

 At present, China Telecom's IoT open platform supports both encrypted and non-encrypted access devices. The encrypted service data interaction port is port 5684. Port 5684 is accessed through the DTLS+CoAP protocol channel, the non-encrypted port is 5683, and the access protocol is CoAP.

When the NB-IOT device uses an encrypted port to access, it provides the necessary data credentials and supports the standard DTLS protocol.

Before the device logs in to the platform, the port of the device docking platform needs to be set to 5684 (that is, through the DTLS encrypted channel).
It is recommended to preset the PSK key of the device before leaving the factory into the China Telecom IoT Open Platform. The data type of the PSK key is String, and the length ranges from 8 to 32 bits. Call 5.3 Register Device Interface to set the device PSK to the platform.
When using non-encrypted port access, you only need to use the original CoAP protocol for transmission, and set the docking platform to 5683.
Regardless of whether the registration interface
 is encrypted or non-encrypted, the device only needs to use the standard OMA interface to register. The parameters in the CoAP url may include: ep = {Endpoint Client Name}<={Lifetime}&sms={MSISDN}&lwm2m={ version}&b={binding mode}&{ObjectLinks}, in order to be compatible with the old protocol, all are optional except ep.
5.6. Device goes online

When this step is completed, the device can already be connected to the platform. Configure the network, turn on the device, and observe whether the device is successfully connected to the platform.

Log in to the device management page of SP Portal and view the device list. The field ID is the deviceId generated when registering the device in the third step. The status field indicates the online status of the device. If the status is online (online), it means that the device has been successfully connected. To the platform, then you can receive the data of the device.

6. Examples

6.1. Registration: Search for "Tianyi IoT Industry Alliance" on the WeChat public account, apply for registration after paying attention, and you will get two emails the next day

6.1.1. [China Telecom Internet of Things Open Platform (Docking Test)] Account Opening Password Notice

6.1.2. Service email: 

        Test platform address
        developer portal address   
        test platform application docking address (enterprise application access address)
        test platform device docking address (terminal device access address)

6.2. Enter the download area to download all the information

6.3. Preparations

6.3.1. Install jdk1.8

6.3.2. Prepare an HTTPS server and corresponding certificate (it is recommended to use Ali's free certificate)

6.4. Register application: log in to the test platform, register an application, and must select "basic API package" and "utility (NB-Iot) API package"

6.5. Upload certificate: Log in to the developer platform, select docking information, click the application list, and upload the HTTPS certificate in the format of PEM

6.6. Upload profile file:

    Can be generated by online editing;

    Log in to the developer platform->Profile development->Profile import: select a zip file example (WaterMeter_Huawei_NBIoTDevice.zip) in "China Telecom Internet of Things Open Platform Profile Sample"

6.7. Plug-in writing and uploading: 

6.7.1. Import the source code in "China Telecom Internet of Things Open Platform Device Codec Plug-in Source Code and Sample", pack the jar, pay attention to the com.thrid.party.codec.demo files in the source code, this is the data The core of upload and download

6.7.2. Log in to the developer platform -> plug-in management -> codec plug-in management, upload the plug-in, just use the routine directly, and modify it according to the business after the debugging is passed.

6.8. Device management

6.8.1. Device template: the name is consistent with the selected profile file, such as the WaterMeter_Huawei_NBIoTDevice.zip you selected, unzip it, open the profile folder, open the json file inside, find "serviceId": "WaterMeterBasic", the service name and id are Fill WaterMeterBasic

6.8.2. Service template: the content and attributes are consistent with the profile file. The command first defines a "SET_DEVICE_LEVEL" (randomly choose a command to issue, and you can change it later), and the event selects "deviceDataChanged" (required for data upload)

6.9. Use the northbound API debugging tool of China Telecom Internet of Things Open Platform-_GUI_APPDemo-master
  
6.9.1. Register the device: two drop-down boxes, select
               NB-IOT Device Manager
               Register Direct Device
  
6.9.2. Modify the device: Modify Device Info
 
6.9 .3. Device online: "Platform Access Process Description" has an instruction manual. In SSCOM, operate through a series of AT commands. 6.9.4.
 
Check the activation status Query Device Status Enter the device id, click the button "check status", and return to "evice Status: ONLINE.
”Success

6.10. Data reporting  

6.10.1. To subscribe to the service on the platform, you can use the API debugging tool -_GUI_APPDemo, the two drop-down boxes, respectively select NB-IOT Subscribe Manager
      Notify Type, select "deviceDataChanged" callback URL, fill in the callback htts address

6.10.2. The first eight digits of the data reported by the device are AA720000, others are optional, and the form is similar to AA720000AAAAAAAAAAAAAAAAAAAAAAAAAA

6.11. Command Issuance  

6.11.1. To subscribe to the service on the platform, you can use the API debugging tool -_GUI_APPDemo, select "commandRsp" for the Notify Type, and fill in the callback http URL

6.11.2, the json of the issued command

      {"expireTime":"0","callbackUrl":"https://回调地址","deviceId":"111-111-11-11","command":{"method":"SET_DEVICE_LEVEL","paras":{"value":"自定义"},"serviceId":"服务ID"}}


————————————————
Copyright statement: This article is an original article of CSDN blogger "Jianyi Business", which follows the CC 4.0 BY-SA copyright agreement. For reprinting, please attach the original source link and this statement.
Original link: https://blog.csdn.net/liwei16611/article/details/82705855

Guess you like

Origin blog.csdn.net/qq_36647209/article/details/114401148
Recommended