diff --git a/common/esp32/ygg_wifi.c b/common/esp32/ygg_wifi.c index 9d4bdcd..363a01f 100644 --- a/common/esp32/ygg_wifi.c +++ b/common/esp32/ygg_wifi.c @@ -15,7 +15,7 @@ static const char *TAG = "YGG_WIFI"; static EventGroupHandle_t s_wifi_event_group; -void wifi_event_handler(void* arg, esp_event_base_t event_base, +void ygg_wifi_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) { static int s_retry_num = 0; @@ -38,7 +38,7 @@ void wifi_event_handler(void* arg, esp_event_base_t event_base, } } -void wifi_init_sta(void) +void ygg_wifi_init_sta(void) { s_wifi_event_group = xEventGroupCreate(); @@ -53,12 +53,12 @@ void wifi_init_sta(void) esp_event_handler_instance_t instance_got_ip; ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, - &wifi_event_handler, + &ygg_wifi_event_handler, NULL, &instance_any_id)); ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, - &wifi_event_handler, + &ygg_wifi_event_handler, NULL, &instance_got_ip)); diff --git a/common/esp32/ygg_wifi.h b/common/esp32/ygg_wifi.h index d13c73d..cc73bbd 100644 --- a/common/esp32/ygg_wifi.h +++ b/common/esp32/ygg_wifi.h @@ -4,8 +4,8 @@ #include "freertos/event_groups.h" #include "esp_event.h" -void wifi_event_handler(void* arg, esp_event_base_t event_base, +void ygg_wifi_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data); -void wifi_init_sta(void); +void ygg_wifi_init_sta(void); #endif diff --git a/thermo_sensor/main/thermo_sensor.c b/thermo_sensor/main/thermo_sensor.c index d84b5ee..d2d1cb8 100644 --- a/thermo_sensor/main/thermo_sensor.c +++ b/thermo_sensor/main/thermo_sensor.c @@ -19,22 +19,33 @@ bmp280_t dev_bmp_280; void main_loop(void *pvParameters) { while (1) { - vTaskDelay(pdMS_TO_TICKS(10000)); ygg_bmp280_read_sensor(&dev_bmp_280); ygg_send_sensor_readouts(SENSOR_NAME, CURR_READOUT); + vTaskDelay(pdMS_TO_TICKS(10000)); } } void app_main() { + // NVS - Non-Volatile Storage, this memory stays untouched + // after power off. It is key value memory stored + // in separate partition of flash. It takes about 20kB. + // Here it is not used directly. It is required by WiFi + // driver to store SSID and password. + // NVS is organized into pages. Single page is one flash + // sector - typically 4096B esp_err_t ret = nvs_flash_init(); + if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { + // ESP_ERR_NVS_NEW_VERSION_FOUND - NVS header page is + // stored in newer version (newer IDF) than version + // it is used by this application ESP_ERROR_CHECK(nvs_flash_erase()); - ret = nvs_flash_init(); + ESP_ERROR_CHECK(nvs_flash_init()); } - ESP_ERROR_CHECK(ret); - wifi_init_sta(); + + ygg_wifi_init_sta(); httpd_handle_t server = ygg_start_webserver(); httpd_register_uri_handler(server, &ygg_temp_uri);