Implemented WEB server control during photo upload, fixed MCU startup issue, and added jQuery source file.
parent
079378a22c
commit
ebb0e41e5f
|
|
@ -37,6 +37,7 @@ void Configuration::Init() {
|
||||||
Log->AddEvent(LogLevel_Warning, "First MCU start! Set factory cfg");
|
Log->AddEvent(LogLevel_Warning, "First MCU start! Set factory cfg");
|
||||||
DefaultCfg();
|
DefaultCfg();
|
||||||
SaveFirstMcuStartFlag(CFG_FIRST_MCU_START_NAK);
|
SaveFirstMcuStartFlag(CFG_FIRST_MCU_START_NAK);
|
||||||
|
Log->SetLogLevel(LoadLogLevel());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set reset pin */
|
/* set reset pin */
|
||||||
|
|
@ -1062,6 +1063,23 @@ uint8_t Configuration::LoadAgcGain() {
|
||||||
return ret;
|
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() {
|
String Configuration::LoadPrusaConnectHostname() {
|
||||||
Log->AddEvent(LogLevel_Info, "PrusaConnect hostname: ", false);
|
Log->AddEvent(LogLevel_Info, "PrusaConnect hostname: ", false);
|
||||||
String ret = LoadString(EEPROM_ADDR_HOSTNAME_START, EEPROM_ADDR_HOSTNAME_LENGTH, true);
|
String ret = LoadString(EEPROM_ADDR_HOSTNAME_START, EEPROM_ADDR_HOSTNAME_LENGTH, true);
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,7 @@ public:
|
||||||
uint16_t LoadAecValue();
|
uint16_t LoadAecValue();
|
||||||
bool LoadGainCtrl();
|
bool LoadGainCtrl();
|
||||||
uint8_t LoadAgcGain();
|
uint8_t LoadAgcGain();
|
||||||
|
LogLevel_enum LoadLogLevel();
|
||||||
String LoadPrusaConnectHostname();
|
String LoadPrusaConnectHostname();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
bool PrusaConnect::SendDataToBackend(String *i_data, String i_content_type, String i_type, String i_url_path, bool i_fragmentation) {
|
||||||
WiFiClientSecure client;
|
WiFiClientSecure client;
|
||||||
|
Server_pause();
|
||||||
BackendReceivedStatus = "";
|
BackendReceivedStatus = "";
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
log->AddEvent(LogLevel_Info, "Sending " + i_type + " to PrusaConnect");
|
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 */
|
/* check fingerprint and token length */
|
||||||
if ((Fingerprint.length() > 0) && (Token.length() > 0)) {
|
if ((Fingerprint.length() > 0) && (Token.length() > 0)) {
|
||||||
client.setCACert(root_CAs);
|
client.setCACert(root_CAs);
|
||||||
|
client.setTimeout(1000);
|
||||||
log->AddEvent(LogLevel_Verbose, "Connecting to server...");
|
log->AddEvent(LogLevel_Verbose, "Connecting to server...");
|
||||||
|
|
||||||
/* 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));
|
log->AddEvent(LogLevel_Info, "Upload done. Response code: " + BackendReceivedStatus + " ,BA:" + CovertBackendAvailabilitStatusToString(BackendAvailability));
|
||||||
|
Server_resume();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -459,4 +462,52 @@ String PrusaConnect::CovertBackendAvailabilitStatusToString(BackendAvailabilitSt
|
||||||
return ret;
|
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 */
|
/* EOF */
|
||||||
|
|
@ -25,6 +25,7 @@
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
#include "cfg.h"
|
#include "cfg.h"
|
||||||
#include "Certificate.h"
|
#include "Certificate.h"
|
||||||
|
#include "server.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief BackendAvailabilitStatus enum
|
* @brief BackendAvailabilitStatus enum
|
||||||
|
|
@ -42,6 +43,7 @@ private:
|
||||||
String BackendReceivedStatus; ///< status of backend response
|
String BackendReceivedStatus; ///< status of backend response
|
||||||
BackendAvailabilitStatus BackendAvailability; ///< status of backend availability
|
BackendAvailabilitStatus BackendAvailability; ///< status of backend availability
|
||||||
bool SendDeviceInformationToBackend; ///< flag for sending device information to backend
|
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 Token; ///< token for backend communication
|
||||||
String Fingerprint; ///< fingerprint for backend communication
|
String Fingerprint; ///< fingerprint for backend communication
|
||||||
|
|
@ -81,6 +83,12 @@ public:
|
||||||
String GetPrusaConnectHostname();
|
String GetPrusaConnectHostname();
|
||||||
BackendAvailabilitStatus GetBackendAvailabilitStatus();
|
BackendAvailabilitStatus GetBackendAvailabilitStatus();
|
||||||
String CovertBackendAvailabilitStatusToString(BackendAvailabilitStatus);
|
String CovertBackendAvailabilitStatusToString(BackendAvailabilitStatus);
|
||||||
|
|
||||||
|
void IncreaseSendingIntervalCounter();
|
||||||
|
void SetSendingIntervalCounter(uint8_t);
|
||||||
|
void SetSendingIntervalExpired();
|
||||||
|
uint8_t GetSendingIntervalCounter();
|
||||||
|
bool CheckSendingIntervalExpired();
|
||||||
};
|
};
|
||||||
|
|
||||||
extern PrusaConnect Connect; ///< PrusaConnect object
|
extern PrusaConnect Connect; ///< PrusaConnect object
|
||||||
|
|
|
||||||
|
|
@ -387,7 +387,7 @@ void Server_InitWebServer_Actions() {
|
||||||
SystemLog.AddEvent(LogLevel_Verbose, "WEB server: /action_send send photo to cloud");
|
SystemLog.AddEvent(LogLevel_Verbose, "WEB server: /action_send send photo to cloud");
|
||||||
if (Server_CheckBasicAuth(request) == false)
|
if (Server_CheckBasicAuth(request) == false)
|
||||||
return;
|
return;
|
||||||
Connect.SendPhotoToBackend();
|
Connect.SetSendingIntervalExpired();
|
||||||
request->send_P(200, "text/plain", "Send Photo");
|
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() {
|
void Server_InitWebServer_Stream() {
|
||||||
server.on("/stream.mjpg", HTTP_GET, Server_streamJpg);
|
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
|
* @brief Handle cache request
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,9 @@ void Server_InitWebServer_Sets();
|
||||||
void Server_InitWebServer_Update();
|
void Server_InitWebServer_Update();
|
||||||
void Server_InitWebServer_Stream();
|
void Server_InitWebServer_Stream();
|
||||||
|
|
||||||
|
void Server_pause();
|
||||||
|
void Server_resume();
|
||||||
|
|
||||||
void Server_handleCacheRequest(AsyncWebServerRequest*, const char*, const char*);
|
void Server_handleCacheRequest(AsyncWebServerRequest*, const char*, const char*);
|
||||||
void Server_handleNotFound(AsyncWebServerRequest *);
|
void Server_handleNotFound(AsyncWebServerRequest *);
|
||||||
String Server_GetJsonData();
|
String Server_GetJsonData();
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,9 @@ void System_UpdateInit() {
|
||||||
void System_Main() {
|
void System_Main() {
|
||||||
/* check new FW version */
|
/* check new FW version */
|
||||||
if (false == FirmwareUpdate.CheckNewVersionAfterBoot) {
|
if (false == FirmwareUpdate.CheckNewVersionAfterBoot) {
|
||||||
|
Server_pause();
|
||||||
System_CheckNewVersion();
|
System_CheckNewVersion();
|
||||||
|
Server_resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* task for download and flash FW from server */
|
/* task for download and flash FW from server */
|
||||||
|
|
@ -494,11 +496,10 @@ void System_TaskMain(void *pvParameters) {
|
||||||
void System_TaskCaptureAndSendPhoto(void *pvParameters) {
|
void System_TaskCaptureAndSendPhoto(void *pvParameters) {
|
||||||
SystemLog.AddEvent(LogLevel_Info, "Task photo processing. core: " + String(xPortGetCoreID()));
|
SystemLog.AddEvent(LogLevel_Info, "Task photo processing. core: " + String(xPortGetCoreID()));
|
||||||
TickType_t xLastWakeTime = xTaskGetTickCount();
|
TickType_t xLastWakeTime = xTaskGetTickCount();
|
||||||
uint16_t SendingIntervalCounter = 0; ///< counter for sending interval
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (Connect.GetRefreshInterval() <= SendingIntervalCounter) {
|
if (Connect.CheckSendingIntervalExpired()) {
|
||||||
SendingIntervalCounter = 0;
|
Connect.SetSendingIntervalCounter(0);
|
||||||
/* send network information to backend */
|
/* send network information to backend */
|
||||||
if ((WL_CONNECTED == WiFi.status()) && (false == FirmwareUpdate.Processing)) {
|
if ((WL_CONNECTED == WiFi.status()) && (false == FirmwareUpdate.Processing)) {
|
||||||
esp_task_wdt_reset();
|
esp_task_wdt_reset();
|
||||||
|
|
@ -513,7 +514,7 @@ void System_TaskCaptureAndSendPhoto(void *pvParameters) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* update counter */
|
/* update counter */
|
||||||
SendingIntervalCounter++;
|
Connect.IncreaseSendingIntervalCounter();
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemLog.AddEvent(LogLevel_Verbose, "Photo processing task. Stack free size: " + String(uxTaskGetStackHighWaterMark(NULL)) + " bytes");
|
SystemLog.AddEvent(LogLevel_Verbose, "Photo processing task. Stack free size: " + String(uxTaskGetStackHighWaterMark(NULL)) + " bytes");
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,8 @@ void WiFiMngt::Init() {
|
||||||
} else {
|
} else {
|
||||||
log->AddEvent(LogLevel_Warning, "Wifi unavailable. Skip connecting to WiFi: " + WifiSsid);
|
log->AddEvent(LogLevel_Warning, "Wifi unavailable. Skip connecting to WiFi: " + WifiSsid);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
ScanWiFiNetwork();
|
||||||
}
|
}
|
||||||
TaskAp_previousMillis = millis();
|
TaskAp_previousMillis = millis();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -271,3 +271,4 @@ Standard commands sequence for camera basic settings is
|
||||||
## Potential issue
|
## 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.
|
- 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
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue