ESP8266 Arduino:GitHub - esp8266/Arduino: ESP8266 core for Arduino
ESP8266 Arduino Core 文档:
Welcome to ESP8266 Arduino Core’s documentation! — ESP8266 Arduino Core documentationWelcome to ESP8266 Arduino Core’s documentation! — ESP8266 Arduino Core 3.0.2 documentation
人生最烦的事情,为啥不写注释。
class ESP8266WiFiClass : public ESP8266WiFiGenericClass, public ESP8266WiFiSTAClass, public ESP8266WiFiScanClass, public ESP8266WiFiAPClass {
public:
// workaround same function name with different signature
using ESP8266WiFiGenericClass::channel;
using ESP8266WiFiSTAClass::SSID;
using ESP8266WiFiSTAClass::RSSI;
using ESP8266WiFiSTAClass::BSSID;
using ESP8266WiFiSTAClass::BSSIDstr;
using ESP8266WiFiScanClass::SSID;
using ESP8266WiFiScanClass::encryptionType;
using ESP8266WiFiScanClass::RSSI;
using ESP8266WiFiScanClass::BSSID;
using ESP8266WiFiScanClass::BSSIDstr;
using ESP8266WiFiScanClass::channel;
using ESP8266WiFiScanClass::isHidden;
// ----------------------------------------------------------------------------------------------
// ------------------------------------------- Debug --------------------------------------------
// ----------------------------------------------------------------------------------------------
public:
void printDiag(Print& dest);
friend class WiFiClient;
friend class WiFiServer;
};
extern ESP8266WiFiClass WiFi;
ESP8266WiFiGeneric.h
class ESP8266WiFiGenericClass {
// ----------------------------------------------------------------------------------------------
// -------------------------------------- Generic WiFi function ---------------------------------
// ----------------------------------------------------------------------------------------------
public:
ESP8266WiFiGenericClass();
// Note: this function is deprecated. Use one of the functions below instead.
void onEvent(WiFiEventCb cb, WiFiEvent_t event = WIFI_EVENT_ANY) __attribute__((deprecated));
// Subscribe to specific event and get event information as an argument to the callback
WiFiEventHandler onStationModeConnected(std::function<void(const WiFiEventStationModeConnected&)>);
WiFiEventHandler onStationModeDisconnected(std::function<void(const WiFiEventStationModeDisconnected&)>);
WiFiEventHandler onStationModeAuthModeChanged(std::function<void(const WiFiEventStationModeAuthModeChanged&)>);
WiFiEventHandler onStationModeGotIP(std::function<void(const WiFiEventStationModeGotIP&)>);
WiFiEventHandler onStationModeDHCPTimeout(std::function<void(void)>);
WiFiEventHandler onSoftAPModeStationConnected(std::function<void(const WiFiEventSoftAPModeStationConnected&)>);
WiFiEventHandler onSoftAPModeStationDisconnected(std::function<void(const WiFiEventSoftAPModeStationDisconnected&)>);
WiFiEventHandler onSoftAPModeProbeRequestReceived(std::function<void(const WiFiEventSoftAPModeProbeRequestReceived&)>);
WiFiEventHandler onWiFiModeChange(std::function<void(const WiFiEventModeChange&)>);
uint8_t channel(void);
bool setSleepMode(WiFiSleepType_t type, uint8_t listenInterval = 0);
WiFiSleepType_t getSleepMode();
uint8_t getListenInterval ();
bool isSleepLevelMax ();
bool setPhyMode(WiFiPhyMode_t mode);
WiFiPhyMode_t getPhyMode();
void setOutputPower(float dBm);
void persistent(bool persistent);
bool mode(WiFiMode_t, WiFiState* state = nullptr);
WiFiMode_t getMode();
bool enableSTA(bool enable);
bool enableAP(bool enable);
bool forceSleepBegin(uint32 sleepUs = 0);
bool forceSleepWake();
static uint32_t shutdownCRC (const WiFiState* state);
static bool shutdownValidCRC (const WiFiState* state);
static void preinitWiFiOff (); //meant to be called in user-defined preinit()
protected:
static bool _persistent;
static WiFiMode_t _forceSleepLastMode;
static void _eventCallback(void *event);
// called by WiFi.mode(SHUTDOWN/RESTORE, state)
// - sleepUs is WiFi.forceSleepBegin() parameter, 0 = forever
// - saveState is the user's state to hold configuration on restore
bool shutdown (uint32 sleepUs = 0, WiFiState* stateSave = nullptr);
bool resumeFromShutdown (WiFiState* savedState = nullptr);
// ----------------------------------------------------------------------------------------------
// ------------------------------------ Generic Network function --------------------------------
// ----------------------------------------------------------------------------------------------
public:
int hostByName(const char* aHostname, IPAddress& aResult);
int hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms);
#if LWIP_IPV4 && LWIP_IPV6
int hostByName(const char* aHostname, IPAddress& aResult, uint32_t timeout_ms, DNSResolveType resolveType);
#endif
bool getPersistent();
protected:
friend class ESP8266WiFiSTAClass;
friend class ESP8266WiFiScanClass;
friend class ESP8266WiFiAPClass;
};
ESP8266WiFiSTA.h
class ESP8266WiFiSTAClass: public LwipIntf {
// ----------------------------------------------------------------------------------------------
// ---------------------------------------- STA function ----------------------------------------
// ----------------------------------------------------------------------------------------------
public:
wl_status_t begin(const char* ssid, const char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true);
wl_status_t begin(char* ssid, char *passphrase = NULL, int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true);
wl_status_t begin(const String& ssid, const String& passphrase = emptyString, int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true);
wl_status_t begin();
//The argument order for ESP is not the same as for Arduino. However, there is compatibility code under the hood
//to detect Arduino arg order, and handle it correctly. Be aware that the Arduino default value handling doesn't
//work here (see Arduino docs for gway/subnet defaults). In other words: at least 3 args must always be given.
bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000);
bool reconnect();
bool disconnect(bool wifioff = false);
bool isConnected();
bool setAutoConnect(bool autoConnect);
bool getAutoConnect();
bool setAutoReconnect(bool autoReconnect);
bool getAutoReconnect();
int8_t waitForConnectResult(unsigned long timeoutLength = 60000);
// STA network info
IPAddress localIP();
uint8_t * macAddress(uint8_t* mac);
String macAddress();
IPAddress subnetMask();
IPAddress gatewayIP();
IPAddress dnsIP(uint8_t dns_no = 0);
// STA WiFi info
wl_status_t status();
String SSID() const;
String psk() const;
uint8_t * BSSID();
String BSSIDstr();
int8_t RSSI();
static void enableInsecureWEP (bool enable = true) { _useInsecureWEP = enable; }
protected:
static bool _useStaticIp;
static bool _useInsecureWEP;
// ----------------------------------------------------------------------------------------------
// ------------------------------------ STA remote configure -----------------------------------
// ----------------------------------------------------------------------------------------------
public:
bool beginWPSConfig(void);
bool beginSmartConfig();
bool stopSmartConfig();
bool smartConfigDone();
protected:
static bool _smartConfigStarted;
static bool _smartConfigDone;
static void _smartConfigCallback(uint32_t status, void* result);
};
ESP8266WiFiScan.h
class ESP8266WiFiScanClass {
// ----------------------------------------------------------------------------------------------
// ----------------------------------------- scan function --------------------------------------
// ----------------------------------------------------------------------------------------------
public:
int8_t scanNetworks(bool async = false, bool show_hidden = false, uint8 channel = 0, uint8* ssid = NULL);
void scanNetworksAsync(std::function<void(int)> onComplete, bool show_hidden = false);
int8_t scanComplete();
void scanDelete();
// scan result
bool getNetworkInfo(uint8_t networkItem, String &ssid, uint8_t &encryptionType, int32_t &RSSI, uint8_t* &BSSID, int32_t &channel, bool &isHidden);
String SSID(uint8_t networkItem);
uint8_t encryptionType(uint8_t networkItem);
int32_t RSSI(uint8_t networkItem);
uint8_t * BSSID(uint8_t networkItem);
String BSSIDstr(uint8_t networkItem);
int32_t channel(uint8_t networkItem);
bool isHidden(uint8_t networkItem);
protected:
static bool _scanAsync;
static bool _scanStarted;
static bool _scanComplete;
static size_t _scanCount;
static void* _scanResult;
static std::function<void(int)> _onComplete;
static void _scanDone(void* result, int status);
static void * _getScanInfoByIndex(int i);
};
ESP8266WiFiAP.h
class ESP8266WiFiAPClass {
// ----------------------------------------------------------------------------------------------
// ----------------------------------------- AP function ----------------------------------------
// ----------------------------------------------------------------------------------------------
public:
bool softAP(const char* ssid, const char* passphrase = NULL, int channel = 1, int ssid_hidden = 0, int max_connection = 4);
bool softAP(const String& ssid,const String& passphrase = emptyString,int channel = 1,int ssid_hidden = 0,int max_connection = 4);
bool softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet);
bool softAPdisconnect(bool wifioff = false);
uint8_t softAPgetStationNum();
IPAddress softAPIP();
uint8_t* softAPmacAddress(uint8_t* mac);
String softAPmacAddress(void);
String softAPSSID() const;
String softAPPSK() const;
protected:
};