From 5aac9724eeba929ea88bd1ebf1d9fe2d7203180d Mon Sep 17 00:00:00 2001 From: John Bain Date: Fri, 7 Jan 2022 17:28:47 -0500 Subject: [PATCH 1/5] first push --- .vscode/settings.json | 37 ++++++++++++++++++ esp3d/config.h | 1 + esp3d/notifications_service.cpp | 67 ++++++++++++++++++++++++++++++++- esp3d/notifications_service.h | 1 + 4 files changed, 105 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index fed5a7bd3..db798a72d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,5 +2,42 @@ "terminal.integrated.env.windows": { "PATH": "C:\\Users\\user\\.platformio\\penv\\Scripts;C:\\Users\\user\\.platformio\\penv;C:\\ImageMagick\\ImageMagick-7.0.8-Q16;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\iCLS\\;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\iCLS\\;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\Program Files\\Intel\\WiFi\\bin\\;C:\\Program Files\\Common Files\\Intel\\WirelessCommon\\;C:\\Program Files\\PuTTY\\;C:\\Program Files\\Git\\cmd;C:\\Program Files\\nodejs\\;C:\\Program Files\\TortoiseGit\\bin;C:\\Program Files\\dotnet\\;C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\110\\Tools\\Binn\\;C:\\Program Files (x86)\\Microsoft SQL Server\\120\\Tools\\Binn\\;C:\\Program Files\\Microsoft SQL Server\\120\\Tools\\Binn\\;C:\\Program Files\\Microsoft SQL Server\\120\\DTS\\Binn\\;C:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit\\;C:\\Program Files\\LLVM\\bin;C:\\Program Files\\Microsoft VS Code\\bin;C:\\Users\\user\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Program Files\\Intel\\WiFi\\bin\\;C:\\Program Files\\Common Files\\Intel\\WirelessCommon\\;C:\\Users\\user\\AppData\\Local\\GitHubDesktop\\bin;C:\\Eclipse\\GNUTools\\2.6-201507152002\\bin;C:\\Users\\user\\AppData\\Roaming\\npm;C:\\Users\\user\\AppData\\Local\\atom\\bin;C:\\Unxtools;;%USERPROFILE%\\AppData\\Local\\Microsoft\\WindowsApps;C:\\ImageMagick\\ImageMagick-7.0.8-Q16;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\iCLS\\;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\iCLS\\;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\Program Files\\Intel\\WiFi\\bin\\;C:\\Program Files\\Common Files\\Intel\\WirelessCommon\\;C:\\Program Files\\PuTTY\\;C:\\Program Files\\Git\\cmd;C:\\Program Files\\nodejs\\;C:\\Program Files\\TortoiseGit\\bin;C:\\Program Files\\dotnet\\;C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\110\\Tools\\Binn\\;C:\\Program Files (x86)\\Microsoft SQL Server\\120\\Tools\\Binn\\;C:\\Program Files\\Microsoft SQL Server\\120\\Tools\\Binn\\;C:\\Program Files\\Microsoft SQL Server\\120\\DTS\\Binn\\;C:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit\\;C:\\Program Files\\LLVM\\bin;C:\\Program Files\\Microsoft VS Code\\bin;C:\\Users\\user\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Program Files\\Intel\\WiFi\\bin\\;C:\\Program Files\\Common Files\\Intel\\WirelessCommon\\;C:\\Users\\user\\AppData\\Local\\GitHubDesktop\\bin;C:\\Eclipse\\GNUTools\\2.6-201507152002\\bin;C:\\Users\\user\\AppData\\Roaming\\npm;C:\\Users\\user\\AppData\\Local\\atom\\bin;C:\\Unxtools;;%USERPROFILE%\\AppData\\Local\\Microsoft\\WindowsApps", "PLATFORMIO_CALLER": "vscode" + }, + "files.associations": { + "string": "cpp", + "*.tcc": "cpp", + "unordered_map": "cpp", + "array": "cpp", + "atomic": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "list": "cpp", + "vector": "cpp", + "exception": "cpp", + "fstream": "cpp", + "functional": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "ostream": "cpp", + "numeric": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "cinttypes": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "typeinfo": "cpp" } } \ No newline at end of file diff --git a/esp3d/config.h b/esp3d/config.h index 2cd7e43a4..e458df4af 100644 --- a/esp3d/config.h +++ b/esp3d/config.h @@ -420,6 +420,7 @@ const int DEFAULT_DHT_INTERVAL = 30; #define ESP_PUSHOVER_NOTIFICATION 1 #define ESP_EMAIL_NOTIFICATION 2 #define ESP_LINE_NOTIFICATION 3 +#define ESP_IFTTT_NOTIFICATION 4 #ifdef SDCARD_FEATURE #define DEFAULT_IS_DIRECT_SD 1 diff --git a/esp3d/notifications_service.cpp b/esp3d/notifications_service.cpp index 4b7a40eec..3c6fa7cde 100644 --- a/esp3d/notifications_service.cpp +++ b/esp3d/notifications_service.cpp @@ -59,6 +59,10 @@ typedef WiFiClientSecure TSecureClient; #define LINESERVER "notify-api.line.me" #define LINEPORT 443 +#define IFTTTTIMEOUT 5000 +#define IFTTTSERVER "maker.ifttt.com" +#define IFTTTPORT 443 + #define EMAILTIMEOUT 5000 NotificationsService notificationsservice; @@ -132,6 +136,8 @@ const char * NotificationsService::getTypeString() return "Email"; case ESP_LINE_NOTIFICATION: return "Line"; + case ESP_IFTTT_NOTIFICATION: + return "IFTTT"; default: break; } @@ -154,6 +160,9 @@ bool NotificationsService::sendMSG(const char * title, const char * message) case ESP_LINE_NOTIFICATION : return sendLineMSG(title,message); break; + case ESP_IFTTT_NOTIFICATION : + return sendIFTTTMSG(title,message); + break; default: break; } @@ -329,6 +338,51 @@ bool NotificationsService::sendLineMSG(const char * title, const char * message) Notificationclient.stop(); return res; } +//IFTTT +bool NotificationsService::sendIFTTTMSG(const char * title, const char * message) +{ + String data; + String postcmd; + + bool res; + + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" + TSecureClient Notificationclient; + #pragma GCC diagnostic pop + #if defined(ARDUINO_ARCH_ESP8266) && !defined(USING_AXTLS) + Notificationclient.setInsecure(); + #endif //ARDUINO_ARCH_ESP8266 && !USING_AXTLS + (void)title; + if (!Notificationclient.connect(_serveraddress.c_str(), _port)) { + //log_esp3d("Error connecting server %s:%d", _serveraddress.c_str(), _port); + return false; + } + + std::string authTokens; + + //split authentication + authTokens = _token1.c_str(); + std::string webhookEvent = authTokens.substr(0, authTokens.find(";")); + std::string authToken = authTokens.substr(1, authTokens.find(";")); + + //build data for post + data = "message="; + data += message; + //build post query + postcmd = "POST /trigger/" + webhookEvent + "/with/key/" + authToken + "?value1=value1&value2=value2&value3=value3" + " HTTP/1.1\r\nHost: notify-api.line.me\r\nConnection: close\r\nCache-Control: no-cache\r\nUser-Agent: ESP3D\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nContent-Type: application/x-www-form-urlencoded\r\n"; + postcmd += "Content-Length: "; + postcmd += data.length(); + postcmd +="\r\n\r\n"; + postcmd +=data; + //log_esp3d("Query: %s", postcmd.c_str()); + //send query + Notificationclient.print(postcmd); + res = Wait4Answer(Notificationclient, "{", "\"status\":200", LINETIMEOUT); + Notificationclient.stop(); + return res; +} + //Email#serveraddress:port bool NotificationsService::getPortFromSettings() { @@ -386,7 +440,6 @@ bool NotificationsService::getEmailFromSettings() return true; } - bool NotificationsService::begin() { bool res = true; @@ -416,6 +469,17 @@ bool NotificationsService::begin() _port = LINEPORT; _serveraddress = LINESERVER; break; + case ESP_IFTTT_NOTIFICATION: + if (CONFIG::read_string (ESP_NOTIFICATION_TOKEN1, sbuf, MAX_NOTIFICATION_TOKEN_LENGTH) ) { + _token1 = sbuf; + } + if (CONFIG::read_string (ESP_NOTIFICATION_TOKEN2, sbuf, MAX_NOTIFICATION_TOKEN_LENGTH) ) { + _token2 = sbuf; + } + _port = IFTTTPORT; + _serveraddress = IFTTTSERVER; + break; + case ESP_EMAIL_NOTIFICATION: if (CONFIG::read_string (ESP_NOTIFICATION_TOKEN1, sbuf, MAX_NOTIFICATION_TOKEN_LENGTH) ) { _token1 = base64::encode(sbuf); @@ -462,4 +526,5 @@ void NotificationsService::handle() } } + #endif //NOTIFICATION_FEATURE diff --git a/esp3d/notifications_service.h b/esp3d/notifications_service.h index 54909b1e8..b69ef35c3 100644 --- a/esp3d/notifications_service.h +++ b/esp3d/notifications_service.h @@ -50,6 +50,7 @@ class NotificationsService bool sendPushoverMSG(const char * title, const char * message); bool sendEmailMSG(const char * title, const char * message); bool sendLineMSG(const char * title, const char * message); + bool sendIFTTTMSG(const char * title, const char * message); bool getPortFromSettings(); bool getServerAddressFromSettings(); bool getEmailFromSettings(); From 8df49d921ffc27d8015e6811dfa7407cd8bc914e Mon Sep 17 00:00:00 2001 From: John Bain Date: Fri, 7 Jan 2022 18:54:05 -0500 Subject: [PATCH 2/5] modified post to work with IFTTT --- esp3d/command.cpp | 6 +++++- esp3d/notifications_service.cpp | 35 ++++++++++----------------------- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/esp3d/command.cpp b/esp3d/command.cpp index 7e2b8776d..083fdf048 100644 --- a/esp3d/command.cpp +++ b/esp3d/command.cpp @@ -1244,6 +1244,8 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a ESPCOM::print ( (const char *) CONFIG::intTostr (ESP_EMAIL_NOTIFICATION), output, espresponse); ESPCOM::print (F("\"},{\"Line\":\""), output, espresponse); ESPCOM::print ( (const char *) CONFIG::intTostr (ESP_LINE_NOTIFICATION), output, espresponse); + ESPCOM::print (F("\"},{\"IFTTT\":\""), output, espresponse); + ESPCOM::print ( (const char *) CONFIG::intTostr (ESP_IFTTT_NOTIFICATION), output, espresponse); ESPCOM::print (F("\"}]}"), output, espresponse); ESPCOM::println (F (","), output, espresponse); //Token 1 @@ -1737,7 +1739,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a } char sbuf[MAX_DATA_LENGTH + 1]; static String tmp; - tmp = (Ntype == ESP_PUSHOVER_NOTIFICATION)?"PUSHOVER":(Ntype == ESP_EMAIL_NOTIFICATION)?"EMAIL":(Ntype == ESP_LINE_NOTIFICATION)?"LINE":"NONE"; + tmp = (Ntype == ESP_PUSHOVER_NOTIFICATION)?"PUSHOVER":(Ntype == ESP_EMAIL_NOTIFICATION)?"EMAIL":(Ntype == ESP_LINE_NOTIFICATION)?"LINE":(Ntype == ESP_IFTTT_NOTIFICATION)?"IFTTT":"NONE"; if (CONFIG::read_string (ESP_NOTIFICATION_SETTINGS, sbuf, MAX_NOTIFICATION_SETTINGS_LENGTH) ) { tmp+= " "; tmp += sbuf; @@ -1758,6 +1760,8 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a Ntype = ESP_EMAIL_NOTIFICATION; } else if (parameter == "LINE") { Ntype = ESP_LINE_NOTIFICATION; + } else if (parameter == "IFTTT") { + Ntype = ESP_IFTTT_NOTIFICATION; } else { ESPCOM::println (INCORRECT_CMD_MSG, output, espresponse); return false; diff --git a/esp3d/notifications_service.cpp b/esp3d/notifications_service.cpp index 3c6fa7cde..2b647eae2 100644 --- a/esp3d/notifications_service.cpp +++ b/esp3d/notifications_service.cpp @@ -343,42 +343,27 @@ bool NotificationsService::sendIFTTTMSG(const char * title, const char * message { String data; String postcmd; - bool res; - - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" TSecureClient Notificationclient; - #pragma GCC diagnostic pop - #if defined(ARDUINO_ARCH_ESP8266) && !defined(USING_AXTLS) - Notificationclient.setInsecure(); - #endif //ARDUINO_ARCH_ESP8266 && !USING_AXTLS - (void)title; +#pragma GCC diagnostic pop +#if defined(ARDUINO_ARCH_ESP8266) && !defined(USING_AXTLS) + Notificationclient.setInsecure(); +#endif //ARDUINO_ARCH_ESP8266 && !USING_AXTLS if (!Notificationclient.connect(_serveraddress.c_str(), _port)) { //log_esp3d("Error connecting server %s:%d", _serveraddress.c_str(), _port); return false; } - std::string authTokens; - - //split authentication - authTokens = _token1.c_str(); - std::string webhookEvent = authTokens.substr(0, authTokens.find(";")); - std::string authToken = authTokens.substr(1, authTokens.find(";")); - - //build data for post - data = "message="; - data += message; //build post query - postcmd = "POST /trigger/" + webhookEvent + "/with/key/" + authToken + "?value1=value1&value2=value2&value3=value3" + " HTTP/1.1\r\nHost: notify-api.line.me\r\nConnection: close\r\nCache-Control: no-cache\r\nUser-Agent: ESP3D\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nContent-Type: application/x-www-form-urlencoded\r\n"; - postcmd += "Content-Length: "; - postcmd += data.length(); - postcmd +="\r\n\r\n"; - postcmd +=data; + + postcmd = "POST /trigger/" + _token1 + "/with/key/" + _token2 +"/?value1=" + title + "&value2=" + message + "&value3=" + wifi_config.get_hostname() + " HTTP/1.1\r\nHost: maker.ifttt.com\r\nConnection: close\r\nCache-Control: no-cache\r\nUser-Agent: ESP3D\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nContent-Type: application/x-www-form-urlencoded\r\n"; + //log_esp3d("Query: %s", postcmd.c_str()); //send query Notificationclient.print(postcmd); - res = Wait4Answer(Notificationclient, "{", "\"status\":200", LINETIMEOUT); + res = Wait4Answer(Notificationclient, "{", "\"status\":1", PUSHOVERTIMEOUT); Notificationclient.stop(); return res; } From cec183f535f660388b06de3ecca625c02c370555 Mon Sep 17 00:00:00 2001 From: John Bain Date: Fri, 7 Jan 2022 22:11:42 -0500 Subject: [PATCH 3/5] working but returning wrong error code --- esp3d/config.h | 2 +- esp3d/notifications_service.cpp | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/esp3d/config.h b/esp3d/config.h index e458df4af..f690b0799 100644 --- a/esp3d/config.h +++ b/esp3d/config.h @@ -154,7 +154,7 @@ //DEBUG Flag do not do this when connected to printer !!! //be noted all upload may failed if enabled -//#define DEBUG_ESP3D +#define DEBUG_ESP3D //#define DEBUG_OUTPUT_SPIFFS //#define DEBUG_OUTPUT_SERIAL //#define DEBUG_OUTPUT_TCP diff --git a/esp3d/notifications_service.cpp b/esp3d/notifications_service.cpp index 2b647eae2..c4419e5a6 100644 --- a/esp3d/notifications_service.cpp +++ b/esp3d/notifications_service.cpp @@ -198,6 +198,7 @@ bool NotificationsService::sendPushoverMSG(const char * title, const char * mess data += message; data += "&device="; data += wifi_config.get_hostname(); + //build post query postcmd = "POST /1/messages.json HTTP/1.1\r\nHost: api.pushover.net\r\nConnection: close\r\nCache-Control: no-cache\r\nUser-Agent: ESP3D\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nContent-Length: "; postcmd += data.length(); @@ -356,14 +357,25 @@ bool NotificationsService::sendIFTTTMSG(const char * title, const char * message return false; } + //build data for post + + data ="value1="; + data += title; + data += "&value2="; + data += message; + data += "&value3="; + data += wifi_config.get_hostname(); + //build post query - - postcmd = "POST /trigger/" + _token1 + "/with/key/" + _token2 +"/?value1=" + title + "&value2=" + message + "&value3=" + wifi_config.get_hostname() + " HTTP/1.1\r\nHost: maker.ifttt.com\r\nConnection: close\r\nCache-Control: no-cache\r\nUser-Agent: ESP3D\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nContent-Type: application/x-www-form-urlencoded\r\n"; + postcmd = "POST /trigger/" + _token1 + "/with/key/" + _token2 + " HTTP/1.1\r\nHost: maker.ifttt.com\r\nConnection: close\r\nCache-Control: no-cache\r\nUser-Agent: ESP3D\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: "; + postcmd += data.length(); + postcmd +="\r\n\r\n"; + postcmd +=data; //log_esp3d("Query: %s", postcmd.c_str()); //send query Notificationclient.print(postcmd); - res = Wait4Answer(Notificationclient, "{", "\"status\":1", PUSHOVERTIMEOUT); + res = Wait4Answer(Notificationclient, "{", "\"status\":200", IFTTTTIMEOUT); Notificationclient.stop(); return res; } From 389a312e11107d802d033d4ea831e5c2733659b6 Mon Sep 17 00:00:00 2001 From: John Bain Date: Fri, 7 Jan 2022 22:47:29 -0500 Subject: [PATCH 4/5] command successfully being sent to, IFTTT --- esp3d/command.cpp | 2 +- esp3d/config.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/esp3d/command.cpp b/esp3d/command.cpp index 083fdf048..00883efb8 100644 --- a/esp3d/command.cpp +++ b/esp3d/command.cpp @@ -1721,7 +1721,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a } break; //Set/Get Notification settings - //[ESP610]type= T1= T2= TS= [pwd=] + //[ESP610]type= T1= T2= TS= [pwd=] //Get will give type and settings only not the protected T1/T2 case 610: #ifdef AUTHENTICATION_FEATURE diff --git a/esp3d/config.h b/esp3d/config.h index f690b0799..e458df4af 100644 --- a/esp3d/config.h +++ b/esp3d/config.h @@ -154,7 +154,7 @@ //DEBUG Flag do not do this when connected to printer !!! //be noted all upload may failed if enabled -#define DEBUG_ESP3D +//#define DEBUG_ESP3D //#define DEBUG_OUTPUT_SPIFFS //#define DEBUG_OUTPUT_SERIAL //#define DEBUG_OUTPUT_TCP From 13cf62b63bf864e8e6c4f89c1041e90050ed4f81 Mon Sep 17 00:00:00 2001 From: John Bain Date: Fri, 7 Jan 2022 23:19:46 -0500 Subject: [PATCH 5/5] resolved issue with ESP600 returing "Wrong Command --- esp3d/notifications_service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esp3d/notifications_service.cpp b/esp3d/notifications_service.cpp index c4419e5a6..0d733be95 100644 --- a/esp3d/notifications_service.cpp +++ b/esp3d/notifications_service.cpp @@ -375,7 +375,7 @@ bool NotificationsService::sendIFTTTMSG(const char * title, const char * message //log_esp3d("Query: %s", postcmd.c_str()); //send query Notificationclient.print(postcmd); - res = Wait4Answer(Notificationclient, "{", "\"status\":200", IFTTTTIMEOUT); + res = Wait4Answer(Notificationclient, "Congratulations", "Congratulations", IFTTTTIMEOUT); Notificationclient.stop(); return res; }