From 2c1661007d07da8da083cadcb1d50e78aec35918 Mon Sep 17 00:00:00 2001 From: Luc <8822552+luc-github@users.noreply.github.com> Date: Thu, 8 Feb 2024 10:32:24 +0100 Subject: [PATCH] ESP214/ESP212 and hooks (#999) * Add expandString to ESP214 * Implement ESP212 for sending text to printer screen (M117) * Implement hooks for got IP and got DateTime * Allow finish processing current stream before adding new one instead of reject * Add parmeter to expandString to escape space * Update notifications_service.cpp * Add sanity check for hooks and autoscript --- docs/Commands.md | 3 + docs/authentication.md | 1 + docs/espXXX.md | 38 +++++++++++- esp3d/configuration.h | 16 ++++- esp3d/src/core/commands/ESP0.cpp | 6 ++ esp3d/src/core/commands/ESP212.cpp | 61 +++++++++++++++++++ esp3d/src/core/commands/ESP214.cpp | 2 + esp3d/src/core/esp3d.cpp | 3 + esp3d/src/core/esp3d_commands.cpp | 15 ++++- esp3d/src/core/esp3d_commands.h | 3 + esp3d/src/core/esp3d_string.cpp | 25 ++++---- esp3d/src/core/esp3d_string.h | 2 +- esp3d/src/include/esp3d_sanity.h | 18 +++++- esp3d/src/modules/gcode_host/gcode_host.cpp | 19 +++--- esp3d/src/modules/network/netconfig.cpp | 27 +++++--- esp3d/src/modules/network/netservices.cpp | 3 + .../notifications/notifications_service.cpp | 2 +- esp3d/src/modules/time/time_service.cpp | 23 +++++++ 18 files changed, 228 insertions(+), 39 deletions(-) create mode 100644 esp3d/src/core/commands/ESP212.cpp diff --git a/docs/Commands.md b/docs/Commands.md index 92428840..97e2dfe5 100644 --- a/docs/Commands.md +++ b/docs/Commands.md @@ -124,6 +124,9 @@ label can be: light/framesize/quality/contrast/brightness/saturation/gainceiling * Get Sensor Value / type/Set Sensor type `[ESP210] json= pwd=` +* Output to printer screen status + `[ESP212] json= pwd=` + * Output to esp screen status `[ESP214] json= pwd=` diff --git a/docs/authentication.md b/docs/authentication.md index a1cc30a9..1b24830c 100644 --- a/docs/authentication.md +++ b/docs/authentication.md @@ -104,6 +104,7 @@ Here the scope of right for each authentication level: | ESP201 | No | No | Get/Set | Get/Set | | ESP202 | No | No | Get | Get/Set | | ESP210 | No | No | Get | Get/Set | +| ESP212 | No | No | Set | Set | | ESP214 | No | No | Set | Set | | ESP215 | No | No | No | Set | | ESP220 | No | No | Get | Get | diff --git a/docs/espXXX.md b/docs/espXXX.md index 7b0aa84f..46c1d659 100644 --- a/docs/espXXX.md +++ b/docs/espXXX.md @@ -1292,6 +1292,43 @@ the admin password if authentication is enabled * `status` status of command, should be `ok` * `data` content of response, here `ok` ++++ +archetype = "section" +title = "[ESP212]" +weight = 800 ++++ +Output to printer screen status + +## Input +`[ESP212] json= pwd=` + +* json=no +the output format +can be in JSON or plain text + +* pwd= +the admin password if authentication is enabled + +* Text + * if Text is not empty, it will set the Text + * if Text is empty, it will clear current Text + +## Output + +- In json format + +```json +{ + "cmd":"212", + "status":"ok", + "data":"ok" +} +``` + +* `cmd` Id of requested command, should be `212` +* `status` status of command, should be `ok` +* `data` content of response, here `ok` + +++ archetype = "section" title = "[ESP214]" @@ -1329,7 +1366,6 @@ the admin password if authentication is enabled * `status` status of command, should be `ok` * `data` content of response, here `ok` - +++ archetype = "section" title = "[ESP215]" diff --git a/esp3d/configuration.h b/esp3d/configuration.h index 84d5215c..ebf8d0e0 100644 --- a/esp3d/configuration.h +++ b/esp3d/configuration.h @@ -561,10 +561,22 @@ */ // #define ESP_LUA_INTERPRETER_FEATURE +/* Hook when got IP + * Commands to run on event + * Separate commands with ';' + */ +#define ESP_GOT_IP_HOOK "[ESP212]IP:%ESP_IP%" + +/* Hook when got date time + * Commands to run on event + * Separate commands with ';' + */ +#define ESP_GOT_DATE_TIME_HOOK "[ESP212]DATE:%ESP_DATETIME%" + /* Gcode Host Feature * This feature allows to process Gcode files like macros. */ -// #define GCODE_HOST_FEATURE +#define GCODE_HOST_FEATURE /* Settings location * SETTINGS_IN_EEPROM //ESP8266/ESP32 @@ -614,7 +626,7 @@ * Do not modify ************************************/ -#if defined(SD_TIMESTAMP_FEATURE) || defined(FILESYSTEM_TIMESTAMP_FEATURE) +#if defined(ESP_GOT_DATE_TIME_HOOK) ||defined(SD_TIMESTAMP_FEATURE) || defined(FILESYSTEM_TIMESTAMP_FEATURE) #define TIMESTAMP_FEATURE #endif // SD_TIMESTAMP_FEATURE || FILESYSTEM_TIMESTAMP_FEATURE diff --git a/esp3d/src/core/commands/ESP0.cpp b/esp3d/src/core/commands/ESP0.cpp index beb0b0f1..ce993f84 100644 --- a/esp3d/src/core/commands/ESP0.cpp +++ b/esp3d/src/core/commands/ESP0.cpp @@ -102,6 +102,9 @@ const char* help[] = { "[ESP210](type=NONE/xxx) (interval=xxxx) - display and read/set SENSOR " "info", #endif // SENSOR_DEVICE +#if defined(PRINTER_HAS_DISPLAY) + "[ESP212](text) - display (text) to printer screen status", +#endif // PRINTER_HAS_DISPLAY #if defined(DISPLAY_DEVICE) "[ESP214](text) - display (text) to ESP screen status", #if defined(DISPLAY_TOUCH_DRIVER) @@ -240,6 +243,9 @@ const uint cmdlist[] = { #ifdef SENSOR_DEVICE 210, #endif // SENSOR_DEVICE +#if defined(PRINTER_HAS_DISPLAY) + 212, +#endif // PRINTER_HAS_DISPLAY #if defined(DISPLAY_DEVICE) 214, #if defined(DISPLAY_TOUCH_DRIVER) diff --git a/esp3d/src/core/commands/ESP212.cpp b/esp3d/src/core/commands/ESP212.cpp new file mode 100644 index 00000000..ccd1ad6b --- /dev/null +++ b/esp3d/src/core/commands/ESP212.cpp @@ -0,0 +1,61 @@ +/* + ESP212.cpp - ESP3D command class + + Copyright (c) 2014 Luc Lebosse. All rights reserved. + + This code is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This code is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with This code; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#include "../../include/esp3d_config.h" +#if defined(PRINTER_HAS_DISPLAY) +#include "../../modules/authentication/authentication_service.h" +#include "../../modules/display/display.h" +#include "../esp3d_commands.h" +#include "../esp3d_settings.h" +#include "../esp3d_string.h" + +#define COMMAND_ID 212 +// Output to printer screen status +//[ESP212]json= pwd= +void ESP3DCommands::ESP212(int cmd_params_pos, ESP3DMessage* msg) { + ESP3DClientType target = msg->origin; + ESP3DRequest requestId = msg->request_id; + (void)requestId; + msg->target = target; + msg->origin = ESP3DClientType::command; + bool hasError = false; + String error_msg = "Invalid parameters"; + String ok_msg = "ok"; + bool json = hasTag(msg, cmd_params_pos, "json"); + String tmpstr; +#if defined(AUTHENTICATION_FEATURE) + if (msg->authentication_level == ESP3DAuthenticationLevel::guest) { + msg->authentication_level = ESP3DAuthenticationLevel::not_authenticated; + dispatchAuthenticationError(msg, COMMAND_ID, json); + return; + } +#endif // AUTHENTICATION_FEATURE + tmpstr = get_clean_param(msg, cmd_params_pos); + tmpstr = esp3d_string::expandString(tmpstr.c_str()); + hasError = !esp3d_commands.dispatch(tmpstr.c_str(), ESP3DClientType::remote_screen, + no_id, ESP3DMessageType::unique, + ESP3DClientType::system, + ESP3DAuthenticationLevel::admin); + if (!dispatchAnswer(msg, COMMAND_ID, json, hasError, + hasError ? error_msg.c_str() : ok_msg.c_str())) { + esp3d_log_e("Error sending response to clients"); + } +} + +#endif // PRINTER_HAS_DISPLAY diff --git a/esp3d/src/core/commands/ESP214.cpp b/esp3d/src/core/commands/ESP214.cpp index dca8338c..6df10fb4 100644 --- a/esp3d/src/core/commands/ESP214.cpp +++ b/esp3d/src/core/commands/ESP214.cpp @@ -23,6 +23,7 @@ #include "../../modules/display/display.h" #include "../esp3d_commands.h" #include "../esp3d_settings.h" +#include "../esp3d_string.h" #define COMMAND_ID 214 // Output to esp screen status @@ -46,6 +47,7 @@ void ESP3DCommands::ESP214(int cmd_params_pos, ESP3DMessage* msg) { } #endif // AUTHENTICATION_FEATURE tmpstr = get_clean_param(msg, cmd_params_pos); + tmpstr = esp3d_string::expandString(tmpstr.c_str()); esp3d_display.setStatus(tmpstr.c_str()); if (!dispatchAnswer(msg, COMMAND_ID, json, hasError, hasError ? error_msg.c_str() : ok_msg.c_str())) { diff --git a/esp3d/src/core/esp3d.cpp b/esp3d/src/core/esp3d.cpp index e19b0016..e936bbaf 100644 --- a/esp3d/src/core/esp3d.cpp +++ b/esp3d/src/core/esp3d.cpp @@ -72,6 +72,9 @@ bool Esp3D::begin() { BootDelay bd; ESP3DHal::begin(); ESP3D_LOG_INIT_FN +#if defined(GCODE_HOST_FEATURE) + esp3d_gcode_host.begin(); +#endif // GCODE_HOST_FEATURE #if COMMUNICATION_PROTOCOL == SOCKET_SERIAL Serial2Socket.enable(); #endif // COMMUNICATION_PROTOCOL == SOCKET_SERIAL diff --git a/esp3d/src/core/esp3d_commands.cpp b/esp3d/src/core/esp3d_commands.cpp index b9f63337..a3a8e813 100644 --- a/esp3d/src/core/esp3d_commands.cpp +++ b/esp3d/src/core/esp3d_commands.cpp @@ -596,6 +596,13 @@ void ESP3DCommands::execute_internal_command(int cmd, int cmd_params_pos, ESP210(cmd_params_pos, msg); break; #endif // #ifdef SENSOR_DEVICE +#if defined (PRINTER_HAS_DISPLAY) + // Output to printer screen status + //[ESP212]json= pwd= + case 212: + ESP212(cmd_params_pos, msg); + break; +#endif // PRINTER_HAS_DISPLAY #if defined(DISPLAY_DEVICE) // Output to esp screen status //[ESP214]pwd= @@ -1231,6 +1238,10 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) { // currently only echo back no test done on success // TODO check add is successful switch (msg->target) { +case ESP3DClientType::no_client: + esp3d_log("No client message"); + ESP3DMessageManager::deleteMsg(msg); + break; #if COMMUNICATION_PROTOCOL == RAW_SERIAL case ESP3DClientType::serial: esp3d_log("Serial message"); @@ -1528,8 +1539,8 @@ bool ESP3DCommands::dispatch(ESP3DMessage *msg) { } break; default: - esp3d_log_e("No valid target specified %d", - static_cast(msg->target)); + esp3d_log_e("No valid target specified %d for %s", + static_cast(msg->target), (char *)msg->data); sendOk = false; } // clear message diff --git a/esp3d/src/core/esp3d_commands.h b/esp3d/src/core/esp3d_commands.h index 924aa46f..f63f1b56 100644 --- a/esp3d/src/core/esp3d_commands.h +++ b/esp3d/src/core/esp3d_commands.h @@ -117,6 +117,9 @@ class ESP3DCommands { #ifdef DIRECT_PIN_FEATURE void ESP201(int cmd_params_pos, ESP3DMessage* msg); #endif // DIRECT_PIN_FEATURE +#if defined(PRINTER_HAS_DISPLAY) + void ESP212(int cmd_params_pos, ESP3DMessage* msg); +#endif // PRINTER_HAS_DISPLAY #if defined(DISPLAY_DEVICE) void ESP214(int cmd_params_pos, ESP3DMessage* msg); #if defined(DISPLAY_TOUCH_DRIVER) diff --git a/esp3d/src/core/esp3d_string.cpp b/esp3d/src/core/esp3d_string.cpp index d289ec6c..73db32a9 100644 --- a/esp3d/src/core/esp3d_string.cpp +++ b/esp3d/src/core/esp3d_string.cpp @@ -23,7 +23,7 @@ #include "../include/esp3d_config.h" -#if defined(WIFI_FEATURE) || defined(ETH_FEATURE) +#if defined(WIFI_FEATURE) || defined(ETH_FEATURE) #include "../modules/network/netconfig.h" #endif // WIFI_FEATURE || ETH_FEATURE @@ -184,31 +184,32 @@ const char* esp3d_string::formatBytes(uint64_t bytes) { return res.c_str(); } -bool esp3d_string::isPrintableChar(char ch){ - int c = static_cast(ch); -if (c==9 || (c >= 32 && c <= 126) || c>=128) { +bool esp3d_string::isPrintableChar(char ch) { + int c = static_cast(ch); + if (c == 9 || (c >= 32 && c <= 126) || c >= 128) { return true; } return false; } -const char * esp3d_string::expandString(const char *s){ +const char* esp3d_string::expandString(const char* s, bool formatspace) { static String tmp; tmp = s; if (tmp.indexOf("%") != -1) { -#if defined(WIFI_FEATURE) || defined(ETH_FEATURE) - tmp.replace("%ESP_IP%", NetConfig::localIP().c_str()); - tmp.replace("%ESP_NAME%", NetConfig::hostname()); +#if defined(WIFI_FEATURE) || defined(ETH_FEATURE) + tmp.replace("%ESP_IP%", NetConfig::localIP().c_str()); + tmp.replace("%ESP_NAME%", NetConfig::hostname()); #else - tmp.replace("%ESP_IP%", "???"); - tmp.replace("%ESP_NAME%", "???"); + tmp.replace("%ESP_IP%", "???"); + tmp.replace("%ESP_NAME%", "???"); #endif // WIFI_FEATURE || ETH_FEATURE #if defined(TIMESTAMP_FEATURE) - tmp.replace("%ESP_DATETIME%", timeService.getCurrentTime()); + String dt = timeService.getCurrentTime(); + if (formatspace) dt.replace(" ", "\\ "); + tmp.replace("%ESP_DATETIME%", dt.c_str()); #else tmp.replace("%ESP_DATETIME%", "???"); #endif // TIMESTAMP_FEATURE - } return tmp.c_str(); } \ No newline at end of file diff --git a/esp3d/src/core/esp3d_string.h b/esp3d/src/core/esp3d_string.h index b49f0c37..5bf60855 100644 --- a/esp3d/src/core/esp3d_string.h +++ b/esp3d/src/core/esp3d_string.h @@ -28,7 +28,7 @@ const char* getContentType(const char* filename); const char* encodeString(const char* s); const char* formatBytes(uint64_t bytes); bool isPrintableChar(char c); -const char * expandString(const char *s); +const char * expandString(const char *s, bool formatspace = false); } // namespace esp3d_string #endif //_ESP3D_STRING_H diff --git a/esp3d/src/include/esp3d_sanity.h b/esp3d/src/include/esp3d_sanity.h index bd935102..900759ca 100644 --- a/esp3d/src/include/esp3d_sanity.h +++ b/esp3d/src/include/esp3d_sanity.h @@ -20,7 +20,7 @@ #ifndef _SANITY_ESP3D_H #define _SANITY_ESP3D_H -#if not defined(ESP_NO_SANITY_CHECK) + /************************** * Settings * ***********************/ @@ -39,7 +39,9 @@ #if defined(ESP_LOG_FEATURE) #if ESP_LOG_FEATURE == ESP_SERIAL_OUTPUT +#if not defined(ESP_NO_SANITY_CHECK) #warning You use same serial for output and log +#endif // SANITY_ESP3D_H #endif // ESP_LOG_FEATURE == ESP_SERIAL_OUTPUT #if (ESP_LOG_FEATURE == LOG_OUTPUT_SERIAL2) && defined(ARDUINO_ARCH_ESP8266) #error Serial 2 is not available in ESP8266 for log @@ -88,8 +90,19 @@ #endif /************************** - * Time + * Hooks * ***********************/ +#if defined(ESP_AUTOSTART_SCRIPT) || defined(ESP_AUTOSTART_SCRIPT_FILE) || defined(ESP_GOT_IP_HOOK) || defined(ESP_GOT_DATE_TIME_HOOK) +#ifndef GCODE_HOST_FEATURE +#error GCODE_HOST_FEATURE is necessary for ESP_AUTOSTART_SCRIPT/ESP_AUTOSTART_SCRIPT_FILE/ESP_GOT_IP_HOOK/ESP_GOT_DATE_TIME_HOOK +#endif //ifndef GCODE_HOST_FEATURE +#endif //#if defined(ESP_AUTOSTART_SCRIPT) || defined(ESP_AUTOSTART_SCRIPT_FILE) || defined(ESP_GOT_IP_HOOK) || defined(ESP_GOT_DATE_TIME_HOOK) + +#if defined(ESP_GOT_IP_HOOK) || defined(ESP_GOT_DATE_TIME_HOOK) +#if !defined(WIFI_FEATURE) && !defined(ETH_FEATURE) +#error Hooks need at least one network defined (WIFI_FEATURE or ETH_FEATURE) +#endif //!defined(WIFI_FEATURE) && !defined(ETH_FEATURE) +#endif //#if defined(ESP_GOT_IP_HOOK) || defined(ESP_GOT_DATE_TIME_HOOK) /************************** * Filesystem @@ -183,4 +196,3 @@ #endif // ESP_NO_SANITY_CHECK -#endif // SANITY_ESP3D_H diff --git a/esp3d/src/modules/gcode_host/gcode_host.cpp b/esp3d/src/modules/gcode_host/gcode_host.cpp index a06b6025..4650e354 100644 --- a/esp3d/src/modules/gcode_host/gcode_host.cpp +++ b/esp3d/src/modules/gcode_host/gcode_host.cpp @@ -318,7 +318,7 @@ void GcodeHost::processCommand() { (uint8_t *)_currentCommand.c_str(), _currentCommand.length()); if (isESPcmd) { ESP3DMessage *msg = ESP3DMessageManager::newMsg( - ESP3DClientType::stream, esp3d_commands.getOutputClient(), + ESP3DClientType::no_client, esp3d_commands.getOutputClient(), (uint8_t *)_currentCommand.c_str(), _currentCommand.length(), _auth); if (msg) { // process command @@ -493,17 +493,20 @@ uint32_t GcodeHost::getCommandNumber(String &response) { bool GcodeHost::processScript(const char *line, ESP3DAuthenticationLevel auth_type) { + if (_step != HOST_NO_STREAM) { + esp3d_log("Streaming already in progress"); + while(_step != HOST_NO_STREAM){ + handle(); + } + } _script = line; _script.trim(); esp3d_log("Processing script: %s", _script.c_str()); if (_script.length() == 0) { - esp3d_log("No script to process"); - return false; - } - if (_step != HOST_NO_STREAM) { - esp3d_log("Streaming already in progress"); + esp3d_log_e("No script to process"); return false; } + _fsType = TYPE_SCRIPT_STREAM; _step = HOST_START_STREAM; _auth_type = auth_type; @@ -519,11 +522,11 @@ bool GcodeHost::processFile(const char *filename, _fileName.trim(); esp3d_log("Processing file: %s", filename); if (_fileName.length() == 0) { - esp3d_log("No file to process"); + esp3d_log_e("No file to process"); return false; } if (_step != HOST_NO_STREAM) { - esp3d_log("Streaming already in progress"); + esp3d_log_e("Streaming already in progress"); return false; } // TODO UD = USB DISK diff --git a/esp3d/src/modules/network/netconfig.cpp b/esp3d/src/modules/network/netconfig.cpp index 89f68891..b504b452 100644 --- a/esp3d/src/modules/network/netconfig.cpp +++ b/esp3d/src/modules/network/netconfig.cpp @@ -42,7 +42,11 @@ #endif // BLUETOOTH_FEATURE #include "../../core/esp3d_commands.h" #include "../../core/esp3d_settings.h" +#include "../../core/esp3d_string.h" #include "netservices.h" +#if defined(GCODE_HOST_FEATURE) +#include "../gcode_host/gcode_host.h" +#endif // GCODE_HOST_FEATURE String NetConfig::_hostname = ""; bool NetConfig::_needReconnect2AP = false; @@ -210,10 +214,11 @@ void NetConfig::onWiFiEvent(WiFiEvent_t event) { } break; case WIFI_EVENT_STAMODE_GOT_IP: { #if COMMUNICATION_PROTOCOL != MKS_SERIAL - esp3d_commands.dispatch(WiFi.localIP().toString().c_str(), - ESP3DClientType::all_clients, no_id, - ESP3DMessageType::unique, ESP3DClientType::system, - ESP3DAuthenticationLevel::admin); + #if defined (ESP_GOT_IP_HOOK) && defined (GCODE_HOST_FEATURE) + String ipMsg = esp3d_string::expandString(ESP_GOT_IP_HOOK); + esp3d_log("Got IP, sending hook: %s", ipMsg.c_str()); + esp3d_gcode_host.processScript(ipMsg.c_str(), ESP3DAuthenticationLevel::admin); + #endif // #if defined (ESP_GOT_IP_HOOK) && defined (GCODE_HOST_FEATURE) #endif // #if COMMUNICATION_PROTOCOL == MKS_SERIAL } break; case WIFI_EVENT_SOFTAPMODE_STACONNECTED: { @@ -251,12 +256,16 @@ void NetConfig::onWiFiEvent(WiFiEvent_t event) { ESP3DAuthenticationLevel::admin); EthConfig::setConnected(false); } break; - case ARDUINO_EVENT_ETH_GOT_IP: - esp3d_commands.dispatch(ETH.localIP().toString().c_str(), - ESP3DClientType::all_clients, no_id, - ESP3DMessageType::unique, ESP3DClientType::system, - ESP3DAuthenticationLevel::admin); + case ARDUINO_EVENT_ETH_GOT_IP:{ +#if COMMUNICATION_PROTOCOL != MKS_SERIAL + #if defined (ESP_GOT_IP_HOOK) && defined (GCODE_HOST_FEATURE) + String ipMsg = esp3d_string::expandString(ESP_GOT_IP_HOOK); + esp3d_log("Got IP, sending hook: %s", ipMsg.c_str()); + esp3d_gcode_host.processScript(ipMsg.c_str(), ESP3DAuthenticationLevel::admin); + #endif // #if defined (ESP_GOT_IP_HOOK) && defined (GCODE_HOST_FEATURE) +#endif // #if COMMUNICATION_PROTOCOL == MKS_SERIAL EthConfig::setConnected(true); + } break; case ARDUINO_EVENT_ETH_STOP: EthConfig::setConnected(false); diff --git a/esp3d/src/modules/network/netservices.cpp b/esp3d/src/modules/network/netservices.cpp index df5c1dcc..8048e768 100644 --- a/esp3d/src/modules/network/netservices.cpp +++ b/esp3d/src/modules/network/netservices.cpp @@ -488,6 +488,9 @@ void NetServices::handle() { #ifdef NOTIFICATION_FEATURE notificationsservice.handle(); #endif // NOTIFICATION_FEATURE +#if defined (TIMESTAMP_FEATURE) && (defined (ESP_GOT_IP_HOOK) || defined (ESP_GOT_DATE_TIME_HOOK)) + timeService.handle(); +#endif // TIMESTAMP_FEATURE } if (_restart) { begin(); diff --git a/esp3d/src/modules/notifications/notifications_service.cpp b/esp3d/src/modules/notifications/notifications_service.cpp index 934a2210..666ef548 100644 --- a/esp3d/src/modules/notifications/notifications_service.cpp +++ b/esp3d/src/modules/notifications/notifications_service.cpp @@ -670,7 +670,7 @@ void NotificationsService::end() { _started = false; _notificationType = 0; _token1 = ""; - _token1 = ""; + _token2 = ""; _settings = ""; _serveraddress = ""; _port = 0; diff --git a/esp3d/src/modules/time/time_service.cpp b/esp3d/src/modules/time/time_service.cpp index 3cf1fe45..1754353e 100644 --- a/esp3d/src/modules/time/time_service.cpp +++ b/esp3d/src/modules/time/time_service.cpp @@ -23,6 +23,7 @@ #include "../../core/esp3d_message.h" #include "../../core/esp3d_settings.h" +#include "../../core/esp3d_string.h" #include "time_service.h" #if defined(WIFI_FEATURE) @@ -35,6 +36,10 @@ #include "../ethernet/ethconfig.h" #endif // ETH_FEATURE +#if defined(GCODE_HOST_FEATURE) +#include "../gcode_host/gcode_host.h" +#endif // GCODE_HOST_FEATURE + TimeService timeService; const char* SupportedTimeZones[] = { @@ -232,7 +237,25 @@ void TimeService::end() { // currently not used void TimeService::handle() { + static bool isSet = false; if (_started) { + // check if time is set + time_t now = time(nullptr); + if (now < (8 * 3600 * 2)) { + esp3d_log("Time not set, retry"); + isSet = false; + } else { + if (!isSet) { + esp3d_log("Time set"); + isSet = true; +#if COMMUNICATION_PROTOCOL != MKS_SERIAL +#if defined(ESP_GOT_DATE_TIME_HOOK) && defined(GCODE_HOST_FEATURE) + String dateMsg = esp3d_string::expandString(ESP_GOT_DATE_TIME_HOOK, true); + esp3d_gcode_host.processScript(dateMsg.c_str()); +#endif // #if defined (ESP_GOT_IP_HOOK) && defined (GCODE_HOST_FEATURE) +#endif // #if COMMUNICATION_PROTOCOL == MKS_SERIAL + } + } } }