diff --git a/ESP32_PrusaConnectCam/ESP32_PrusaConnectCam.ino b/ESP32_PrusaConnectCam/ESP32_PrusaConnectCam.ino
index 57fc881..eb67852 100644
--- a/ESP32_PrusaConnectCam/ESP32_PrusaConnectCam.ino
+++ b/ESP32_PrusaConnectCam/ESP32_PrusaConnectCam.ino
@@ -114,12 +114,12 @@ void setup() {
SystemLog.AddEvent(LogLevel_Info, F("Start tasks"));
xTaskCreatePinnedToCore(System_TaskMain, "SystemNtpOtaUpdate", 8000, NULL, 1, &Task_SystemMain, 0); /*function, description, stack size, parameters, priority, task handle, core*/
xTaskCreatePinnedToCore(System_TaskCaptureAndSendPhoto, "CaptureAndSendPhoto", 6000, NULL, 2, &Task_CapturePhotoAndSend, 0); /*function, description, stack size, parameters, priority, task handle, core*/
- xTaskCreatePinnedToCore(System_TaskWifiManagement, "WiFiManagement", 2500, NULL, 3, &Task_WiFiManagement, 0); /*function, description, stack size, parameters, priority, task handle, core*/
- xTaskCreatePinnedToCore(System_TaskSdCardCheck, "CheckMicroSdCard", 2200, NULL, 4, &Task_SdCardCheck, 0); /*function, description, stack size, parameters, priority, task handle, core*/
- xTaskCreatePinnedToCore(System_TaskSerialCfg, "CheckSerialConfiguration", 2500, NULL, 5, &Task_SerialCfg, 0); /*function, description, stack size, parameters, priority, task handle, core*/
- xTaskCreatePinnedToCore(System_TaskStreamTelemetry, "PrintStreamTelemetry", 2500, NULL, 6, &Task_StreamTelemetry, 0); /*function, description, stack size, parameters, priority, task handle, core*/
- xTaskCreatePinnedToCore(System_TaskSysLed, "SystemLed", 2000, NULL, 7, &Task_SysLed, 0); /*function, description, stack size, parameters, priority, task handle, core*/
- xTaskCreatePinnedToCore(System_TaskWiFiWatchdog, "WiFiWatchdog", 2200, NULL, 8, &Task_WiFiWatchdog, 0); /*function, description, stack size, parameters, priority, task handle, core*/
+ xTaskCreatePinnedToCore(System_TaskWifiManagement, "WiFiManagement", 3800, NULL, 3, &Task_WiFiManagement, 0); /*function, description, stack size, parameters, priority, task handle, core*/
+ xTaskCreatePinnedToCore(System_TaskSdCardCheck, "CheckMicroSdCard", 3300, NULL, 4, &Task_SdCardCheck, 0); /*function, description, stack size, parameters, priority, task handle, core*/
+ xTaskCreatePinnedToCore(System_TaskSerialCfg, "CheckSerialConfiguration", 3300, NULL, 5, &Task_SerialCfg, 0); /*function, description, stack size, parameters, priority, task handle, core*/
+ xTaskCreatePinnedToCore(System_TaskStreamTelemetry, "PrintStreamTelemetry", 3300, NULL, 6, &Task_StreamTelemetry, 0); /*function, description, stack size, parameters, priority, task handle, core*/
+ xTaskCreatePinnedToCore(System_TaskSysLed, "SystemLed", 3000, NULL, 7, &Task_SysLed, 0); /*function, description, stack size, parameters, priority, task handle, core*/
+ xTaskCreatePinnedToCore(System_TaskWiFiWatchdog, "WiFiWatchdog", 3500, NULL, 8, &Task_WiFiWatchdog, 0); /*function, description, stack size, parameters, priority, task handle, core*/
/* init wdg */
SystemLog.AddEvent(LogLevel_Info, F("Init WDG"));
diff --git a/ESP32_PrusaConnectCam/WebPage.h b/ESP32_PrusaConnectCam/WebPage.h
index 79291fa..996e6ab 100644
--- a/ESP32_PrusaConnectCam/WebPage.h
+++ b/ESP32_PrusaConnectCam/WebPage.h
@@ -204,7 +204,19 @@ const char page_wifi_html[] PROGMEM = R"rawliteral(
@@ -960,6 +972,11 @@ function get_data(val) {
$("#ip").text(obj.ip);
$("#mdns").text(obj.mdns);
$("#wifi_network_status").text(obj.wifi_network_status);
+ document.getElementById('ipcfgid').value = obj.ip_cfg;
+ document.getElementById('net_ip_id').value = obj.net_ip;
+ document.getElementById('net_mask_id').value = obj.net_mask;
+ document.getElementById('net_gw_id').value = obj.net_gw;
+ document.getElementById('net_dns_id').value = obj.net_dns;
if (!document.querySelector('#main-wifi-signal wifi_img')) {
var wifi_img = document.createElement('wifi_img');
@@ -979,7 +996,7 @@ function get_data(val) {
$("#sw_new_ver").text(obj.sw_new_ver);
$("#service_ap_ssid").text(obj.service_ap_ssid);
document.getElementById('mdnsid').value = obj.mdns;
- document.getElementById('loglevelid').value = obj.log_level;
+ document.getElementById('loglevelid').value = obj.log_level;
}
},
error: function(html) {
@@ -1099,6 +1116,14 @@ function setWifi(val_ssid, val_pass) {
get_data("wifi");
}
+function setWifiNet(val_ip, val_mask, val_gw, val_dns) {
+ var xmlHttp = new XMLHttpRequest();
+ xmlHttp.open("GET", "wifi_net_cfg?ip=" + encodeURIComponent(val_ip) + "&mask=" + encodeURIComponent(val_mask) + "&gw=" + encodeURIComponent(val_gw) + "&dns=" + encodeURIComponent(val_dns), false);
+ xmlHttp.send(null);
+ alert(xmlHttp.responseText);
+ get_data("wifi");
+}
+
function scanWifi() {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "wifi_scan?", false);
@@ -1151,11 +1176,11 @@ function setAuth(val_name, val_pass) {
get_data("auth");
}
-function changeValue(val, url, reload) {
+function changeValue(val, url, reload, msg) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", url + val, false);
xmlHttp.send(null);
- if ((url == "set_int?refresh=") || (url == "set_token?token=") || (url == "set_mdns?mdns=")) {
+ if ((url == "set_int?refresh=") || (url == "set_token?token=") || (url == "set_mdns?mdns=") || (url == "set_int?ipcfg=")) {
alert(xmlHttp.responseText);
}
if (url == "set_flash_time?flash_time=") {
@@ -1393,4 +1418,4 @@ const char cookies_html[] PROGMEM = R"rawliteral(
#endif
-/* EOF */
+/* EOF */
diff --git a/ESP32_PrusaConnectCam/cfg.cpp b/ESP32_PrusaConnectCam/cfg.cpp
index 918c7d1..029cee3 100644
--- a/ESP32_PrusaConnectCam/cfg.cpp
+++ b/ESP32_PrusaConnectCam/cfg.cpp
@@ -161,6 +161,11 @@ void Configuration::DefaultCfg() {
SaveAgcGain(FACTORY_CFG_AGC_GAIN);
SaveLogLevel(LogLevel_Info);
SavePrusaConnectHostname(FACTORY_CFG_HOSTNAME);
+ SaveNetworkIpMethod(FACTORY_CFG_NETWORK_IP_METHOD);
+ SaveNetworkIp(FACTORY_CFG_NETWORK_STATIC_IP);
+ SaveNetworkMask(FACTORY_CFG_NETWORK_STATIC_MASK);
+ SaveNetworkGateway(FACTORY_CFG_NETWORK_STATIC_GATEWAY);
+ SaveNetworkDns(FACTORY_CFG_NETWORK_STATIC_DNS);
Log->AddEvent(LogLevel_Warning, F("+++++++++++++++++++++++++++"));
}
@@ -312,6 +317,24 @@ void Configuration::SaveString(uint16_t address, uint16_t max_length, String dat
Log->AddEvent(LogLevel_Verbose, F("Skip write string"));
}
}
+
+/**
+ @info Function for save IP address to EEPROM
+ @param uint16_t data address
+ @param String data
+ @return none
+*/
+void Configuration::SaveIpAddress(uint16_t address, String data) {
+ IPAddress ip;
+ if (ip.fromString(data)) {
+ EEPROM.write(address, ip[0]);
+ EEPROM.write(address + 1, ip[1]);
+ EEPROM.write(address + 2, ip[2]);
+ EEPROM.write(address + 3, ip[3]);
+ EEPROM.commit();
+ }
+}
+
/**
@info Function for read uint16_t data from EEPROM
@param uint16_t fist byte address
@@ -321,6 +344,7 @@ uint16_t Configuration::LoadUint16(uint16_t address) {
uint16_t tmp = uint16_t(EEPROM.read(address) << 8) | (EEPROM.read(address + 1));
return tmp;
}
+
/**
@info Function for load string from EEPROM
@param uint16_t data address
@@ -351,6 +375,16 @@ String Configuration::LoadString(uint16_t address, uint16_t max_length, bool sho
return tmp;
}
+String Configuration::LoadIpAddress(uint16_t address) {
+ IPAddress ip;
+ ip[0] = EEPROM.read(address);
+ ip[1] = EEPROM.read(address + 1);
+ ip[2] = EEPROM.read(address + 2);
+ ip[3] = EEPROM.read(address + 3);
+
+ return ip.toString();
+}
+
/**
@info save refresh interval to eeprom
@param uint8_t - refresh interval
@@ -704,6 +738,57 @@ void Configuration::SavePrusaConnectHostname(String i_data) {
SaveString(EEPROM_ADDR_HOSTNAME_START, EEPROM_ADDR_HOSTNAME_LENGTH, i_data);
}
+/**
+ @info Save network ip method
+ @param uint8_t - value. 0 - DHCP, 1 - static
+ @return none
+*/
+void Configuration::SaveNetworkIpMethod(uint8_t i_data) {
+ Log->AddEvent(LogLevel_Verbose, "Save network ip method: " + (i_data == 0) ? "DHCP" : "Static");
+ SaveUint8(EEPROM_ADDR_NETWORK_IP_METHOD_START, i_data);
+}
+
+/**
+ @info Save network static ip
+ @param String - ip address
+ @return none
+*/
+void Configuration::SaveNetworkIp(String i_data) {
+ Log->AddEvent(LogLevel_Verbose, "Save network static ip: " + i_data);
+ SaveIpAddress(EEPROM_ADDR_NETWORK_STATIC_IP_START, i_data);
+
+}
+
+/**
+ @info Save network static mask
+ @param String - mask
+ @return none
+*/
+void Configuration::SaveNetworkMask(String i_data) {
+ Log->AddEvent(LogLevel_Verbose, "Save network static mask: " + i_data);
+ SaveIpAddress(EEPROM_ADDR_NETWORK_STATIC_MASK_START, i_data);
+}
+
+/**
+ @info Save network static gateway
+ @param String - gateway
+ @return none
+*/
+void Configuration::SaveNetworkGateway(String i_data) {
+ Log->AddEvent(LogLevel_Verbose, "Save network static gateway: " + i_data);
+ SaveIpAddress(EEPROM_ADDR_NETWORK_STATIC_GATEWAY_START, i_data);
+}
+
+/**
+ @info Save network static dns
+ @param String - dns
+ @return none
+*/
+void Configuration::SaveNetworkDns(String i_data) {
+ Log->AddEvent(LogLevel_Verbose, "Save network static dns: " + i_data);
+ SaveIpAddress(EEPROM_ADDR_NETWORK_STATIC_DNS_START, i_data);
+}
+
/**
@info load refresh interval from eeprom
@param none
@@ -1116,4 +1201,69 @@ String Configuration::LoadPrusaConnectHostname() {
return ret;
}
+/**
+ * @brief Load network ip method from EEPROM
+ *
+ * @return uint8_t - ip method. 0 - DHCP, 1 - static
+ */
+uint8_t Configuration::LoadNetworkIpMethod() {
+ uint8_t ret = EEPROM.read(EEPROM_ADDR_NETWORK_IP_METHOD_START);
+
+ if (255 == ret) {
+ ret = 0;
+ }
+
+ Log->AddEvent(LogLevel_Info, String("Network IP method: ") + ((ret == 0) ? "DHCP" : "Static"));
+
+ return ret;
+}
+
+/**
+ * @brief Load network static ip from EEPROM
+ *
+ * @return String - ip address
+ */
+String Configuration::LoadNetworkIp() {
+ String ret = LoadIpAddress(EEPROM_ADDR_NETWORK_STATIC_IP_START);
+ Log->AddEvent(LogLevel_Info, "Network static IP: " + ret);
+
+ return ret;
+}
+
+/**
+ * @brief Load network static mask from EEPROM
+ *
+ * @return String - mask
+ */
+String Configuration::LoadNetworkMask() {
+ String ret = LoadIpAddress(EEPROM_ADDR_NETWORK_STATIC_MASK_START);
+ Log->AddEvent(LogLevel_Info, "Network static mask: " + ret);
+
+ return ret;
+}
+
+/**
+ * @brief Load network static gateway from EEPROM
+ *
+ * @return String - gateway
+ */
+String Configuration::LoadNetworkGateway() {
+ String ret = LoadIpAddress(EEPROM_ADDR_NETWORK_STATIC_GATEWAY_START);
+ Log->AddEvent(LogLevel_Info, "Network static gateway: " + ret);
+
+ return ret;
+}
+
+/**
+ * @brief Load network static dns from EEPROM
+ *
+ * @return String - dns
+ */
+String Configuration::LoadNetworkDns() {
+ String ret = LoadIpAddress(EEPROM_ADDR_NETWORK_STATIC_DNS_START);
+ Log->AddEvent(LogLevel_Info, "Network static DNS: " + ret);
+
+ return ret;
+}
+
/* EOF */
\ No newline at end of file
diff --git a/ESP32_PrusaConnectCam/cfg.h b/ESP32_PrusaConnectCam/cfg.h
index 65bcd28..c0be20f 100644
--- a/ESP32_PrusaConnectCam/cfg.h
+++ b/ESP32_PrusaConnectCam/cfg.h
@@ -66,6 +66,11 @@ public:
void SaveAgcGain(uint8_t);
void SaveLogLevel(LogLevel_enum);
void SavePrusaConnectHostname(String);
+ void SaveNetworkIpMethod(uint8_t);
+ void SaveNetworkIp(String);
+ void SaveNetworkMask(String);
+ void SaveNetworkGateway(String);
+ void SaveNetworkDns(String);
uint8_t LoadRefreshInterval();
String LoadToken();
@@ -101,6 +106,11 @@ public:
uint8_t LoadAgcGain();
LogLevel_enum LoadLogLevel();
String LoadPrusaConnectHostname();
+ uint8_t LoadNetworkIpMethod();
+ String LoadNetworkIp();
+ String LoadNetworkMask();
+ String LoadNetworkGateway();
+ String LoadNetworkDns();
private:
Logs *Log; ///< Pointer to Logs object
@@ -117,8 +127,10 @@ private:
void SaveBool(uint16_t, bool);
void SaveUint16(uint16_t, uint16_t);
void SaveString(uint16_t, uint16_t, String);
+ void SaveIpAddress(uint16_t, String);
uint16_t LoadUint16(uint16_t);
String LoadString(uint16_t, uint16_t, bool);
+ String LoadIpAddress(uint16_t);
};
extern Configuration SystemConfig; ///< Configuration object
diff --git a/ESP32_PrusaConnectCam/mcu_cfg.h b/ESP32_PrusaConnectCam/mcu_cfg.h
index b99db7c..3d8ca2c 100644
--- a/ESP32_PrusaConnectCam/mcu_cfg.h
+++ b/ESP32_PrusaConnectCam/mcu_cfg.h
@@ -87,6 +87,9 @@
#define SERVICE_LOCAL_MASK "255.255.255.0" ///< service WI-FI module mask
#define SERVICE_LOCAL_DNS "192.168.0.1" ///< service WI-FI module DNS
+/* ----------------- IPv4 CFG -------------------*/
+#define IPV4_ADDR_MAX_LENGTH 15 ///< maximum length for IPv4 address
+
/* ----------------- WiFi CFG -------------------*/
#define WIFI_STA_WDG_TIMEOUT 60000 ///< STA watchdog timeout [ms]
@@ -126,6 +129,11 @@
#define FACTORY_CFG_AGC_GAIN 0 ///< automatic gain controll gain
#define FACTORY_CFG_HOSTNAME "connect.prusa3d.com" ///< hostname for Prusa Connect
#define FACTORY_CFG_ENABLE_SERVICE_AP 1 ///< enable service AP mode
+#define FACTORY_CFG_NETWORK_IP_METHOD 0 ///< 0 - DHCP, 1 - Static IP
+#define FACTORY_CFG_NETWORK_STATIC_IP "255.255.255.255" ///< Static IP address
+#define FACTORY_CFG_NETWORK_STATIC_MASK "255.255.255.255" ///< Static Mask
+#define FACTORY_CFG_NETWORK_STATIC_GATEWAY "255.255.255.255" ///< Static Gateway
+#define FACTORY_CFG_NETWORK_STATIC_DNS "255.255.255.255" ///< Static DNS
/* ---------------- CFG FLAGS ------------------*/
#define CFG_WIFI_SETTINGS_SAVED 0x0A ///< flag saved config
@@ -243,6 +251,22 @@
#define EEPROM_ADDR_SERVICE_AP_ENABLE_START (EEPROM_ADDR_HOSTNAME_START + EEPROM_ADDR_HOSTNAME_LENGTH)
#define EEPROM_ADDR_SERVICE_AP_ENABLE_LENGTH 1
+#define EEPROM_ADDR_NETWORK_IP_METHOD_START (EEPROM_ADDR_SERVICE_AP_ENABLE_START + EEPROM_ADDR_SERVICE_AP_ENABLE_LENGTH)
+#define EEPROM_ADDR_NETWORK_IP_METHOD_LENGTH 1
+
+#define EEPROM_ADDR_NETWORK_STATIC_IP_START (EEPROM_ADDR_NETWORK_IP_METHOD_START + EEPROM_ADDR_NETWORK_IP_METHOD_LENGTH)
+#define EEPROM_ADDR_NETWORK_STATIC_IP_LENGTH 4
+
+#define EEPROM_ADDR_NETWORK_STATIC_MASK_START (EEPROM_ADDR_NETWORK_STATIC_IP_START + EEPROM_ADDR_NETWORK_STATIC_IP_LENGTH)
+#define EEPROM_ADDR_NETWORK_STATIC_MASK_LENGTH 4
+
+#define EEPROM_ADDR_NETWORK_STATIC_GATEWAY_START (EEPROM_ADDR_NETWORK_STATIC_MASK_START + EEPROM_ADDR_NETWORK_STATIC_MASK_LENGTH)
+#define EEPROM_ADDR_NETWORK_STATIC_GATEWAY_LENGTH 4
+
+#define EEPROM_ADDR_NETWORK_STATIC_DNS_START (EEPROM_ADDR_NETWORK_STATIC_GATEWAY_START + EEPROM_ADDR_NETWORK_STATIC_GATEWAY_LENGTH)
+#define EEPROM_ADDR_NETWORK_STATIC_DNS_LENGTH 4
+
+
#define EEPROM_SIZE (EEPROM_ADDR_REFRESH_INTERVAL_LENGTH + EEPROM_ADDR_FINGERPRINT_LENGTH + EEPROM_ADDR_TOKEN_LENGTH + \
EEPROM_ADDR_FRAMESIZE_LENGTH + EEPROM_ADDR_BRIGHTNESS_LENGTH + EEPROM_ADDR_CONTRAST_LENGTH + \
EEPROM_ADDR_SATURATION_LENGTH + EEPROM_ADDR_HMIRROR_LENGTH + EEPROM_ADDR_VFLIP_LENGTH + \
@@ -255,7 +279,9 @@
EEPROM_ADDR_AWB_MODE_ENABLE_LENGTH + EEPROM_ADDR_BPC_ENABLE_LENGTH + EEPROM_ADDR_WPC_ENABLE_LENGTH + \
EEPROM_ADDR_RAW_GAMA_ENABLE_LENGTH + EEPROM_ADDR_AEC2_LENGTH + EEPROM_ADDR_AE_LEVEL_LENGTH + \
EEPROM_ADDR_AEC_VALUE_LENGTH + EEPROM_ADDR_GAIN_CTRL_LENGTH + EEPROM_ADDR_AGC_GAIN_LENGTH + EEPROM_ADDR_LOG_LEVEL_LENGTH + \
- EEPROM_ADDR_HOSTNAME_LENGTH + EEPROM_ADDR_SERVICE_AP_ENABLE_LENGTH) ///< how many bits do we need for eeprom memory
+ EEPROM_ADDR_HOSTNAME_LENGTH + EEPROM_ADDR_SERVICE_AP_ENABLE_LENGTH + EEPROM_ADDR_NETWORK_IP_METHOD_LENGTH +\
+ EEPROM_ADDR_NETWORK_STATIC_IP_LENGTH + EEPROM_ADDR_NETWORK_STATIC_MASK_LENGTH + EEPROM_ADDR_NETWORK_STATIC_GATEWAY_LENGTH + \
+ EEPROM_ADDR_NETWORK_STATIC_DNS_LENGTH) ///< how many bits do we need for eeprom memory
#endif
diff --git a/ESP32_PrusaConnectCam/serial_cfg.cpp b/ESP32_PrusaConnectCam/serial_cfg.cpp
index b938167..bff9c91 100644
--- a/ESP32_PrusaConnectCam/serial_cfg.cpp
+++ b/ESP32_PrusaConnectCam/serial_cfg.cpp
@@ -11,7 +11,7 @@
#include "serial_cfg.h"
-SerialCfg SystemSerialCfg(&SystemConfig, &SystemLog, &SystemWifiMngt, &Connect);
+SerialCfg SystemSerialCfg(&SystemConfig, &SystemLog, &SystemWifiMngt, &Connect, &SystemCamera);
/**
@brief Constructor
@@ -21,11 +21,12 @@ SerialCfg SystemSerialCfg(&SystemConfig, &SystemLog, &SystemWifiMngt, &Connect);
@param PrusaConnect * - pointer to PrusaConnect object
@return none
*/
-SerialCfg::SerialCfg(Configuration *i_conf, Logs *i_log, WiFiMngt *i_wifi, PrusaConnect *i_connect) {
+SerialCfg::SerialCfg(Configuration *i_conf, Logs *i_log, WiFiMngt *i_wifi, PrusaConnect *i_connect, Camera *i_cam) {
config = i_conf;
log = i_log;
wifim = i_wifi;
connect = i_connect;
+ cam = i_cam;
}
/**
@@ -108,6 +109,37 @@ String lastTwoChars = command.substring(command.length() - 2);
} else if (command.startsWith("getserviceapssid") && command.endsWith(";")) {
log->AddEvent(LogLevel_Info, F("--> Console print service WiFi AP SSID..."));
Serial.print("getserviceapssid:" + wifim->GetServiceApSsid() + ";");
+
+ } else if (command.startsWith("otaupdate") && command.endsWith(";")) {
+ log->AddEvent(LogLevel_Warning, F("--> Start OTA update process!"));
+ FirmwareUpdate.StartOtaUpdate = true;
+
+ } else if (command.startsWith("resolution:") && command.endsWith(";")) {
+ uint8_t resolution = command.substring(11, command.length() -1).toInt();
+ log->AddEvent(LogLevel_Info, "--> Console set photo resolution: " + String(resolution));
+ if ((resolution >= 0) && (resolution <= 6)) {
+ cam->SetFrameSize(resolution);
+ } else {
+ log->AddEvent(LogLevel_Warning, F("--> Bad resolution size!"));
+ }
+ } else if (command.startsWith("photoquality:") && command.endsWith(";")) {
+ uint8_t quality = command.substring(13, command.length() -1).toInt();
+ log->AddEvent(LogLevel_Info, "--> Console set photo quality: " + String(quality));
+ if ((quality >= 10) && (quality <= 63)) {
+ cam->SetPhotoQuality(quality);
+ } else {
+ log->AddEvent(LogLevel_Warning, F("--> Bad photo quality!"));
+ }
+
+ } else if (command.startsWith("setflash") && command.endsWith(";")) {
+ cam->SetCameraFlashEnable(!cam->GetCameraFlashEnable());
+ cam->SetFlashStatus(false);
+ log->AddEvent(LogLevel_Warning, "--> Console set FLASH: " + String(cam->GetCameraFlashEnable()));
+
+ } else if (command.startsWith("setlight") && command.endsWith(";")) {
+ cam->SetCameraFlashEnable(false);
+ cam->SetFlashStatus(!cam->GetFlashStatus());
+ log->AddEvent(LogLevel_Warning, "--> Console set LIGHT: " + String(cam->GetFlashStatus()));
} else if (command.startsWith("mcureboot") && command.endsWith(";")) {
log->AddEvent(LogLevel_Warning, F("--> Reboot MCU!"));
@@ -130,17 +162,33 @@ String lastTwoChars = command.substring(command.length() - 2);
@return none
*/
void SerialCfg::PrintAvailableCommands() {
+ Serial.println(F("-----------------------------------"));
Serial.println(F("Available commands: "));
- Serial.println(F("setwifissid:SSID; - set WiFi SSID"));
- Serial.println(F("setwifipass:PASS; - set WiFi password"));
- Serial.println(F("setauthtoken:TOKEN; - set auth TOKEN for backend"));
- Serial.println(F("wificonnect; - connect to WiFi network"));
- Serial.println(F("getwifimode; - get WiFi mode (AP/STA)"));
- Serial.println(F("getwifistastatus; - get STA status (connected/disconnected)"));
- Serial.println(F("getwifistaip; - get STA IP address"));
- Serial.println(F("getserviceapssid;- get service WiFi AP SSID"));
- Serial.println(F("mcureboot; - reboot MCU"));
- Serial.println(F("commandslist; - print available commands"));
+ Serial.println(F(" Command - Description"));
+ Serial.println(F("setwifissid:SSID; - set WiFi SSID"));
+ Serial.println(F("setwifipass:PASS; - set WiFi password"));
+ Serial.println(F("setauthtoken:TOKEN; - set auth TOKEN for backend"));
+ Serial.println(F("wificonnect; - connect to WiFi network"));
+ Serial.println(F("getwifimode; - get WiFi mode (AP/STA)"));
+ Serial.println(F("getwifistastatus; - get STA status (connected/disconnected)"));
+ Serial.println(F("getwifistaip; - get STA IP address"));
+ Serial.println(F("getserviceapssid; - get service WiFi AP SSID"));
+ Serial.println(F("otaupdate; - start OTA update process"));
+ Serial.println(F("resolution:INDEX; - set photo resolution"));
+ Serial.println(F(" | Index - Resolution"));
+ Serial.println(F(" |-> 0 - 320x240"));
+ Serial.println(F(" |-> 1 - 352x288"));
+ Serial.println(F(" |-> 2 - 640x480"));
+ Serial.println(F(" |-> 3 - 800x600"));
+ Serial.println(F(" |-> 4 - 1024x768"));
+ Serial.println(F(" |-> 5 - 1280x1024"));
+ Serial.println(F(" |-> 6 - 1600x1200"));
+ Serial.println(F("photoquality:QUALITY; - set photo quality. 10-63 lower number means higher quality "));
+ Serial.println(F("setflash; - enable/disable LED flash"));
+ Serial.println(F("setlight; - enable/disable LED light"));
+ Serial.println(F("mcureboot; - reboot MCU"));
+ Serial.println(F("commandslist; - print available commands"));
+ Serial.println(F("-----------------------------------"));
}
/* EOF */
\ No newline at end of file
diff --git a/ESP32_PrusaConnectCam/serial_cfg.h b/ESP32_PrusaConnectCam/serial_cfg.h
index 475013a..30798b6 100644
--- a/ESP32_PrusaConnectCam/serial_cfg.h
+++ b/ESP32_PrusaConnectCam/serial_cfg.h
@@ -20,6 +20,7 @@
#include "wifi_mngt.h"
#include "cfg.h"
#include "connect.h"
+#include "camera.h"
class WiFiMngt;
class PrusaConnect;
@@ -30,13 +31,14 @@ private:
Logs *log; ///< pointer to Logs object
WiFiMngt *wifim; ///< pointer to WiFiMngt object
PrusaConnect *connect; ///< pointer to PrusaConnect object
+ Camera *cam; ///< pointer to camera object
String wifi_ssid; ///< wifi ssid
String wifi_pass; ///< wifi password
String auth_token; ///< auth token
public:
- SerialCfg(Configuration*, Logs*, WiFiMngt*, PrusaConnect*);
+ SerialCfg(Configuration*, Logs*, WiFiMngt*, PrusaConnect*, Camera*);
~SerialCfg(){};
void ProcessIncommingData();
diff --git a/ESP32_PrusaConnectCam/server.cpp b/ESP32_PrusaConnectCam/server.cpp
index f0caf51..2ca20e4 100644
--- a/ESP32_PrusaConnectCam/server.cpp
+++ b/ESP32_PrusaConnectCam/server.cpp
@@ -537,6 +537,15 @@ void Server_InitWebServer_Sets() {
response = true;
}
+ /* set network ip method. 0 - DHCP, 1 - Static */
+ if (request->hasParam("ipcfg")) {
+ SystemLog.AddEvent(LogLevel_Verbose, F("Set ipcfg"));
+ SystemWifiMngt.SetNetIpMethod(request->getParam("ipcfg")->value().toInt());
+ response_msg = MSG_SAVE_OK_REBOOT;
+
+ response = true;
+ }
+
if (true == response) {
request->send_P(200, F("text/html"), response_msg.c_str());
}
@@ -702,6 +711,54 @@ void Server_InitWebServer_Sets() {
}
});
+ /* route for set WI-FI static IP address */
+ server.on("/wifi_net_cfg", HTTP_GET, [](AsyncWebServerRequest* request) {
+ SystemLog.AddEvent(LogLevel_Verbose, F("WEB server: set WI-FI static IP address"));
+ if (Server_CheckBasicAuth(request) == false)
+ return;
+
+ String tmpIp = "";
+ String tmpMask = "";
+ String tmpGw = "";
+ String tmpDns = "";
+
+ /* get ip */
+ if (request->hasParam("ip")) {
+ tmpIp = request->getParam("ip")->value();
+ }
+
+ /* get mask */
+ if (request->hasParam("mask")) {
+ tmpMask = request->getParam("mask")->value();
+ }
+
+ /* get gw */
+ if (request->hasParam("gw")) {
+ tmpGw = request->getParam("gw")->value();
+ }
+
+ /* get dns */
+ if (request->hasParam("dns")) {
+ tmpDns = request->getParam("dns")->value();
+ }
+
+ /* check min and max length network parameters */
+ if (((tmpIp.length() > 0) && (tmpMask.length() > 0) && (tmpGw.length() > 0) && (tmpDns.length() > 0)) &&
+ ((tmpIp.length() <= IPV4_ADDR_MAX_LENGTH) && (tmpMask.length() <= IPV4_ADDR_MAX_LENGTH) &&
+ (tmpGw.length() <= IPV4_ADDR_MAX_LENGTH) && (tmpDns.length() <= IPV4_ADDR_MAX_LENGTH))) {
+
+ /* save ssid and password */
+ SystemWifiMngt.SetNetworkConfig(tmpIp, tmpMask, tmpGw, tmpDns);
+
+ /* send OK response */
+ request->send_P(200, F("text/html"), MSG_SAVE_OK_REBOOT);
+
+ } else {
+ request->send_P(200, F("text/html"), MSG_SAVE_NOTOK);
+ }
+ });
+
+
/* route for set basic auth */
server.on("/basicauth_cfg", HTTP_GET, [](AsyncWebServerRequest* request) {
SystemLog.AddEvent(LogLevel_Verbose, F("WEB server: set basic auth user name and password"));
@@ -997,6 +1054,11 @@ String Server_GetJsonData() {
doc_json["uptime"] = uptime;
doc_json["user_name"] = WebBasicAuth.UserName;
doc_json["hostname"] = Connect.GetPrusaConnectHostname();
+ doc_json["ip_cfg"] = SystemWifiMngt.GetNetIpMethod();
+ doc_json["net_ip"] = SystemWifiMngt.GetNetStaticIp();
+ doc_json["net_mask"] = SystemWifiMngt.GetNetStaticMask();
+ doc_json["net_gw"] = SystemWifiMngt.GetNetStaticGateway();
+ doc_json["net_dns"] = SystemWifiMngt.GetNetStaticDns();
doc_json["sw_build"] = SW_BUILD;
doc_json["sw_ver"] = SW_VERSION;
doc_json["sw_new_ver"] = FirmwareUpdate.NewVersionFw;
diff --git a/ESP32_PrusaConnectCam/system.cpp b/ESP32_PrusaConnectCam/system.cpp
index a216e64..6f4ea29 100644
--- a/ESP32_PrusaConnectCam/system.cpp
+++ b/ESP32_PrusaConnectCam/system.cpp
@@ -624,6 +624,12 @@ void System_TaskSysLed(void *pvParameters) {
}
}
+/**
+ * @brief Function for WiFi watchdog task
+ *
+ * @param void *pvParameters
+ * @return none
+ */
void System_TaskWiFiWatchdog(void *pvParameters) {
SystemLog.AddEvent(LogLevel_Info, "WiFiWatchdog task. core: " + String(xPortGetCoreID()));
TickType_t xLastWakeTime = xTaskGetTickCount();
diff --git a/ESP32_PrusaConnectCam/wifi_mngt.cpp b/ESP32_PrusaConnectCam/wifi_mngt.cpp
index c915ec8..4f92b42 100644
--- a/ESP32_PrusaConnectCam/wifi_mngt.cpp
+++ b/ESP32_PrusaConnectCam/wifi_mngt.cpp
@@ -42,8 +42,15 @@ WiFiMngt::WiFiMngt(Configuration *i_conf, Logs *i_log, Camera *i_cam) {
void WiFiMngt::LoadCfgFromEeprom() {
WifiSsid = config->LoadWifiSsid();
WifiPassword = config->LoadWifiPassowrd();
+
mDNS_record = config->LoadMdnsRecord();
EnableServiceAp = config->LoadEnableServiceAp();
+
+ NetIpMethod = config->LoadNetworkIpMethod();
+ NetStaticIp.fromString(config->LoadNetworkIp());
+ NetStaticMask.fromString(config->LoadNetworkMask());
+ NetStaticGateway.fromString(config->LoadNetworkGateway());
+ NetStaticDns.fromString(config->LoadNetworkDns());
}
/**
@@ -60,6 +67,7 @@ void WiFiMngt::Init() {
SetWifiEvents();
CreateApSsid();
+ /* check enable service AP mode */
if (true == GetEnableServiceAp()) {
log->AddEvent(LogLevel_Info, F("Service AP mode enabled"));
WiFi.mode(WIFI_AP_STA);
@@ -76,6 +84,16 @@ void WiFiMngt::Init() {
WiFiMode = "Client";
}
+ /* Set STA IP method. Static or DHCP */
+ if (NetIpMethod == NetworkIpMethodStatic) {
+ log->AddEvent(LogLevel_Info, F("STA IP Method: Static IP"));
+ if (!WiFi.config(NetStaticIp, NetStaticGateway, NetStaticMask, NetStaticDns)) {
+ log->AddEvent(LogLevel_Error, F("STA Failed to configure static IP"));
+ }
+ } else {
+ log->AddEvent(LogLevel_Info, F("STA IP Method: DHCP"));
+ }
+
esp_wifi_set_ps(WIFI_PS_NONE);
WiFi.setHostname(DEVICE_HOSTNAME);
FirstConnected = false;
@@ -678,6 +696,51 @@ bool WiFiMngt::GetFirstConnection() {
return FirstConnected;
}
+/**
+ @brief function for get STA IP method
+ @param none
+ @return uint8_t - value. 0 - DHCP, 1 - Static
+*/
+uint8_t WiFiMngt::GetNetIpMethod() {
+ return NetIpMethod;
+}
+
+/**
+ @brief function for get static IP configuration
+ @param none
+ @return String - value
+*/
+String WiFiMngt::GetNetStaticIp() {
+ return NetStaticIp.toString();
+}
+
+/**
+ * @brief function for get static mask configuration
+ *
+ * @return String
+ */
+String WiFiMngt::GetNetStaticMask() {
+ return NetStaticMask.toString();;
+}
+
+/**
+ * @brief function for get static gateway configuration
+ *
+ * @return String
+ */
+String WiFiMngt::GetNetStaticGateway() {
+ return NetStaticGateway.toString();;
+}
+
+/**
+ * @brief function for get static DNS configuration
+ *
+ * @return String
+ */
+String WiFiMngt::GetNetStaticDns() {
+ return NetStaticDns.toString();;
+}
+
/**
@brief function for set STA credentials
@param String - ssid
@@ -761,6 +824,33 @@ void WiFiMngt::SetFirstConnection(bool i_data) {
FirstConnected = i_data;
}
+/**
+ @brief function for set static IP configuration
+ @param bool - data
+ @return none
+*/
+void WiFiMngt::SetNetworkConfig(String i_ip, String i_mask, String i_gw, String i_dns) {
+ NetStaticIp.fromString(i_ip);
+ NetStaticMask.fromString(i_mask);
+ NetStaticGateway.fromString(i_gw);
+ NetStaticDns.fromString(i_dns);
+
+ config->SaveNetworkIp(NetStaticIp.toString());
+ config->SaveNetworkMask(NetStaticMask.toString());
+ config->SaveNetworkGateway(NetStaticGateway.toString());
+ config->SaveNetworkDns(NetStaticDns.toString());
+}
+
+/**
+ @brief function for set STA IP method. 0 - DHCP, 1 - Static
+ @param uint8_t - data
+ @return none
+*/
+void WiFiMngt::SetNetIpMethod(uint8_t i_data) {
+ NetIpMethod = i_data;
+ config->SaveNetworkIpMethod(NetIpMethod);
+}
+
/* ----------------------- Static function ----------------------- */
/**
diff --git a/ESP32_PrusaConnectCam/wifi_mngt.h b/ESP32_PrusaConnectCam/wifi_mngt.h
index 787c07d..4f4201a 100644
--- a/ESP32_PrusaConnectCam/wifi_mngt.h
+++ b/ESP32_PrusaConnectCam/wifi_mngt.h
@@ -42,6 +42,11 @@ void WiFiMngt_WiFiEventApStaDisconnected(WiFiEvent_t , WiFiEventInfo_t);
void WiFiMngt_WiFiEventApStaIpAssigned(WiFiEvent_t , WiFiEventInfo_t);
void WiFiMngt_WiFiEventApStaProbeReqRecved(WiFiEvent_t , WiFiEventInfo_t);
+enum NetworkIpMethod_enum {
+ NetworkIpMethodDhcp = 0, ///< DHCP IP
+ NetworkIpMethodStatic = 1, ///< STATIC IP
+};
+
class WiFiMngt {
private:
String WifiSsid; ///< WI-FI SSID
@@ -53,6 +58,12 @@ private:
bool NtpFirstSync; ///< flag about first NTP sync status
bool EnableServiceAp; ///< flag about enable service AP mode
+ uint8_t NetIpMethod; ///< flag about IP address obtained. 0 - DHCP, 1 - Static
+ IPAddress NetStaticIp; ///< Static IP address of the STA
+ IPAddress NetStaticMask; ///< Static Mask of the STA
+ IPAddress NetStaticGateway; ///< Static Gateway of the STA
+ IPAddress NetStaticDns; ///< Static DNS of the STA
+
uint8_t WiFiStaNetworkBssid[6]; ///< BSSID of the network
bool WiFiStaMultipleNetwork; ///< flag about multiple STA networks
@@ -109,6 +120,11 @@ public:
bool GetkActifeWifiCfgFlag();
bool GetNtpFirstTimeSync();
bool GetFirstConnection();
+ uint8_t GetNetIpMethod();
+ String GetNetStaticIp();
+ String GetNetStaticMask();
+ String GetNetStaticGateway();
+ String GetNetStaticDns();
void SetStaCredentials(String, String);
void SetStaSsid(String);
@@ -117,6 +133,8 @@ public:
void ConnectToSta();
void SetMdns(String);
void SetFirstConnection(bool);
+ void SetNetworkConfig(String, String, String, String);
+ void SetNetIpMethod(uint8_t);
};
extern WiFiMngt SystemWifiMngt; ///< global variable for wifi management
diff --git a/webpage/page_wifi.html b/webpage/page_wifi.html
index e7e3186..be2f910 100644
--- a/webpage/page_wifi.html
+++ b/webpage/page_wifi.html
@@ -59,7 +59,19 @@
diff --git a/webpage/scripts.js b/webpage/scripts.js
index e79b7cb..e6a7092 100644
--- a/webpage/scripts.js
+++ b/webpage/scripts.js
@@ -76,6 +76,11 @@ function get_data(val) {
$("#ip").text(obj.ip);
$("#mdns").text(obj.mdns);
$("#wifi_network_status").text(obj.wifi_network_status);
+ document.getElementById('ipcfgid').value = obj.ip_cfg;
+ document.getElementById('net_ip_id').value = obj.net_ip;
+ document.getElementById('net_mask_id').value = obj.net_mask;
+ document.getElementById('net_gw_id').value = obj.net_gw;
+ document.getElementById('net_dns_id').value = obj.net_dns;
if (!document.querySelector('#main-wifi-signal wifi_img')) {
var wifi_img = document.createElement('wifi_img');
@@ -95,7 +100,7 @@ function get_data(val) {
$("#sw_new_ver").text(obj.sw_new_ver);
$("#service_ap_ssid").text(obj.service_ap_ssid);
document.getElementById('mdnsid').value = obj.mdns;
- document.getElementById('loglevelid').value = obj.log_level;
+ document.getElementById('loglevelid').value = obj.log_level;
}
},
error: function(html) {
@@ -215,6 +220,14 @@ function setWifi(val_ssid, val_pass) {
get_data("wifi");
}
+function setWifiNet(val_ip, val_mask, val_gw, val_dns) {
+ var xmlHttp = new XMLHttpRequest();
+ xmlHttp.open("GET", "wifi_net_cfg?ip=" + encodeURIComponent(val_ip) + "&mask=" + encodeURIComponent(val_mask) + "&gw=" + encodeURIComponent(val_gw) + "&dns=" + encodeURIComponent(val_dns), false);
+ xmlHttp.send(null);
+ alert(xmlHttp.responseText);
+ get_data("wifi");
+}
+
function scanWifi() {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "wifi_scan?", false);
@@ -267,11 +280,11 @@ function setAuth(val_name, val_pass) {
get_data("auth");
}
-function changeValue(val, url, reload) {
+function changeValue(val, url, reload, msg) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", url + val, false);
xmlHttp.send(null);
- if ((url == "set_int?refresh=") || (url == "set_token?token=") || (url == "set_mdns?mdns=")) {
+ if ((url == "set_int?refresh=") || (url == "set_token?token=") || (url == "set_mdns?mdns=") || (url == "set_int?ipcfg=")) {
alert(xmlHttp.responseText);
}
if (url == "set_flash_time?flash_time=") {