refactor + documentation

This commit is contained in:
2026-09-17 19:49:23 +02:00
parent a1dae20cbf
commit a89fc4b4b8
3 changed files with 21 additions and 10 deletions
+4 -4
View File
@@ -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));
+2 -2
View File
@@ -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
+15 -4
View File
@@ -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);