[ WiFi 智能家居项目 ] [ 5 ] Station & AP

代码

#define SSID "October"
#define PASSWORD "19971002"
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_init(void)
{
    printf("SDK version:%s\n", system_get_sdk_version());

    /* need to set opmode before you set config */
    wifi_set_opmode(STATION_MODE);
    struct station_config *config = (struct station_config *)\
        zalloc(sizeof(struct station_config));
    sprintf(config->ssid, SSID);
    sprintf(config->password, PASSWORD);

    wifi_station_set_config(config);
    free(config);

    wifi_station_set_auto_connect(TRUE);

    //xTaskCreate(smartconfig_task, "smartconfig_task", 256, NULL, 2, NULL);
}
#define SSID "ESP8266"
#define PASSWORD "19971002"
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_init(void)
{
    printf("SDK version:%s\n", system_get_sdk_version());

    /* need to set opmode before you set config */
    wifi_set_opmode(SOFTAP_MODE);
    struct softap_config *config = (struct softap_config *)\
        zalloc(sizeof(struct softap_config));
    wifi_softap_get_config(config);
    sprintf(config->ssid, SSID);
    sprintf(config->password, PASSWORD);

    config->authmode = AUTH_WPA2_PSK;
    config->ssid_len = 0;
    config->max_connection = 10;

    wifi_softap_set_config(config);
    free(config);

    //xTaskCreate(smartconfig_task, "smartconfig_task", 256, NULL, 2, NULL);
}

介绍

AP 是无线接入点,是一个无线网络的创建者,是网络的中心节点。一般家庭或办公室使用的无线路由器就是一个 AP,众多站点(STA)加入到它所组成的无线网络,网络中的所有通信都通过 AP 来转发完成。

Station(简称 STA),每一个连接到无线网络中的终端(如笔记本电脑、PDA及其他可以联网的用户设备)都可以称为一个站点。

流程图

image.png