testing
This commit is contained in:
parent
0ee138b022
commit
7a58c8dece
47
src/OTA.cpp
47
src/OTA.cpp
@ -4,16 +4,23 @@ const BintrayClient bintray(BINTRAY_USER, BINTRAY_REPO, BINTRAY_PACKAGE);
|
|||||||
|
|
||||||
bool Wifi_Connected = false;
|
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) {
|
switch (event->event_id) {
|
||||||
case SYSTEM_EVENT_STA_START:
|
case SYSTEM_EVENT_STA_START:
|
||||||
esp_wifi_connect();
|
esp_wifi_connect();
|
||||||
|
ESP_LOGI(TAG, "Event STA_START");
|
||||||
break;
|
break;
|
||||||
case SYSTEM_EVENT_STA_GOT_IP:
|
case SYSTEM_EVENT_STA_GOT_IP:
|
||||||
Wifi_Connected = true;
|
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;
|
break;
|
||||||
case SYSTEM_EVENT_STA_DISCONNECTED:
|
case SYSTEM_EVENT_STA_DISCONNECTED:
|
||||||
Wifi_Connected = false;
|
Wifi_Connected = false;
|
||||||
|
ESP_LOGI(TAG, "Event STA_DISCONNECTED");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -22,30 +29,38 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) {
|
|||||||
|
|
||||||
void ota_wifi_init(void) {
|
void ota_wifi_init(void) {
|
||||||
|
|
||||||
|
tcpip_adapter_if_t tcpip_if = TCPIP_ADAPTER_IF_STA;
|
||||||
|
|
||||||
// initialize the tcp stack
|
// initialize the tcp stack
|
||||||
|
// nvs_flash_init();
|
||||||
tcpip_adapter_init();
|
tcpip_adapter_init();
|
||||||
|
tcpip_adapter_set_hostname(tcpip_if, PROGNAME);
|
||||||
|
tcpip_adapter_dhcpc_start(tcpip_if);
|
||||||
|
|
||||||
// initialize the wifi event handler
|
// initialize the wifi event handler
|
||||||
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
|
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
|
||||||
|
|
||||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
// switch off monitor more
|
||||||
wifi_config_t sta_config = {};
|
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);
|
wifi_sta_config_t cfg;
|
||||||
strcpy((char *)sta_config.sta.password, WIFI_PASS);
|
strcpy((char *)cfg.ssid, WIFI_SSID);
|
||||||
sta_config.sta.bssid_set = false;
|
strcpy((char *)cfg.password, WIFI_PASS);
|
||||||
|
cfg.bssid_set = false;
|
||||||
|
|
||||||
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
|
wifi_config_t sta_cfg;
|
||||||
ESP_ERROR_CHECK(esp_wifi_init(&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_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());
|
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() {
|
void start_ota_update() {
|
||||||
@ -57,6 +72,8 @@ void start_ota_update() {
|
|||||||
|
|
||||||
ESP_LOGI(TAG, "Connecting to %s", WIFI_SSID);
|
ESP_LOGI(TAG, "Connecting to %s", WIFI_SSID);
|
||||||
ota_wifi_init();
|
ota_wifi_init();
|
||||||
|
delay(2000);
|
||||||
|
delay(2000);
|
||||||
checkFirmwareUpdates();
|
checkFirmwareUpdates();
|
||||||
ESP.restart(); // reached if update was not successful
|
ESP.restart(); // reached if update was not successful
|
||||||
}
|
}
|
@ -6,7 +6,7 @@
|
|||||||
static const char TAG[] = "wifi";
|
static const char TAG[] = "wifi";
|
||||||
|
|
||||||
static wifi_country_t wifi_country = {WIFI_MY_COUNTRY, WIFI_CHANNEL_MIN,
|
static wifi_country_t wifi_country = {WIFI_MY_COUNTRY, WIFI_CHANNEL_MIN,
|
||||||
WIFI_CHANNEL_MAX, 0,
|
WIFI_CHANNEL_MAX, 100,
|
||||||
WIFI_COUNTRY_POLICY_MANUAL};
|
WIFI_COUNTRY_POLICY_MANUAL};
|
||||||
|
|
||||||
// using IRAM_:ATTR here to speed up callback function
|
// using IRAM_:ATTR here to speed up callback function
|
||||||
|
Loading…
Reference in New Issue
Block a user