Wifi callbacks and ip address

This commit is contained in:
Florian Hoss 2022-07-26 09:18:19 +02:00
parent 86fe791dec
commit eb4b133de1

View file

@ -16,23 +16,47 @@ int lwip_hook_ip4_input(struct pbuf *pbuf, struct netif *input_netif)
return 0; 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() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
Serial.println(); setup_wifi();
WiFi.begin(ssid, psk);
while (!WiFi.isConnected())
{
Serial.print(".");
delay(200);
}
Serial.println();
Serial.print("[WiFi] IP: ");
Serial.println(WiFi.localIP());
} }
void loop() void loop()
{ {
Serial.println("test"); sleep(60);
sleep(1000);
} }