From 05cf212e79728c2bf1449ee5cfdf7dd6b1a8c4fd Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 10 May 2022 15:47:05 +0200 Subject: refactor(minion): create request class --- minion/src/gymnasiearbete.cpp | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) (limited to 'minion/src/gymnasiearbete.cpp') 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(connection_id)); + Serial.print("Connection ID: "); + Serial.println(static_cast(connection_id)); - Serial.print("\nRaw request: "); - Serial.println(raw_request); + Serial.print("Request method: "); + Serial.println(http_request_method_strs[static_cast(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); } -- cgit v1.2.3-18-g5258