summaryrefslogtreecommitdiff
path: root/minion/src/gymnasiearbete.cpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-05-10 15:47:05 +0200
committerHampusM <hampus@hampusmat.com>2022-05-11 23:14:41 +0200
commit05cf212e79728c2bf1449ee5cfdf7dd6b1a8c4fd (patch)
treef613790a2df7b0ac6a5a339f83e43dbd9d547a6a /minion/src/gymnasiearbete.cpp
parent6decaf83fc2b1e751876a76d72c4370b3b66a507 (diff)
refactor(minion): create request class
Diffstat (limited to 'minion/src/gymnasiearbete.cpp')
-rw-r--r--minion/src/gymnasiearbete.cpp42
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);
}