From ca5386fe5e220f95f9fb796bc5781b440e55f2d8 Mon Sep 17 00:00:00 2001 From: Maximilian Bundscherer Date: Thu, 4 Aug 2022 14:46:23 +0200 Subject: [PATCH 1/2] Update to v.0.3.2 and Improve Escape Data --- docs/escape-rules.md | 3 +++ independer-app/src/device/mb-utils.h | 10 ++++++++++ independer-app/src/main.cpp | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/escape-rules.md b/docs/escape-rules.md index d0b5012..b67b60a 100644 --- a/docs/escape-rules.md +++ b/docs/escape-rules.md @@ -16,3 +16,6 @@ - 10 - `%` - 11 - `-` - 12 - `_` +- 13 - `"` +- 14 - `'` +- 15 - `\` diff --git a/independer-app/src/device/mb-utils.h b/independer-app/src/device/mb-utils.h index e1068d9..dce8297 100644 --- a/independer-app/src/device/mb-utils.h +++ b/independer-app/src/device/mb-utils.h @@ -92,6 +92,11 @@ String utils_encode_data(String data) data.replace("-", "`11`"); data.replace("_", "`12`"); + data.replace("\"", "`13`"); + data.replace("'", "`14`"); + + data.replace("\\", "`15`"); + return data; } @@ -114,6 +119,11 @@ String utils_decode_data(String data) data.replace("`11`", "-"); data.replace("`12`", "_"); + data.replace("`13`", "\""); + data.replace("`14`", "'"); + + data.replace("`15`", "\\"); + return data; } diff --git a/independer-app/src/main.cpp b/independer-app/src/main.cpp index 1149ae4..1c2b7e5 100644 --- a/independer-app/src/main.cpp +++ b/independer-app/src/main.cpp @@ -24,7 +24,7 @@ boolean c_actor_mode = false; * #################################### */ // Product Config -String c_product_version = "v.0.3.1"; +String c_product_version = "v.0.3.2"; boolean c_demo_mode = false; /* From 0355da183c7963ea40e6fff7211a2bb87fd91d3a Mon Sep 17 00:00:00 2001 From: Maximilian Bundscherer Date: Thu, 4 Aug 2022 14:59:40 +0200 Subject: [PATCH 2/2] Implement Delete Messages --- independer-app/src/device/mb-wifi.h | 84 ++++++++++++++++++++ independer-app/src/workflow/workflow-actor.h | 8 +- 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/independer-app/src/device/mb-wifi.h b/independer-app/src/device/mb-wifi.h index 75b75cc..e1a5091 100644 --- a/independer-app/src/device/mb-wifi.h +++ b/independer-app/src/device/mb-wifi.h @@ -221,5 +221,89 @@ String wifi_get_chat_messages(String myId, String serverUrl, int serverPort, int i_wifi_disconnect(); + return ret_status; +} + +/* + * #################################### + * Clear Chat Message Section + * #################################### + */ + +boolean wifi_clear_message(String myId, String serverUrl, int serverPort, int serverTimeout) +{ + + char *c_wifi_server_url = const_cast(serverUrl.c_str()); + int c_wifi_server_port = serverPort; + int c_wifi_timeout = serverTimeout; + + boolean ret_status = false; + + if (i_wifi_connect()) + { + + // Code Start + Serial.println("[Send GET REQUEST] START"); + Serial.println("Connect to server (timeout " + String(c_wifi_timeout) + ")"); + if (!i_wifi_client.connect(c_wifi_server_url, c_wifi_server_port, c_wifi_timeout)) + { + Serial.println("Connection failed!"); + } + else + { + Serial.println("Connected to server!"); + /* create HTTP request */ + + int c_mail_max_fails = 150; + + int mail_fail_connect_counter = 0; + + String send_string = String("GET ") + "/v1/clearmsg/" + myId + " HTTP/1.1\r\n" + + "Host: " + String(c_wifi_server_url) + ":" + String(c_wifi_server_port) + "\r\n" + + "Content-Type: application/json" + "\r\n" + + "Connection: close\r\n\r\n"; + + Serial.println("Send String is '" + send_string + "'"); + + i_wifi_client.print(send_string); + + Serial.println("[Waiting for response] START"); + while (!i_wifi_client.available() and mail_fail_connect_counter < c_mail_max_fails) + { + mail_fail_connect_counter++; + Serial.print("AM=" + String(mail_fail_connect_counter) + "/" + String(c_mail_max_fails) + " "); + delay(50); // + } + Serial.println("\n[Waiting for response] STOP"); + + String line = ""; + while (i_wifi_client.available()) + { + line += i_wifi_client.readStringUntil('\r'); + } + Serial.print("Response '" + line + "'"); + + if (line.endsWith("OK")) + { + ret_status = true; + } + + /* if the server disconnected, stop the client */ + if (!i_wifi_client.connected()) + { + Serial.println(); + Serial.println("Server disconnected"); + } + + i_wifi_client.stop(); + } + Serial.println("[Send GET Request] STOP"); + // Mail Cod Stop + } + else + Serial.println("Could not send mail: WiFi is not connected"); + + i_wifi_disconnect(); + return ret_status; } \ No newline at end of file diff --git a/independer-app/src/workflow/workflow-actor.h b/independer-app/src/workflow/workflow-actor.h index 8f24a36..8360346 100644 --- a/independer-app/src/workflow/workflow-actor.h +++ b/independer-app/src/workflow/workflow-actor.h @@ -224,7 +224,13 @@ void i_communication_chat_menu() else if (selected_wrapper.success and selected_wrapper.value == 1) application_actor_query_msgs_from_internet(state_my_id); else if (selected_wrapper.success and selected_wrapper.value == 2) - gui_msg_animated("Info", "Leider ist die Funktion\n'Chat leeren'\nnoch nicht verfügbar.", C_GUI_DELAY_MSG_SHORT_I); + { + gui_msg_static("Hinweis", "Chat wird\ngelöscht..."); + if (wifi_clear_message(state_my_id, state_wifi_server_url, state_wifi_server_port, state_wifi_server_timeout)) + gui_msg_animated("Info", "Chat wurde\ngelöscht.", C_GUI_DELAY_MSG_SHORT_I); + else + gui_msg_animated("Info", "Chat konnte nicht\ngelöscht werden.", C_GUI_DELAY_MSG_SHORT_I); + } else fin_flag = true; }