1 前言
本文主要实现了 Funpack第二季第六期 "一起玩 开发板" nRF7002-DK 任务二.
- 基于nRF7002-DK提供的WiFi连接功能,连接网络,并实现远程控制板卡LED和读取按键信息。
本文主要内容包括基于VSCODE的NCS开发环境搭建、基于NCS的WiFi与MQTT连接实现设备远程控制等
2 准备工作
本文当前主要使用到如下资源:
- nRF7002 DK
- nordic开发板
- nRF Connect SDK
- NCS v2.4.2
- Visual Studio Code with nRF Connect for VS Code extension
- nordic基于VSCODE的集成开发环境
- MQTT Broker
- 使用免费开放的 test.mosquitto.org
- MQTT客户端
- MQTTX - https://mqttx.app/zh
2.1 nRF7002-DK简介
nRF7002 DK 是一个硬件开发平台,可促进 Wi-Fi6 应用的设计和开发。 该开发套件 (DK) 将 nRF7002 配套集成电路 (IC) 的 Wi-Fi 6 功能与 nRF5340 片上系统 (SoC) 相结合。
本文主要使用了nRF7002 DK如下功能模块:
- nRF5340 双核蓝牙5.3 SoC,作为板子的主控MCU
- 采用的是双核Arm® Cortex®-M33架构
- 支持蓝牙低功耗、蓝牙mesh、NFC、Thread和Zigbee等等
- nRF7002 Wi-Fi协同IC,通过QSPI接口与主控MCU nRF5340交互。
- 支持双频 2.4 GHz 和 5 GHz Wi-Fi 6
- 用户可编程 LED (2) 和按钮 (2)
- SEGGER J-Link 板载编程器/调试器
- nRF7002 DK 上的接口 MCU 运行 SEGGER J-Link 板载接口固件,用于对 nRF5340 SoC 的固件进行编程和调试
图 1:nRF7002 DK (PCA10143)
2.2 NCS开发环境搭建
NCS是nRF Connect SDK的缩写,是基于zephyr构建的SDK全家桶。 nRF Connect SDK介绍的官方链接:nRF Connect SDK - nordicsemi.com。 NCS官方开发文档链接:https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/getting_started.html
2.2.1 安装nRF Connet for Desktop安装
nRF Connet for Desktop是 Nordic Semiconductor 开发的一款免费工具,可以针对多种无线技术开发和测试应用程序。
- 下载安装最新版本即可。
https://www.nordicsemi.com/Products/Development-tools/nRF-Connect-for-desktop/Download#infotabs
- 打开nRF Connet for Desktop, 找到“Toolchain Manager”并安装
- 打开上述安装好的"Toolchain Manager”界面
- 安装nRF Connect SDK。Toolchain Manager提供了多个版本SDK,根据需要选择安装(如nRF Connect SDK v2.4.2)
RF Connect SDK的安装包括Toolchains和nrf sdk,zephyr sdk等软件模块,安装过程需要较长时间,可能会因为网络原因,出现安装失败的情况。
2.2.2 安装nRF Command Line Tools
下载安装最新版本即可。 https://www.nordicsemi.com/Products/Development-tools/nRF-Command-Line-Tools/Download
2.2.3 安装VS code
下载地址 https://code.visualstudio.com/
2.2.4 NCS SDK搭建blinky示例
- 打开"Open VS Code"
- 首次会跳出安装VS Code插件,选择"Install missing extensions"。
- 跳转到vscode,点击 nRF Connect for VS Code extension
- 点击“Create a new application”, “Copy a sample”
- 右侧搜索框输入"blink"搜索Blinky例程,点击“Blinky Sample”,选择本地保存路径与项目工程文件夹
- 创建编译“Create new build configuration”
- 选择Board, 输入 nrf7002,选择 “nrf7002dk_nrf5340_cpuapp
- 然后点击“Build”
- 如果板子正常连接电脑后,VSCODE 找不到设备,需设置nRF Connect For VS Code扩展“Device Provider”为 “nrfjprog”,具体如下所示
选择识别到的板子ID,执行下载"Flash"
- 打开串口工具,选择串口端口号(编号较大的),波特率115200。重启设备后,LED闪烁,并输出上电信息,如下所示
*** Booting Zephyr OS build v3.3.99-ncs1-1 ***
至此,基于VSCODE的NCS开发环境搭建完成。
3 系统总体功能
3.1 软件系统框图
NCS基于Zephyr系统,提供了丰富的物联网联网能力。
3.2 硬件接口电路
nRF7002 DK板载了主控nRF5340、nRF7002、Jlink、用户按键、LED、NFC等
3.2.1 WIFI接口电路
nRF7002 WiFi模块通过QSPI与nRF5340进行数据交互。
3.2.2 LED接口电路
板载2颗用户LED
3.2.3 按键接口电路
板载2路用户按键,另外还有一路复位按键
4 功能实现
4.1 创建MQTT工程
创建基于WIFI的MQTT工程,以 nrf/samples/net/mqtt作为模版
该示例应用层主要包含6个模块,分别是
- Trigger模块:定时触发,向MQTT Broker定期发布消息。同时检测按键按键,也会触发
- Sampler模块:当前Trigger触发,采样数据并发送。当前采样数据采用的是一串模拟字符串。
- Transport模块:复杂处理MQTT连接,发布消息与接收并解析订阅的消息。本文在此基础上,新增处理LED远程控制与远程读取状态
- Network模块:负责WIFI网络连接
- LED:根据其他功能模块发出的消息,控制LED的状态
- Error:监控其他功能模块发出的报错消息。
4.2 Kconfig配置WIFI SSID与密码
当前示例采用静态方式配置WIFI的SSID与密码。
- 点击“nRF Kconfig GUI”,进行WIFI参数的静态配置
- 右侧搜索框输入 wifi, 找到 “Static Wi-Fi network configuration”,输入可用的 WiFi SSID、Password
- 点击“Save to file”保存到 当前工程/prj.conf,查看prj.conf,其新增了CONFIG_WIFI_CREDENTIALS_STATIC_SSID与CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD等
4.3 按键触发上报服务器与远程按键状态读取
4.3.1 BUTTON设备树定义
button设备树定义如下
buttons {
compatible = "gpio-keys";
button0: button_0 {
gpios = <&gpio1 8 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
label = "Push button 1";
};
button1: button_1 {
gpios = <&gpio1 9 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
label = "Push button 2";
};
};
DK Buttons Library 在Zephyr GPIO API之上实现的API,通过读取指定输入引脚逻辑电平
#define DK_NO_BTNS_MSK (0)
#define DK_BTN1 0
#define DK_BTN2 1
有按键按下的情况下,通过引脚中断回调 button_pressed--> buttons_scan -> gpio_pin_get_dt 通过dk_get_buttons可以获取button1、button2的状态。
4.3.2 kconfig新增按键触发消息与读取按键状态
通过Kconfig,定义一组按键控制命令(字符串),用于按键按下状态上报、按键状态读取。
config BUTTON1_EVENT_PUBLISH_MSG
string "The message to publish on a button event"
default "Button 1 Pressed"
config BUTTON2_EVENT_PUBLISH_MSG
string "The message to publish on a button event"
default "Button 2 Pressed"
config BUTTON1_EVENT_PUBLISH_MSG_RELEASED
string "The message to publish on a button event"
default "Button 1 Released"
config BUTTON2_EVENT_PUBLISH_MSG_RELEASED
string "The message to publish on a button event"
default "Button 2 Released"
config BUTTON1_READ_CMD
string "Command to read BUTTON1"
default "BUTTON1READ"
config BUTTON2_READ_CMD
string "Command to read BUTTON2"
default "BUTTON2READ"
4.3.3 按键触发数据上报服务器
有按键按下,发布按键按下消息
static int message_send_msg(uint8_t *data)
{
int err;
err = zbus_chan_pub(&PAYLOAD_CHAN, data, K_SECONDS(1));
if (err) {
LOG_ERR("zbus_chan_pub, error: %d", err);
SEND_FATAL_ERROR();
}
return err;
}
static void button_handler(uint32_t button_states, uint32_t has_changed)
{
switch (has_changed) {
case DK_BTN1_MSK:
if (button_states & DK_BTN1_MSK){
int err = message_send_msg(CONFIG_BUTTON1_EVENT_PUBLISH_MSG);
if (err) {
LOG_ERR("Failed to send message, %d", err);
return;
}
}
break;
case DK_BTN2_MSK:
if (button_states & DK_BTN2_MSK){
int err = message_send_msg(CONFIG_BUTTON2_EVENT_PUBLISH_MSG);
if (err) {
LOG_ERR("Failed to send message, %d", err);
return;
}
}
break;
}
}
4.3.4 远程读取按键状态
通过MQTTX客户端发布按键状态读取。板卡接收到订阅消息后,解析该命令,随后发布当前按键状态消息。
static void on_mqtt_publish(struct mqtt_helper_buf topic, struct mqtt_helper_buf payload)
{
LOG_INF("Received payload: %.*s on topic: %.*s", payload.size,
payload.ptr,
topic.size,
topic.ptr);
uint32_t button_state;
int err;
uint8_t *data_ptr;
else if(strncmp(payload.ptr,CONFIG_BUTTON1_STATE_READ_CMD,sizeof(CONFIG_BUTTON1_STATE_READ_CMD)-1) ==0){
button_state=dk_get_buttons();
if(button_state & DK_BTN1_MSK){
data_ptr = CONFIG_BUTTON1_EVENT_PUBLISH_MSG;
}
else{
data_ptr = CONFIG_BUTTON1_EVENT_PUBLISH_MSG_RELEASED;
}
err = message_send_msg(data_ptr);
if (err) {
LOG_ERR("Failed to send message, %d", err);
}
}
else if(strncmp(payload.ptr,CONFIG_BUTTON2_STATE_READ_CMD,sizeof(CONFIG_BUTTON2_STATE_READ_CMD)-1) ==0){
button_state=dk_get_buttons();
if(button_state & DK_BTN2_MSK){
data_ptr = CONFIG_BUTTON2_EVENT_PUBLISH_MSG;
}
else{
data_ptr = CONFIG_BUTTON2_EVENT_PUBLISH_MSG_RELEASED;
}
err = message_send_msg(data_ptr);
if (err) {
LOG_ERR("Failed to send message, %d", err);
}
}
}
4.3 远程控制LED
4.3.1 LED设备树定义
led设备树定义如下所示
leds {
compatible = "gpio-leds";
led0: led_0 {
gpios = <&gpio1 6 GPIO_ACTIVE_HIGH>;
label = "Green LED 0";
};
led1: led_1 {
gpios = <&gpio1 7 GPIO_ACTIVE_HIGH>;
label = "Green LED 1";
};
};
DK LED Library 在Zephyr GPIO API之上实现的API,如dk_set_led_on -->dk_set_led -> gpio_pin_set_dt
#define DK_NO_LEDS_MSK (0)
#define DK_LED1 0
#define DK_LED2 1
4.3.2 kconfig新增LED控制命令
通过Kconfig,定义一组LED控制命令(字符串),用于LED开与关控制。
config TURN_LED1_ON_CMD
string "Command to turn on LED"
default "LED1ON"
config TURN_LED1_OFF_CMD
string "Command to turn off LED"
default "LED1OFF"
config TURN_LED2_ON_CMD
string "Command to turn on LED"
default "LED2ON"
config TURN_LED2_OFF_CMD
string "Command to turn off LED"
default "LED2OFF"
4.3.3 远程开关LED
通过MQTTX客户端发布LED1、LED2的打开与关闭命令。板卡接收到订阅消息后,解析该LED控制命令,实现LED远程控制
#define DK_LED1 1
#define DK_LED2 0
static void on_mqtt_publish(struct mqtt_helper_buf topic, struct mqtt_helper_buf payload)
{
LOG_INF("Received payload: %.*s on topic: %.*s", payload.size,
payload.ptr,
topic.size,
topic.ptr);
// Control LED1 and LED2
if(strncmp(payload.ptr,CONFIG_TURN_LED1_ON_CMD,sizeof(CONFIG_TURN_LED1_ON_CMD)-1) == 0){
dk_set_led_on(DK_LED1);
}
else if(strncmp(payload.ptr,CONFIG_TURN_LED1_OFF_CMD,sizeof(CONFIG_TURN_LED1_OFF_CMD)-1) == 0){
dk_set_led_off(DK_LED1);
}
else if(strncmp(payload.ptr,CONFIG_TURN_LED2_ON_CMD,sizeof(CONFIG_TURN_LED2_ON_CMD)-1) == 0){
dk_set_led_on(DK_LED2);
}
else if(strncmp(payload.ptr,CONFIG_TURN_LED2_OFF_CMD,sizeof(CONFIG_TURN_LED2_OFF_CMD)-1) == 0){
dk_set_led_off(DK_LED2);
}
}
5 功能测试
使用MQTTX客户端连接开放的MQTT Broker,然后与nRF7002板卡的MQTT客户端应用程序进行通信。
5.1 建立MQTTX客户端
打开PC端的MQTTX客户端,点击“+”新建连接,在右侧填入MQTT连接的基本信息 Name: 与MQTT协议无关,可任意定义 MQTT Broker 使用免费的test.mosquitto.org Client ID:可以使用默认定义(可任意定义),因为使用的是公共免费MQTT Broker,不要填写容易与他人重复的ID即可。 其他先保持默认即可。 nRF7002板卡上电后,自动进行WIFI连接,然后连接到MQTT broker(test.mosquitto.org)
5.2 nRF7002板卡发布消息
nRF7002板卡周期性发布的主题消息“Hello MQTT! Current uptime is: 6180664”。
[01:42:01.021,179] <inf> network: IPv4 address lost
[01:42:01.029,327] <inf> network: Wi-Fi Connected, waiting for IP address
[01:42:01.237,304] <inf> network: IPv4 address acquired
[01:42:06.869,140] <inf> transport: Connected to MQTT broker
[01:42:06.869,171] <inf> transport: Hostname: test.mosquitto.org
[01:42:06.869,201] <inf> transport: Client ID: F4CE3600173C
[01:42:06.869,232] <inf> transport: Port: 1883
[01:42:06.869,232] <inf> transport: TLS: No
[01:42:06.869,293] <inf> transport: Subscribing to: F4CE3600173C/my/subscribe/topic
[01:42:07.071,166] <inf> transport: Subscribed to topic F4CE3600173C/my/subscribe/topic
[01:43:00.673,828] <inf> transport: Published message: "Hello MQTT! Current uptime is: 6180664" on topic: "F4CE3600173C/my/publish/topic"
[01:44:00.673,797] <inf> transport: Published message: "Hello MQTT! Current uptime is: 6240664" on topic: "F4CE3600173C/my/publish/topic"
[01:45:00.673,797] <inf> transport: Published message: "Hello MQTT! Current uptime is: 6300664" on topic: "F4CE3600173C/my/publish/topic"
[01:46:00.673,858] <inf> transport: Published message: "Hello MQTT! Current uptime is: 6360664" on topic: "F4CE3600173C/my/publish/topic"
[01:47:00.673,858] <inf> transport: Published message: "Hello MQTT! Current uptime is: 6420664" on topic: "F4CE3600173C/my/publish/topic"
[01:48:00.667,877] <inf> transport: Published message: "Hello MQTT! Current uptime is: 6480664" on topic: "F4CE3600173C/my/publish/topic"
[01:49:00.674,835] <inf> transport: Published message: "Hello MQTT! Current uptime is: 6540664" on topic: "F4CE3600173C/my/publish/topic"
[01:50:00.674,835] <inf> transport: Published message: "Hello MQTT! Current uptime is: 6600664" on topic: "F4CE3600173C/my/publish/topic"
[01:51:00.674,865] <inf> transport: Published message: "Hello MQTT! Current uptime is: 6660665" on topic: "F4CE3600173C/my/publish/topic"
[01:52:00.674,835] <inf> transport: Published message: "Hello MQTT! Current uptime is: 6720665" on topic: "F4CE3600173C/my/publish/topic"
[01:53:00.670,806] <inf> transport: Published message: "Hello MQTT! Current uptime is: 6780665" on topic: "F4CE3600173C/my/publish/topic"
[01:54:00.674,835] <inf> transport: Published message: "Hello MQTT! Current uptime is: 6840665" on topic: "F4CE3600173C/my/publish/topic"
[01:55:00.674,865] <inf> transport: Published message: "Hello MQTT! Current uptime is: 6900665" on topic: "F4CE3600173C/my/publish/topic"
[01:56:00.674,865] <inf> transport: Published message: "Hello MQTT! Current uptime is: 6960665" on topic: "F4CE3600173C/my/publish/topic"
[01:57:00.667,236] <inf> transport: Published message: "Hello MQTT! Current uptime is: 7020665" on topic: "F4CE3600173C/my/publish/topic"
[01:58:00.674,835] <inf> transport: Published message: "Hello MQTT! Current uptime is: 7080665" on topic: "F4CE3600173C/my/publish/topic"
nRF7002板卡按下key1、key2,发布按键按下。
*** Booting Zephyr OS build v3.3.99-ncs1-1 ***
[00:00:01.476,654] <wrn> wifi_credentials: Cannot retrieve WiFi credentials, no entry found for the provided SSID
[00:00:01.476,715] <inf> wifi_mgmt_ext: Adding statically configured WiFi network [Green-Forest-2G4] to internal list.
[00:00:08.129,516] <inf> network: Wi-Fi Connected, waiting for IP address
[00:00:08.330,871] <inf> network: IPv4 address acquired
[00:00:14.185,699] <inf> transport: Connected to MQTT broker
[00:00:14.185,729] <inf> transport: Hostname: test.mosquitto.org
[00:00:14.185,760] <inf> transport: Client ID: F4CE3600173C
[00:00:14.185,760] <inf> transport: Port: 1883
[00:00:14.185,791] <inf> transport: TLS: No
[00:00:14.185,821] <inf> transport: Subscribing to: F4CE3600173C/my/subscribe/topic
[00:00:14.461,181] <inf> transport: Subscribed to topic F4CE3600173C/my/subscribe/topic
[00:00:37.509,460] <inf> transport: Received payload: LED2ON on topic: F4CE3600173C/my/subscribe/topic
[00:00:52.953,155] <inf> transport: Received payload: LED2OFF on topic: F4CE3600173C/my/subscribe/topic
[00:00:57.459,655] <inf> transport: Received payload: LED1OFF on topic: F4CE3600173C/my/subscribe/topic
[00:01:00.484,832] <inf> transport: Published message: "Hello MQTT! Current uptime is: 60475" on topic: "F4CE3600173C/my/publish/topic"
[00:01:01.860,809] <inf> transport: Published message: "Button 1 Pressed" on topic: "F4CE3600173C/my/publish/topic"
[00:01:11.065,460] <inf> transport: Published message: "Button 2 Pressed" on topic: "F4CE3600173C/my/publish/topic"
5.3 MQTTX客户端发布消息
MQTTX客户端发布“Hello EETree”, 关闭LED "LED1OFF"、打开"LED2ON", 读取按键状态"BUTTON1READ"、"BUTTON2READ"等消息,nRF7002板卡返回BUTTON1\2当前按键状态。
*** Booting Zephyr OS build v3.3.99-ncs1-1 ***
[00:00:01.508,026] <wrn> wifi_credentials: Cannot retrieve WiFi credentials, no entry found for the provided SSID
[00:00:01.508,087] <inf> wifi_mgmt_ext: Adding statically configured WiFi network [Green-Forest-2G4] to internal list.
[00:00:08.137,573] <inf> network: Wi-Fi Connected, waiting for IP address
[00:00:08.296,325] <inf> network: IPv4 address acquired
[00:00:13.721,984] <inf> transport: Connected to MQTT broker
[00:00:13.722,015] <inf> transport: Hostname: test.mosquitto.org
[00:00:13.722,045] <inf> transport: Client ID: F4CE3600173C
[00:00:13.722,045] <inf> transport: Port: 1883
[00:00:13.722,076] <inf> transport: TLS: No
[00:00:13.722,106] <inf> transport: Subscribing to: F4CE3600173C/my/subscribe/topic
[00:00:13.923,065] <inf> transport: Subscribed to topic F4CE3600173C/my/subscribe/topic
[00:01:00.516,845] <inf> transport: Published message: "Hello MQTT! Current uptime is: 60507" on topic: "F4CE3600173C/my/publish/topic"
[00:01:09.183,685] <inf> transport: Received payload: LED1OFF on topic: F4CE3600173C/my/subscribe/topic
[00:01:26.375,823] <inf> transport: Received payload: LED2OFF on topic: F4CE3600173C/my/subscribe/topic
[00:01:38.656,341] <inf> transport: Received payload: LED2ON on topic: F4CE3600173C/my/subscribe/topic
[00:01:44.082,733] <inf> transport: Received payload: LED2OFF on topic: F4CE3600173C/my/subscribe/topic
[00:01:54.193,817] <inf> transport: Published message: "Button 1 Pressed" on topic: "F4CE3600173C/my/publish/topic"
[00:01:57.622,802] <inf> transport: Published message: "Button 2 Pressed" on topic: "F4CE3600173C/my/publish/topic"
[00:01:58.304,412] <inf> transport: Published message: "Button 1 Pressed" on topic: "F4CE3600173C/my/publish/topic"
[00:01:59.715,820] <inf> transport: Published message: "Button 2 Pressed" on topic: "F4CE3600173C/my/publish/topic"
[00:02:00.507,720] <inf> transport: Published message: "Hello MQTT! Current uptime is: 120507" on topic: "F4CE3600173C/my/publish/topic"
[00:02:10.993,774] <inf> transport: Received payload: LED2ON on topic: F4CE3600173C/my/subscribe/topic
[00:02:37.300,872] <inf> transport: Received payload: LED1ON on topic: F4CE3600173C/my/subscribe/topic
[00:02:37.498,626] <inf> transport: Received payload: LED1ON on topic: F4CE3600173C/my/subscribe/topic
[00:02:37.499,908] <inf> transport: Received payload: LED1OFF on topic: F4CE3600173C/my/subscribe/topic
[00:02:37.500,183] <inf> transport: Received payload: LED1ON on topic: F4CE3600173C/my/subscribe/topic
[00:02:37.500,488] <inf> transport: Received payload: LED1ON on topic: F4CE3600173C/my/subscribe/topic
[00:02:52.747,192] <inf> transport: Received payload: LED1OFF on topic: F4CE3600173C/my/subscribe/topic
[00:02:57.044,036] <inf> transport: Received payload: LED2OFF on topic: F4CE3600173C/my/subscribe/topic
[00:03:00.514,984] <inf> transport: Published message: "Hello MQTT! Current uptime is: 180507" on topic: "F4CE3600173C/my/publish/topic"
[00:03:53.331,634] <inf> transport: Received payload: BUTTON1READ on topic: F4CE3600173C/my/subscribe/topic
[00:03:53.333,770] <inf> transport: Published message: "Button 1 Released" on topic: "F4CE3600173C/my/publish/topic"
[00:04:00.516,845] <inf> transport: Published message: "Hello MQTT! Current uptime is: 240507" on topic: "F4CE3600173C/my/publish/topic"
[00:04:03.970,703] <inf> transport: Received payload: BUTTON2READ on topic: F4CE3600173C/my/subscribe/topic
[00:04:03.973,205] <inf> transport: Published message: "Button 2 Released" on topic: "F4CE3600173C/my/publish/topic"
[00:05:00.516,845] <inf> transport: Published message: "Hello MQTT! Current uptime is: 300507" on topic: "F4CE3600173C/my/publish/topic"
nRF7002板卡输出收到订阅的消息“Hello EETree”,并根据led控制命令,打开与关闭板载led1、led2
*** Booting Zephyr OS build v3.3.99-ncs1-1 ***
[00:00:01.525,604] <wrn> wifi_credentials: Cannot retrieve WiFi credentials, no entry found for the provided SSID
[00:00:01.525,634] <inf> wifi_mgmt_ext: Adding statically configured WiFi network [Green-Forest-2G4] to internal list.
[00:00:08.168,212] <inf> network: Wi-Fi Connected, waiting for IP address
[00:00:08.393,890] <inf> network: IPv4 address acquired
[00:00:14.237,823] <inf> transport: Connected to MQTT broker
[00:00:14.237,854] <inf> transport: Hostname: test.mosquitto.org
[00:00:14.237,884] <inf> transport: Client ID: F4CE3600173C
[00:00:14.237,884] <inf> transport: Port: 1883
[00:00:14.237,915] <inf> transport: TLS: No
[00:00:14.237,976] <inf> transport: Subscribing to: F4CE3600173C/my/subscribe/topic
[00:00:14.516,967] <inf> transport: Subscribed to topic F4CE3600173C/my/subscribe/topic
[00:00:00.507,110] <inf> fs_nvs: 6 Sectors of 4096 bytes
[00:00:00.507,141] <inf> fs_nvs: alloc wra: 0, fe8
[00:00:00.507,171] <inf> fs_nvs: data wra: 0, 0
*** Booting Zephyr OS build v3.3.99-ncs1-1 ***
[00:00:01.510,925] <wrn> wifi_credentials: Cannot retrieve WiFi credentials, no entry found for the provided SSID
[00:00:01.510,955] <inf> wifi_mgmt_ext: Adding statically configured WiFi network [Green-Forest-2G4] to internal list.
[00:00:08.149,932] <inf> network: Wi-Fi Connected, waiting for IP address
[00:00:08.362,274] <inf> network: IPv4 address acquired
[00:00:13.896,179] <inf> transport: Connected to MQTT broker
[00:00:13.896,209] <inf> transport: Hostname: test.mosquitto.org
[00:00:13.896,240] <inf> transport: Client ID: F4CE3600173C
[00:00:13.896,270] <inf> transport: Port: 1883
[00:00:13.896,270] <inf> transport: TLS: No
[00:00:13.896,331] <inf> transport: Subscribing to: F4CE3600173C/my/subscribe/topic
[00:00:14.093,536] <inf> transport: Subscribed to topic F4CE3600173C/my/subscribe/topic
[00:00:29.038,116] <inf> transport: Received payload:
Hello EETree on topic: F4CE3600173C/my/subscribe/topic
[00:01:00.518,829] <inf> transport: Published message: "Hello MQTT! Current uptime is: 60510" on topic: "F4CE3600173C/my/publish/topic"
[00:01:10.797,698] <inf> transport: Received payload: LED1OFF on topic: F4CE3600173C/my/subscribe/topic
[00:01:22.653,778] <inf> transport: Received payload: LED2ON on topic: F4CE3600173C/my/subscribe/topic
[00:02:00.519,805] <inf> transport: Published message: "Hello MQTT! Current uptime is: 120510" on topic: "F4CE3600173C/my/publish/topic"
[00:03:00.511,871] <inf> transport: Published message: "Hello MQTT! Current uptime is: 180510" on topic: "F4CE3600173C/my/publish/topic"
[00:04:00.513,458] <inf> transport: Published message: "Hello MQTT! Current uptime is: 240510" on topic: "F4CE3600173C/my/publish/topic"
6 参考资料
- nrf7002-mqtt over wifi
- https://www.zephyrproject.org/implementing-mqtt-over-wi-fi-on-the-nrf7002-dev-kit/
- MQTT over WiFi 示例演练
- NCS官方开发文档
- https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/getting_started.html
7 心得体会
通过参与nRF7002-DK 一起玩活动,学习了nRF7002-DK板卡的丰富软硬件资源,nRF7002-DK作为硬件开发平台非常强大,也进一步熟悉了NCS开发方式,NCS基于物联网操作系统zephyr,整个系统非常庞大,具备强大的物联网连接能力、满足不同等级的安全能力、优异的可移植性、行业领先代码开发与管理理念等等,同时提供了丰富的示例工程,使得应用开发、维护、迭代等非常方便与快捷,后续还需不断学习探索。
在此非常感谢主办方举办Funpack有趣活动