Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions esp/speaker-netsender/components/netsender/netsender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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<short>(number);
ESP_LOGI(TAG, "monPeriod changed: %d", this->config.monPeriod);
changed = true;
Expand Down
7 changes: 6 additions & 1 deletion esp/speaker-netsender/components/pipi/pipi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <unistd.h>

#include "esp_err.h"
#include "esp_log.h"

// Logging Tag.
static constexpr auto TAG = "Pipi";
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions esp/speaker-netsender/components/tas5805/tas5805.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint16_t>(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.
Expand Down
4 changes: 4 additions & 0 deletions esp/speaker-netsender/main/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ esp_err_t init_log_queue()
static std::optional<std::vector<uint8_t>> 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);
Expand Down
Loading