Skip to content

Commit

Permalink
used mdns as camera name for prusa connect
Browse files Browse the repository at this point in the history
  • Loading branch information
johnyHV committed May 16, 2024
1 parent 532ed3e commit 85ac1c9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion ESP32_PrusaConnectCam/WebPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 style="height: 1px;"></td><td style="height: 1px;"></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>
<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')">
Expand Down
19 changes: 8 additions & 11 deletions ESP32_PrusaConnectCam/connect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "connect.h"

PrusaConnect Connect(&SystemConfig, &SystemLog, &SystemCamera);
PrusaConnect Connect(&SystemConfig, &SystemLog, &SystemCamera, &SystemWifiMngt);

/**
* @brief Constructor for PrusaConnect class
Expand All @@ -20,10 +20,11 @@ PrusaConnect Connect(&SystemConfig, &SystemLog, &SystemCamera);
* @param Logs* - pointer to Logs 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;
log = i_log;
camera = i_camera;
wifi = i_wifi;
BackendAvailability = WaitForFirstConnection;
SendDeviceInformationToBackend = true;
}
Expand All @@ -36,8 +37,6 @@ PrusaConnect::PrusaConnect(Configuration *i_conf, Logs *i_log, Camera *i_camera)
*/
void PrusaConnect::Init() {
log->AddEvent(LogLevel_Info, F("Init PrusaConnect lib"));
//camera->CapturePhoto();
//camera->CaptureReturnFrameBuffer();
}

/**
Expand Down Expand Up @@ -121,7 +120,7 @@ bool PrusaConnect::SendDataToBackend(String *i_data, int i_data_length, String i
size_t sendet_data = 0;
/* sending photo */
if (SendPhoto == i_data_type) {
log->AddEvent(LogLevel_Verbose, F("Send data photo"));
log->AddEvent(LogLevel_Verbose, F("Sendig photo"));

/* sending photo */
uint8_t *fbBuf = camera->GetPhotoFb()->buf;
Expand All @@ -136,18 +135,17 @@ bool PrusaConnect::SendDataToBackend(String *i_data, int i_data_length, String i
sendet_data += client.write(fbBuf, remainder);
}
}

client.println("\r\n");
client.flush();
log->AddEvent(LogLevel_Verbose, String(i_data_length) + "/" + String(sendet_data));

/* sending device information */
} 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);
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();

/* read response from server */
Expand Down Expand Up @@ -203,7 +201,6 @@ void PrusaConnect::SendPhotoToBackend() {
log->AddEvent(LogLevel_Info, F("Start sending photo to prusaconnect"));
String Photo = "";
SendDataToBackend(&Photo, camera->GetPhotoFb()->len, "image/jpg", "Photo", HOST_URL_CAM_PATH, SendPhoto);
SystemLog.AddEvent(LogLevel_Info, "Free RAM: " + String(ESP.getFreeHeap()) + " bytes");
}

/**
Expand All @@ -221,7 +218,7 @@ void PrusaConnect::SendInfoToBackend() {
String json_string = "";

JsonObject config = json_data["config"].to<JsonObject>();
config["name"] = "ESP32-CAM";
config["name"] = wifi->GetMdns();

JsonObject resolution = config["resolution"].to<JsonObject>();
resolution["width"] = SystemCamera.GetFrameSizeWidth();
Expand Down
5 changes: 4 additions & 1 deletion ESP32_PrusaConnectCam/connect.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "Certificate.h"
#include "server.h"

class WiFiMngt;

/**
* @brief BackendAvailabilitStatus enum
* status of backend availability
Expand Down Expand Up @@ -61,11 +63,12 @@ class PrusaConnect {
Configuration *config; ///< pointer to configuration object
Logs *log; ///< pointer to logs object
Camera *camera; ///< pointer to camera object
WiFiMngt *wifi; ///< pointer to wifi object

bool SendDataToBackend(String *, int, String, String, String, SendDataToBackendType);

public:
PrusaConnect(Configuration*, Logs*, Camera*);
PrusaConnect(Configuration*, Logs*, Camera*, WiFiMngt*);
~PrusaConnect(){};

void Init();
Expand Down
4 changes: 4 additions & 0 deletions ESP32_PrusaConnectCam/wifi_mngt.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ void WiFiMngt_WiFiEventApStaDisconnected(WiFiEvent_t , WiFiEventInfo_t);
void WiFiMngt_WiFiEventApStaIpAssigned(WiFiEvent_t , WiFiEventInfo_t);
void WiFiMngt_WiFiEventApStaProbeReqRecved(WiFiEvent_t , WiFiEventInfo_t);

/**
* @brief NetworkIpMethod_enum
* method for obtaining IP address
*/
enum NetworkIpMethod_enum {
NetworkIpMethodDhcp = 0, ///< DHCP IP
NetworkIpMethodStatic = 1, ///< STATIC IP
Expand Down
2 changes: 1 addition & 1 deletion webpage/page_system.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 style="height: 1px;"></td><td style="height: 1px;"></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>
<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')">
Expand Down

0 comments on commit 85ac1c9

Please sign in to comment.