Merge branch 'fix/serial-manager-invalid-json' into beta

# Conflicts:
#	ESP/lib/src/io/Serial/SerialManager.cpp
#	ESP/lib/src/network/wifihandler/wifihandler.cpp
This commit is contained in:
lorow 2024-05-31 18:03:15 +02:00
commit 84cb556a71
2 changed files with 26 additions and 28 deletions

View File

@ -5,10 +5,6 @@ SerialManager::SerialManager(CommandManager* commandManager, ProjectConfig& proj
#ifdef ETVR_EYE_TRACKER_USB_API #ifdef ETVR_EYE_TRACKER_USB_API
void SerialManager::send_frame() { void SerialManager::send_frame() {
// if we failed to capture the frame, we bail, but we still want to listen to commands
if (err != ESP_OK)
return;
if (!last_frame) if (!last_frame)
last_frame = esp_timer_get_time(); last_frame = esp_timer_get_time();
@ -21,14 +17,17 @@ void SerialManager::send_frame() {
if (fb) { if (fb) {
len = fb->len; len = fb->len;
buf = fb->buf; buf = fb->buf;
} else { } else
log_e("Camera capture failed with response: %s", esp_err_to_name(err));
err = ESP_FAIL; err = ESP_FAIL;
// if we failed to capture the frame, we bail, but we still want to listen to
// commands
if (err != ESP_OK) {
log_e("Camera capture failed with response: %s", esp_err_to_name(err));
return;
} }
if (err == ESP_OK) Serial.write(ETVR_HEADER, 2);
Serial.write(ETVR_HEADER, 2);
Serial.write(ETVR_HEADER_FRAME, 2); Serial.write(ETVR_HEADER_FRAME, 2);
len_bytes[0] = len & 0xFF; len_bytes[0] = len & 0xFF;
len_bytes[1] = (len >> CHAR_BIT) & 0xFF; len_bytes[1] = (len >> CHAR_BIT) & 0xFF;
@ -54,7 +53,7 @@ void SerialManager::send_frame() {
void SerialManager::init() { void SerialManager::init() {
Serial.begin(3000000); Serial.begin(3000000);
if (SERIAL_FLUSH_ENABLED){ if (SERIAL_FLUSH_ENABLED) {
Serial.flush(); Serial.flush();
} }
} }
@ -64,7 +63,7 @@ void SerialManager::run() {
JsonDocument doc; JsonDocument doc;
std::string serial_data = Serial.readString().c_str(); std::string serial_data = Serial.readString().c_str();
DeserializationError deserializationError = deserializeJson(doc, serial_data); DeserializationError deserializationError = deserializeJson(doc, serial_data);
this->projectConfig.setDeviceConfig("test", "test", serial_data, "", 81, false); this->projectConfig.setDeviceConfig("test", "test", serial_data, "", 81, false);
this->projectConfig.deviceConfigSave(); this->projectConfig.deviceConfigSave();

View File

@ -18,14 +18,14 @@ WiFiHandler::WiFiHandler(ProjectConfig& configManager,
WiFiHandler::~WiFiHandler() {} WiFiHandler::~WiFiHandler() {}
void WiFiHandler::begin() { void WiFiHandler::begin() {
log_i("Starting WiFi Handler \n\r");
// just to be sure, we reeset everything before we do anything, some boards were having problems otherwise
// forcefully disconnect to reset anything that could've been saved before
WiFi.disconnect(); WiFi.disconnect();
// we purposefully set the lowest min required security level, some boards have problems connecting otherwise // we purposefully set the lowest min required security level, some boards have problems connecting otherwise
// https://github.com/espressif/arduino-esp32/issues/8770
WiFi.setMinSecurity(WIFI_AUTH_WEP); WiFi.setMinSecurity(WIFI_AUTH_WEP);
log_i("Starting WiFi Handler \n\r");
if (this->_enable_adhoc || if (this->_enable_adhoc ||
wifiStateManager.getCurrentState() == WiFiState_e::WiFiState_ADHOC) { wifiStateManager.getCurrentState() == WiFiState_e::WiFiState_ADHOC) {
log_d("ADHOC is enabled, setting up ADHOC network \n\r"); log_d("ADHOC is enabled, setting up ADHOC network \n\r");
@ -46,13 +46,11 @@ void WiFiHandler::begin() {
if (networks.empty()) { if (networks.empty()) {
log_i("No networks found in config, trying the default one \n\r"); log_i("No networks found in config, trying the default one \n\r");
// since networks may not have a password, we only need to check if we have an ssid
// bail if we don't
if (this->iniSTA( if (this->iniSTA(
this->ssid, this->ssid,
this->password, this->password,
this->channel, this->channel,
(wifi_power_t)txpower.power (wifi_power_t)txpower.power
) )
) { ) {
@ -141,10 +139,12 @@ bool WiFiHandler::iniSTA(const std::string& ssid,
const std::string& password, const std::string& password,
uint8_t channel, uint8_t channel,
wifi_power_t power) { wifi_power_t power) {
// since networks may not have a password, we only need to check if we have an ssid
// bail if we don't
if (ssid == ""){ if (ssid == ""){
log_d("ssid missing, bailing"); log_d("ssid missing, bailing");
return false; return false;
} }
unsigned long currentMillis = millis(); unsigned long currentMillis = millis();
@ -155,22 +155,22 @@ bool WiFiHandler::iniSTA(const std::string& ssid,
wifiStateManager.setState(WiFiState_e::WiFiState_Connecting); wifiStateManager.setState(WiFiState_e::WiFiState_Connecting);
log_i("Trying to connect to: %s with password: %s\n\r", ssid.c_str(), password.c_str()); log_i("Trying to connect to: %s with password: %s\n\r", ssid.c_str(), password.c_str());
auto mdnsConfig = configManager.getMDNSConfig(); auto mdnsConfig = configManager.getMDNSConfig();
log_d("Setting hostname %s \n\r");
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE,
INADDR_NONE); // need to call before setting hostname INADDR_NONE); // need to call before setting hostname
log_d("Setting hostname %s \n\r");
WiFi.setHostname(mdnsConfig.hostname.c_str()); WiFi.setHostname(mdnsConfig.hostname.c_str());
log_i("Setting TX power to: %d \n\r", (uint8_t)power);
WiFi.setTxPower(power); // https://github.com/espressif/arduino-esp32/issues/5698 WiFi.setTxPower(power); // https://github.com/espressif/arduino-esp32/issues/5698
WiFi.begin(ssid.c_str(), password.c_str(), channel); WiFi.begin(ssid.c_str(), password.c_str(), channel);
log_d("Waiting for WiFi to connect... \n\r"); log_d("Waiting for WiFi to connect... \n\r");
while (WiFi.status() != WL_CONNECTED) { while (WiFi.status() != WL_CONNECTED) {
progress++; progress++;
currentMillis = millis(); currentMillis = millis();
// log_i("."); // log_i(".");
// log_d("Progress: %d \n\r", progress); // log_d("Progress: %d \n\r", progress);
if ((currentMillis - startingMillis) >= connectionTimeout) { if ((currentMillis - startingMillis) >= connectionTimeout) {
wifiStateManager.setState(WiFiState_e::WiFiState_Error); wifiStateManager.setState(WiFiState_e::WiFiState_Error);
@ -193,7 +193,6 @@ bool WiFiHandler::iniSTA(const std::string& ssid,
} }
wifiStateManager.setState(WiFiState_e::WiFiState_Connected); wifiStateManager.setState(WiFiState_e::WiFiState_Connected);
log_i("Successfully connected to %s \n\r", ssid.c_str()); log_i("Successfully connected to %s \n\r", ssid.c_str());
log_i("Setting TX power to: %d \n\r", (uint8_t)power);
return true; return true;
} }