Skip to content

Commit

Permalink
Merge pull request #117 from maxbundscherer/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
maxbundscherer authored Aug 4, 2022
2 parents 8fdde76 + 0355da1 commit 4350ad6
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/escape-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
- 10 - `%`
- 11 - `-`
- 12 - `_`
- 13 - `"`
- 14 - `'`
- 15 - `\`
10 changes: 10 additions & 0 deletions independer-app/src/device/mb-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
84 changes: 84 additions & 0 deletions independer-app/src/device/mb-wifi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<char *>(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;
}
2 changes: 1 addition & 1 deletion independer-app/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/*
Expand Down
8 changes: 7 additions & 1 deletion independer-app/src/workflow/workflow-actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 4350ad6

Please sign in to comment.