diff options
author | HampusM <hampus@hampusmat.com> | 2022-05-13 21:00:25 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-05-13 21:00:25 +0200 |
commit | fc1a41c627f25c1fa52c87d002d08870fa8876ac (patch) | |
tree | 78ad84e86d69dd986127735d3967fc670703f4b9 /minion | |
parent | 481ef51ac14ad5b3bf0935dd6110b6a7d8afe731 (diff) |
fix(minion): conform to the http/1.1 response syntax
Diffstat (limited to 'minion')
-rw-r--r-- | minion/src/gymnasiearbete.cpp | 2 | ||||
-rw-r--r-- | minion/src/wifi_module.cpp | 13 | ||||
-rw-r--r-- | minion/src/wifi_module.hpp | 7 |
3 files changed, 18 insertions, 4 deletions
diff --git a/minion/src/gymnasiearbete.cpp b/minion/src/gymnasiearbete.cpp index 42e03a1..47e386e 100644 --- a/minion/src/gymnasiearbete.cpp +++ b/minion/src/gymnasiearbete.cpp @@ -98,7 +98,7 @@ void loop() Serial.print("\nData: "); Serial.println(request->data()); - wifi_module.send_response(connection_id, "lmao!"); + wifi_module.send_response(connection_id, 200U, "hello there!"); wifi_module.close_connection(connection_id); diff --git a/minion/src/wifi_module.cpp b/minion/src/wifi_module.cpp index 7c3e5bc..2f4e57c 100644 --- a/minion/src/wifi_module.cpp +++ b/minion/src/wifi_module.cpp @@ -329,11 +329,16 @@ auto WiFiModule::close_connection(size_t connection_id) noexcept -> bool return true; } -auto WiFiModule::send_response(size_t connection_id, const char *data) noexcept -> bool +auto WiFiModule::send_response( + size_t connection_id, + size_t status_code, + const char *data +) noexcept -> bool { const auto *cmd = "AT+CIPSEND"; - const auto data_length = strlen(data); + const auto data_length = strlen(RESPONSE_HTTP_VERSION) + 1 + + RESPONSE_STATUS_CODE_LENGTH + 4 + strlen(data); auto command_length = strlen(cmd) + 50U + data_length + 1U; @@ -355,6 +360,10 @@ auto WiFiModule::send_response(size_t connection_id, const char *data) noexcept _read(TIMEOUT_MEDIUM, response); + _serial.print(RESPONSE_HTTP_VERSION); + _serial.print(" "); + _serial.print(status_code); + _serial.print("\r\n\r\n"); _serial.print(data); strcpy(response, ""); diff --git a/minion/src/wifi_module.hpp b/minion/src/wifi_module.hpp index 9852d1e..447f056 100644 --- a/minion/src/wifi_module.hpp +++ b/minion/src/wifi_module.hpp @@ -19,6 +19,9 @@ constexpr auto TIMEOUT_SHORT = 1500U; constexpr auto TIMEOUT_MEDIUM = 4000U; constexpr auto TIMEOUT_LONG = 10000U; +constexpr auto RESPONSE_HTTP_VERSION = "HTTP/1.1"; +constexpr auto RESPONSE_STATUS_CODE_LENGTH = 3U; + enum WifiMode { Station = 1, @@ -95,7 +98,9 @@ public: auto close_connection(size_t connection_id) noexcept -> bool; - auto send_response(size_t connection_id, const char *data) noexcept -> bool; + auto + send_response(size_t connection_id, size_t status_code, const char *data) noexcept + -> bool; private: SoftwareSerial _serial; |