From 079378a22c5903df5e8d95bc5a947e1b2618412b Mon Sep 17 00:00:00 2001 From: Miroslav Pivovarsky Date: Fri, 19 Apr 2024 16:02:14 +0200 Subject: [PATCH] Updated serial communication and readme.md --- ESP32_PrusaConnectCam/serial_cfg.cpp | 30 +++++++++++++++++++--------- README.md | 26 ++++++++++++++++++++---- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/ESP32_PrusaConnectCam/serial_cfg.cpp b/ESP32_PrusaConnectCam/serial_cfg.cpp index 129ccce..c0258fc 100644 --- a/ESP32_PrusaConnectCam/serial_cfg.cpp +++ b/ESP32_PrusaConnectCam/serial_cfg.cpp @@ -39,13 +39,18 @@ void SerialCfg::ProcessIncommingData() { while (Serial.available() > 0) { char incomingChar = Serial.read(); +#if (CONSOLE_VERBOSE_DEBUG == true) + Serial.print("0x"); + Serial.print(incomingChar, HEX); + Serial.print(" "); +#endif - if (incomingChar == '\n') { - // Ak nájdeme nový riadok, spracujeme prikaz - ParseIncommingData(inputBuffer); - inputBuffer = ""; // Vynulujeme buffer pre ďalší príkaz + if ((incomingChar == '\n') || (incomingChar == '\r')) { + if (inputBuffer.length() > 1) { + ParseIncommingData(inputBuffer); + } + inputBuffer = ""; } else { - // Inak pridáme znak do bufferu inputBuffer += incomingChar; } } @@ -57,23 +62,30 @@ void SerialCfg::ProcessIncommingData() { @return none */ void SerialCfg::ParseIncommingData(String command) { - /* check command */ +String lastTwoChars = command.substring(command.length() - 2); + + /* remove end of line symbol */ + while (!command.isEmpty() && ((command.endsWith("\r") || command.endsWith("\n")))) { + command.remove(command.length() - 1); + } + + /* check command */ if (command.startsWith("setwifissid:") && command.endsWith(";")) { /* remove prefix "setwifissid:" and end of command symbol ";" */ - wifi_ssid = command.substring(12, command.length() - 1); + wifi_ssid = command.substring(12, command.length() -1); log->AddEvent(LogLevel_Info, "--> Console set WiFi SSID: " + wifi_ssid); wifim->SetStaSsid(wifi_ssid); } else if (command.startsWith("setwifipass:") && command.endsWith(";")) { /* remove prefix "setwifipass:" and end of command symbol ";" */ - wifi_pass = command.substring(12, command.length() - 1); + wifi_pass = command.substring(12, command.length() -1); log->AddEvent(LogLevel_Info, "--> Console set WiFi password: " + wifi_pass); wifim->SetStaPassword(wifi_pass); } else if (command.startsWith("setauthtoken:") && command.endsWith(";")) { /* remove prefix "setauthtoken:" and end of command symbol ";" */ - auth_token = command.substring(13, command.length() - 1); + auth_token = command.substring(13, command.length() -1); log->AddEvent(LogLevel_Info, "--> Console set auth TOKEN for backend: " + auth_token); connect->SetToken(auth_token); diff --git a/README.md b/README.md index 0027ee6..d224313 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ What we need for functionality - Power supply [here](#power_supply) - Debug logs [here](#logs) - Serial console configuration [here](#serial_cfg) +- Potential issue [here](#issue) ## ESP32-CAM AI-thinker board @@ -106,7 +107,8 @@ After the initial firmware upload to the MCU, it's necessary to disable this opt To upload the firmware on the MAC or Linux platform, you must use the console. First, ensure you have installed esptool for Python. You can find it on the manufacturer's website, ESPRESSIF, [here](https://docs.espressif.com/projects/esp-at/en/latest/esp32/Get_Started/Downloading_guide.html). -And command for FLASH FW is here, where **/dev/ttya0** is your serial interface for communication with the ESP32-cam board. +And command for FLASH FW is here, where **/dev/ttya0** is your serial interface for communication with the ESP32-cam board. This is command for first flash FW to MCU. + ``` python3 -m esptool -p /dev/ttya0 -b 460800 --before default_reset --after hard_reset --chip esp32 write_flash --erase-all --flash_mode dio --flash_size 4MB --flash_freq 80m 0x1000 @@ -114,6 +116,17 @@ ESP32_PrusaConnectCam_web.ino.bootloader.bin 0x8000 ESP32_PrusaConnectCam_web.ino.partitions.bin 0x10000 ESP32_PrusaConnectCam_web.ino.bin ``` +This command contains the parameter **--eras-all**, which erases the entire flash in the MCU. So, for just updating the firmware, it is necessary to remove the parameter **--eras-all**; otherwise, the MCU configuration will also be deleted. The basic command list can be found [here](https://docs.espressif.com/projects/esptool/en/latest/esp32s3/esptool/basic-commands.html) + +Here is the command for updating the firmware in the MCU without erasing the MCU configuration + +``` +python3 -m esptool -p /dev/ttya0 -b 460800 --before default_reset --after hard_reset --chip +esp32 write_flash --flash_mode dio --flash_size 4MB --flash_freq 80m 0x1000 +ESP32_PrusaConnectCam_web.ino.bootloader.bin 0x8000 +ESP32_PrusaConnectCam_web.ino.partitions.bin 0x10000 ESP32_PrusaConnectCam_web.ino.bin +``` + Here is the partitions table: | Name | Type | SubType | Offset | Size | Flags | @@ -227,9 +240,9 @@ Currently is possible set the basicaly camera configuration during serial consol Commands for configuration have simple syntax -| command | separator | variable | termination | line terminator | -|--------------|-----------|-----------|-------------|-----------------| -| setwifissid | : | SSID | ; | \n | +| command | separator | variable | termination | line terminator | +|--------------|-----------|-----------|-------------|--------------------------| +| setwifissid | : | SSID | ; | \n or \r or \n\r or \r\n | Currently available commands are listed in the table below: @@ -253,3 +266,8 @@ Standard commands sequence for camera basic settings is - wificonnect; - setauthtoken:TOKEN; - mcureboot; + + +## Potential issue + +- A potential issue may arise with connecting to the service AP. If the connection fails and an authentication error occurs, it is necessary to clear the FLASH memory of the processor, and FLASH FW again. This can be done either through the Arduino IDE or using official software.