mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-11 14:07:11 +03:00
more ota work-ota cmd line implemented-not tested
This commit is contained in:
@@ -27,21 +27,46 @@
|
||||
#include "sdkconfig.h"
|
||||
|
||||
static const char * TAG = "platform_esp32";
|
||||
|
||||
extern void start_ota(const char * bin_url);
|
||||
static struct {
|
||||
struct arg_str *url;
|
||||
struct arg_end *end;
|
||||
} ota_args;
|
||||
/* 'heap' command prints minumum heap size */
|
||||
static int perform_ota_update(int argc, char **argv)
|
||||
{
|
||||
int nerrors = arg_parse(argc, argv, (void **) &ota_args);
|
||||
if (nerrors != 0) {
|
||||
arg_print_errors(stderr, ota_args.end, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char *url = ota_args.url->sval[0];
|
||||
|
||||
esp_err_t err=ESP_OK;
|
||||
start_ota(url);
|
||||
|
||||
|
||||
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "%s", esp_err_to_name(err));
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void register_ota_cmd()
|
||||
void register_ota_cmd()
|
||||
{
|
||||
ota_args.url= arg_str1(NULL, NULL, "<url>", "url of the binary app file");
|
||||
ota_args.end = arg_end(2);
|
||||
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = "ota_update",
|
||||
.help = "Updates the application binary from the provided URL",
|
||||
.hint = NULL,
|
||||
.func = &perform_ota_update,
|
||||
.argtable = &ota_args
|
||||
};
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
// Register system functions
|
||||
static void register_ota_cmd();
|
||||
void register_ota_cmd();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -41,12 +41,15 @@ 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");
|
||||
break;
|
||||
case HTTP_EVENT_ON_CONNECTED:
|
||||
ESP_LOGD(TAG, "HTTP_EVENT_ON_CONNECTED");
|
||||
break;
|
||||
strncpy(ota_status,sizeof(ota_status)-1,"HTTP_EVENT_ON_CONNECTED");
|
||||
break;
|
||||
case HTTP_EVENT_HEADER_SENT:
|
||||
ESP_LOGD(TAG, "HTTP_EVENT_HEADER_SENT");
|
||||
strncpy(ota_status,sizeof(ota_status)-1,"HTTP_EVENT_HEADER_SENT");
|
||||
break;
|
||||
case HTTP_EVENT_ON_HEADER:
|
||||
ESP_LOGD(TAG, "HTTP_EVENT_ON_HEADER, key=%s, value=%s", evt->header_key, evt->header_value);
|
||||
@@ -59,6 +62,7 @@ esp_err_t _http_event_handler(esp_http_client_event_t *evt)
|
||||
break;
|
||||
case HTTP_EVENT_DISCONNECTED:
|
||||
ESP_LOGD(TAG, "HTTP_EVENT_DISCONNECTED");
|
||||
strncpy(ota_status,sizeof(ota_status)-1,"HTTP_EVENT_DISCONNECTED");
|
||||
break;
|
||||
}
|
||||
return ESP_OK;
|
||||
|
||||
Reference in New Issue
Block a user