network changes
This commit is contained in:
+52
-51
@@ -1,5 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_pm.h"
|
||||
#include "esp_system.h"
|
||||
@@ -9,70 +10,70 @@
|
||||
#include "nvs_flash.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "soc/gpio_num.h"
|
||||
#include "esp_event.h"
|
||||
|
||||
#include "types.hpp"
|
||||
#include "led.hpp"
|
||||
#include "network.hpp"
|
||||
#include "types.hpp"
|
||||
|
||||
static const char *TAG = "ClientMain";
|
||||
|
||||
extern "C" void app_main()
|
||||
{
|
||||
ESP_LOGI(TAG, "Hello, Calendink Client!");
|
||||
ESP_LOGI(TAG, "Hello, Calendink Client!");
|
||||
|
||||
// Initialize NVS (required for some Wi-Fi configurations and network features)
|
||||
esp_err_t ret = nvs_flash_init();
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
ret = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(ret);
|
||||
// Initialize NVS (required for some Wi-Fi configurations and network
|
||||
// features)
|
||||
esp_err_t ret = nvs_flash_init();
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND)
|
||||
{
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
ret = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(ret);
|
||||
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
|
||||
setup_led();
|
||||
ESP_LOGI(TAG, "LED setup complete");
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
setup_led();
|
||||
|
||||
ESP_LOGI(TAG, "LED blink 4");
|
||||
led_blink_number(4, 255,255,255);
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
// Connect to WiFi ESP_LOGI(TAG, "Initializing WiFi connection");
|
||||
initialize_network();
|
||||
|
||||
ESP_LOGI(TAG, "LED blink 2");
|
||||
led_blink_number(2, 255,255,255);
|
||||
esp_err_t err = connect_wifi(CONFIG_CALENDINK_WIFI_SSID,
|
||||
CONFIG_CALENDINK_WIFI_PASSWORD, false);
|
||||
|
||||
turn_off_led();
|
||||
ESP_LOGI(TAG, "LED blink complete");
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
|
||||
// Connect to WiFi
|
||||
// ESP_LOGI(TAG, "Initializing WiFi connection");
|
||||
|
||||
// // Attempting to connect, we don't necessarily need to block forever here
|
||||
// // as network.cpp already handles some of the retries
|
||||
// esp_err_t err = connect_wifi(CONFIG_CALENDINK_WIFI_SSID, CONFIG_CALENDINK_WIFI_PASSWORD, false);
|
||||
|
||||
// if (err == ESP_OK) {
|
||||
// uint8_t retries = 1;
|
||||
// do {
|
||||
// err = check_wifi_connection(retries);
|
||||
// if (err != ESP_OK) {
|
||||
// ESP_LOGW(TAG, "WiFi connection check timeout, retrying... (%d)", retries);
|
||||
// vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
// }
|
||||
// retries++;
|
||||
// } while (err == ESP_ERR_TIMEOUT && retries <= CONFIG_CALENDINK_WIFI_RETRIES);
|
||||
// }
|
||||
|
||||
// if (err == ESP_OK) {
|
||||
// ESP_LOGI(TAG, "Successfully connected to WiFi!");
|
||||
// } else {
|
||||
// ESP_LOGE(TAG, "Failed to connect to WiFi.");
|
||||
// }
|
||||
|
||||
while (true)
|
||||
if (err == ESP_OK)
|
||||
{
|
||||
uint8_t retries = 1;
|
||||
do
|
||||
{
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
err = check_wifi_connection(retries);
|
||||
if (err != ESP_OK)
|
||||
{
|
||||
ESP_LOGW(TAG, "WiFi connection check timeout, retrying... (%d)",
|
||||
retries);
|
||||
|
||||
led_blink_number(3, 255, 0, 0);
|
||||
}
|
||||
retries++;
|
||||
} while (err == ESP_ERR_TIMEOUT &&
|
||||
retries <= CONFIG_CALENDINK_WIFI_RETRIES);
|
||||
}
|
||||
|
||||
if (err == ESP_OK)
|
||||
{
|
||||
ESP_LOGI(TAG, "Successfully connected to WiFi!");
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to connect to WiFi.");
|
||||
}
|
||||
|
||||
turn_off_led();
|
||||
|
||||
while (true)
|
||||
{
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
|
||||
shutdown_network();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user