1 代码说明

  1. 初始化Wi-Fi协议栈,可以使用mxos_network_init只初始化Wi-Fi协议栈,也可以使用mxos_system_init初始化系统顺便初始化Wi-Fi协议栈
  2. 使用mxos_system_notify_register注册【WiFi状态改变】事件的回调函数wifi_status_notify
  3. 定义AP的网络属性
    1. localip
    2. netmask
    3. dnsserver
    4. gateway
  4. 调用mwifi_softap_start启动热点
  5. 调用mwifi_softap_stop可以关闭热点

1.1 mxos_system_notify_register

https://www.yuque.com/zhaohongyu-jn3s2/mxchip/pfr1nm#xqRXV

1.2 回调函数

  1. void wifi_status_notify(int event, void *arg)
  • 第一个参数是事件类型,定义如下: ```cpp enum { NOTIFY_STATION_UP = 1, // STA模式,连接路由器成功 NOTIFY_STATION_DOWN, // STA模式,断开与路由器的连接

    NOTIFY_AP_UP, // AP热点启动 NOTIFY_AP_DOWN, // AP热点关闭

    NOTIFY_ETH_UP, // NOTIFY_ETH_DOWN, // };

  1. <a name="RoExg"></a>
  2. ## 1.3 mwifi_softap_start
  3. ```cpp
  4. /**
  5. * @brief start soft-ap
  6. * @param ssid ssid of the soft-ap
  7. * @param key passphrase of the soft-ap
  8. * @param channel channel of the soft-ap
  9. * @param attr ip address atrributes of soft-ap
  10. *
  11. * @return result
  12. * @retval kNoErr sucess
  13. * @retval others failure
  14. */
  15. merr_t mwifi_softap_start(const char *ssid, char *key, int channel, mwifi_ip_attr_t *attr);

结构体mwifi_ip_attr_t

  1. /**
  2. * @brief IP address attributes
  3. */
  4. typedef struct
  5. {
  6. char localip[16]; /**< lcoal ip address */
  7. char netmask[16]; /**< netmask */
  8. char gateway[16]; /**< gateway ip address */
  9. char dnserver[16]; /**< dns server ip address */
  10. } mwifi_ip_attr_t;

1.4 mwifi_softap_stop

  1. /**
  2. * @brief stop soft-ap
  3. *
  4. * @return result
  5. * @retval kNoErr sucess
  6. * @retval others failure
  7. */
  8. merr_t mwifi_softap_stop(void);

1.5 实现dhcps_client_new

  1. void dhcps_client_new(uint32_t client_ip, uint8_t *chaddr)
  2. {
  3. app_log("%s, ip = %d.%d.%d.%d(%08X), mac = %02X:%02X:%02X:%02X:%02X:%02X", __FUNCTION__, (uint8_t)((uint32_t)client_ip & 0x000000FF), (uint8_t)(((uint32_t)client_ip & 0x0000FFFF) >> 8), (uint8_t)(((uint32_t)client_ip & 0x00FFFFFF) >> 16), (uint8_t)(((uint32_t)client_ip & 0xFFFFFFFF) >> 24), (unsigned int)client_ip, chaddr[0], chaddr[1], chaddr[2], chaddr[3], chaddr[4], chaddr[5]);
  4. }

函数功能:当有终端连接到模组的热点时,系统会调用此函数
第一个参数:连到模组热点的终端的IP地址,如C000000A,表示10.0.0.192
第二个参数:连到模组热点的终端的MAC地址,6个字节

:::info 注意:有些芯片不支持这个功能。详见本文第2节。 :::

2 各模组情况

No 芯片 编译命令 dhcps_client_new
1 MX1300 mdev build wifi/softap/ emc3080
mdev build wifi/softap/ emc3180
不支持
2 MX131x mdev build wifi/softap/ emc3280
mdev build wifi/softap/ emc3380
未知
3 TG7100C mdev不支持对此芯片执行-f操作,需要使用其他软件烧录固件
mdev build hal/adc/ emc3020
支持
4 MX1290 mdev build wifi/softap/ emw3080 支持
5
6
7