Fix uninitialized string on empty NVS
This commit is contained in:
parent
9aa25cd1c4
commit
ee5285bf8b
2 changed files with 79 additions and 20 deletions
18
erase.sh
Executable file
18
erase.sh
Executable file
|
@ -0,0 +1,18 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
set -u
|
||||||
|
|
||||||
|
export IDF_PATH="$PWD/esp-idf"
|
||||||
|
export IDF_EXPORT_QUIET=0
|
||||||
|
source "$IDF_PATH"/export.sh
|
||||||
|
|
||||||
|
if [ "$#" -eq 1 ]; then
|
||||||
|
idf.py erase-flash -p $1
|
||||||
|
else
|
||||||
|
if [ "$#" -ne 0 ]; then
|
||||||
|
echo "Illegal number of parameters"
|
||||||
|
else
|
||||||
|
idf.py erase-flash
|
||||||
|
fi
|
||||||
|
fi
|
81
main/main.c
81
main/main.c
|
@ -419,29 +419,70 @@ void app_main(void) {
|
||||||
} else if (menu_action == ACTION_OTA) {
|
} else if (menu_action == ACTION_OTA) {
|
||||||
graphics_task(pax_buffer, ili9341, framebuffer, NULL, "Firmware update...");
|
graphics_task(pax_buffer, ili9341, framebuffer, NULL, "Firmware update...");
|
||||||
} else if (menu_action == ACTION_SETTINGS) {
|
} else if (menu_action == ACTION_SETTINGS) {
|
||||||
menu_wifi_settings(buttonQueue, pax_buffer, ili9341, framebuffer, &menu_action);
|
while (true) {
|
||||||
if (menu_action == ACTION_WIFI_MANUAL) {
|
menu_wifi_settings(buttonQueue, pax_buffer, ili9341, framebuffer, &menu_action);
|
||||||
nvs_handle_t handle;
|
if (menu_action == ACTION_WIFI_MANUAL) {
|
||||||
nvs_open("system", NVS_READWRITE, &handle);
|
nvs_handle_t handle;
|
||||||
char ssid[33];
|
nvs_open("system", NVS_READWRITE, &handle);
|
||||||
char password[33];
|
char ssid[33];
|
||||||
size_t requiredSize;
|
char password[33];
|
||||||
nvs_get_str(handle, "wifi.ssid", NULL, &requiredSize);
|
size_t requiredSize;
|
||||||
if (requiredSize < sizeof(ssid)) {
|
esp_err_t res = nvs_get_str(handle, "wifi.ssid", NULL, &requiredSize);
|
||||||
nvs_get_str(handle, "wifi.ssid", ssid, &requiredSize);
|
if (res != ESP_OK) {
|
||||||
|
strcpy(ssid, "");
|
||||||
|
strcpy(password, "");
|
||||||
|
} else if (requiredSize < sizeof(ssid)) {
|
||||||
|
res = nvs_get_str(handle, "wifi.ssid", ssid, &requiredSize);
|
||||||
|
if (res != ESP_OK) strcpy(ssid, "");
|
||||||
|
res = nvs_get_str(handle, "wifi.password", NULL, &requiredSize);
|
||||||
|
if (res != ESP_OK) {
|
||||||
|
strcpy(password, "");
|
||||||
|
} else if (requiredSize < sizeof(password)) {
|
||||||
|
res = nvs_get_str(handle, "wifi.password", password, &requiredSize);
|
||||||
|
if (res != ESP_OK) strcpy(password, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool accepted = keyboard(buttonQueue, pax_buffer, ili9341, framebuffer, 30, 30, pax_buffer->width - 60, pax_buffer->height - 60, "WiFi SSID", "Press HOME to exit", ssid, sizeof(ssid));
|
||||||
|
if (accepted) {
|
||||||
|
accepted = keyboard(buttonQueue, pax_buffer, ili9341, framebuffer, 30, 30, pax_buffer->width - 60, pax_buffer->height - 60, "WiFi password", "Press HOME to exit", password, sizeof(password));
|
||||||
|
}
|
||||||
|
if (accepted) {
|
||||||
|
nvs_set_str(handle, "wifi.ssid", ssid);
|
||||||
|
nvs_set_str(handle, "wifi.password", password);
|
||||||
|
graphics_task(pax_buffer, ili9341, framebuffer, NULL, "WiFi settings stored");
|
||||||
|
} else {
|
||||||
|
graphics_task(pax_buffer, ili9341, framebuffer, NULL, "Canceled");
|
||||||
|
}
|
||||||
|
nvs_close(&handle);
|
||||||
|
} else if (menu_action == ACTION_WIFI_LIST) {
|
||||||
|
nvs_handle_t handle;
|
||||||
|
nvs_open("system", NVS_READWRITE, &handle);
|
||||||
|
char ssid[33];
|
||||||
|
char password[33];
|
||||||
|
size_t requiredSize;
|
||||||
|
esp_err_t res = nvs_get_str(handle, "wifi.ssid", NULL, &requiredSize);
|
||||||
|
if (res != ESP_OK) {
|
||||||
|
strcpy(ssid, "");
|
||||||
|
} else if (requiredSize < sizeof(ssid)) {
|
||||||
|
res = nvs_get_str(handle, "wifi.ssid", ssid, &requiredSize);
|
||||||
|
if (res != ESP_OK) strcpy(ssid, "");
|
||||||
|
res = nvs_get_str(handle, "wifi.password", NULL, &requiredSize);
|
||||||
|
if (res != ESP_OK) {
|
||||||
|
strcpy(password, "");
|
||||||
|
} else if (requiredSize < sizeof(password)) {
|
||||||
|
res = nvs_get_str(handle, "wifi.password", password, &requiredSize);
|
||||||
|
if (res != ESP_OK) strcpy(password, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nvs_close(&handle);
|
||||||
|
char buffer[300];
|
||||||
|
snprintf(buffer, sizeof(buffer), "SSID is %s\nPassword is %s", ssid, password);
|
||||||
|
graphics_task(pax_buffer, ili9341, framebuffer, NULL, buffer);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
nvs_get_str(handle, "wifi.password", NULL, &requiredSize);
|
|
||||||
if (requiredSize < sizeof(password)) {
|
|
||||||
nvs_get_str(handle, "wifi.password", password, &requiredSize);
|
|
||||||
}
|
|
||||||
keyboard(buttonQueue, pax_buffer, ili9341, framebuffer, 30, 30, pax_buffer->width - 60, pax_buffer->height - 60, "WiFi SSID", "Press HOME to exit", ssid, sizeof(ssid));
|
|
||||||
keyboard(buttonQueue, pax_buffer, ili9341, framebuffer, 30, 30, pax_buffer->width - 60, pax_buffer->height - 60, "WiFi password", "Press HOME to exit", password, sizeof(password));
|
|
||||||
nvs_set_str(handle, "wifi.ssid", ssid);
|
|
||||||
nvs_set_str(handle, "wifi.password", password);
|
|
||||||
nvs_close(&handle);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
graphics_task(pax_buffer, ili9341, framebuffer, NULL, "Please wait...");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue