diff --git a/.gitmodules b/.gitmodules index fbed601..7692a74 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,3 @@ [submodule "ESP32Firewall/components/arduino"] path = ESP32Firewall/components/arduino url = https://github.com/espressif/arduino-esp32.git -[submodule "ESP32Firewall/esp_firewall_api"] - path = ESP32Firewall/lib/esp_firewall_api - url = https://github.com/flohoss/esp_firewall_api -[submodule "ESP32Firewall/lib/esp_firewall_api"] - path = ESP32Firewall/lib/esp_firewall_api - url = https://github.com/flohoss/esp_firewall_api diff --git a/ESP32Firewall/.gitignore b/ESP32Firewall/.gitignore index 21e08c7..e2ffe7e 100644 --- a/ESP32Firewall/.gitignore +++ b/ESP32Firewall/.gitignore @@ -2,4 +2,3 @@ .vscode include/theSecrets.h components/arduino -lib/esp_firewall_api diff --git a/ESP32Firewall/platformio.ini b/ESP32Firewall/platformio.ini index 7e0bfb4..d18905e 100644 --- a/ESP32Firewall/platformio.ini +++ b/ESP32Firewall/platformio.ini @@ -16,6 +16,8 @@ platform = espressif32 board = az-delivery-devkit-v4 framework = espidf monitor_speed = 115200 +lib_compat_mode = off build_flags = - '-I include' - '-D ESP_IDF_LWIP_HOOK_FILENAME="lwip_hooks.h"' + '-Iinclude' + '-DESP_IDF_LWIP_HOOK_FILENAME="lwip_hooks.h"' +lib_deps = https://github.com/flohoss/esp32_firewall_api diff --git a/ESP32Firewall/src/main.cpp b/ESP32Firewall/src/main.cpp index 6e2583e..10a85f1 100644 --- a/ESP32Firewall/src/main.cpp +++ b/ESP32Firewall/src/main.cpp @@ -3,6 +3,12 @@ #include "WiFi.h" #include "lwip_hooks.h" +#include "Firewall.hpp" +#include "API.hpp" + +fw::Firewall *firewall; +fw::API *firewallApi; + int lwip_hook_ip4_input(struct pbuf *pbuf, struct netif *input_netif) { const struct ip_hdr *iphdr; @@ -16,8 +22,15 @@ int lwip_hook_ip4_input(struct pbuf *pbuf, struct netif *input_netif) return 0; } +void initFirewall(const String ip) +{ + firewall = new fw::Firewall(); + firewallApi = new fw::API(firewall, username, password, ip); +} + void handle_wifi_events(WiFiEvent_t event, WiFiEventInfo_t info) { + String ip; Serial.print("[WiFi] "); switch (event) { @@ -31,8 +44,10 @@ void handle_wifi_events(WiFiEvent_t event, WiFiEventInfo_t info) Serial.println("disconnected"); break; case ARDUINO_EVENT_WIFI_STA_GOT_IP: + ip = WiFi.localIP().toString(); Serial.print("IP: "); - Serial.println(WiFi.localIP().toString().c_str()); + Serial.println(ip); + initFirewall(ip); break; default: Serial.print("other event: "); @@ -40,8 +55,9 @@ void handle_wifi_events(WiFiEvent_t event, WiFiEventInfo_t info) } } -void setup_wifi() +void setup() { + Serial.begin(115200); WiFi.mode(WIFI_STA); WiFi.onEvent(handle_wifi_events, ARDUINO_EVENT_MAX); WiFi.begin(ssid, psk); @@ -50,13 +66,8 @@ void setup_wifi() WiFi.config(((u32_t)0x0UL), ((u32_t)0x0UL), ((u32_t)0x0UL)); } -void setup() -{ - Serial.begin(115200); - setup_wifi(); -} - void loop() { - sleep(60); + // https://docs.espressif.com/projects/arduino-esp32/en/latest/esp-idf_component.html + sleep(1); } \ No newline at end of file diff --git a/ESPFirewall/lib/Firewall/src/API.cpp b/ESPFirewall/lib/Firewall/src/API.cpp index a954adf..cacdba9 100644 --- a/ESPFirewall/lib/Firewall/src/API.cpp +++ b/ESPFirewall/lib/Firewall/src/API.cpp @@ -2,10 +2,10 @@ namespace fw { - API::API(fw::Firewall *firewall, const char *cert, const char *key, const char *username, const char *password, const uint16_t port) + API::API(fw::Firewall *firewall, const char *cert, const char *key, const char *username, const char *password, const String ip, const uint16_t port) { this->firewall = firewall; - this->api_ip = WiFi.localIP().toString(); + this->api_ip = ip; this->api_port = port; if (this->setup_auth(username, password) == ERROR) endless_loop(); diff --git a/ESPFirewall/lib/Firewall/src/API.hpp b/ESPFirewall/lib/Firewall/src/API.hpp index cbe59ed..c583b12 100644 --- a/ESPFirewall/lib/Firewall/src/API.hpp +++ b/ESPFirewall/lib/Firewall/src/API.hpp @@ -16,7 +16,7 @@ namespace fw class API { public: - API(Firewall *, const char *cert, const char *key, const char *username, const char *password, const uint16_t port = 8080); + API(Firewall *, const char *cert, const char *key, const char *username, const char *password, const String ip, const uint16_t port = 8080); ~API(); void handle_client(); diff --git a/ESPFirewall/src/main.cpp b/ESPFirewall/src/main.cpp index aab0d28..9324a7b 100644 --- a/ESPFirewall/src/main.cpp +++ b/ESPFirewall/src/main.cpp @@ -47,7 +47,7 @@ void setup() Serial.print("[WiFi] IP: "); Serial.println(WiFi.localIP()); firewall = new fw::Firewall(); - firewallApi = new fw::API(firewall, cert, key, username, password); + firewallApi = new fw::API(firewall, cert, key, username, password, WiFi.localIP().toString()); wifiServer.begin(); }