diff --git a/esp/speaker-netsender/components/netsender/netsender.cpp b/esp/speaker-netsender/components/netsender/netsender.cpp index 8269a63..2d6e4ea 100644 --- a/esp/speaker-netsender/components/netsender/netsender.cpp +++ b/esp/speaker-netsender/components/netsender/netsender.cpp @@ -67,6 +67,10 @@ static constexpr const auto MAX_URL_LEN = 256; static constexpr const auto STORAGE_NAMESPACE = "netsender"; static constexpr const auto CONFIG_NVS_KEY = "config"; +// Used when no monitoring period is configured, so an unconfigured device +// does not poll continuously. +static constexpr const auto RETRY_PERIOD = 5; + static constexpr const char *TAG = "netsender"; // Static definition of the netsender task stack. @@ -134,6 +138,11 @@ Netsender::Netsender() this->configured = true; } + // Avoid polling continuously if no monitoring period is stored. + if (this->config.monPeriod <= 0) { + this->config.monPeriod = RETRY_PERIOD; + } + // Initialise HTTP handler. ESP_ERROR_CHECK(init_http_handle()); } @@ -441,13 +450,13 @@ esp_err_t Netsender::req_config() // Parse the incoming config from the fixed response buffer. A single // buffer is large enough for every config field. - static_assert(NETSENDER_IO_SIZE >= NETSENDER_WIFI_SIZE, "config parameter buffer too small"); - char param[NETSENDER_IO_SIZE]; + constexpr auto PARAM_BUF_LEN = NETSENDER_IO_SIZE > NETSENDER_WIFI_SIZE ? NETSENDER_IO_SIZE : NETSENDER_WIFI_SIZE; + char param[PARAM_BUF_LEN]; int32_t number = 0; if (netsender_extract_json(resp_buf, "mp", param, sizeof(param)) && parse_int(param, number) && number != this->config.monPeriod) { - if (number >= 0 && number <= SHRT_MAX) { + if (number > 0 && number <= SHRT_MAX) { this->config.monPeriod = static_cast(number); ESP_LOGI(TAG, "monPeriod changed: %d", this->config.monPeriod); changed = true; diff --git a/esp/speaker-netsender/components/pipi/pipi.cpp b/esp/speaker-netsender/components/pipi/pipi.cpp index 023a175..a824b31 100644 --- a/esp/speaker-netsender/components/pipi/pipi.cpp +++ b/esp/speaker-netsender/components/pipi/pipi.cpp @@ -40,6 +40,7 @@ #include #include "esp_err.h" +#include "esp_log.h" // Logging Tag. static constexpr auto TAG = "Pipi"; @@ -207,7 +208,11 @@ esp_err_t Pipi::FileLogger::log(char *msg) int Pipi::FileLogger::get_logs() { - ESP_ERROR_CHECK(this->new_file()); + auto err = this->new_file(); + if (err != ESP_OK) { + ESP_LOGE(TAG, "unable to start new log file: %s", esp_err_to_name(err)); + return -1; + } return this->prev_file; } diff --git a/esp/speaker-netsender/components/tas5805/tas5805.cpp b/esp/speaker-netsender/components/tas5805/tas5805.cpp index 6820b4d..c1ce7d3 100644 --- a/esp/speaker-netsender/components/tas5805/tas5805.cpp +++ b/esp/speaker-netsender/components/tas5805/tas5805.cpp @@ -77,6 +77,8 @@ TAS5805::TAS5805(i2c_master_bus_handle_t i2c_bus_handle, i2s_chan_handle_t i2s_t .dev_addr_length = I2C_ADDR_BIT_LEN_7, .device_address = static_cast(CONFIG_AMP_I2C_ADDRESS), .scl_speed_hz = CONFIG_AMP_I2C_CLOCK_SPEED, + .scl_wait_us = 0, // Use the driver default timeout. + .flags = {}, }; // Add the device to the bus. diff --git a/esp/speaker-netsender/main/log.cpp b/esp/speaker-netsender/main/log.cpp index 3269539..b90f56e 100644 --- a/esp/speaker-netsender/main/log.cpp +++ b/esp/speaker-netsender/main/log.cpp @@ -114,6 +114,10 @@ esp_err_t init_log_queue() static std::optional> read_logs() { auto logs_fd = p->get_logs(); + if (logs_fd < 0) { + ESP_LOGE(TAG, "unable to open a log file for reading"); + return std::nullopt; + } if (::lseek(logs_fd, 0, SEEK_SET) == -1) { ESP_LOGE(TAG, "unable to seek logs: %s (%d)", strerror(errno), errno);