latest code

Signed-off-by: Peter Siegmund <peter@rdkr.com>
This commit is contained in:
Peter Siegmund
2024-09-06 16:29:56 +02:00
parent d1f4beed3b
commit 7774417a35
19 changed files with 8002 additions and 12422 deletions

View File

@@ -1 +1,3 @@
BasedOnStyle: Chromium
ColumnLimit: 120
IndentWidth: 4

View File

@@ -1,6 +1,8 @@
idf_component_register(SRCS "connectivity.c" "ntp.c"
idf_component_register(SRCS "networking.c" "connectivity.c" "sntp_utils.c"
INCLUDE_DIRS "include"
PRIV_REQUIRES
esp_event
esp_http_client
esp_wifi
json
nvs_flash)

View File

@@ -0,0 +1 @@
#pragma once

View File

@@ -5,7 +5,7 @@
#ifdef __cplusplus
extern "C" {
#endif
esp_err_t init_ntp(void);
esp_err_t init_sntp(void);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,81 @@
#include "networking.h"
#include <string.h>
#include "cJSON.h"
#include "esp_err.h"
#include "esp_http_client.h"
#include "esp_log.h"
static const char* TAG = "JSON";
esp_err_t download_and_parse_json(const char* url) {
// 1. Create HTTP Client
esp_http_client_config_t config = {
.url = url,
.event_handler = NULL, // You can add an event handler for more control
};
esp_http_client_handle_t client = esp_http_client_init(&config);
if (client == NULL) {
ESP_LOGE(TAG, "Failed to create HTTP client");
return ESP_FAIL;
}
// 2. Perform GET request
esp_err_t err = esp_http_client_perform(client);
if (err != ESP_OK) {
ESP_LOGE(TAG, "HTTP GET request failed: %s", esp_err_to_name(err));
esp_http_client_cleanup(client);
return err;
}
// 3. Check response status code
int status_code = esp_http_client_get_status_code(client);
if (status_code != 200) {
ESP_LOGE(TAG, "HTTP GET request failed with status code: %d", status_code);
esp_http_client_cleanup(client);
return ESP_FAIL;
}
// 4. Read response content
int content_length = esp_http_client_get_content_length(client);
char* response_buffer = malloc(content_length + 1);
if (response_buffer == NULL) {
ESP_LOGE(TAG, "Failed to allocate memory for response buffer");
esp_http_client_cleanup(client);
return ESP_FAIL;
}
int data_read = esp_http_client_read_response(client, response_buffer, content_length);
if (data_read != content_length) {
ESP_LOGE(TAG, "Failed to read complete response");
free(response_buffer);
esp_http_client_cleanup(client);
return ESP_FAIL;
}
response_buffer[data_read] = '\0'; // Null-terminate the string
// 5. Parse JSON
cJSON* root = cJSON_Parse(response_buffer);
if (root == NULL) {
const char* error_ptr = cJSON_GetErrorPtr();
if (error_ptr != NULL) {
ESP_LOGE(TAG, "Error before: %s", error_ptr);
}
free(response_buffer);
esp_http_client_cleanup(client);
return ESP_FAIL;
}
// 6. Access JSON data
// Example: Print the value of a key called "message"
cJSON* message_item = cJSON_GetObjectItem(root, "message");
if (cJSON_IsString(message_item) && (message_item->valuestring != NULL)) {
ESP_LOGI(TAG, "Message: %s", message_item->valuestring);
}
// 7. Clean up
cJSON_Delete(root);
free(response_buffer);
esp_http_client_cleanup(client);
return ESP_OK;
}

View File

@@ -1,76 +0,0 @@
#include "ntp.h"
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include "esp_attr.h"
#include "esp_event.h"
#include "esp_log.h"
#include "esp_netif_sntp.h"
#include "esp_sleep.h"
#include "esp_sntp.h"
#include "esp_system.h"
#include "lwip/ip_addr.h"
#include "nvs_flash.h"
#include "sdkconfig.h"
static const char* TAG = "NTP";
void obtain_time(void) {
ESP_LOGI(TAG, "Initializing SNTP");
esp_sntp_config_t config =
ESP_NETIF_SNTP_DEFAULT_CONFIG(CONFIG_SNTP_TIME_SERVER);
config.start = false;
config.server_from_dhcp = true;
config.renew_servers_after_new_IP = true;
config.index_of_first_server = 1;
config.ip_event_to_renew = IP_EVENT_STA_GOT_IP;
esp_netif_sntp_init(&config);
ESP_LOGI(TAG, "Starting SNTP");
esp_netif_sntp_start();
// wait for time to be set
time_t now = 0;
struct tm timeinfo = {0};
int retry = 0;
const int retry_count = 15;
while (esp_netif_sntp_sync_wait(2000 / portTICK_PERIOD_MS) ==
ESP_ERR_TIMEOUT &&
++retry < retry_count) {
ESP_LOGI(TAG, "Waiting for system time to be set... (%d/%d)", retry,
retry_count);
}
time(&now);
localtime_r(&now, &timeinfo);
esp_netif_sntp_deinit();
}
esp_err_t init_ntp(void) {
time_t now;
struct tm timeinfo;
time(&now);
localtime_r(&now, &timeinfo);
if (timeinfo.tm_year < (2016 - 1900)) {
ESP_LOGI(
TAG,
"Time is not set yet. Connecting to WiFi and getting time over NTP.");
obtain_time();
}
char strftime_buf[64];
// Set timezone to Eastern Standard Time and print local time
setenv("TZ", "CET-1CEST,M3.5.0,M10.5.0/3", 1);
tzset();
time(&now);
localtime_r(&now, &timeinfo);
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
ESP_LOGI(TAG, "The current date/time in Berlin/Europe is: %s", strftime_buf);
return ESP_OK;
}

View File

@@ -0,0 +1,63 @@
#include "sntp_utils.h"
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include "esp_attr.h"
#include "esp_log.h"
#include "esp_netif_sntp.h"
#include "esp_sleep.h"
#include "esp_sntp.h"
#include "esp_system.h"
#include "lwip/ip_addr.h"
#include "nvs_flash.h"
#include "sdkconfig.h"
static const char* TAG = "NTP";
void obtain_time(void) {
ESP_LOGI(TAG, "Initializing SNTP");
esp_sntp_config_t config = ESP_NETIF_SNTP_DEFAULT_CONFIG(CONFIG_SNTP_TIME_SERVER);
config.start = false;
config.server_from_dhcp = true;
config.renew_servers_after_new_IP = true;
config.index_of_first_server = 1;
config.ip_event_to_renew = IP_EVENT_STA_GOT_IP;
esp_netif_sntp_init(&config);
ESP_LOGI(TAG, "Starting SNTP");
esp_netif_sntp_start();
// wait for time to be set
int retry = 0;
const int retry_count = 15;
while (esp_netif_sntp_sync_wait(pdMS_TO_TICKS(2000)) == ESP_ERR_TIMEOUT && ++retry < retry_count) {
ESP_LOGI(TAG, "Waiting for system time to be set... (%d/%d)", retry, retry_count);
}
esp_netif_sntp_deinit();
}
esp_err_t init_sntp(void) {
time_t now;
struct tm timeinfo;
time(&now);
localtime_r(&now, &timeinfo);
if (timeinfo.tm_year < (2016 - 1900)) {
ESP_LOGI(TAG, "Time is not set yet. Connecting to WiFi and getting time over NTP.");
obtain_time();
}
char strftime_buf[64];
setenv("TZ", "CET-1CEST,M3.5.0,M10.5.0/3", 1);
tzset();
time(&now);
localtime_r(&now, &timeinfo);
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
ESP_LOGI(TAG, "The current date/time in Berlin/Europe is: %s", strftime_buf);
return ESP_OK;
}

View File

@@ -1,2 +1,2 @@
idf_component_register(SRCS "fota.c"
INCLUDE_DIRS ".")
INCLUDE_DIRS "include")

View File

@@ -1,7 +1,6 @@
#include <stdio.h>
#include "fota.h"
#include <stdio.h>
void func(void)
{
void func(void) {
///
}

View File

@@ -1 +1,3 @@
#pragma once
void func(void);

File diff suppressed because it is too large Load Diff

View File

@@ -18,76 +18,72 @@ GFXfont currentFont;
enum alignment { LEFT, RIGHT, CENTER };
void drawString(int32_t x, int32_t y, std::string text, alignment align) {
char* data = const_cast<char*>(text.c_str());
int32_t x1, y1; // the bounds of x,y and w and h of the variable 'text' in
// pixels.
int32_t w, h;
int32_t xx = x, yy = y;
get_text_bounds(&currentFont, data, &xx, &yy, &x1, &y1, &w, &h, NULL);
if (align == RIGHT)
x = x - w;
if (align == CENTER)
x = x - w / 2;
int32_t cursor_y = y + h;
int32_t padding = 4;
epd_fill_rect(x - padding, y - padding, w + 2 * padding, h + 2 * padding, 255,
framebuffer);
write_string(&currentFont, data, &x, &cursor_y, framebuffer);
char* data = const_cast<char*>(text.c_str());
int32_t x1, y1; // the bounds of x,y and w and h of the variable 'text' in
// pixels.
int32_t w, h;
int32_t xx = x, yy = y;
get_text_bounds(&currentFont, data, &xx, &yy, &x1, &y1, &w, &h, NULL);
if (align == RIGHT)
x = x - w;
if (align == CENTER)
x = x - w / 2;
int32_t cursor_y = y + h;
int32_t padding = 4;
epd_fill_rect(x - padding, y - padding, w + 2 * padding, h + 2 * padding, 255, framebuffer);
write_string(&currentFont, data, &x, &cursor_y, framebuffer);
}
void drawVessel(int32_t x, int32_t y, std::string vesselName) {
currentFont = OpenSans;
int32_t radius = 10;
epd_fill_circle(x, y, radius, 255, framebuffer);
epd_draw_circle(x, y, radius, 0, framebuffer);
drawString(x, y + 2 * radius, vesselName, CENTER);
currentFont = OpenSans;
int32_t radius = 10;
epd_fill_circle(x, y, radius, 255, framebuffer);
epd_draw_circle(x, y, radius, 0, framebuffer);
drawString(x, y + 2 * radius, vesselName, CENTER);
}
void mapView(void* args) {
framebuffer =
(uint8_t*)heap_caps_malloc(EPD_WIDTH * EPD_HEIGHT / 2, MALLOC_CAP_SPIRAM);
framebuffer = (uint8_t*)heap_caps_malloc(EPD_WIDTH * EPD_HEIGHT / 2, MALLOC_CAP_SPIRAM);
if (!framebuffer) {
printf("alloc memory failed !!!");
while (1) {
if (!framebuffer) {
printf("alloc memory failed !!!");
while (1) {
}
}
}
std::memset(framebuffer, 0xFF, EPD_WIDTH * EPD_HEIGHT / 2);
std::memset(framebuffer, 0xFF, EPD_WIDTH * EPD_HEIGHT / 2);
while (1) {
int32_t width = staticmap_width;
int32_t height = staticmap_height;
const uint8_t* data = staticmap_data;
while (1) {
int32_t width = staticmap_width;
int32_t height = staticmap_height;
const uint8_t* data = staticmap_data;
Rect_t area = {
.x = EPD_WIDTH - width, .y = 0, .width = width, .height = height};
epd_copy_to_framebuffer(area, (uint8_t*)data, framebuffer);
epd_draw_rect(area.x, area.y, area.width, area.height, 0, framebuffer);
Rect_t area = {.x = EPD_WIDTH - width, .y = 0, .width = width, .height = height};
epd_copy_to_framebuffer(area, (uint8_t*)data, framebuffer);
epd_draw_rect(area.x, area.y, area.width, area.height, 0, framebuffer);
int32_t x = area.x / 2;
int32_t y = 26;
currentFont = OpenSans26B;
drawString(x, y, "Tide Display", CENTER);
int32_t x = area.x / 2;
int32_t y = 26;
currentFont = OpenSans26B;
drawString(x, y, "Tide Display", CENTER);
time_t now;
struct tm timeinfo;
char strftime_buf[64];
time_t now;
struct tm timeinfo;
char strftime_buf[64];
currentFont = OpenSans12B;
time(&now);
localtime_r(&now, &timeinfo);
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
drawString(6, area.height - 33, strftime_buf, LEFT);
currentFont = OpenSans12B;
time(&now);
localtime_r(&now, &timeinfo);
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
drawString(area.x / 2, area.height - 33, strftime_buf, CENTER);
drawVessel(EPD_WIDTH - EPD_WIDTH / 4, EPD_HEIGHT - EPD_HEIGHT / 5,
"DEEPENSCHRIEWER 1");
drawVessel(EPD_WIDTH - EPD_WIDTH / 4, EPD_HEIGHT - EPD_HEIGHT / 5, "DEEPENSCHRIEWER 1");
epd_poweron();
epd_clear();
epd_draw_grayscale_image(epd_full_screen(), framebuffer);
epd_poweroff_all();
epd_poweron();
epd_clear();
epd_draw_grayscale_image(epd_full_screen(), framebuffer);
epd_poweroff_all();
vTaskDelay(pdMS_TO_TICKS(60000));
}
vTaskDelay(pdMS_TO_TICKS(60000));
}
}

View File

@@ -1,5 +1,5 @@
idf_component_register(SRCS "smartconfig.cpp"
INCLUDE_DIRS "."
INCLUDE_DIRS "include"
PRIV_REQUIRES
nvs_flash
esp_wifi

View File

@@ -29,97 +29,86 @@ static const char* TAG = "smartconfig";
static void smartconfig_task(void* parm);
static void event_handler(void* arg,
esp_event_base_t event_base,
int32_t event_id,
void* event_data) {
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
xTaskCreate(smartconfig_task, "smartconfig_task", 4096, NULL, 3, NULL);
} else if (event_base == WIFI_EVENT &&
event_id == WIFI_EVENT_STA_DISCONNECTED) {
esp_wifi_connect();
xEventGroupClearBits(s_wifi_event_group, CONNECTED_BIT);
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
xEventGroupSetBits(s_wifi_event_group, CONNECTED_BIT);
} else if (event_base == SC_EVENT && event_id == SC_EVENT_SCAN_DONE) {
ESP_LOGI(TAG, "Scan done");
} else if (event_base == SC_EVENT && event_id == SC_EVENT_FOUND_CHANNEL) {
ESP_LOGI(TAG, "Found channel");
} else if (event_base == SC_EVENT && event_id == SC_EVENT_GOT_SSID_PSWD) {
ESP_LOGI(TAG, "Got SSID and password");
static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) {
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
xTaskCreate(smartconfig_task, "smartconfig_task", 4096, NULL, 3, NULL);
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
esp_wifi_connect();
xEventGroupClearBits(s_wifi_event_group, CONNECTED_BIT);
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
xEventGroupSetBits(s_wifi_event_group, CONNECTED_BIT);
} else if (event_base == SC_EVENT && event_id == SC_EVENT_SCAN_DONE) {
ESP_LOGI(TAG, "Scan done");
} else if (event_base == SC_EVENT && event_id == SC_EVENT_FOUND_CHANNEL) {
ESP_LOGI(TAG, "Found channel");
} else if (event_base == SC_EVENT && event_id == SC_EVENT_GOT_SSID_PSWD) {
ESP_LOGI(TAG, "Got SSID and password");
smartconfig_event_got_ssid_pswd_t* evt =
(smartconfig_event_got_ssid_pswd_t*)event_data;
wifi_config_t wifi_config;
uint8_t rvd_data[33] = {0};
smartconfig_event_got_ssid_pswd_t* evt = (smartconfig_event_got_ssid_pswd_t*)event_data;
wifi_config_t wifi_config;
uint8_t rvd_data[33] = {0};
bzero(&wifi_config, sizeof(wifi_config_t));
memcpy(wifi_config.sta.ssid, evt->ssid, sizeof(wifi_config.sta.ssid));
memcpy(wifi_config.sta.password, evt->password,
sizeof(wifi_config.sta.password));
bzero(&wifi_config, sizeof(wifi_config_t));
memcpy(wifi_config.sta.ssid, evt->ssid, sizeof(wifi_config.sta.ssid));
memcpy(wifi_config.sta.password, evt->password, sizeof(wifi_config.sta.password));
if (evt->type == SC_TYPE_ESPTOUCH_V2) {
ESP_ERROR_CHECK(esp_smartconfig_get_rvd_data(rvd_data, sizeof(rvd_data)));
ESP_LOGI(TAG, "RVD_DATA:");
for (int i = 0; i < 33; i++) {
printf("%02x ", rvd_data[i]);
}
printf("\n");
if (evt->type == SC_TYPE_ESPTOUCH_V2) {
ESP_ERROR_CHECK(esp_smartconfig_get_rvd_data(rvd_data, sizeof(rvd_data)));
ESP_LOGI(TAG, "RVD_DATA:");
for (int i = 0; i < 33; i++) {
printf("%02x ", rvd_data[i]);
}
printf("\n");
}
ESP_ERROR_CHECK(esp_wifi_disconnect());
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
esp_wifi_connect();
} else if (event_base == SC_EVENT && event_id == SC_EVENT_SEND_ACK_DONE) {
xEventGroupSetBits(s_wifi_event_group, ESPTOUCH_DONE_BIT);
}
ESP_ERROR_CHECK(esp_wifi_disconnect());
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
esp_wifi_connect();
} else if (event_base == SC_EVENT && event_id == SC_EVENT_SEND_ACK_DONE) {
xEventGroupSetBits(s_wifi_event_group, ESPTOUCH_DONE_BIT);
}
}
static void initialise_wifi(void) {
ESP_ERROR_CHECK(esp_netif_init());
s_wifi_event_group = xEventGroupCreate();
ESP_ERROR_CHECK(esp_event_loop_create_default());
esp_netif_t* sta_netif = esp_netif_create_default_wifi_sta();
assert(sta_netif);
ESP_ERROR_CHECK(esp_netif_init());
s_wifi_event_group = xEventGroupCreate();
ESP_ERROR_CHECK(esp_event_loop_create_default());
esp_netif_t* sta_netif = esp_netif_create_default_wifi_sta();
assert(sta_netif);
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID,
&event_handler, NULL));
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP,
&event_handler, NULL));
ESP_ERROR_CHECK(esp_event_handler_register(SC_EVENT, ESP_EVENT_ANY_ID,
&event_handler, NULL));
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL));
ESP_ERROR_CHECK(esp_event_handler_register(SC_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_ERROR_CHECK(esp_wifi_start());
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_ERROR_CHECK(esp_wifi_start());
}
static void smartconfig_task(void* parm) {
EventBits_t uxBits;
ESP_ERROR_CHECK(esp_smartconfig_set_type(SC_TYPE_ESPTOUCH));
smartconfig_start_config_t cfg = SMARTCONFIG_START_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_smartconfig_start(&cfg));
while (1) {
uxBits = xEventGroupWaitBits(s_wifi_event_group,
CONNECTED_BIT | ESPTOUCH_DONE_BIT, true, false,
portMAX_DELAY);
if (uxBits & CONNECTED_BIT) {
ESP_LOGI(TAG, "WiFi Connected to ap");
}
if (uxBits & ESPTOUCH_DONE_BIT) {
ESP_LOGI(TAG, "smartconfig over");
esp_smartconfig_stop();
EventBits_t uxBits;
ESP_ERROR_CHECK(esp_smartconfig_set_type(SC_TYPE_ESPTOUCH));
smartconfig_start_config_t cfg = SMARTCONFIG_START_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_smartconfig_start(&cfg));
while (1) {
uxBits = xEventGroupWaitBits(s_wifi_event_group, CONNECTED_BIT | ESPTOUCH_DONE_BIT, true, false, portMAX_DELAY);
if (uxBits & CONNECTED_BIT) {
ESP_LOGI(TAG, "WiFi Connected to ap");
}
if (uxBits & ESPTOUCH_DONE_BIT) {
ESP_LOGI(TAG, "smartconfig over");
esp_smartconfig_stop();
xTaskCreatePinnedToCore(mapView, "mapView", 4096, NULL, 3, NULL, 1);
xTaskCreatePinnedToCore(mapView, "mapView", 4096, NULL, 3, NULL, 1);
vTaskDelete(NULL);
vTaskDelete(NULL);
}
}
}
}
void init_smartconfig() {
ESP_ERROR_CHECK(nvs_flash_init());
initialise_wifi();
ESP_ERROR_CHECK(nvs_flash_init());
initialise_wifi();
}

View File

@@ -6,4 +6,4 @@ extern "C" {
void splash_screen(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -4,78 +4,75 @@
#include "connectivity.h"
#include "epd_driver.h"
#include "fonts/opensans16.h"
#include "ntp.h"
#include "nvs_flash.h"
#include "sdkconfig.h"
#include "sntp_utils.h"
void nvs_init(void) {
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_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);
}
void wifi_init(void) {
epd_clear();
int32_t x = 100;
int32_t y = 100;
const int16_t bufferSize = 200;
char buffer[bufferSize];
snprintf(buffer, bufferSize, "Connecting to SSDI: %s", CONFIG_WIFI_SSID);
writeln(&OpenSans16, buffer, &x, &y, NULL);
esp_err_t ret = init_wifi();
if (ret != ESP_OK) {
epd_clear();
x = 100;
y = 100;
snprintf(buffer, bufferSize, "Failed to connect to WiFi: %s",
esp_err_to_name(ret));
int32_t x = 100;
int32_t y = 100;
const int16_t bufferSize = 200;
char buffer[bufferSize];
snprintf(buffer, bufferSize, "Connecting to SSDI: %s", CONFIG_WIFI_SSID);
writeln(&OpenSans16, buffer, &x, &y, NULL);
epd_poweroff();
while (1) {
vTaskDelay(pdMS_TO_TICKS(100));
};
}
esp_err_t ret = init_wifi();
if (ret != ESP_OK) {
epd_clear();
x = 100;
y = 100;
snprintf(buffer, bufferSize, "Failed to connect to WiFi: %s", esp_err_to_name(ret));
writeln(&OpenSans16, buffer, &x, &y, NULL);
epd_poweroff();
while (1) {
vTaskDelay(pdMS_TO_TICKS(100));
};
}
}
void time_init(void) {
epd_clear();
int32_t x = 100;
int32_t y = 100;
const int16_t bufferSize = 200;
char buffer[bufferSize];
snprintf(buffer, bufferSize, "Loading NTP Data...");
writeln(&OpenSans16, buffer, &x, &y, NULL);
esp_err_t ret = init_ntp();
if (ret != ESP_OK) {
epd_clear();
x = 100;
y = 100;
snprintf(buffer, bufferSize, "Failed to get NTP data and timezone: %s",
esp_err_to_name(ret));
int32_t x = 100;
int32_t y = 100;
const int16_t bufferSize = 200;
char buffer[bufferSize];
snprintf(buffer, bufferSize, "Loading SNTP Data...");
writeln(&OpenSans16, buffer, &x, &y, NULL);
epd_poweroff();
while (1) {
vTaskDelay(pdMS_TO_TICKS(100));
};
}
esp_err_t ret = init_sntp();
if (ret != ESP_OK) {
epd_clear();
x = 100;
y = 100;
snprintf(buffer, bufferSize, "Failed to get NTP data and timezone: %s", esp_err_to_name(ret));
writeln(&OpenSans16, buffer, &x, &y, NULL);
epd_poweroff();
while (1) {
vTaskDelay(pdMS_TO_TICKS(100));
};
}
}
void splash_screen(void) {
epd_init();
nvs_init();
epd_init();
nvs_init();
epd_poweron();
epd_poweron();
wifi_init();
time_init();
wifi_init();
time_init();
epd_poweroff();
epd_poweroff();
}

View File

@@ -12,7 +12,7 @@ dependencies:
idf:
source:
type: idf
version: 5.2.2
version: 5.3.0
direct_dependencies:
- espressif/zlib
- idf

View File

@@ -6,8 +6,8 @@
#include "splash_screen.h"
extern "C" void app_main(void) {
splash_screen();
splash_screen();
xTaskCreatePinnedToCore(mapView, "mapView", 4096, NULL, 5, NULL, 1);
vTaskDelete(NULL);
xTaskCreatePinnedToCore(mapView, "mapView", 4096, NULL, 5, NULL, 1);
vTaskDelete(NULL);
}