Fixed wifi issues
This commit is contained in:
+42
-4
@@ -1,18 +1,39 @@
|
||||
#include <cstdlib>
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_sntp.h"
|
||||
#include "esp_wifi.h"
|
||||
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "driver/gpio.h"
|
||||
#include "inc/gpio.h"
|
||||
#include "inc/wifi.h"
|
||||
|
||||
static TaskHandle_t devTaskHandle = NULL;
|
||||
static void devTask(void* parameters);
|
||||
static GPIO gpio0(0, GPIO_DIRECTION_OUTPUT);
|
||||
static GPIO gpio1(1, GPIO_DIRECTION_OUTPUT);
|
||||
static GPIO gpio0(4, GPIO_DIRECTION_OUTPUT);
|
||||
static GPIO gpio1(18, GPIO_DIRECTION_OUTPUT);
|
||||
static time_t currentTime;
|
||||
//
|
||||
//static void wifi_init(void);
|
||||
static void event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
|
||||
void wifi_init_sta(void);
|
||||
|
||||
extern "C" void app_main(void)
|
||||
{
|
||||
esp_log_level_set("*", ESP_LOG_WARN);
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
// Create the development task
|
||||
if(xTaskCreate(devTask, "DevTask", 2048, NULL, 3, &devTaskHandle) != pdPASS)
|
||||
@@ -20,8 +41,25 @@ extern "C" void app_main(void)
|
||||
printf("Task not created");
|
||||
}
|
||||
|
||||
Wifi wifi;
|
||||
wifi.start_client();
|
||||
|
||||
// Start NTP
|
||||
setenv("TZ", "CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00", 1);
|
||||
tzset();
|
||||
sntp_setoperatingmode(SNTP_OPMODE_POLL);
|
||||
sntp_setservername(0, "pool.ntp.org");
|
||||
sntp_init();
|
||||
|
||||
while (true)
|
||||
{
|
||||
|
||||
struct tm tm;
|
||||
time(¤tTime);
|
||||
localtime_r(¤tTime, &tm);
|
||||
|
||||
printf("%lld\n\r", currentTime);
|
||||
printf("%i:%i:%i\n\r", tm.tm_hour, tm.tm_min, tm.tm_sec);
|
||||
vTaskDelay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user