mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2026-01-27 04:40:48 +03:00
Merge branch 'master-v4.3' of https://github.com/wizmo2/squeezelite-esp32 into led_visu-v4.3
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
idf_component_register(SRC_DIRS .
|
||||
PRIV_REQUIRES _override esp_common wifi-manager pthread squeezelite-ota platform_console telnet display targets led_strip
|
||||
EMBED_FILES ../server_certs/github.pem
|
||||
LDFRAGMENTS "linker.lf"
|
||||
)
|
||||
#get_target_property(ill ${COMPONENT_LIB} INTERFACE_LINK_LIBRARIES)
|
||||
|
||||
@@ -117,7 +117,7 @@ menu "Squeezelite-ESP32"
|
||||
string
|
||||
default "dc=27,data=19,clk=18" if TWATCH2020
|
||||
default "mosi=15,miso=2,clk=14" if MUSE
|
||||
default ""
|
||||
default ""
|
||||
config DISPLAY_CONFIG
|
||||
string
|
||||
default "SPI,driver=ST7789,width=240,height=240,cs=5,back=12,speed=16000000,HFlip,VFlip" if TWATCH2020
|
||||
@@ -125,7 +125,7 @@ menu "Squeezelite-ESP32"
|
||||
config ETH_CONFIG
|
||||
string
|
||||
default ""
|
||||
# AGGREGATES - end
|
||||
# AGGREGATES - end
|
||||
config DAC_CONTROLSET
|
||||
string
|
||||
default "{ \"init\": [ {\"reg\":41, \"val\":128}, {\"reg\":18, \"val\":255} ], \"poweron\": [ {\"reg\":18, \"val\":64, \"mode\":\"or\"} ], \"poweroff\": [ {\"reg\":18, \"val\":191, \"mode\":\"and\"} ] }" if TWATCH2020
|
||||
@@ -168,6 +168,9 @@ menu "Squeezelite-ESP32"
|
||||
int
|
||||
default 13 if SQUEEZEAMP
|
||||
default -1
|
||||
config SET_GPIO
|
||||
string
|
||||
default "0=ir" if SQUEEZEAMP
|
||||
endmenu
|
||||
|
||||
menu "Audio settings"
|
||||
@@ -342,14 +345,15 @@ menu "Squeezelite-ESP32"
|
||||
data=<gpio>,clk=<gpio>[,d/c=<num>][,host=<0|1|2>]
|
||||
config SET_GPIO
|
||||
string "Special GPIO configuration"
|
||||
default ""
|
||||
help
|
||||
Set parameters of shared GPIO with special values.
|
||||
<gpio_1>=Vcc|GND|amp[:0|1]|jack[:0|1][,<gpio_n>=Vcc|GND|amp[:0|1]|jack[:0|1]]
|
||||
<gpio_1>=Vcc|GND|amp[:0|1]|jack[:0|1][ir][spkfault[:0|1][,<gpio_n>=Vcc|GND|amp[:0|1]|jack[:0|1]]
|
||||
'amp' => GPIO that is set when playback starts
|
||||
'jack' => GPIO used for audio jack detection
|
||||
'green', 'red' => GPIO for status LED
|
||||
'[:0|1] means set the active value for that GPIO can be low or high
|
||||
'spkfault' => GPIO used for speaker fault detection
|
||||
'ir' => GPIO used for Infrared Receiver
|
||||
[:0|1] means set the active value for that GPIO can be low or high
|
||||
config ROTARY_ENCODER
|
||||
string "Rotary Encoder configuration"
|
||||
default ""
|
||||
|
||||
@@ -48,9 +48,6 @@
|
||||
#include "cmd_system.h"
|
||||
#include "tools.h"
|
||||
|
||||
static const char certs_namespace[] = "certificates";
|
||||
static const char certs_key[] = "blob";
|
||||
static const char certs_version[] = "version";
|
||||
const char unknown_string_placeholder[] = "unknown";
|
||||
const char null_string_placeholder[] = "null";
|
||||
EventGroupHandle_t network_event_group;
|
||||
@@ -68,8 +65,6 @@ RTC_NOINIT_ATTR uint16_t ColdBootIndicatorFlag;
|
||||
bool cold_boot=true;
|
||||
|
||||
static bool bNetworkConnected=false;
|
||||
extern const uint8_t server_cert_pem_start[] asm("_binary_github_pem_start");
|
||||
extern const uint8_t server_cert_pem_end[] asm("_binary_github_pem_end");
|
||||
|
||||
// as an exception _init function don't need include
|
||||
extern void services_init(void);
|
||||
@@ -156,119 +151,11 @@ esp_log_level_t get_log_level_from_char(char * level){
|
||||
if(!strcasecmp(level, "VERBOSE" )) { return ESP_LOG_VERBOSE;}
|
||||
return ESP_LOG_WARN;
|
||||
}
|
||||
|
||||
void set_log_level(char * tag, char * level){
|
||||
esp_log_level_set(tag, get_log_level_from_char(level));
|
||||
}
|
||||
|
||||
|
||||
esp_err_t update_certificates(bool force){
|
||||
|
||||
nvs_handle handle;
|
||||
esp_err_t esp_err;
|
||||
esp_app_desc_t running_app_info;
|
||||
|
||||
ESP_LOGI(TAG, "About to check if certificates need to be updated in flash");
|
||||
esp_err = nvs_open_from_partition(settings_partition, certs_namespace, NVS_READWRITE, &handle);
|
||||
if (esp_err != ESP_OK) {
|
||||
LOG_SEND(MESSAGING_INFO,"Unable to update HTTPS certificates. Could not open NVS namespace %s. Error %s", certs_namespace, esp_err_to_name(esp_err));
|
||||
return esp_err;
|
||||
}
|
||||
|
||||
const esp_partition_t *running = esp_ota_get_running_partition();
|
||||
ESP_LOGI(TAG, "Running partition [%s] type %d subtype %d (offset 0x%08x)", running->label, running->type, running->subtype, running->address);
|
||||
|
||||
if (esp_ota_get_partition_description(running, &running_app_info) == ESP_OK) {
|
||||
ESP_LOGI(TAG, "Running version: %s", running_app_info.version);
|
||||
}
|
||||
|
||||
size_t len=0;
|
||||
char *str=NULL;
|
||||
bool changed=false;
|
||||
if ( (esp_err= nvs_get_str(handle, certs_version, NULL, &len)) == ESP_OK) {
|
||||
str=(char *)malloc_init_external(len+1);
|
||||
if(str){
|
||||
if ( (esp_err = nvs_get_str(handle, certs_version, str, &len)) == ESP_OK) {
|
||||
ESP_LOGI(TAG,"Certificate version: %s", str);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(str!=NULL && running->subtype !=ESP_PARTITION_SUBTYPE_APP_FACTORY){
|
||||
// If certificates were found in nvs, only update if we're not
|
||||
// running recovery. This will prevent rolling back to an older version
|
||||
if(strcmp((char *)running_app_info.version,(char *)str )){
|
||||
// Versions are different
|
||||
ESP_LOGW(TAG,"Found a different software version. Updating certificates");
|
||||
changed=true;
|
||||
}
|
||||
free(str);
|
||||
}
|
||||
else if(str==NULL){
|
||||
ESP_LOGW(TAG,"No certificate found. Adding certificates");
|
||||
changed=true;
|
||||
}
|
||||
|
||||
if(changed || force){
|
||||
|
||||
esp_err = nvs_set_blob(handle, certs_key, server_cert_pem_start, (server_cert_pem_end-server_cert_pem_start));
|
||||
if(esp_err!=ESP_OK){
|
||||
log_send_messaging(MESSAGING_ERROR,"Failed to store certificate data: %s", esp_err_to_name(esp_err));
|
||||
}
|
||||
else {
|
||||
esp_err = nvs_set_str(handle, certs_version, running_app_info.version);
|
||||
if(esp_err!=ESP_OK){
|
||||
log_send_messaging(MESSAGING_ERROR,"Unable to update HTTPS Certificates version: %s",esp_err_to_name(esp_err));
|
||||
}
|
||||
else {
|
||||
esp_err = nvs_commit(handle);
|
||||
if(esp_err!=ESP_OK){
|
||||
log_send_messaging(MESSAGING_ERROR,"Failed to commit certificates changes : %s",esp_err_to_name(esp_err));
|
||||
}
|
||||
else {
|
||||
log_send_messaging(MESSAGING_INFO,"HTTPS Certificates were updated with version: %s",running_app_info.version);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nvs_close(handle);
|
||||
return ESP_OK;
|
||||
}
|
||||
const char * get_certificate(){
|
||||
nvs_handle handle;
|
||||
esp_err_t esp_err;
|
||||
char *blob =NULL;
|
||||
//
|
||||
ESP_LOGD(TAG, "Fetching certificate.");
|
||||
esp_err = nvs_open_from_partition(settings_partition, certs_namespace, NVS_READONLY, &handle);
|
||||
if(esp_err == ESP_OK){
|
||||
size_t len;
|
||||
esp_err = nvs_get_blob(handle, certs_key, NULL, &len);
|
||||
if( esp_err == ESP_OK) {
|
||||
blob = (char *) malloc_init_external(len+1);
|
||||
if(!blob){
|
||||
log_send_messaging(MESSAGING_ERROR,"Unable to retrieve HTTPS certificates. %s","Memory allocation failed");
|
||||
return "";
|
||||
}
|
||||
memset(blob,0x00,len+1);
|
||||
esp_err = nvs_get_blob(handle, certs_key, blob, &len);
|
||||
if ( esp_err == ESP_OK) {
|
||||
ESP_LOGD(TAG,"Certificates content is %d bytes long: ", len);
|
||||
}
|
||||
else {
|
||||
log_send_messaging(MESSAGING_ERROR,"Unable to retrieve HTTPS certificates. Get blob failed: %s", esp_err_to_name(esp_err));
|
||||
}
|
||||
}
|
||||
else{
|
||||
log_send_messaging(MESSAGING_ERROR,"Unable to retrieve HTTPS certificates. Get blob failed: %s",esp_err_to_name(esp_err));
|
||||
}
|
||||
nvs_close(handle);
|
||||
}
|
||||
else{
|
||||
log_send_messaging(MESSAGING_ERROR,"Unable to retrieve HTTPS certificates. NVS name space %s open failed: %s",certs_namespace, esp_err_to_name(esp_err));
|
||||
}
|
||||
return blob;
|
||||
}
|
||||
|
||||
#define DEFAULT_NAME_WITH_MAC(var,defval) char var[strlen(defval)+sizeof(macStr)]; strcpy(var,defval); strcat(var,macStr)
|
||||
void register_default_string_val(const char * key, char * value){
|
||||
char * existing =(char *)config_alloc_get(NVS_TYPE_STR,key );
|
||||
@@ -283,28 +170,53 @@ void register_default_string_val(const char * key, char * value){
|
||||
FREE_AND_NULL(existing);
|
||||
}
|
||||
|
||||
void register_default_with_mac(const char* key, char* defval) {
|
||||
char * alloc_get_string_with_mac(const char * val) {
|
||||
uint8_t mac[6];
|
||||
char macStr[LOCAL_MAC_SIZE + 1];
|
||||
char* fullvalue = NULL;
|
||||
esp_read_mac((uint8_t*)&mac, ESP_MAC_WIFI_STA);
|
||||
snprintf(macStr, LOCAL_MAC_SIZE - 1, "-%x%x%x", mac[3], mac[4], mac[5]);
|
||||
fullvalue = malloc_init_external(strlen(defval)+sizeof(macStr)+1);
|
||||
fullvalue = malloc_init_external(strlen(val)+sizeof(macStr)+1);
|
||||
if(fullvalue){
|
||||
strcpy(fullvalue, defval);
|
||||
strcpy(fullvalue, val);
|
||||
strcat(fullvalue, macStr);
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG,"Memory allocation failed when getting mac value for %s", val);
|
||||
}
|
||||
return fullvalue;
|
||||
|
||||
}
|
||||
void register_default_with_mac(const char* key, char* defval) {
|
||||
char * fullvalue=alloc_get_string_with_mac(defval);
|
||||
if(fullvalue){
|
||||
register_default_string_val(key,fullvalue);
|
||||
FREE_AND_NULL(fullvalue);
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG,"Memory allocation failed when registering default value for %s", key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void register_default_nvs(){
|
||||
#ifdef CONFIG_CSPOT_SINK
|
||||
register_default_string_val("enable_cspot", STR(CONFIG_CSPOT_SINK));
|
||||
cJSON * cspot_config=config_alloc_get_cjson("cspot_config");
|
||||
if(!cspot_config){
|
||||
char * name = alloc_get_string_with_mac(DEFAULT_HOST_NAME);
|
||||
if(name){
|
||||
cjson_update_string(&cspot_config,"deviceName",name);
|
||||
cjson_update_number(&cspot_config,"bitrate",160);
|
||||
// the call below saves the config and frees the json pointer
|
||||
config_set_cjson_str_and_free("cspot_config",cspot_config);
|
||||
FREE_AND_NULL(name);
|
||||
}
|
||||
else {
|
||||
register_default_string_val("cspot_config", "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_AIRPLAY_SINK
|
||||
@@ -370,11 +282,7 @@ void register_default_nvs(){
|
||||
register_default_string_val("ethtmout","8");
|
||||
register_default_string_val("dhcp_tmout","8");
|
||||
register_default_string_val("target", CONFIG_TARGET);
|
||||
register_default_string_val("led_vu_config", "");
|
||||
#ifdef CONFIG_CSPOT_SINK
|
||||
register_default_string_val("enable_cspot", STR(CONFIG_CSPOT_SINK));
|
||||
register_default_string_val("cspot_config", "");
|
||||
#endif
|
||||
register_default_string_val("led_vu_config", "");
|
||||
wait_for_commit();
|
||||
ESP_LOGD(TAG,"Done setting default values in nvs.");
|
||||
}
|
||||
@@ -484,11 +392,6 @@ void app_main()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ESP_LOGI(TAG,"Checking if certificates need to be updated");
|
||||
update_certificates(false);
|
||||
MEMTRACE_PRINT_DELTA();
|
||||
|
||||
ESP_LOGD(TAG,"Getting firmware OTA URL (if any)");
|
||||
fwurl = process_ota_url();
|
||||
|
||||
@@ -534,8 +437,7 @@ void app_main()
|
||||
network_register_state_callback(NETWORK_INITIALIZING_STATE,-1, "handle_ap_connect", &handle_ap_connect);
|
||||
network_register_state_callback(NETWORK_ETH_ACTIVE_STATE,ETH_ACTIVE_LINKDOWN_STATE, "handle_network_up", &handle_network_up);
|
||||
network_register_state_callback(NETWORK_WIFI_ACTIVE_STATE,WIFI_INITIALIZING_STATE, "handle_network_up", &handle_network_up);
|
||||
MEMTRACE_PRINT_DELTA();
|
||||
|
||||
MEMTRACE_PRINT_DELTA();
|
||||
}
|
||||
MEMTRACE_PRINT_DELTA_MESSAGE("Starting Console");
|
||||
console_start();
|
||||
|
||||
Reference in New Issue
Block a user