used mdns as camera name for prusa connect

pull/32/head v1.0.2-rc2
Miroslav Pivovarsky 2024-05-16 22:42:52 +02:00
parent 532ed3e46f
commit 85ac1c9806
5 changed files with 18 additions and 14 deletions

View File

@ -330,7 +330,7 @@ const char page_system_html[] PROGMEM = R"rawliteral(
<tr><td class="ps1">Available software update</td><td class="ps2"><span id="sw_new_ver"></span> <span class="underlined-text" onclick="checkUpdate()">Check update from cloud</span></td></tr> <tr><td class="ps1">Available software update</td><td class="ps2"><span id="sw_new_ver"></span> <span class="underlined-text" onclick="checkUpdate()">Check update from cloud</span></td></tr>
<tr><td style="height: 1px;"></td><td style="height: 1px;"></td></tr> <tr><td style="height: 1px;"></td><td style="height: 1px;"></td></tr>
<tr><td class="ps3">System configuration</td><td></td></tr> <tr><td class="ps3">System configuration</td><td></td></tr>
<tr><td class="pc1">mDNS record</td><td ><input type="text" name="mdns" id=mdnsid ><span class=pc1>.local</span>&nbsp;<button class="btn_save" onclick="changeValue(document.getElementById('mdnsid').value, 'set_mdns?mdns=', 'system')">Save</button></td></tr> <tr><td class="pc1">Cam name & mDNS record</td><td ><input type="text" name="mdns" id=mdnsid ><span class=pc1>.local</span>&nbsp;<button class="btn_save" onclick="changeValue(document.getElementById('mdnsid').value, 'set_mdns?mdns=', 'system')">Save</button></td></tr>
<tr> <tr>
<td class="pc1">Log level</td><td><label for="loglevel"></label> <td class="pc1">Log level</td><td><label for="loglevel"></label>
<select class="select" id="loglevelid" name="loglevel" onchange="changeValue(this.value, 'set_int?log_level=', 'system')"> <select class="select" id="loglevelid" name="loglevel" onchange="changeValue(this.value, 'set_int?log_level=', 'system')">

View File

@ -11,7 +11,7 @@
#include "connect.h" #include "connect.h"
PrusaConnect Connect(&SystemConfig, &SystemLog, &SystemCamera); PrusaConnect Connect(&SystemConfig, &SystemLog, &SystemCamera, &SystemWifiMngt);
/** /**
* @brief Constructor for PrusaConnect class * @brief Constructor for PrusaConnect class
@ -20,10 +20,11 @@ PrusaConnect Connect(&SystemConfig, &SystemLog, &SystemCamera);
* @param Logs* - pointer to Logs class * @param Logs* - pointer to Logs class
* @param Camera* - pointer to Camera class * @param Camera* - pointer to Camera class
*/ */
PrusaConnect::PrusaConnect(Configuration *i_conf, Logs *i_log, Camera *i_camera) { PrusaConnect::PrusaConnect(Configuration *i_conf, Logs *i_log, Camera *i_camera, WiFiMngt *i_wifi) {
config = i_conf; config = i_conf;
log = i_log; log = i_log;
camera = i_camera; camera = i_camera;
wifi = i_wifi;
BackendAvailability = WaitForFirstConnection; BackendAvailability = WaitForFirstConnection;
SendDeviceInformationToBackend = true; SendDeviceInformationToBackend = true;
} }
@ -36,8 +37,6 @@ PrusaConnect::PrusaConnect(Configuration *i_conf, Logs *i_log, Camera *i_camera)
*/ */
void PrusaConnect::Init() { void PrusaConnect::Init() {
log->AddEvent(LogLevel_Info, F("Init PrusaConnect lib")); log->AddEvent(LogLevel_Info, F("Init PrusaConnect lib"));
//camera->CapturePhoto();
//camera->CaptureReturnFrameBuffer();
} }
/** /**
@ -121,7 +120,7 @@ bool PrusaConnect::SendDataToBackend(String *i_data, int i_data_length, String i
size_t sendet_data = 0; size_t sendet_data = 0;
/* sending photo */ /* sending photo */
if (SendPhoto == i_data_type) { if (SendPhoto == i_data_type) {
log->AddEvent(LogLevel_Verbose, F("Send data photo")); log->AddEvent(LogLevel_Verbose, F("Sendig photo"));
/* sending photo */ /* sending photo */
uint8_t *fbBuf = camera->GetPhotoFb()->buf; uint8_t *fbBuf = camera->GetPhotoFb()->buf;
@ -136,18 +135,17 @@ bool PrusaConnect::SendDataToBackend(String *i_data, int i_data_length, String i
sendet_data += client.write(fbBuf, remainder); sendet_data += client.write(fbBuf, remainder);
} }
} }
client.println("\r\n"); client.println("\r\n");
client.flush(); client.flush();
log->AddEvent(LogLevel_Verbose, String(i_data_length) + "/" + String(sendet_data));
/* sending device information */ /* sending device information */
} else if (SendInfo == i_data_type) { } else if (SendInfo == i_data_type) {
log->AddEvent(LogLevel_Verbose, F("Send data info")); log->AddEvent(LogLevel_Verbose, F("Sending info"));
sendet_data = client.print(*i_data); sendet_data = client.print(*i_data);
client.flush();
} }
log->AddEvent(LogLevel_Info, "Send done: " + String(sendet_data) + " bytes"); log->AddEvent(LogLevel_Info, "Send done: " + String(i_data_length) + "/" + String(sendet_data) + " bytes");
esp_task_wdt_reset(); esp_task_wdt_reset();
/* read response from server */ /* read response from server */
@ -203,7 +201,6 @@ void PrusaConnect::SendPhotoToBackend() {
log->AddEvent(LogLevel_Info, F("Start sending photo to prusaconnect")); log->AddEvent(LogLevel_Info, F("Start sending photo to prusaconnect"));
String Photo = ""; String Photo = "";
SendDataToBackend(&Photo, camera->GetPhotoFb()->len, "image/jpg", "Photo", HOST_URL_CAM_PATH, SendPhoto); SendDataToBackend(&Photo, camera->GetPhotoFb()->len, "image/jpg", "Photo", HOST_URL_CAM_PATH, SendPhoto);
SystemLog.AddEvent(LogLevel_Info, "Free RAM: " + String(ESP.getFreeHeap()) + " bytes");
} }
/** /**
@ -221,7 +218,7 @@ void PrusaConnect::SendInfoToBackend() {
String json_string = ""; String json_string = "";
JsonObject config = json_data["config"].to<JsonObject>(); JsonObject config = json_data["config"].to<JsonObject>();
config["name"] = "ESP32-CAM"; config["name"] = wifi->GetMdns();
JsonObject resolution = config["resolution"].to<JsonObject>(); JsonObject resolution = config["resolution"].to<JsonObject>();
resolution["width"] = SystemCamera.GetFrameSizeWidth(); resolution["width"] = SystemCamera.GetFrameSizeWidth();

View File

@ -27,6 +27,8 @@
#include "Certificate.h" #include "Certificate.h"
#include "server.h" #include "server.h"
class WiFiMngt;
/** /**
* @brief BackendAvailabilitStatus enum * @brief BackendAvailabilitStatus enum
* status of backend availability * status of backend availability
@ -61,11 +63,12 @@ private:
Configuration *config; ///< pointer to configuration object Configuration *config; ///< pointer to configuration object
Logs *log; ///< pointer to logs object Logs *log; ///< pointer to logs object
Camera *camera; ///< pointer to camera object Camera *camera; ///< pointer to camera object
WiFiMngt *wifi; ///< pointer to wifi object
bool SendDataToBackend(String *, int, String, String, String, SendDataToBackendType); bool SendDataToBackend(String *, int, String, String, String, SendDataToBackendType);
public: public:
PrusaConnect(Configuration*, Logs*, Camera*); PrusaConnect(Configuration*, Logs*, Camera*, WiFiMngt*);
~PrusaConnect(){}; ~PrusaConnect(){};
void Init(); void Init();

View File

@ -42,6 +42,10 @@ void WiFiMngt_WiFiEventApStaDisconnected(WiFiEvent_t , WiFiEventInfo_t);
void WiFiMngt_WiFiEventApStaIpAssigned(WiFiEvent_t , WiFiEventInfo_t); void WiFiMngt_WiFiEventApStaIpAssigned(WiFiEvent_t , WiFiEventInfo_t);
void WiFiMngt_WiFiEventApStaProbeReqRecved(WiFiEvent_t , WiFiEventInfo_t); void WiFiMngt_WiFiEventApStaProbeReqRecved(WiFiEvent_t , WiFiEventInfo_t);
/**
* @brief NetworkIpMethod_enum
* method for obtaining IP address
*/
enum NetworkIpMethod_enum { enum NetworkIpMethod_enum {
NetworkIpMethodDhcp = 0, ///< DHCP IP NetworkIpMethodDhcp = 0, ///< DHCP IP
NetworkIpMethodStatic = 1, ///< STATIC IP NetworkIpMethodStatic = 1, ///< STATIC IP

View File

@ -13,7 +13,7 @@
<tr><td class="ps1">Available software update</td><td class="ps2"><span id="sw_new_ver"></span> <span class="underlined-text" onclick="checkUpdate()">Check update from cloud</span></td></tr> <tr><td class="ps1">Available software update</td><td class="ps2"><span id="sw_new_ver"></span> <span class="underlined-text" onclick="checkUpdate()">Check update from cloud</span></td></tr>
<tr><td style="height: 1px;"></td><td style="height: 1px;"></td></tr> <tr><td style="height: 1px;"></td><td style="height: 1px;"></td></tr>
<tr><td class="ps3">System configuration</td><td></td></tr> <tr><td class="ps3">System configuration</td><td></td></tr>
<tr><td class="pc1">mDNS record</td><td ><input type="text" name="mdns" id=mdnsid ><span class=pc1>.local</span>&nbsp;<button class="btn_save" onclick="changeValue(document.getElementById('mdnsid').value, 'set_mdns?mdns=', 'system')">Save</button></td></tr> <tr><td class="pc1">Cam name & mDNS record</td><td ><input type="text" name="mdns" id=mdnsid ><span class=pc1>.local</span>&nbsp;<button class="btn_save" onclick="changeValue(document.getElementById('mdnsid').value, 'set_mdns?mdns=', 'system')">Save</button></td></tr>
<tr> <tr>
<td class="pc1">Log level</td><td><label for="loglevel"></label> <td class="pc1">Log level</td><td><label for="loglevel"></label>
<select class="select" id="loglevelid" name="loglevel" onchange="changeValue(this.value, 'set_int?log_level=', 'system')"> <select class="select" id="loglevelid" name="loglevel" onchange="changeValue(this.value, 'set_int?log_level=', 'system')">