diff options
Diffstat (limited to 'minion/src/gymnasiearbete.cpp')
-rw-r--r-- | minion/src/gymnasiearbete.cpp | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/minion/src/gymnasiearbete.cpp b/minion/src/gymnasiearbete.cpp index 927cd1c..30e5605 100644 --- a/minion/src/gymnasiearbete.cpp +++ b/minion/src/gymnasiearbete.cpp @@ -1,3 +1,4 @@ +#include "http/request.hpp" #include "secrets.hpp" #include "wifi_module.hpp" @@ -9,13 +10,11 @@ constexpr auto HTTP_PORT = 80U; constexpr auto BAUDRATE = 9600U; -constexpr auto NETWORK_MODULE_RX_PIN = 3; -constexpr auto NETWORK_MODULE_TX_PIN = 2; +constexpr auto NETWORK_MODULE_RX_PIN = 13U; +constexpr auto NETWORK_MODULE_TX_PIN = 11U; constexpr auto SECOND_IN_MILLIS = 1000U; -constexpr auto MAX_HTTP_REQUEST_SIZE = 200U; - auto wifi_module = WiFiModule({ NETWORK_MODULE_RX_PIN, NETWORK_MODULE_TX_PIN }); void setup() @@ -74,22 +73,35 @@ void setup() void loop() { - if (wifi_module.has_incoming_request()) + const auto *request = wifi_module.read_incoming_request(); + + if (request == nullptr) { - char raw_request[MAX_HTTP_REQUEST_SIZE] = ""; + return; + } - const auto connection_id = wifi_module.read_incoming_request(raw_request); + const auto connection_id = request->connection_id(); - Serial.print("Connection ID: "); - Serial.println(static_cast<unsigned int>(connection_id)); + Serial.print("Connection ID: "); + Serial.println(static_cast<unsigned int>(connection_id)); - Serial.print("\nRaw request: "); - Serial.println(raw_request); + Serial.print("Request method: "); + Serial.println(http_request_method_strs[static_cast<size_t>(request->method())]); - wifi_module.send(connection_id, "lmao!"); + Serial.print("Request HTTP version: "); + Serial.println(request->http_version()); - wifi_module.close_connection(connection_id); + Serial.print("Request path: "); + Serial.println(request->path()); - delay(SECOND_IN_MILLIS); - } + Serial.print("\nData: "); + Serial.println(request->data()); + + wifi_module.send(connection_id, "lmao!"); + + wifi_module.close_connection(connection_id); + + delete request; + + delay(SECOND_IN_MILLIS); } |