diff --git a/src/OTA.cpp b/src/OTA.cpp index 23d64f5c..1ec3be8e 100644 --- a/src/OTA.cpp +++ b/src/OTA.cpp @@ -4,16 +4,23 @@ const BintrayClient bintray(BINTRAY_USER, BINTRAY_REPO, BINTRAY_PACKAGE); bool Wifi_Connected = false; -static esp_err_t event_handler(void *ctx, system_event_t *event) { +esp_err_t event_handler(void *ctx, system_event_t *event) { switch (event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); + ESP_LOGI(TAG, "Event STA_START"); break; case SYSTEM_EVENT_STA_GOT_IP: Wifi_Connected = true; + ESP_LOGI(TAG, "Event STA_GOT_IP"); + // print the local IP address + tcpip_adapter_ip_info_t ip_info; + ESP_ERROR_CHECK(tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info)); + ESP_LOGI(TAG, "IP %s", ip4addr_ntoa(&ip_info.ip)); break; case SYSTEM_EVENT_STA_DISCONNECTED: Wifi_Connected = false; + ESP_LOGI(TAG, "Event STA_DISCONNECTED"); break; default: break; @@ -22,30 +29,38 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) { void ota_wifi_init(void) { + tcpip_adapter_if_t tcpip_if = TCPIP_ADAPTER_IF_STA; + // initialize the tcp stack + // nvs_flash_init(); tcpip_adapter_init(); + tcpip_adapter_set_hostname(tcpip_if, PROGNAME); + tcpip_adapter_dhcpc_start(tcpip_if); // initialize the wifi event handler ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL)); - wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); - wifi_config_t sta_config = {}; + // switch off monitor more + ESP_ERROR_CHECK( + esp_wifi_set_promiscuous(false)); // now switch on monitor mode + ESP_ERROR_CHECK(esp_wifi_set_promiscuous_rx_cb(NULL)); - strcpy((char *)sta_config.sta.ssid, WIFI_SSID); - strcpy((char *)sta_config.sta.password, WIFI_PASS); - sta_config.sta.bssid_set = false; + wifi_sta_config_t cfg; + strcpy((char *)cfg.ssid, WIFI_SSID); + strcpy((char *)cfg.password, WIFI_PASS); + cfg.bssid_set = false; - ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM)); - ESP_ERROR_CHECK(esp_wifi_init(&cfg)); + wifi_config_t sta_cfg; + sta_cfg.sta = cfg; + + wifi_init_config_t wifi_cfg = WIFI_INIT_CONFIG_DEFAULT(); + + ESP_ERROR_CHECK(esp_wifi_init(&wifi_cfg)); + ESP_ERROR_CHECK( + esp_wifi_set_storage(WIFI_STORAGE_RAM)); // we don't need NVRAM ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); - ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &sta_config)); + ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &sta_cfg)); ESP_ERROR_CHECK(esp_wifi_start()); - - // print the local IP address - tcpip_adapter_ip_info_t ip_info; - ESP_ERROR_CHECK(tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info)); - ESP_LOGI(TAG, "IP %s", ip4addr_ntoa(&ip_info.ip)); - } void start_ota_update() { @@ -57,6 +72,8 @@ void start_ota_update() { ESP_LOGI(TAG, "Connecting to %s", WIFI_SSID); ota_wifi_init(); + delay(2000); + delay(2000); checkFirmwareUpdates(); ESP.restart(); // reached if update was not successful } \ No newline at end of file diff --git a/src/wifiscan.cpp b/src/wifiscan.cpp index 9cb2ae98..24d6504f 100644 --- a/src/wifiscan.cpp +++ b/src/wifiscan.cpp @@ -6,7 +6,7 @@ static const char TAG[] = "wifi"; static wifi_country_t wifi_country = {WIFI_MY_COUNTRY, WIFI_CHANNEL_MIN, - WIFI_CHANNEL_MAX, 0, + WIFI_CHANNEL_MAX, 100, WIFI_COUNTRY_POLICY_MANUAL}; // using IRAM_:ATTR here to speed up callback function