tuanpmt / esp_mqtt

MQTT client library for ESP8266
http://tuanpm.net/post/esp_mqtt/
MIT License
1.15k stars 401 forks source link

Problem with SoftAP + STA mode #49

Open aignacio opened 9 years ago

aignacio commented 9 years ago

Hi tuan,

I have been trying at least two weeks ago to configure the device with softap+sta mode with your firmware, but always I can't see the ESP in my network list as AP, the code that I use to configure is this below. Have you tried to use the ESP in this mode with mqtt? I call this function before to connect with MQTT....

void configureAP()
{
    static char ssid[33];
    static char password[33];
    static uint8_t macaddr[6];

    struct softap_config apConfig;

    os_bzero(&apConfig, sizeof(struct softap_config));
    wifi_softap_get_config(&apConfig);

    wifi_set_opmode(0x3);
    switch(wifi_get_opmode())
    {
        case STATION_MODE:
            INFO("Modo de operação: Station");
        break;
        case SOFTAP_MODE:
            INFO("Modo de operação: Access Point Mode");

        break;
        case STATIONAP_MODE:
            INFO("Modo de operação: Access Point Mode + Station");

        break;
    }

    os_memset(apConfig.password, 0, sizeof(apConfig.password));
    os_sprintf(password, "%s", WIFI_APPASSWORD);
    os_memcpy(apConfig.password, password, os_strlen(password));

    os_memset(apConfig.ssid, 0, sizeof(apConfig.ssid));
    os_sprintf(ssid, "%s", WIFI_APSSID);
    os_memcpy(apConfig.ssid, ssid, os_strlen(ssid));

    //apConfig.authmode = AUTH_WEP;
    apConfig.authmode = AUTH_WPA_WPA2_PSK;
    //apConfig.authmode = AUTH_OPEN;
    apConfig.channel = 4;
    apConfig.max_connection = 2;
    apConfig.ssid_hidden = 0;
    wifi_softap_set_config(&apConfig);

    wifi_softap_dhcps_start();
    switch(wifi_softap_dhcps_status())
    {
        case DHCP_STOPPED:
            INFO("\nDHCP Server parou!\n");
        break;
        case DHCP_STARTED:
            INFO("\nDHCP Server foi iniciado!\n");
        break;
    }
}
Werquinx commented 9 years ago

check "wifi.c" in modules. It sets the module systematically in station only mode by default !