1、介紹
bc28_mqtt 是基於移遠 BC28 模塊 AT 固件的 MQTT 軟件包,使用 UART 與 MCU 通信,目前實現了與阿里雲物聯網平臺的連接。
從手冊來看,BC35-G、BC28 和 BC95 的 AT 指令是兼容的,因此本軟件包應該同時支持這三類模組。但是由於本人手上只有 BC28 模塊,因此暫時無法驗證,歡迎各位開發者參與驗證。
GitHub 倉庫:https://github.com/luhuadong/rtt-bc28-mqtt
1.1 特性
- 支持掉線重連
- 支持多實例
- 線程安全
1.2 目錄結構
名稱 | 說明 |
---|---|
docs | 文檔目錄 |
examples | 例子目錄 |
inc | 頭文件目錄 |
src | 源代碼目錄 |
1.3 許可證
bc28_mqtt 軟件包遵循 LGPL-2.1 許可,詳見 LICENSE
文件。
1.4 依賴
- RT-Thread 4.0+
- AT 組件
2、獲取 bc28_mqtt 軟件包
使用 bc28_mqtt 軟件包需要在 RT-Thread 的包管理器中選擇它,具體路徑如下:
RT-Thread online packages --->
internet of things --->
[*] BC28 MQTT: connect to Aliyun with Quectel BC28 model --->
保存配置參數後,使用 pkgs --update
命令更新包到 BSP 中。
3、使用 bc28_mqtt 軟件包
3.1 版本說明
版本 | 說明 |
---|---|
latest | 目前支持 MQTT 連接阿里雲物聯網平臺,將持續維護 |
目前處於公測階段,建議開發者使用 latest 版本。
3.2 配置選項
目前有如下幾個配置項:
配置項 | 數據類型 | 說明 |
---|---|---|
AT client device name | string | AT Client 串口設備名稱,如 uart3 |
Select baud rate | int | 串口波特率,可選 4800、9600、115200 |
Reset pin | int | BC28 復位引腳號 |
ADC pin | int | BC28 ADC 引腳號(暫時無效) |
Product Key | string | 阿里雲三元組信息 |
Device Name | string | 阿里雲三元組信息 |
Device Secret | string | 阿里雲三元組信息 |
Keep-alive time | int | MQTT 保活時間 |
4、API 說明
4.1 MQTT 功能接口
int bc28_mqtt_auth(void);
int bc28_mqtt_open(void);
int bc28_mqtt_close(void);
int bc28_mqtt_connect(void);
int bc28_mqtt_disconnect(void);
int bc28_mqtt_subscribe(const char *topic);
int bc28_mqtt_unsubscribe(const char *topic);
int bc28_mqtt_publish(const char *topic, const char *msg);
4.2 網絡附着和去附着
int at_client_attach(void);
int at_client_deattach(void);
4.3 網絡初始化接口
int bc28_init(void);
int build_mqtt_network(void);
int rebuild_mqtt_network(void);