#include "theSecrets.h" #include "theCerts.h" #ifdef ESP32 #include "WiFi.h" #elif defined(ESP8266) #include "ESP8266WiFi.h" #endif #include "Firewall.hpp" #include "API.hpp" fw::Firewall *firewall; fw::API *firewallApi; WiFiServer wifiServer(80); void connectToWifi() { WiFi.begin(ssid, psk); while (WiFi.status() != WL_CONNECTED) { delay(200); } } void handle_wifi_events(WiFiEvent_t event, WiFiEventInfo_t info) { Serial.print("[WiFi] "); switch (event) { case ARDUINO_EVENT_WIFI_STA_START: Serial.printf("Attempting to connect to WPA SSID: %s\n", ssid); break; case ARDUINO_EVENT_WIFI_STA_CONNECTED: Serial.println("connected"); break; case ARDUINO_EVENT_WIFI_STA_DISCONNECTED: Serial.println("disconnected"); break; case ARDUINO_EVENT_WIFI_STA_GOT_IP: Serial.print("IP address: "); Serial.println(WiFi.localIP()); break; default: Serial.println(event); } } void setup_wifi() { WiFi.mode(WIFI_STA); WiFi.onEvent(handle_wifi_events, ARDUINO_EVENT_MAX); connectToWifi(); } void setup() { Serial.begin(115200); setup_wifi(); firewall = new fw::Firewall(); firewallApi = new fw::API(firewall, cert, key, username, password); wifiServer.begin(); } void loop() { firewallApi->handle_client(); WiFiClient client = wifiServer.available(); if (client) { if (firewall->is_client_allowed(client)) { Serial.println("allowed"); client.stop(); } else { Serial.println("rejected"); client.flush(); } } }