This commit is contained in:
e2002
2024-12-17 15:31:43 +03:00
parent 3f5ed098de
commit 9ad82acc80
9 changed files with 77 additions and 13 deletions

View File

@@ -234,6 +234,12 @@ Work is in progress...
--- ---
## Version history ## Version history
### v0.9.380
- fixed compilation error for ESP32 cores >= 3.1.0
- fixed freezing error with incorrectly configured RTC module
- [www|uart|telnet] new command `mode` - change SD/WEB mode. (0 - WEB, 1 - SD, 2 - Toggle)
example: http://<ipaddr>/?mode=2
#### v0.9.375 #### v0.9.375
- fixed the issue with saving settings for TIMEZONE. - fixed the issue with saving settings for TIMEZONE.

View File

@@ -31,6 +31,20 @@ extern "C"{
} }
#include "esp_task_wdt.h" #include "esp_task_wdt.h"
#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 1, 0)
#define TCP_MUTEX_LOCK() \
if (!sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)) { \
LOCK_TCPIP_CORE(); \
}
#define TCP_MUTEX_UNLOCK() \
if (sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)) { \
UNLOCK_TCPIP_CORE(); \
}
#else
#define TCP_MUTEX_LOCK()
#define TCP_MUTEX_UNLOCK()
#endif
/* /*
* TCP/IP Event Task * TCP/IP Event Task
* */ * */
@@ -690,10 +704,11 @@ bool AsyncClient::connect(IPAddress ip, uint16_t port){
ip_addr_t addr; ip_addr_t addr;
addr.type = IPADDR_TYPE_V4; addr.type = IPADDR_TYPE_V4;
addr.u_addr.ip4.addr = ip; addr.u_addr.ip4.addr = ip;
TCP_MUTEX_LOCK();
tcp_pcb* pcb = tcp_new_ip_type(IPADDR_TYPE_V4); tcp_pcb* pcb = tcp_new_ip_type(IPADDR_TYPE_V4);
if (!pcb){ if (!pcb){
log_e("pcb == NULL"); log_e("pcb == NULL");
TCP_MUTEX_UNLOCK();
return false; return false;
} }
@@ -702,6 +717,7 @@ bool AsyncClient::connect(IPAddress ip, uint16_t port){
tcp_recv(pcb, &_tcp_recv); tcp_recv(pcb, &_tcp_recv);
tcp_sent(pcb, &_tcp_sent); tcp_sent(pcb, &_tcp_sent);
tcp_poll(pcb, &_tcp_poll, 1); tcp_poll(pcb, &_tcp_poll, 1);
TCP_MUTEX_UNLOCK();
//_tcp_connect(pcb, &addr, port,(tcp_connected_fn)&_s_connected); //_tcp_connect(pcb, &addr, port,(tcp_connected_fn)&_s_connected);
_tcp_connect(pcb, _closed_slot, &addr, port,(tcp_connected_fn)&_tcp_connected); _tcp_connect(pcb, _closed_slot, &addr, port,(tcp_connected_fn)&_tcp_connected);
return true; return true;
@@ -714,8 +730,9 @@ bool AsyncClient::connect(const char* host, uint16_t port){
log_e("failed to start task"); log_e("failed to start task");
return false; return false;
} }
TCP_MUTEX_LOCK();
err_t err = dns_gethostbyname(host, &addr, (dns_found_callback)&_tcp_dns_found, this); err_t err = dns_gethostbyname(host, &addr, (dns_found_callback)&_tcp_dns_found, this);
TCP_MUTEX_UNLOCK();
if(err == ERR_OK) { if(err == ERR_OK) {
return connect(IPAddress(addr.u_addr.ip4.addr), port); return connect(IPAddress(addr.u_addr.ip4.addr), port);
} else if(err == ERR_INPROGRESS) { } else if(err == ERR_INPROGRESS) {
@@ -803,11 +820,13 @@ int8_t AsyncClient::_close(){
int8_t err = ERR_OK; int8_t err = ERR_OK;
if(_pcb) { if(_pcb) {
//log_i(""); //log_i("");
TCP_MUTEX_LOCK();
tcp_arg(_pcb, NULL); tcp_arg(_pcb, NULL);
tcp_sent(_pcb, NULL); tcp_sent(_pcb, NULL);
tcp_recv(_pcb, NULL); tcp_recv(_pcb, NULL);
tcp_err(_pcb, NULL); tcp_err(_pcb, NULL);
tcp_poll(_pcb, NULL, 0); tcp_poll(_pcb, NULL, 0);
TCP_MUTEX_UNLOCK();
_tcp_clear_events(this); _tcp_clear_events(this);
err = _tcp_close(_pcb, _closed_slot); err = _tcp_close(_pcb, _closed_slot);
if(err != ERR_OK) { if(err != ERR_OK) {
@@ -865,6 +884,7 @@ int8_t AsyncClient::_connected(void* pcb, int8_t err){
void AsyncClient::_error(int8_t err) { void AsyncClient::_error(int8_t err) {
if(_pcb){ if(_pcb){
TCP_MUTEX_LOCK();
tcp_arg(_pcb, NULL); tcp_arg(_pcb, NULL);
if(_pcb->state == LISTEN) { if(_pcb->state == LISTEN) {
tcp_sent(_pcb, NULL); tcp_sent(_pcb, NULL);
@@ -872,6 +892,7 @@ void AsyncClient::_error(int8_t err) {
tcp_err(_pcb, NULL); tcp_err(_pcb, NULL);
tcp_poll(_pcb, NULL, 0); tcp_poll(_pcb, NULL, 0);
} }
TCP_MUTEX_UNLOCK();
_pcb = NULL; _pcb = NULL;
} }
if(_error_cb) { if(_error_cb) {
@@ -1274,12 +1295,14 @@ void AsyncServer::begin(){
return; return;
} }
int8_t err; int8_t err;
TCP_MUTEX_LOCK();
_pcb = tcp_new_ip_type(IPADDR_TYPE_V4); _pcb = tcp_new_ip_type(IPADDR_TYPE_V4);
if (!_pcb){ if (!_pcb){
log_e("_pcb == NULL"); log_e("_pcb == NULL");
TCP_MUTEX_UNLOCK();
return; return;
} }
TCP_MUTEX_UNLOCK();
ip_addr_t local_addr; ip_addr_t local_addr;
local_addr.type = IPADDR_TYPE_V4; local_addr.type = IPADDR_TYPE_V4;
local_addr.u_addr.ip4.addr = (uint32_t) _addr; local_addr.u_addr.ip4.addr = (uint32_t) _addr;
@@ -1297,17 +1320,21 @@ void AsyncServer::begin(){
log_e("listen_pcb == NULL"); log_e("listen_pcb == NULL");
return; return;
} }
TCP_MUTEX_LOCK();
tcp_arg(_pcb, (void*) this); tcp_arg(_pcb, (void*) this);
tcp_accept(_pcb, &_s_accept); tcp_accept(_pcb, &_s_accept);
TCP_MUTEX_UNLOCK();
} }
void AsyncServer::end(){ void AsyncServer::end(){
if(_pcb){ if(_pcb){
TCP_MUTEX_LOCK();
tcp_arg(_pcb, NULL); tcp_arg(_pcb, NULL);
tcp_accept(_pcb, NULL); tcp_accept(_pcb, NULL);
if(tcp_close(_pcb) != ERR_OK){ if(tcp_close(_pcb) != ERR_OK){
_tcp_abort(_pcb, -1); _tcp_abort(_pcb, -1);
} }
TCP_MUTEX_UNLOCK();
_pcb = NULL; _pcb = NULL;
} }
} }

View File

@@ -7,6 +7,10 @@
#ifdef ESP32 #ifdef ESP32
#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 1, 0)
#define pxCurrentTCB pxCurrentTCBs
#endif
// This is the ESP32 version of the Sync Lock, using the FreeRTOS Semaphore // This is the ESP32 version of the Sync Lock, using the FreeRTOS Semaphore
class AsyncWebLock class AsyncWebLock
{ {

View File

@@ -59,7 +59,6 @@ void Config::init() {
if (store.config_set != 4262) { if (store.config_set != 4262) {
setDefaults(); setDefaults();
eepromWrite(EEPROM_START, store);
} }
if(store.version>CONFIG_VERSION) store.version=1; if(store.version>CONFIG_VERSION) store.version=1;
while(store.version!=CONFIG_VERSION) _setupVersion(); while(store.version!=CONFIG_VERSION) _setupVersion();
@@ -285,7 +284,6 @@ template <class T> int Config::eepromRead(int ee, T& value) {
void Config::reset(){ void Config::reset(){
setDefaults(); setDefaults();
eepromWrite(EEPROM_START, store);
delay(500); delay(500);
ESP.restart(); ESP.restart();
} }
@@ -341,6 +339,7 @@ void Config::setDefaults() {
store.forcemono = false; store.forcemono = false;
store.i2sinternal = false; store.i2sinternal = false;
store.rotate90 = false; store.rotate90 = false;
eepromWrite(EEPROM_START, store);
} }
void Config::setTimezone(int8_t tzh, int8_t tzm) { void Config::setTimezone(int8_t tzh, int8_t tzm) {

View File

@@ -250,7 +250,8 @@ class Config {
if (strcmp(field, value) == 0 && !force) return; if (strcmp(field, value) == 0 && !force) return;
strlcpy(field, value, N); strlcpy(field, value, N);
size_t address = getAddr(field); size_t address = getAddr(field);
for (size_t i = 0; i <= strlen(field); i++) EEPROM.write(address + i, field[i]); size_t fieldlen = strlen(field);
for (size_t i = 0; i <=fieldlen ; i++) EEPROM.write(address + i, field[i]);
if(commit) if(commit)
EEPROM.commit(); EEPROM.commit();
} }

View File

@@ -840,6 +840,18 @@ void handleHTTPArgs(AsyncWebServerRequest * request) {
if (request->hasArg("next")) { player.next(); commandFound=true; } if (request->hasArg("next")) { player.next(); commandFound=true; }
if (request->hasArg("volm")) { player.stepVol(false); commandFound=true; } if (request->hasArg("volm")) { player.stepVol(false); commandFound=true; }
if (request->hasArg("volp")) { player.stepVol(true); commandFound=true; } if (request->hasArg("volp")) { player.stepVol(true); commandFound=true; }
#ifdef USE_SD
if (request->hasArg("mode")) {
AsyncWebParameter* p = request->getParam("mode");
int mm = atoi(p->value().c_str());
if(mm>2) mm=0;
if(mm==2)
config.changeMode();
else
config.changeMode(mm);
commandFound=true;
}
#endif
if (request->hasArg("reset")) { request->redirect("/"); request->send(200); config.reset(); return; } if (request->hasArg("reset")) { request->redirect("/"); request->send(200); config.reset(); return; }
if (request->hasArg("trebble") && request->hasArg("middle") && request->hasArg("bass")) { if (request->hasArg("trebble") && request->hasArg("middle") && request->hasArg("bass")) {
AsyncWebParameter* pt = request->getParam("trebble", request->method() == HTTP_POST); AsyncWebParameter* pt = request->getParam("trebble", request->method() == HTTP_POST);

View File

@@ -50,9 +50,11 @@ void ticks() {
} }
} }
#if RTCSUPPORTED #if RTCSUPPORTED
if(config.isRTCFound()){
rtc.getTime(&network.timeinfo); rtc.getTime(&network.timeinfo);
mktime(&network.timeinfo); mktime(&network.timeinfo);
display.putRequest(CLOCK); display.putRequest(CLOCK);
}
#else #else
if(network.timeinfo.tm_year>100 || network.status == SDREADY) { if(network.timeinfo.tm_year>100 || network.status == SDREADY) {
network.timeinfo.tm_sec++; network.timeinfo.tm_sec++;
@@ -185,9 +187,11 @@ void MyNetwork::begin() {
if(REAL_LEDBUILTIN!=255) digitalWrite(REAL_LEDBUILTIN, LOW); if(REAL_LEDBUILTIN!=255) digitalWrite(REAL_LEDBUILTIN, LOW);
#if RTCSUPPORTED #if RTCSUPPORTED
if(config.isRTCFound()){
rtc.getTime(&network.timeinfo); rtc.getTime(&network.timeinfo);
mktime(&network.timeinfo); mktime(&network.timeinfo);
display.putRequest(CLOCK); display.putRequest(CLOCK);
}
#endif #endif
ctimer.attach(1, ticks); ctimer.attach(1, ticks);
if (network_on_connect) network_on_connect(); if (network_on_connect) network_on_connect();

View File

@@ -1,7 +1,7 @@
#ifndef options_h #ifndef options_h
#define options_h #define options_h
#define YOVERSION "0.9.375" #define YOVERSION "0.9.380"
/******************************************************* /*******************************************************
DO NOT EDIT THIS FILE. DO NOT EDIT THIS FILE.

View File

@@ -296,6 +296,17 @@ void Telnet::on_input(const char* str, uint8_t clientId) {
player.sendCommand({PR_PLAY, (uint16_t)sb}); player.sendCommand({PR_PLAY, (uint16_t)sb});
return; return;
} }
#ifdef USE_SD
int mm;
if (sscanf(str, "mode %d", &mm) == 1 ) {
if (mm > 2) mm = 0;
if(mm==2)
config.changeMode();
else
config.changeMode(mm);
return;
}
#endif
if (strcmp(str, "sys.tzo") == 0 || strcmp(str, "tzo") == 0) { if (strcmp(str, "sys.tzo") == 0 || strcmp(str, "tzo") == 0) {
printf(clientId, "##SYS.TZO#: %d:%d\n> ", config.store.tzHour, config.store.tzMin); printf(clientId, "##SYS.TZO#: %d:%d\n> ", config.store.tzHour, config.store.tzMin);
return; return;