重现步骤
从最近源码更新了一次后,以前的可执行文件使用出错了,请问有没有大哥知道新一版源码怎么编写代码进行操作网络模块canmv_net_mgmt。
或者是操作canmv_net_mgmt的头文件都是哪些,可以参考些什么
期待结果和实际结果
软硬件版本信息
错误日志
尝试解决过程
补充材料
以前使用的连接方法:
#include <rtthread.h>
#include <rtdevice.h>
#include <string.h>
#include <wlan_mgnt.h>
#ifndef RT_WLAN_SSID_MAX_LENGTH
#define RT_WLAN_SSID_MAX_LENGTH 32
#endif
#ifndef RT_WLAN_PASSWORD_MAX_LENGTH
#define RT_WLAN_PASSWORD_MAX_LENGTH 64
#endif
#ifndef IOCTRL_WM_STA_CONNECT
#define IOCTRL_WM_STA_CONNECT 0x10
#endif
int retry_count = 3;
struct rt_wlan_connect_config {
int use_info;
union {
rt_wlan_ssid_t ssid;
struct rt_wlan_info info;
};
rt_wlan_key_t key;
};
int connect_to_wifi(const char *ssid, const char *password) {
struct rt_wlan_connect_config config;
rt_device_t net_mgmt_dev;
config.use_info = 0;
strncpy((char *)config.ssid.val, ssid, RT_WLAN_SSID_MAX_LENGTH);
strncpy((char *)config.key.val, password, RT_WLAN_PASSWORD_MAX_LENGTH);
// 查找网络管理设备
net_mgmt_dev = rt_device_find("canmv_net_mgmt");
if (net_mgmt_dev == RT_NULL) {
rt_kprintf("Cannot find net_mgmt device!\n");
return -1;
}
if (rt_device_open(net_mgmt_dev, RT_DEVICE_FLAG_RDWR) != RT_EOK) {
rt_kprintf("Cannot open net_mgmt device!\n");
return -1;
}
while (retry_count--) {
if (rt_device_control(net_mgmt_dev, IOCTRL_WM_STA_CONNECT, &config) == RT_EOK) {
rt_kprintf("Successfully connected to WiFi: %s\n", ssid);
return 0;
}
rt_kprintf("Retrying to connect...\n");
rt_thread_mdelay(3000);
}
rt_kprintf("Failed to connect after retries.\n");
return -1;
}
int main(void) {
connect_to_wifi("……", "……");
return 0;
}