代码拉取完成,页面将自动刷新
同步操作将从 yocop/drv_wifi_at_w800 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
W800芯片是一款串口转无线模芯片,内部自带固件,用户操作简单,无需编写时序信号等。
特性:
无。
首先,先了解一下NETHAL相关的一个重要结构体net_ops_t
。WiFi特有相关的操作和接口都封装在net_ops_t
这个结构体中,相关定义在文件:net_impl.h
。
typedef struct net_ops {
int (*get_mac_addr)(aos_dev_t *dev, uint8_t *mac);
int (*set_mac_addr)(aos_dev_t *dev, const uint8_t *mac);
int (*get_dns_server)(aos_dev_t *dev, ip_addr_t ipaddr[], uint32_t num);
int (*set_dns_server)(aos_dev_t *dev, ip_addr_t ipaddr[], uint32_t num);
int (*set_hostname)(aos_dev_t *dev, const char *name);
const char* (*get_hostname)(aos_dev_t *dev);
int (*set_link_up)(aos_dev_t *dev);
int (*set_link_down)(aos_dev_t *dev);
int (*start_dhcp)(aos_dev_t *dev);
int (*stop_dhcp)(aos_dev_t *dev);
int (*set_ipaddr)(aos_dev_t *dev, const ip_addr_t *ipaddr, const ip_addr_t *netmask, const ip_addr_t *gw);
int (*get_ipaddr)(aos_dev_t *dev, ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw);
int (*ping)(aos_dev_t *dev, int type, char *remote_ip);
int (*subscribe)(aos_dev_t *dev, uint32_t event, event_callback_t cb, void *param);
int (*unsubscribe)(aos_dev_t *dev, uint32_t event, event_callback_t cb, void *param);
} net_ops_t;
成员 | 说明 |
---|---|
get_mac_addr、set_mac_addr | 设置(获取)mac地址 |
get_dns_server、set_dns_server | 设置(获取)dns地址 |
set_hostname、get_hostname | 设置(获取)主机名 |
start_dhcp、stop_dhcp | 启动(停止)dhcp |
set_ipaddr、get_ipaddr | 设置(获取)ip相关信息,ipaddr、netmask及gw |
ping | 网络测试(Packet Internet Groper) |
subscribe、 unsubscribe | 订阅及取消订阅相关事件 |
首先,先了解一下sal相关的一个重要结构体sal_op_t
。sal特有相关的操作和接口都封装在sal_op_t
这个结构体中,相关定义在文件:sal.h。
typedef struct sal_op_s {
char *version; /* Reserved for furture use. */
/**
* Module low level init so that it's ready to setup socket connection.
*
* @return 0 - success, -1 - failure
*/
int (*init)(void);
/**
* Start a socket connection via module.
*
* @param[in] c - connect parameters which are used to setup
* the socket connection.
*
* @return 0 - success, -1 - failure
*/
int (*start)(sal_conn_t *c);
/**
* Send data via module.
* This function does not return until all data sent.
*
* @param[in] fd - the file descripter to operate on.
* @param[in] data - pointer to data to send.
* @param[in] len - length of the data.
* @param[in] remote_ip - remote ip address (optional).
* @param[in] remote_port - remote port number (optional).
* @param[in] timeout - packet send timeout (ms)
* @return 0 - success, -1 - failure
*/
int (*send)(int fd, uint8_t *data, uint32_t len,
char remote_ip[16], int32_t remote_port, int32_t timeout);
int (*recv)(int fd, uint8_t *data, uint32_t len,
char remote_ip[16], int32_t remote_port);
/**
* Get IP information of the corresponding domain.
* Currently only one IP string is returned (even when the domain
* coresponses to mutliple IPs). Note: only IPv4 is supported.
*
* @param[in] domain - the domain string.
* @param[out] ip - the place to hold the dot-formatted ip string.
*
* @return 0 - success, -1 - failure
*/
int (*domain_to_ip)(char *domain, char ip[16]);
/**
* Close the socket connection.
*
* @param[in] fd - the file descripter to operate on.
* @param[in] remote_port - remote port number (optional).
*
* @return 0 - success, -1 - failure
*/
int (*close)(int fd, int32_t remote_port);
/**
* Destroy SAL or exit low level state if necessary.
*
* @return 0 - success, -1 - failure
*/
int (*deinit)(void);
/**
* Register network connection data input function
* Input data from module.
* This callback should be called when the data is received from the module
* It should tell the sal where the data comes from.
* @param[in] fd - the file descripter to operate on.
* @param[in] data - the received data.
* @param[in] len - expected length of the data when IN,
* and real read len when OUT.
* @param[in] addr - remote ip address. Caller manages the
memory (optional).
* @param[in] port - remote port number (optional).
*
* @return 0 - success, -1 - failure
*/
int (*register_netconn_data_input_cb)(netconn_data_input_cb_t cb);
int (*register_netconn_close_cb)(netconn_close_cb_t cb);
#ifdef SAL_SERVER
/**
* Register remote client status function
* Input data from module.
* This callback should be called when the data is received from the module
* It should tell the sal where the data comes from.
* @param[in] fd - the file descripter to operate on.
* @param[in] status - remote client status
* @param[in] addr - remote ip address. Caller manages the
memory (optional).
* @param[in] port - remote port number (optional).
*
* @return 0 - success, -1 - failure
*/
int (*register_netconn_client_status_notify)(netconn_client_status_notify_t cb);
#endif
} sal_op_t
成员 | 说明 |
---|---|
version | 版本,将来使用 |
init | 初始化函数 |
start | 启动函数 |
send | 数据发送函数 |
recv | 数据接收函数 |
domain_to_ip | 获取域对应的IP地址 |
close | 连接关闭函数 |
deinit | 模块注销函数 |
register_netconn_data_input_cb | 注册网络数据输入回调函数 |
register_netconn_close_cb | 注册网络连接关闭回调函数 |
register_netconn_client_status_notify | 注册客户端状态通知回调函数 |
主要流程为注册网卡驱动----->启动netmgr微服务(netmgr详细说明 网络管理器 )
#include <devices/w800.h>
#include <yoc/netmgr.h>
#include <pin.h>
void board_yoc_init()
{
w800_wifi_param_t esp_param;
wifi_w800_register(NULL, &esp_param);
netmgr_hdl_t app_netmgr_hdl = netmgr_dev_wifi_init();
if (app_netmgr_hdl) {
netmgr_service_init(NULL);
netmgr_start(app_netmgr_hdl);
}
}
void board_cli_init(utask_t *task)
{
...
cli_reg_cmd_ping();
cli_reg_cmd_ifconfig();
...
}
使用ifconfig命令连接网络ifconfig ap ssid psk
,将ssid
和psk
更新为路由器的账号和密码
确认连接网络后,使用ping
命令测试网络是否连接外网,
无。
无。
minilibc: v7.2.0及以上。 aos: v7.2.0及以上。
无。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。