This topic describes how to verify and connect a device to IoT Platform by using a JT/T 808 gateway. In this example, one-party verification is used.
Prerequisites
An Exclusive Enterprise Edition instance is purchased. In this example, an Exclusive Enterprise Edition instance is purchased in the China (Shanghai) region. For more information, see Purchase Enterprise Edition instances.
Background information
You can use JT/T 808 gateways to connect devices to IoT Platform over the Transmission Control Protocol (TCP) or Transport Layer Security (TLS) protocol. We recommend that you use TLS because the TCP-based connection is less secure. If you connect devices to IoT Platform over TLS, you can enable server-side one-way verification, Online Certificate Status Protocol (OCSP) for devices, two-way secure connections between devices and servers, and other features. This topic describes how to perform one-party verification on a device and then connect the device to IoT Platform over TLS or TCP by using a JT/T 808 gateway.
Preparations
In this example, an operating system that runs Ubuntu 22.04 is used as the development environment for devices.
Connect a device to IoT Platform over TLS (recommended)
Custom certificate
In this example, the custom certificate contains the root certificate file named root-ca.crt
, the server-side private key file named server.key
, and the server-side certificate file named server.crt
.
You can use OpenSSL to generate a custom certificate. For more information about how to generate the certificate, see Generate a custom certificate.
Create a gateway
Log on to the IoT Platform console.
In the upper-left corner of the IoT Platform console, select the region where IoT Platform is activated.
On the Overview page, click the card of the Exclusive Enterprise Edition instance.
In the left-side navigation pane, choose Devices>Gateway. Then, click Add Gateway.
In the Add Gateway dialog box, configure the parameters, as shown in the following figure. Set the Private Key of Server Certificate parameter to the content of the
server.key
file, set the Server Certificate parameter to the content of theserver.crt
file, and then click OK.For more information, see Create a JT/T 808 gateway.
On the Gateway page, find the gateway that you created and copy the endpoint and port number in the Gateway URL column of the gateway.
Add a device to the gateway
In the left-side navigation pane, choose Devices > Products. Find the gateway that you created and click Manage Devices in the Actions column.
On the Devices page, click Batch Add.
In the Batch Add Devices dialog box, click Download .csv Template to download a template file in the CSV format.
Enter the identity information about devices that you want to add in the Manufacturer ID, Terminal Model, and Terminal ID columns of the template, as shown in the following figure, and then save the file.
For more information, see Create a JT/T 808 gateway.
Go to the Batch Add Devices dialog box, click Upload File, upload the saved file to the IoT Platform console, and then click OK.
After the identity information of devices is imported, Manufacturer ID, Terminal Model, and Terminal ID parameters The information about the devices is displayed on the Devices page.
Develop a device-side program
After devices are created in the IoT Platform console, you must develop a device-side program to connect the devices to IoT Platform. IoT Platform provides an SDK for C that supports the JT/T 808 protocol. In this example, the SDK for C is used to develop a device named AliyunIoT_TestModel_device1 and connect the device to IoT Platform.
Download the package of the SDK for C that supports JT/T 808, and decompress the package to the
jt808-c-sdk
folder.Open the
jt808_tls_demo.c
file in the jt808-c-sdk directory, and then modify the access and authentication information about the device.NoteThe
jt808_tls_demo.c
file is used to connect the device to IoT Platform over TLS....... /* Specify the actual device information, including the province, city, manufacturer, model, terminal ID, license plate color, and license plate number. */ static jt808_register_t info = { .province = 0x1234, .city = 0x4567, .manufacturer = "AliyunIoT", .model = "TestModel", .terminal = "device1", .colour = 1, .lisence = "Zhejiang C*****", }; /* Specify the mobile phone number that is bound to the device. * / static char *moible_num = "1*********8"; /* Specify the endpoint and port number of the gateway. * / static char *host = "iot-0******.igw.iothub.aliyuncs.com"; static uint16_t port = 7999; /* Specify the custom root certificate. * / const char *jt808_ca_cert = \ { \ "-----BEGIN CERTIFICATE-----\r\n" "MIIDR*************************************************ZIhvcNAQEL\r\n" "BQAwM*************************************************ANBgNVBAMM\r\n" "BklvV*************************************************MxCzAJBgNV\r\n" "BAYTA*************************************************QgQ0EwggEi\r\n" "MA0GC*************************************************S8fWxBF+lw\r\n" "8GKH7*************************************************3Xco/COMjP\r\n" "Q69QH*************************************************wuYc0WMjlS\r\n" "cNO7G*************************************************BABPEIJeLR\r\n" "c6rJ7*************************************************F8nDOm0kUd\r\n" "kvAdK*************************************************t6BEh9AgMB\r\n" "AAGjU*************************************************NVHSMEGDAW\r\n" "gBT4S*************************************************0GCSqGSIb3\r\n" "DQEBC*************************************************+I42UNjbJa\r\n" "ZP9bn*************************************************G+S/Tv6BEn\r\n" "2v1/V*************************************************zNWlwapdvp\r\n" "DRMmf*************************************************Vh/FVBa7gn\r\n" "9DWlU*************************************************AGz0HkVQq6\r\n" "Ks4UI***************************Vzd+\r\n" "-----END CERTIFICATE-----\r\n" }; ......
Parameter
Description
province
The province and city where the device is located. The values must meet the requirements in JT/T 808-2019.
city
manufacturer
The values of the Manufacturer ID, Terminal Model, and Terminal ID parameters that you specified for the device when you added the device to the gateway in the IoT Platform console.
model
terminal
colour
The color of the license plate, the license plate number, and the mobile phone number of the user to which the device belongs. The color of the license plate and the license plate number must meet the requirements in JT/T 808-2019.
lisence
moible_num
host
The endpoint of the JT/T 808 gateway, which is the endpoint in the Gateway URL column of the gateway that you created.
port
The custom port number. Default value:
7999
.jt808_ca_cert
The content of the
root-ca.crt
file.Log on to Ubuntu and upload the modified
jt808-c-sdk
folder.In the
/jt808-c-sdk
root directory, run themake
command to compile a sample program.make clean make
The generated sample program
jt808-tls-demo
is stored in the./output
directory.Run the sample program.
./output/jt808-tls-demo
After the program is successfully run, the device is connected and starts to submit data, as shown in the following figure:
Go back to the Instance Details page of the instance that you want to manage in the IoT Platform console. In the left-side navigation pane, choose Devices > Devices. On the Devices page, find the device that you want to connect to IoT Platform, and view the device status. If the value in the Device Status column is Online, the device is connected to IoT Platform.
In the left-side navigation pane, choose Maintenance > Device Log. Select a product and view all messages of the Device-to-cloud Messages type.
Connect a device to IoT Platform over TCP (not recommended)
Create a gateway and add a device
Create a JT/T 808 gateway: Configure the required parameters, as shown in the following figure.
On the Gateway page, find the gateway that you created and copy the endpoint and port number in the Gateway URL column of the gateway.
Add a device to the JT/T 808 gateway: Specify device information to add devices, as shown in the following figure.
Develop a device-side program
IoT Platform provides an SDK for C that supports the JT/T 808 protocol. In this example, the SDK for C is used to develop a device named AliyunIoT_TestModel_device1 and connect the device to IoT Platform.
Download the package of the SDK for C that supports JT/T 808, and decompress the package to the
jt808-c-sdk
folder.Open the
jt808_basic_demo.c
file in the jt808-c-sdk directory, and then modify the access and authentication information about the device.NoteThe
jt808_basic_demo.c
file is used to connect the device to IoT Platform over TCP....... /* Specify the actual device information, including the province, city, manufacturer, model, terminal ID, license plate color, and license plate number. * / static jt808_register_t info = { .province = 0x1234, .city = 0x4567, .manufacturer = "AliyunIoT", .model = "TestModel", .terminal = "device1", .colour = 1, .lisence = "Zhejiang A*****", }; /* Specify the mobile phone number that is bound to the device. * / static char *moible_num = "1**********"; /* Specify the endpoint and port number of the gateway. * / static char *host = "iot-0******v-0****0.igw.iothub.aliyuncs.com"; static uint16_t port = 7999; ......
Log on to Ubuntu and upload the modified
jt808-c-sdk
folder.In the
/jt808-c-sdk
root directory, run themake
command to compile a sample program.make clean make
The generated sample program
jt808-basic-demo
is stored in the./output
directory.Run the sample program.
./output/jt808-basic-demo
After the program is successfully run, the device is connected and starts to submit data, as shown in the following figure:
You can go back to the Instance Details page of the instance that you want to manage in the IoT Platform console. You can then view the device status and messaging logs in the console.