Example 2: Use the AT framework with a Linux and L610 module
Updated at:
After you adapt a communication module to the AT module driver framework, you must test the module. This topic uses an L610 module in a Linux environment as an example. It describes how to test the device connection to IoT Platform using the C Link software development kit (SDK).
Background information
- For more information about adapting communication modules to the AT module driver framework, see Connection solution overview.
- The device in this example uses the Linux operating system and an L610 communication module. For more information, see L610.
- For more information about how to obtain device credentials, see Obtain device credentials.
Procedure
- Obtain the C Link SDK.For more information, see Obtain C Link SDK.Note When you customize the SDK, set Device OS to Linux and Device Hardware Form to MCU/SOC+Communication Module.
- Adapt the hardware.
- As needed, select a development tool, open the ./portfiles/aiot_port/project/linux/hal_adapter.c file, and enter the device node.The following code provides an example:Note After you connect the module to the Linux device with a USB cable, you can run the
ls /devcommand to view the device node./* Initialize the serial port. The baud rate is 115200. TODO: Enter the actual serial port device name. */ g_uart_fd = aiot_serial_port_open("/dev/ttyUSB1", 115200); - Adapt the module by setting the value of
devicetol610_at_cmd./* AT module */ extern at_device_t ec200_at_cmd; extern at_device_t ec200_at_cmd_ssl; extern at_device_t l610_at_cmd; extern at_device_t l610_at_cmd_ssl; extern at_device_t air724_at_cmd; extern at_device_t air724_at_cmd_ssl; at_device_t *device = &l610_at_cmd;
- As needed, select a development tool, open the ./portfiles/aiot_port/project/linux/hal_adapter.c file, and enter the device node.
- Optional: If the module supports SSL (for example, when
device = l610_at_cmd_ssl), disable the native TLS feature of the C Link SDK. This prevents errors caused by double encryption.Note This example does not support connections over Constrained Application Protocol (CoAP) or device authentication that uses X.509 certificates.- Open the ./core/sysdep/core_adapter.c file.
- Add a comment symbol (
//) to the beginning of the#define CORE_ADAPTER_MBEDTLS_ENABLEDline.
- Open the ./demos/mqtt_at_basic_demo.c file and configure the MQTT connection parameters.For more information, see MQTT connection example.
- Compile the project file and run the test program.For instructions on how to compile the project, see the documentation for your development tool.
Results
- After the demo runs, you can view the device logs.
- Module initialization:
[1632295441050][3] >>>> AT [1632295441176][6] <<<< OK …… …… [1632295442753][13] >>>> AT+MIPCALL=1 [1632295442888][34] <<<< OK +MIPCALL: 10.117.***.*** [1632295442893][20] >>>> AT+GTSET="IPRFMT",2 [1632295443020][6] <<<< OK - Connection setup:
[1632295443.022][LK-0313] MQTT user calls aiot_mqtt_connect api, connect [1632295443.022][LK-0317] LightSwitch&a1wP****** [1632295443.022][LK-0318] 439AE51F4AC6B8805F8697B575E97FA0CCC9A5F103B6EBE713A9562236AD0AD0 [1632295443025][71] >>>> AT+MIPOPEN=1,,"a1wP******.iot-as-mqtt.cn-shanghai.aliyuncs.com",443,0 [1632295443156][6] <<<< OK [1632295443456][17] <<<< +MIPOPEN: 1,1 [1632295443461][17] >>>> AT+MIPSEND=1,244 [1632295443588][5] <<<< > [1632295443592][244] >>>> [1632295443720][51] <<<< OK +MIPPUSH: 1,0 +MIPSEND: 1,0,2048 OK [1632295443880][22] <<<< +MIPRTCP: 1,4, id 0, len 4, res 14 [1632295443.888][LK-0313] MQTT connect success in 858 ms AIOT_MQTTEVT_CONNECT - Data reporting:
[1632295443.888][LK-0309] pub: /sys/a18wP******/LightSwitch/thing/event/property/post [LK-030A] > 7B 22 69 64 22 3A 22 31 22 2C 22 76 65 72 73 69 | {"id":"1","versi [LK-030A] > 6F 6E 22 3A 22 31 2E 30 22 2C 22 70 61 72 61 6D | on":"1.0","param [LK-030A] > 73 22 3A 7B 22 4C 69 67 68 74 53 77 69 74 63 68 | s":{"LightSwitch [LK-030A] > 22 3A 30 7D 7D | ":0}} [1632295443884][17] >>>> AT+MIPSEND=1,118 [1632295444008][5] <<<< > [1632295444009][118] >>>> 0t [1632295444128][51] <<<< OK +MIPPUSH: 1,0 +MIPSEND: 1,0,2048 OK [1632295444128][15] >>>> AT+MIPSEND=1,2 [1632295444252][5] <<<< > [1632295444254][2] >>>> [1632295444440][267] <<<< OK +MIPPUSH: 1,0 +MIPSEND: 1,0,2048 OK - Data receiving:
+MIPRTCP: 1,176,0 id 0, len 176, res 16 [1632295444.444][LK-0309] pub: /sys/a18wP******/LightSwitch/thing/event/property/post_reply [LK-030A] < 7B 22 63 6F 64 65 22 3A 32 30 30 2C 22 64 61 74 | {"code":200,"dat [LK-030A] < 61 22 3A 7B 7D 2C 22 69 64 22 3A 22 31 22 2C 22 | a":{},"id":"1"," [LK-030A] < 6D 65 73 73 61 67 65 22 3A 22 73 75 63 63 65 73 | message":"succes [LK-030A] < 73 22 2C 22 6D 65 74 68 6F 64 22 3A 22 74 68 69 | s","method":"thi [LK-030A] < 6E 67 2E 65 76 65 6E 74 2E 70 72 6F 70 65 72 74 | ng.event.propert [LK-030A] < 79 2E 70 6F 73 74 22 2C 22 76 65 72 73 69 6F 6E | y.post","version [LK-030A] < 22 3A 22 31 2E 30 22 7D | ":"1.0"} pub, qos: 0, topic: /sys/a18wP******/LightSwitch/thing/event/property/post_reply pub, payload: {"code":200,"data":{},"id":"1","message":"success","method":"thing.event.property.post","version":"1.0"}
- Module initialization:
- You can also view logs in the IoT Platform console. For more information, see IoT Platform logs.
Is this page helpful?