From eb4b133de10ee312955db4440244b72e5b062e71 Mon Sep 17 00:00:00 2001 From: Florian Hoss Date: Tue, 26 Jul 2022 09:18:19 +0200 Subject: [PATCH] Wifi callbacks and ip address --- ESP32Firewall/src/main.cpp | 48 ++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/ESP32Firewall/src/main.cpp b/ESP32Firewall/src/main.cpp index 3ca2793..6e2583e 100644 --- a/ESP32Firewall/src/main.cpp +++ b/ESP32Firewall/src/main.cpp @@ -16,23 +16,47 @@ int lwip_hook_ip4_input(struct pbuf *pbuf, struct netif *input_netif) return 0; } +void handle_wifi_events(WiFiEvent_t event, WiFiEventInfo_t info) +{ + Serial.print("[WiFi] "); + switch (event) + { + case ARDUINO_EVENT_WIFI_STA_START: + Serial.println("connecting..."); + 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: "); + Serial.println(WiFi.localIP().toString().c_str()); + break; + default: + Serial.print("other event: "); + Serial.println(event); + } +} + +void setup_wifi() +{ + WiFi.mode(WIFI_STA); + WiFi.onEvent(handle_wifi_events, ARDUINO_EVENT_MAX); + WiFi.begin(ssid, psk); + + // fix for https://github.com/espressif/arduino-esp32/issues/4732 + WiFi.config(((u32_t)0x0UL), ((u32_t)0x0UL), ((u32_t)0x0UL)); +} + void setup() { Serial.begin(115200); - Serial.println(); - WiFi.begin(ssid, psk); - while (!WiFi.isConnected()) - { - Serial.print("."); - delay(200); - } - Serial.println(); - Serial.print("[WiFi] IP: "); - Serial.println(WiFi.localIP()); + setup_wifi(); } void loop() { - Serial.println("test"); - sleep(1000); + sleep(60); } \ No newline at end of file