From 71531bcdc20d7c7da254699855eb2e1e7b2bd48f Mon Sep 17 00:00:00 2001 From: Sebastien Leclerc Date: Tue, 24 Sep 2019 11:59:32 -0400 Subject: [PATCH] More OTA fix, restore UI from previous commit --- .cproject | 58 ++++++ .settings/language.settings.xml | 12 ++ .settings/org.eclipse.cdt.core.prefs | 17 ++ components/cmd_nvs/cmd_nvs.c | 5 +- components/squeezelite-ota/cmd_ota.c | 5 +- components/squeezelite-ota/squeezelite-ota.c | 19 +- components/wifi-manager/code.js | 205 +++++++++++-------- components/wifi-manager/index.html | 138 ++++++++----- 8 files changed, 308 insertions(+), 151 deletions(-) diff --git a/.cproject b/.cproject index 2e3becc6..cc4e126b 100644 --- a/.cproject +++ b/.cproject @@ -97,6 +97,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + @@ -104,6 +152,9 @@ + + + @@ -139,6 +190,7 @@ + @@ -150,6 +202,12 @@ + + + + + + diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index 08c414ab..a9fc742b 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -24,4 +24,16 @@ + + + + + + + + + + + + diff --git a/.settings/org.eclipse.cdt.core.prefs b/.settings/org.eclipse.cdt.core.prefs index cb53cecc..cc43b273 100644 --- a/.settings/org.eclipse.cdt.core.prefs +++ b/.settings/org.eclipse.cdt.core.prefs @@ -24,6 +24,23 @@ environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1476804786/PATH/op environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1476804786/PATH/value=C\:/msys2/opt/xtensa-esp32-elf/bin;C\:/jdk-12.0.2/bin/server;C\:/jdk-12.0.2/bin;C\:\\Windows\\system32;C\:\\Windows;C\:\\Windows\\System32\\Wbem;C\:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C\:\\Program Files\\NVIDIA Corporation\\NVIDIA NvDLISR;C\:\\jdk-12.0.2\\bin;C\:\\Program Files\\PuTTY\\;C\:\\Program Files (x86)\\HP\\IdrsOCR_15.2.10.1114\\;C\:\\eclipse environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1476804786/append=true environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1476804786/appendContributed=true +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291/BATCH_BUILD/delimiter=\: +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291/BATCH_BUILD/operation=append +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291/BATCH_BUILD/value=1 +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291/IDF_PATH/delimiter=\: +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291/IDF_PATH/operation=replace +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291/IDF_PATH/value=C\:/msys32/home/Sebastien/esp/esp-idf +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291/PATH/delimiter=\: +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291/PATH/operation=replace +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291/PATH/value=c\:\\msys32\\opt\\xtensa-esp32-elf\\bin;c\:\\msys32\\mingw32\\bin;c\:\\msys32\\usr\\local\\bin;c\:\\msys32\\usr\\bin;c\:\\msys32\\bin;c\:\\Windows\\System32;c\:\\Windows;c\:\\Windows\\System32\\Wbem;c\:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C\:\\msys32\\usr\\bin\\site_perl;C\:\\msys32\\usr\\bin\\vendor_perl;C\:\\msys32\\usr\\bin\\core_perl;C\:\\msys32\\var\\opt\\xtensa-esp32-elf\\bin\\;C\:\\msys32\\sbin;C\:\\msys32\\bin;C\:\\msys32\\usr\\bin;C\:\\msys32\\usr\\local\\bin;C\:\\msys32\\snap\\bin;C\:\\msys32\\bin;C\:\\msys32\\sbin;C\:\\msys32\\usr\\bin;C\:\\msys32\\usr\\local\\bin;C\:\\msys32\\snap\\bin +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291/PROJECT_NAME/delimiter=\: +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291/PROJECT_NAME/operation=replace +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291/PROJECT_NAME/value=recovery.custom +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291/PROJECT_VER/delimiter=\: +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291/PROJECT_VER/operation=append +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291/PROJECT_VER/value=custom +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291/append=true +environment/project/cdt.managedbuild.toolchain.gnu.cross.base.293933348.1603996291/appendContributed=true environment/project/cdt.managedbuild.toolchain.gnu.cross.base.293933348.839256934/BATCH_BUILD/delimiter=\: environment/project/cdt.managedbuild.toolchain.gnu.cross.base.293933348.839256934/BATCH_BUILD/operation=append environment/project/cdt.managedbuild.toolchain.gnu.cross.base.293933348.839256934/BATCH_BUILD/value=1 diff --git a/components/cmd_nvs/cmd_nvs.c b/components/cmd_nvs/cmd_nvs.c index dcb5faf5..3edc0929 100644 --- a/components/cmd_nvs/cmd_nvs.c +++ b/components/cmd_nvs/cmd_nvs.c @@ -530,7 +530,10 @@ void register_nvs() namespace_args.namespace = arg_str1(NULL, NULL, "", "namespace of the partition to be selected"); namespace_args.end = arg_end(2); - + list_args.partition = arg_str1(NULL, NULL, "", "partition name"); + list_args.namespace = arg_str0("n", "namespace", "", "namespace name"); + list_args.type = arg_str0("t", "type", "", ARG_TYPE_STR); + list_args.end = arg_end(2); const esp_console_cmd_t set_cmd = { .command = "nvs_set", .help = "Set variable in selected namespace. Blob type must be comma separated list of hex values. \n" diff --git a/components/squeezelite-ota/cmd_ota.c b/components/squeezelite-ota/cmd_ota.c index 7220afa7..527e37e2 100644 --- a/components/squeezelite-ota/cmd_ota.c +++ b/components/squeezelite-ota/cmd_ota.c @@ -44,6 +44,7 @@ static int perform_ota_update(int argc, char **argv) const char *url = ota_args.url->sval[0]; esp_err_t err=ESP_OK; + ESP_LOGI(TAG, "Starting ota: %s", url); start_ota(url); @@ -59,10 +60,10 @@ static int perform_ota_update(int argc, char **argv) void register_ota_cmd() { ota_args.url= arg_str1(NULL, NULL, "", "url of the binary app file"); - ota_args.end = arg_end(1); + ota_args.end = arg_end(2); const esp_console_cmd_t cmd = { - .command = "ota_update", + .command = "update", .help = "Updates the application binary from the provided URL", .hint = NULL, .func = &perform_ota_update, diff --git a/components/squeezelite-ota/squeezelite-ota.c b/components/squeezelite-ota/squeezelite-ota.c index 2be9d82a..29dc9385 100644 --- a/components/squeezelite-ota/squeezelite-ota.c +++ b/components/squeezelite-ota/squeezelite-ota.c @@ -41,28 +41,30 @@ esp_err_t _http_event_handler(esp_http_client_event_t *evt) switch (evt->event_id) { case HTTP_EVENT_ERROR: ESP_LOGD(TAG, "HTTP_EVENT_ERROR"); - strncpy(ota_status,sizeof(ota_status)-1,"HTTP_EVENT_ERROR"); + strncpy(ota_status,"HTTP_EVENT_ERROR",sizeof(ota_status)-1); break; case HTTP_EVENT_ON_CONNECTED: ESP_LOGD(TAG, "HTTP_EVENT_ON_CONNECTED"); - strncpy(ota_status,sizeof(ota_status)-1,"HTTP_EVENT_ON_CONNECTED"); + strncpy(ota_status,"HTTP_EVENT_ON_CONNECTED",sizeof(ota_status)-1); break; case HTTP_EVENT_HEADER_SENT: ESP_LOGD(TAG, "HTTP_EVENT_HEADER_SENT"); - strncpy(ota_status,sizeof(ota_status)-1,"HTTP_EVENT_HEADER_SENT"); + strncpy(ota_status,"HTTP_EVENT_HEADER_SENT",sizeof(ota_status)-1); break; case HTTP_EVENT_ON_HEADER: ESP_LOGD(TAG, "HTTP_EVENT_ON_HEADER, key=%s, value=%s", evt->header_key, evt->header_value); + snprintf(ota_status,sizeof(ota_status)-1,"HTTP_EVENT_ON_HEADER, key=%s, value=%s", evt->header_key, evt->header_value); break; case HTTP_EVENT_ON_DATA: ESP_LOGD(TAG, "HTTP_EVENT_ON_DATA, len=%d", evt->data_len); + snprintf(ota_status,sizeof(ota_status)-1, "HTTP_EVENT_ON_DATA, len=%d", evt->data_len); break; case HTTP_EVENT_ON_FINISH: ESP_LOGD(TAG, "HTTP_EVENT_ON_FINISH"); break; case HTTP_EVENT_DISCONNECTED: ESP_LOGD(TAG, "HTTP_EVENT_DISCONNECTED"); - strncpy(ota_status,sizeof(ota_status)-1,"HTTP_EVENT_DISCONNECTED"); + strncpy(ota_status,"HTTP_EVENT_DISCONNECTED",sizeof(ota_status)-1); break; } return ESP_OK; @@ -78,6 +80,7 @@ void ota_task(void *pvParameter) //.cert_pem = (char *)server_cert_pem_start, .event_handler = _http_event_handler, }; + ESP_LOGI(TAG, "Starting ota: %s", bin_url); // todo: review how certificates work config.skip_cert_common_name_check = true; @@ -88,9 +91,8 @@ void ota_task(void *pvParameter) } else { ESP_LOGE(TAG, "Firmware upgrade failed"); } - while (1) { - vTaskDelay(1000 / portTICK_PERIOD_MS); - } + free(pvParameter); + return; } void start_ota(const char * bin_url) @@ -110,5 +112,6 @@ void start_ota(const char * bin_url) char * urlPtr=malloc((strlen(bin_url)+1)*sizeof(char)); strcpy(urlPtr,bin_url); - xTaskCreate(&ota_task, "ota_task", 8192, NULL, 5, urlPtr); + ESP_LOGI(TAG, "Starting ota: %s", urlPtr); + xTaskCreate(&ota_task, "ota_task", 8192,(void *) urlPtr, 5, NULL); } diff --git a/components/wifi-manager/code.js b/components/wifi-manager/code.js index 12328e61..99010f33 100644 --- a/components/wifi-manager/code.js +++ b/components/wifi-manager/code.js @@ -11,7 +11,8 @@ if (!String.prototype.format) { }; } -var recovery = false; +var releaseURL = 'https://api.github.com/repos/sle118/squeezelite-esp32/releases'; +var recovery = true; var enableTimers = true; var commandHeader = 'squeezelite -b 500:2000 -d all=info '; @@ -24,6 +25,7 @@ var StatusIntervalActive = false; var ConfigIntervalActive = false; var RefreshAPIIntervalActive = false; +var output = ''; //TODO check var to = 0, set_int = 0; @@ -65,7 +67,7 @@ function RepeatCheckConfigInterval(){ function RepeatRefreshAPInterval(){ if(RefreshAPIIntervalActive) - startRefreshAPInterval() + startRefreshAPInterval(); } $(document).ready(function(){ @@ -175,18 +177,110 @@ $(document).ready(function(){ $( "#wifi" ).slideDown( "fast", function() {}) }); - $("#update-command").click(function() { - updateAutoexec(); + $("#autoexec-cb").on("click", function() { + autoexec = (this.checked)?1:0; + $.ajax({ + url: '/config.json', + dataType: 'json', + method: 'POST', + cache: false, + headers: { "X-Custom-autoexec": autoexec }, + data: { 'timestamp': Date.now() } + }); + console.log('sent config JSON with headers:', autoexec); + }); + + $("#save-autoexec1").on("click", function() { + autoexec1 = $("#autoexec1").val(); + + $.ajax({ + url: '/config.json', + dataType: 'json', + method: 'POST', + cache: false, + headers: { "X-Custom-autoexec1": autoexec1 }, + data: { 'timestamp': Date.now() } + }); + console.log('sent config JSON with headers:', autoexec1); + }); + + $("#recovery").on("click", function() { + $.ajax({ + url: '/recovery.json', + dataType: 'json', + method: 'POST', + cache: false, + data: { 'timestamp': Date.now()} + }); + }); + + $("#reboot").on("click", function() { + $.ajax({ + url: '/reboot.json', + dataType: 'json', + method: 'POST', + cache: false, + data: { 'timestamp': Date.now()} + }); + }); + + $("#generate-command").on("click", function() { + var commandLine = commandHeader + '-n ' + $("#player").val(); + + if (output == 'bt') { + commandLine += ' -o "BT -n \'' + $("#btsink").val() + '\'" -R -Z 192000'; + } else if (output == 'spdif') { + commandLine += ' -o SPDIF -R -Z 192000'; + } else { + commandLine += ' -o I2S'; + } + if ($("#optional").val() != '') { + commandLine += ' ' + $("#optional").val(); + } + $("#autoexec1").val(commandLine); }); - $("#generate-command").click(function() { - generateCommand(); - }); - - $('[name=audio]').click(function(){ - selectOutput(this); + $('[name=audio]').on("click", function(){ + if (this.id == 'bt') { + $("#btsinkdiv").show(200); + output = 'bt'; + } else if (this.id == 'spdif') { + $("#btsinkdiv").hide(200); + output = 'spdif'; + } else { + $("#btsinkdiv").hide(200); + output = 'i2s'; + } }); + $('#fwcheck').on("click", function(){ + $("#releaseTable").html(""); + $.getJSON(releaseURL, function(data) { + data.forEach(function(release) { + var url = ''; + release.assets.forEach(function(asset) { + if (asset.name.match(/\.bin$/)) { + url = asset.browser_download_url; + } + }); + var [ver, idf, cfg, branch] = release.name.split('-'); + $("#releaseTable").append( + ""+ + ""+ver+""+ + ""+idf+""+ + ""+cfg+""+ + ""+branch+""+ + ""+ + "" + ); + }); + }) + .fail(function() { + alert("failed to fetch release history!"); + }); + }); + + //first time the page loads: attempt to get the connection status and start the wifi scan refreshAP(); getConfig(); @@ -196,6 +290,20 @@ $(document).ready(function(){ startRefreshAPInterval(); }); +function setURL(button) { + var url = button.dataset.url; + $.ajax({ + url: '/config.json', + dataType: 'json', + method: 'POST', + cache: false, + headers: { "X-Custom-fwurl": url }, + data: { 'timestamp': Date.now() } + }); + $('[data-url^="http"]').addClass("btn-success").removeClass("btn-danger"); + $('[data-url="'+url+'"]').addClass("btn-danger").removeClass("btn-success"); +} + function performConnect(conntype){ //stop the status refresh. This prevents a race condition where a status //request would be refreshed with wrong ip info from a previous connection @@ -240,8 +348,6 @@ function performConnect(conntype){ startRefreshAPInterval(); } - - function rssiToIcon(rssi){ if(rssi >= -60){ return 'w0'; @@ -367,16 +473,16 @@ function getConfig() { } else { console.log('turn off autoexec'); $("#autoexec-cb")[0].checked=false; - $("#autoexec-command").hide(200); } } if (data.hasOwnProperty('recovery')) { if (data["recovery"] === 1) { recovery = true; + $("#tab-wifi").removeClass("active show"); + $("#tab-system").addClass("active show"); + $("#navbar").hide(); $("#recoverydiv").hide(); $("#otadiv").show(); - $("#command_line").hide(); - $("#wifi").hide(); } else { recovery = false; $("#recoverydiv").show(); @@ -399,77 +505,8 @@ function getConfig() { }); } -function updateAutoexec(){ - autoexec = ($("#autoexec-cb")[0].checked)?1:0; - autoexec1 = $("#autoexec1").val(); - - $.ajax({ - url: '/config.json', - dataType: 'json', - method: 'POST', - cache: false, - headers: { "X-Custom-autoexec": autoexec, "X-Custom-autoexec1": autoexec1 }, - data: { 'timestamp': Date.now() } - }); - console.log('sent config JSON with headers:', autoexec, autoexec1); -} -var output = ''; -function selectOutput(el) { - if ($(el).attr('id') == 'bt') { - $("#btsinkdiv").show(200); - output = 'bt'; - } else if ($(el).attr('id') == 'spdif') { - $("#btsinkdiv").hide(200); - output = 'spdif'; - } else { - $("#btsinkdiv").hide(200); - output = 'i2s'; - } -} -function generateCommand() { - var commandLine = commandHeader + '-n ' + $("#player").val(); - - if (output == 'bt') { - commandLine += ' -o "BT -n \'' + $("#btsink").val() + '\'" -R -Z 192000'; - } else if (output == 'spdif') { - commandLine += ' -o SPDIF -R -Z 192000'; - } else { - commandLine += ' -o I2S'; - } - if ($("#optional").val() != '') { - commandLine += ' ' + $("#optional").val(); - } - $("#autoexec1").val(commandLine); -} - -function handleClick(item) { - console.log(item); - if (item.id == 'autoexec-cb') { - if (item.checked) { - $("#autoexec-command").show(200); - } else { - $("#autoexec-command").hide(200); - } - } else if (item.id == 'recovery') { - $.ajax({ - url: '/recovery.json', - dataType: 'json', - method: 'POST', - cache: false, - data: { 'timestamp': Date.now()} - }); - } else if (item.id == 'reboot') { - $.ajax({ - url: '/reboot.json', - dataType: 'json', - method: 'POST', - cache: false, - data: { 'timestamp': Date.now()} - }); - } -} //TODO daduke check function file_change() { diff --git a/components/wifi-manager/index.html b/components/wifi-manager/index.html index 830b7b81..52a42039 100644 --- a/components/wifi-manager/index.html +++ b/components/wifi-manager/index.html @@ -4,24 +4,26 @@ + - - + + + esp32-wifi-manager -