Implemented WEB server control during photo upload, fixed MCU startup issue, and added jQuery source file.

pull/1/head
Miroslav Pivovarsky 2024-04-22 23:00:21 +02:00
parent 079378a22c
commit ebb0e41e5f
10 changed files with 117 additions and 5 deletions

View File

@ -37,6 +37,7 @@ void Configuration::Init() {
Log->AddEvent(LogLevel_Warning, "First MCU start! Set factory cfg");
DefaultCfg();
SaveFirstMcuStartFlag(CFG_FIRST_MCU_START_NAK);
Log->SetLogLevel(LoadLogLevel());
}
/* set reset pin */
@ -1062,6 +1063,23 @@ uint8_t Configuration::LoadAgcGain() {
return ret;
}
/**
* @brief Load log level from EEPROM
*
* @return LogLevel_enum - log level
*/
LogLevel_enum Configuration::LoadLogLevel() {
LogLevel_enum ret = (LogLevel_enum) EEPROM.read(EEPROM_ADDR_LOG_LEVEL);
Log->AddEvent(LogLevel_Info, "LogLevel: " + String(ret));
return ret;
}
/**
* @brief Load PrusaConnect hostname from EEPROM
*
* @return String - hostname
*/
String Configuration::LoadPrusaConnectHostname() {
Log->AddEvent(LogLevel_Info, "PrusaConnect hostname: ", false);
String ret = LoadString(EEPROM_ADDR_HOSTNAME_START, EEPROM_ADDR_HOSTNAME_LENGTH, true);

View File

@ -97,6 +97,7 @@ public:
uint16_t LoadAecValue();
bool LoadGainCtrl();
uint8_t LoadAgcGain();
LogLevel_enum LoadLogLevel();
String LoadPrusaConnectHostname();
private:

View File

@ -76,6 +76,7 @@ void PrusaConnect::TakePicture() {
*/
bool PrusaConnect::SendDataToBackend(String *i_data, String i_content_type, String i_type, String i_url_path, bool i_fragmentation) {
WiFiClientSecure client;
Server_pause();
BackendReceivedStatus = "";
bool ret = false;
log->AddEvent(LogLevel_Info, "Sending " + i_type + " to PrusaConnect");
@ -83,6 +84,7 @@ bool PrusaConnect::SendDataToBackend(String *i_data, String i_content_type, Stri
/* check fingerprint and token length */
if ((Fingerprint.length() > 0) && (Token.length() > 0)) {
client.setCACert(root_CAs);
client.setTimeout(1000);
log->AddEvent(LogLevel_Verbose, "Connecting to server...");
/* connecting to server */
@ -167,6 +169,7 @@ bool PrusaConnect::SendDataToBackend(String *i_data, String i_content_type, Stri
}
log->AddEvent(LogLevel_Info, "Upload done. Response code: " + BackendReceivedStatus + " ,BA:" + CovertBackendAvailabilitStatusToString(BackendAvailability));
Server_resume();
return ret;
}
@ -459,4 +462,52 @@ String PrusaConnect::CovertBackendAvailabilitStatusToString(BackendAvailabilitSt
return ret;
}
/**
* @brief Increase sending interval counter
*
* @param none
* @return none
*/
void PrusaConnect::IncreaseSendingIntervalCounter() {
SendingIntervalCounter++;
}
/**
* @brief Set sending interval counter
*
* @param uint8_t i_data - counter
* @return none
*/
void PrusaConnect::SetSendingIntervalCounter(uint8_t i_data) {
SendingIntervalCounter = i_data;
}
void PrusaConnect::SetSendingIntervalExpired() {
SendingIntervalCounter = RefreshInterval;
}
/**
* @brief Get sending interval counter
*
* @return uint8_t - counter
*/
uint8_t PrusaConnect::GetSendingIntervalCounter() {
return SendingIntervalCounter;
}
/**
* @brief Check if sending interval is expired. and can I send the data to the backend. [seconds]
*
* @return true
* @return false
*/
bool PrusaConnect::CheckSendingIntervalExpired() {
bool ret = false;
if (SendingIntervalCounter >= RefreshInterval) {
ret = true;
}
return ret;
}
/* EOF */

View File

@ -25,6 +25,7 @@
#include "camera.h"
#include "cfg.h"
#include "Certificate.h"
#include "server.h"
/**
* @brief BackendAvailabilitStatus enum
@ -42,6 +43,7 @@ private:
String BackendReceivedStatus; ///< status of backend response
BackendAvailabilitStatus BackendAvailability; ///< status of backend availability
bool SendDeviceInformationToBackend; ///< flag for sending device information to backend
uint8_t SendingIntervalCounter; ///< counter for sending interval, represents seconds
String Token; ///< token for backend communication
String Fingerprint; ///< fingerprint for backend communication
@ -81,6 +83,12 @@ public:
String GetPrusaConnectHostname();
BackendAvailabilitStatus GetBackendAvailabilitStatus();
String CovertBackendAvailabilitStatusToString(BackendAvailabilitStatus);
void IncreaseSendingIntervalCounter();
void SetSendingIntervalCounter(uint8_t);
void SetSendingIntervalExpired();
uint8_t GetSendingIntervalCounter();
bool CheckSendingIntervalExpired();
};
extern PrusaConnect Connect; ///< PrusaConnect object

View File

@ -387,7 +387,7 @@ void Server_InitWebServer_Actions() {
SystemLog.AddEvent(LogLevel_Verbose, "WEB server: /action_send send photo to cloud");
if (Server_CheckBasicAuth(request) == false)
return;
Connect.SendPhotoToBackend();
Connect.SetSendingIntervalExpired();
request->send_P(200, "text/plain", "Send Photo");
});
@ -882,10 +882,35 @@ void Server_InitWebServer_Update() {
});
}
/**
@brief Init WEB server stream
@param none
@return none
*/
void Server_InitWebServer_Stream() {
server.on("/stream.mjpg", HTTP_GET, Server_streamJpg);
}
/**
@brief Pause WEB server
@param none
@return none
*/
void Server_pause() {
server.end();
SystemLog.AddEvent(LogLevel_Verbose, "WEB server: pause");
}
/**
@brief Resume WEB server
@param none
@return none
*/
void Server_resume() {
server.begin();
SystemLog.AddEvent(LogLevel_Verbose, "WEB server: resume");
}
/**
* @brief Handle cache request
*

View File

@ -50,6 +50,9 @@ void Server_InitWebServer_Sets();
void Server_InitWebServer_Update();
void Server_InitWebServer_Stream();
void Server_pause();
void Server_resume();
void Server_handleCacheRequest(AsyncWebServerRequest*, const char*, const char*);
void Server_handleNotFound(AsyncWebServerRequest *);
String Server_GetJsonData();

View File

@ -95,7 +95,9 @@ void System_UpdateInit() {
void System_Main() {
/* check new FW version */
if (false == FirmwareUpdate.CheckNewVersionAfterBoot) {
Server_pause();
System_CheckNewVersion();
Server_resume();
}
/* task for download and flash FW from server */
@ -494,11 +496,10 @@ void System_TaskMain(void *pvParameters) {
void System_TaskCaptureAndSendPhoto(void *pvParameters) {
SystemLog.AddEvent(LogLevel_Info, "Task photo processing. core: " + String(xPortGetCoreID()));
TickType_t xLastWakeTime = xTaskGetTickCount();
uint16_t SendingIntervalCounter = 0; ///< counter for sending interval
while (1) {
if (Connect.GetRefreshInterval() <= SendingIntervalCounter) {
SendingIntervalCounter = 0;
if (Connect.CheckSendingIntervalExpired()) {
Connect.SetSendingIntervalCounter(0);
/* send network information to backend */
if ((WL_CONNECTED == WiFi.status()) && (false == FirmwareUpdate.Processing)) {
esp_task_wdt_reset();
@ -513,7 +514,7 @@ void System_TaskCaptureAndSendPhoto(void *pvParameters) {
} else {
/* update counter */
SendingIntervalCounter++;
Connect.IncreaseSendingIntervalCounter();
}
SystemLog.AddEvent(LogLevel_Verbose, "Photo processing task. Stack free size: " + String(uxTaskGetStackHighWaterMark(NULL)) + " bytes");

View File

@ -88,6 +88,8 @@ void WiFiMngt::Init() {
} else {
log->AddEvent(LogLevel_Warning, "Wifi unavailable. Skip connecting to WiFi: " + WifiSsid);
}
} else {
ScanWiFiNetwork();
}
TaskAp_previousMillis = millis();

View File

@ -271,3 +271,4 @@ Standard commands sequence for camera basic settings is
## 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.
- While sending the photo to the backend, the WEB server is temporarily disabled for this short interval. After the photo is sent to the backend, the WEB server is re-enabled. This may cause short unavailability in the WEB server on the camera, lasting several seconds, depending on the internet connection and the quality of the WiFi connection

2
webpage/jquery-3.7.0.min.js vendored Normal file

File diff suppressed because one or more lines are too long