diff --git a/SourceCode/arduino/include/theServer.h b/SourceCode/arduino/include/theServer.h new file mode 100644 index 0000000..adef3ee --- /dev/null +++ b/SourceCode/arduino/include/theServer.h @@ -0,0 +1,39 @@ +#ifndef THESERVER_H +#define THESERVER_H + +#include "WebServer.h" +#include "cJSON.h" + +static WebServer server(8080); + +void custom_message_response(const char *message, int response_code) +{ + cJSON *json_response = cJSON_CreateObject(); + cJSON_AddBoolToObject(json_response, "ok", true); + cJSON_AddStringToObject(json_response, "message", message); + server.send(response_code, "application/json", cJSON_Print(json_response)); + cJSON_Delete(json_response); +} + +static void getFirewallRules() +{ + custom_message_response("firewall rules..", 200); +} + +static void setup_routing() +{ + server.on("/api/v1/firewall", HTTP_GET, getFirewallRules); +} + +void setup_server() +{ + setup_routing(); + server.begin(); +} + +void handle_server_clients() +{ + server.handleClient(); +} + +#endif diff --git a/SourceCode/arduino/include/theWifi.h b/SourceCode/arduino/include/theWifi.h index 1c33737..0f4c2b4 100644 --- a/SourceCode/arduino/include/theWifi.h +++ b/SourceCode/arduino/include/theWifi.h @@ -5,9 +5,9 @@ #include "WiFi.h" #include "theSecrets.h" -const char *serverIp; +const char *esp_ip_address; -void connectWifi() +void setup_wifi() { log_i("Attempting to connect to WPA SSID: %s", ssid); WiFi.mode(WIFI_STA); @@ -16,8 +16,8 @@ void connectWifi() { delay(1000); } - serverIp = WiFi.localIP().toString().c_str(); - log_i("Connected, IP Address: %s", serverIp); + esp_ip_address = WiFi.localIP().toString().c_str(); + log_i("Connected, IP Address: %s", esp_ip_address); } -#endif \ No newline at end of file +#endif diff --git a/SourceCode/arduino/src/main.cpp b/SourceCode/arduino/src/main.cpp index 22db30b..348aabb 100644 --- a/SourceCode/arduino/src/main.cpp +++ b/SourceCode/arduino/src/main.cpp @@ -1,12 +1,14 @@ #include #include "theWifi.h" +#include "theServer.h" void setup() { - connectWifi(); + setup_wifi(); + setup_server(); } void loop() { - // put your main code here, to run repeatedly: + handle_server_clients(); } \ No newline at end of file