ali-iotkit 是 RT-Thread 移植的用于连接阿里云 IoT 平台的软件包。基础 SDK 是阿里提供的 iotkit-embedded C-SDK。
| 名称 | 说明 |
|---|---|
| docs | 文档目录 |
| iotkit-embedded | 阿里 iotkit 原文件目录 |
| ports | 移植文件目录 |
| samples | 示例文件目录 |
ali-iotkit 软件包延用阿里 iotkit-embedded 软件包许可协议,请见 iotkit-embedded/LICENSE 文件。
使用 menuconfig 使能 iotkit 软件包并填写设备信息
RT-Thread online packages --->
IoT - internet of things --->
IoT Cloud --->
[*] Ali-iotkit: Ali Cloud SDK for IoT platform --->
Select Aliyun platform (LinkDevelop Platform) --->
(a1dSQSGZ77X) Config Product Key
(RGB-LED-DEV-1) Config Device Name
(Ghuiyd9nmGowdZzjPqFtxhm3WUHEbIlI) Config Device Secret
-*- Enable MQTT
[*] Enable MQTT sample
[*] Enable MQTT direct connect
[*] Enable SSL
[ ] Enable COAP
[*] Enable OTA
Select OTA channel (Use MQTT OTA channel) --->
version (latest) --->
增加 mbedTLS 帧大小(OTA 的时候至少需要 8K 大小)
RT-Thread online packages --->
security packages --->
-*- mbedtls:An open source, portable, easy to use, readable and flexible SSL library --->
(8192) Maxium fragment length in bytes
使用 pkgs --update 命令下载软件包
在 MSH 中使用命令执行预置的示例程序
该示例程序演示了如何使用 MQTT 发布、订阅 Topic,MSH 命令如下所示:
msh />ali_mqtt_test
ali_mqtt_test|502 :: iotkit-embedded sdk version: V2.10
[inf] iotx_device_info_init(40): device_info created successfully!
[dbg] iotx_device_info_set(50): start to set device info!
[dbg] iotx_device_info_set(64): device_info set successfully!
...
mqtt_client|324 :: out of sample!
该示例程序演示了如何使用 MQTT 发布、订阅 Topic,并一直监听订阅 Topic 的消息,MSH 命令如下所示:
msh />ali_mqtt_test loop
ali_mqtt_test|502 :: iotkit-embedded sdk version: V2.10
[dbg] iotx_device_info_init(32): device_info already created, return!
[dbg] iotx_device_info_set(50): start to set device info!
[dbg] iotx_device_info_set(64): device_info set successfully!
...
[dbg] iotx_mc_cycle(1269): SUBACK
event_handle|111 :: subscribe success, packet-id=0
[dbg] iotx_mc_cycle(1269): SUBACK
event_handle|111 :: subscribe success, packet-id=0
该示例程序演示了如何使用阿里云 OTA 服务,使用 ali_ota_test 命令启动例程,这个时候,设备首先会上报当前版本号到阿里云,然后等待云端下发 OTA 升级命令。
msh />ali_ota_test
ali_ota_main|325 :: iotkit-embedded sdk version: V2.10
[dbg] iotx_device_info_init(32): device_info already created, return!
[dbg] iotx_device_info_set(50): start to set device info!
[dbg] iotx_device_info_set(64): device_info set successfully!
...
mqtt_client|232 :: wait ota upgrade command....
[dbg] iotx_mc_cycle(1260): PUBACK
event_handle|117 :: publish success, packet-id=2
[dbg] iotx_mc_cycle(1269): SUBACK
event_handle|093 :: subscribe success, packet-id=1
mqtt_client|232 :: wait ota upgrade command....
mqtt_client|232 :: wait ota upgrade command....
mqtt_client|232 :: wait ota upgrade command....
menuconfig 里配置自己的设备信息(PRODUCT_KEY、DEVICE_NAME 和 DEVICE_SECRET)