summaryrefslogtreecommitdiff
path: root/minion/src/gymnasiearbete.cpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-05-09 13:35:44 +0200
committerHampusM <hampus@hampusmat.com>2022-05-09 13:38:58 +0200
commitbb6f2ce801e5c4ee617b27beaf30a746807384ea (patch)
treeb3d1669dbe825e477bfd598c673f16e2507209e2 /minion/src/gymnasiearbete.cpp
parent1cd38166b3372f08aa3c4d322f79597de29e8f3b (diff)
refactor(minion): fix complaints given by clang-tidy
Diffstat (limited to 'minion/src/gymnasiearbete.cpp')
-rw-r--r--minion/src/gymnasiearbete.cpp42
1 files changed, 21 insertions, 21 deletions
diff --git a/minion/src/gymnasiearbete.cpp b/minion/src/gymnasiearbete.cpp
index b3c543a..927cd1c 100644
--- a/minion/src/gymnasiearbete.cpp
+++ b/minion/src/gymnasiearbete.cpp
@@ -5,12 +5,18 @@
#include <SoftwareSerial.h>
#include <string.h>
+constexpr auto HTTP_PORT = 80U;
+
constexpr auto BAUDRATE = 9600U;
constexpr auto NETWORK_MODULE_RX_PIN = 3;
constexpr auto NETWORK_MODULE_TX_PIN = 2;
-auto wifi_module = WiFiModule(NETWORK_MODULE_RX_PIN, NETWORK_MODULE_TX_PIN);
+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()
{
@@ -23,7 +29,7 @@ void setup()
wifi_module.reset();
- delay(1000);
+ delay(SECOND_IN_MILLIS);
auto wifi_module_connected = wifi_module.test();
@@ -39,26 +45,20 @@ void setup()
wifi_module.set_echo_enabled(false);
- delay(1000);
+ delay(SECOND_IN_MILLIS);
const auto wifi_connect_success = wifi_module.connect(WIFI_SSID, WIFI_PASSWORD);
- if (wifi_connect_success)
- {
- Serial.print("Connected to wifi network '");
- Serial.print(WIFI_SSID);
- Serial.println("' successfully");
- }
- else
- {
- Serial.print("Failed to connect to wifi network '");
- Serial.print(WIFI_SSID);
- Serial.println("'");
- }
+ Serial.print(
+ wifi_connect_success ? "Connected to wifi network '"
+ : "Failed to connect to wifi network '"
+ );
+ Serial.print(WIFI_SSID);
+ Serial.println("'");
wifi_module.set_wifi_mode(WifiMode::Station);
- delay(3000);
+ delay(SECOND_IN_MILLIS * 3U);
char local_ip[MAX_NETWORK_MODULE_RESPONSE_LENGTH] = "";
@@ -67,21 +67,21 @@ void setup()
wifi_module.set_multiple_connections_enabled(true);
- delay(1000);
+ delay(SECOND_IN_MILLIS);
- wifi_module.create_tcp_server(80U);
+ wifi_module.create_tcp_server(HTTP_PORT);
}
void loop()
{
if (wifi_module.has_incoming_request())
{
- char raw_request[200] = "";
+ char raw_request[MAX_HTTP_REQUEST_SIZE] = "";
const auto connection_id = wifi_module.read_incoming_request(raw_request);
Serial.print("Connection ID: ");
- Serial.println(connection_id);
+ Serial.println(static_cast<unsigned int>(connection_id));
Serial.print("\nRaw request: ");
Serial.println(raw_request);
@@ -90,6 +90,6 @@ void loop()
wifi_module.close_connection(connection_id);
- delay(1000);
+ delay(SECOND_IN_MILLIS);
}
}