Wifi callbacks and ip address
This commit is contained in:
parent
86fe791dec
commit
eb4b133de1
1 changed files with 36 additions and 12 deletions
|
@ -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);
|
||||
}
|
Reference in a new issue