1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-15 00:02:49 +03:00

allow hook WiFi events from sketch

This commit is contained in:
Markus Sattler
2015-12-29 14:33:10 +01:00
parent fd443d4e17
commit 373da3df6b
4 changed files with 37 additions and 12 deletions

View File

@ -51,13 +51,20 @@ extern "C" void esp_yield();
// -----------------------------------------------------------------------------------------------------------------------
bool ESP8266WiFiGenericClass::_persistent = true;
WiFiEventCb ESP8266WiFiGenericClass::_cbEvent = NULL;
ESP8266WiFiGenericClass::ESP8266WiFiGenericClass() {
wifi_set_event_handler_cb((wifi_event_handler_cb_t) &ESP8266WiFiGenericClass::_eventCallback);
}
/**
* set callback function
* @param cbEvent WiFiEventCb
*/
void ESP8266WiFiGenericClass::onEvent(WiFiEventCb cbEvent) {
_cbEvent = cbEvent;
}
/**
* callback for WiFi events
* @param arg
@ -70,11 +77,11 @@ void ESP8266WiFiGenericClass::_eventCallback(void* arg) {
WiFiClient::stopAll();
}
//TODO allow user to hook this event
if(_cbEvent) {
_cbEvent((WiFiEvent_t) event->event);
}
}
/**
* Return the current channel associated with the network
* @return channel (1-13)
@ -236,8 +243,9 @@ int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResul
* @param callback_arg
*/
void wifi_dns_found_callback(const char *name, ip_addr_t *ipaddr, void *callback_arg) {
if(ipaddr)
if(ipaddr) {
(*reinterpret_cast<IPAddress*>(callback_arg)) = ipaddr->addr;
}
esp_schedule(); // resume the hostByName function
}