mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-10 14:42:08 +03:00
allow hook WiFi events from sketch
This commit is contained in:
parent
fd443d4e17
commit
373da3df6b
@ -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
|
||||
}
|
||||
|
||||
|
@ -25,14 +25,19 @@
|
||||
|
||||
#include "ESP8266WiFiType.h"
|
||||
|
||||
typedef void (*WiFiEventCb)(WiFiEvent_t event);
|
||||
|
||||
class ESP8266WiFiGenericClass {
|
||||
// ----------------------------------------------------------------------------------------------
|
||||
// -------------------------------------- Generic WiFi function ---------------------------------
|
||||
// ----------------------------------------------------------------------------------------------
|
||||
|
||||
public:
|
||||
|
||||
ESP8266WiFiGenericClass();
|
||||
|
||||
void onEvent(WiFiEventCb cbEvent);
|
||||
|
||||
int32_t channel(void);
|
||||
|
||||
bool setSleepMode(WiFiSleepType_t type);
|
||||
@ -50,9 +55,10 @@ class ESP8266WiFiGenericClass {
|
||||
bool enableAP(bool enable);
|
||||
|
||||
protected:
|
||||
static bool _persistent;
|
||||
static bool _persistent;
|
||||
static WiFiEventCb _cbEvent;
|
||||
|
||||
static void _eventCallback(void *event);
|
||||
static void _eventCallback(void *event);
|
||||
|
||||
// ----------------------------------------------------------------------------------------------
|
||||
// ------------------------------------ Generic Network function --------------------------------
|
||||
@ -69,5 +75,4 @@ class ESP8266WiFiGenericClass {
|
||||
friend class ESP8266WiFiAPClass;
|
||||
};
|
||||
|
||||
|
||||
#endif /* ESP8266WIFIGENERIC_H_ */
|
||||
|
@ -60,9 +60,7 @@ class ESP8266WiFiScanClass {
|
||||
static void* _scanResult;
|
||||
|
||||
static void _scanDone(void* result, int status);
|
||||
void * _getScanInfoByIndex(int i);
|
||||
|
||||
friend class ESP8266WiFiClass;
|
||||
static void * _getScanInfoByIndex(int i);
|
||||
|
||||
};
|
||||
|
||||
|
@ -44,6 +44,20 @@ typedef enum {
|
||||
} WiFiSleepType_t;
|
||||
|
||||
|
||||
typedef enum {
|
||||
WIFI_EVENT_STAMODE_CONNECTED = 0,
|
||||
WIFI_EVENT_STAMODE_DISCONNECTED,
|
||||
WIFI_EVENT_STAMODE_AUTHMODE_CHANGE,
|
||||
WIFI_EVENT_STAMODE_GOT_IP,
|
||||
WIFI_EVENT_STAMODE_DHCP_TIMEOUT,
|
||||
WIFI_EVENT_SOFTAPMODE_STACONNECTED,
|
||||
WIFI_EVENT_SOFTAPMODE_STADISCONNECTED,
|
||||
WIFI_EVENT_SOFTAPMODE_PROBEREQRECVED,
|
||||
WIFI_EVENT_MAX
|
||||
} WiFiEvent_t;
|
||||
|
||||
|
||||
|
||||
extern "C" {
|
||||
typedef STAILQ_HEAD(, bss_info)
|
||||
bss_info_head_t;
|
||||
|
Loading…
x
Reference in New Issue
Block a user