refactor + documentation
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
static const char *TAG = "YGG_WIFI";
|
static const char *TAG = "YGG_WIFI";
|
||||||
static EventGroupHandle_t s_wifi_event_group;
|
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)
|
int32_t event_id, void* event_data)
|
||||||
{
|
{
|
||||||
static int s_retry_num = 0;
|
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();
|
s_wifi_event_group = xEventGroupCreate();
|
||||||
|
|
||||||
@@ -53,12 +53,12 @@ void wifi_init_sta(void)
|
|||||||
esp_event_handler_instance_t instance_got_ip;
|
esp_event_handler_instance_t instance_got_ip;
|
||||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
|
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
|
||||||
ESP_EVENT_ANY_ID,
|
ESP_EVENT_ANY_ID,
|
||||||
&wifi_event_handler,
|
&ygg_wifi_event_handler,
|
||||||
NULL,
|
NULL,
|
||||||
&instance_any_id));
|
&instance_any_id));
|
||||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
|
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
|
||||||
IP_EVENT_STA_GOT_IP,
|
IP_EVENT_STA_GOT_IP,
|
||||||
&wifi_event_handler,
|
&ygg_wifi_event_handler,
|
||||||
NULL,
|
NULL,
|
||||||
&instance_got_ip));
|
&instance_got_ip));
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
#include "freertos/event_groups.h"
|
#include "freertos/event_groups.h"
|
||||||
#include "esp_event.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);
|
int32_t event_id, void* event_data);
|
||||||
void wifi_init_sta(void);
|
void ygg_wifi_init_sta(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -19,22 +19,33 @@ bmp280_t dev_bmp_280;
|
|||||||
|
|
||||||
void main_loop(void *pvParameters) {
|
void main_loop(void *pvParameters) {
|
||||||
while (1) {
|
while (1) {
|
||||||
vTaskDelay(pdMS_TO_TICKS(10000));
|
|
||||||
ygg_bmp280_read_sensor(&dev_bmp_280);
|
ygg_bmp280_read_sensor(&dev_bmp_280);
|
||||||
ygg_send_sensor_readouts(SENSOR_NAME,
|
ygg_send_sensor_readouts(SENSOR_NAME,
|
||||||
CURR_READOUT);
|
CURR_READOUT);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(10000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_main()
|
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();
|
esp_err_t ret = nvs_flash_init();
|
||||||
|
|
||||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
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());
|
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_handle_t server = ygg_start_webserver();
|
||||||
httpd_register_uri_handler(server, &ygg_temp_uri);
|
httpd_register_uri_handler(server, &ygg_temp_uri);
|
||||||
|
|||||||
Reference in New Issue
Block a user