83 lines
1.9 KiB
C
83 lines
1.9 KiB
C
/****************************************************************************
|
|
* Copyright (C) 2021 by Fabrice Muller *
|
|
* *
|
|
* This file is useful for ESP32 Design course. *
|
|
* *
|
|
****************************************************************************/
|
|
|
|
/**
|
|
* @file main.c
|
|
* @author Fabrice Muller
|
|
* @date 12 Nov. 2021
|
|
* @brief File containing the lab1-1 of Part 7.
|
|
*
|
|
* @see https://github.com/fmuller-pns/esp32-vscode-project-template
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "freertos/event_groups.h"
|
|
#include "esp_wifi.h"
|
|
#include "esp_log.h"
|
|
#include "nvs_flash.h"
|
|
#include "esp_netif.h"
|
|
|
|
#include "wifi_connect.h"
|
|
|
|
static const char *TAG = "WIFI_LAB";
|
|
void ConnectedWifiTask (void *para);
|
|
|
|
/**
|
|
* @brief Starting point function
|
|
*
|
|
*/
|
|
|
|
void app_main() {
|
|
/* ERROR, WARNING, INFO level log */
|
|
esp_log_level_set(TAG, ESP_LOG_INFO);
|
|
|
|
/* Init WiFi */
|
|
wifiInit();
|
|
/* Create connected WiFi Task, STACK=3*1024, Priority=5 */
|
|
|
|
xTaskCreate(&ConnectedWifiTask, "WifiTask",3*1024, NULL, 5, NULL);
|
|
|
|
|
|
/* Delete task */
|
|
vTaskDelete(NULL);
|
|
}
|
|
|
|
|
|
void ConnectedWifiTask (void *para){
|
|
xSemaphoreHandle connectionWifiSem = getConnectionWifiSemaphore();
|
|
for(;;){
|
|
|
|
if (xSemaphoreTake(connectionWifiSem, pdMS_TO_TICKS(10000))){
|
|
ESP_LOGI(TAG,"Connected on %s", WIFI_SSID);
|
|
printf("Run Application\n");
|
|
|
|
xSemaphoreTake(connectionWifiSem,portMAX_DELAY);
|
|
ESP_LOGI(TAG,"Retried connexion on %s", WIFI_SSID);
|
|
}
|
|
else{
|
|
ESP_LOGE(TAG,"Failed to reconnect.Retry in");
|
|
for (int i=0; i<5;i++){
|
|
ESP_LOGE(TAG,"... %d",i);
|
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
|
|
|
}
|
|
|
|
}
|
|
esp_restart();
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|