All Products
Search
Document Center

IoT Platform:Connect a device to IoT Platform by using a JT/T 808 gateway (one-party verification)

Last Updated:May 15, 2023

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

  1. Log on to the IoT Platform console.

  2. In the upper-left corner of the IoT Platform console, select the region where IoT Platform is activated.

  3. On the Overview page, click the card of the Exclusive Enterprise Edition instance.

  4. In the left-side navigation pane, choose Devices>Gateway. Then, click Add Gateway.

  5. 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 the server.crt file, and then click OK.

    For more information, see Create a JT/T 808 gateway.

    image
  6. 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.

    image

Add a device to the gateway

  1. In the left-side navigation pane, choose Devices > Products. Find the gateway that you created and click Manage Devices in the Actions column.

  2. On the Devices page, click Batch Add.

  3. In the Batch Add Devices dialog box, click Download .csv Template to download a template file in the CSV format.

    image
  4. 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.

    image
  5. Go to the Batch Add Devices dialog box, click Upload File, upload the saved file to the IoT Platform console, and then click OK.

    image

    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.

    image

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.

  1. Download the package of the SDK for C that supports JT/T 808, and decompress the package to the jt808-c-sdk folder.

  2. Open the jt808_tls_demo.c file in the jt808-c-sdk directory, and then modify the access and authentication information about the device.

    Note

    The 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.

  3. Log on to Ubuntu and upload the modified jt808-c-sdk folder.

    image
  4. In the /jt808-c-sdk root directory, run the make command to compile a sample program.

    make clean
    make

    The generated sample program jt808-tls-demo is stored in the ./output directory.

  5. 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:

    image
  6. 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.

    image
  7. In the left-side navigation pane, choose Maintenance > Device Log. Select a product and view all messages of the Device-to-cloud Messages type.

    image

Connect a device to IoT Platform over TCP (not recommended)

Create a gateway and add a device

  1. Create a JT/T 808 gateway: Configure the required parameters, as shown in the following figure.

    image
  2. 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.

    image
  3. Add a device to the JT/T 808 gateway: Specify device information to add devices, as shown in the following figure.

    image

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.

  1. Download the package of the SDK for C that supports JT/T 808, and decompress the package to the jt808-c-sdk folder.

  2. Open the jt808_basic_demo.c file in the jt808-c-sdk directory, and then modify the access and authentication information about the device.

    Note

    The 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;
    ......
  3. Log on to Ubuntu and upload the modified jt808-c-sdk folder.

  4. In the /jt808-c-sdk root directory, run the make command to compile a sample program.

    make clean
    make

    The generated sample program jt808-basic-demo is stored in the ./output directory.

  5. 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:

    image

    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.