Station.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * Station.h
8  *
9  ****/
10 
11 #pragma once
12 
13 #include <WString.h>
14 #include <WVector.h>
15 #include <IpAddress.h>
16 #include <MacAddress.h>
17 #include "BssInfo.h"
18 
38 };
39 
42  SCT_None = -1,
46 };
47 
55 };
56 
62  bool bssidSet = false;
64 };
65 
66 #define WPS_STATUS_MAP(XX) \
67  XX(Success) \
68  XX(Failed) \
69  XX(Timeout) \
70  XX(WEP)
71 
73 enum class WpsStatus {
74 #define XX(name) name,
76 #undef XX
77 };
78 
79 #define XX(name) constexpr WpsStatus eWPS_##name{WpsStatus::name};
81 #undef XX
82 
83 String toString(WpsStatus status);
84 
89 
97 
104 
108 {
109 public:
110  virtual ~StationClass()
111  {
112  }
113 
119  virtual void enable(bool enabled, bool save = false) = 0;
120 
124  virtual bool isEnabled() const = 0;
125 
132  virtual bool config(const String& ssid, const String& password, bool autoConnectOnStartup = true,
133  bool save = true) = 0;
134 
137  virtual bool connect() = 0;
138 
141  virtual bool disconnect() = 0;
142 
146  bool isConnected() const;
147 
151  bool isConnectionFailed() const;
152 
156  virtual StationConnectionStatus getConnectionStatus() const = 0;
157 
161  String getConnectionStatusName() const;
162 
166  virtual bool isEnabledDHCP() const = 0;
167 
171  virtual void enableDHCP(bool enable) = 0;
172 
176  virtual void setHostname(const String& hostname) = 0;
177 
181  virtual String getHostname() const = 0;
182 
186  virtual IpAddress getIP() const = 0;
187 
191  virtual MacAddress getMacAddress() const = 0;
192 
197  String getMAC(char sep = '\0') const;
198 
211  virtual bool setMacAddress(const MacAddress& addr) const = 0;
212 
216  virtual IpAddress getNetworkMask() const = 0;
217 
221  virtual IpAddress getNetworkGateway() const = 0;
222 
226  virtual IpAddress getNetworkBroadcast() const = 0;
227 
233  bool isLocal(IpAddress address)
234  {
235  return address.compare(getIP(), getNetworkMask());
236  }
237 
242  bool setIP(IpAddress address);
243 
250  virtual bool setIP(IpAddress address, IpAddress netmask, IpAddress gateway) = 0;
251 
255  virtual String getSSID() const = 0;
256 
260  virtual String getPassword() const = 0;
261 
265  virtual int8_t getRssi() const = 0;
266 
270  virtual uint8_t getChannel() const = 0;
271 
276  virtual bool startScan(ScanCompletedDelegate scanCompleted) = 0;
277 
278 #ifdef ENABLE_SMART_CONFIG
279 
285  virtual bool smartConfigStart(SmartConfigType sctype, SmartConfigDelegate callback = nullptr) = 0;
286 
289  virtual void smartConfigStop() = 0;
290 #endif
291 
292 #ifdef ENABLE_WPS
293 
296  virtual bool wpsConfigStart(WPSConfigDelegate callback = nullptr) = 0;
297 
301  bool beginWPSConfig() SMING_DEPRECATED
302  {
303  return wpsConfigStart(nullptr);
304  }
305 
308  virtual void wpsConfigStop() = 0;
309 #endif
310 
311 protected:
312  ScanCompletedDelegate scanCompletedCallback = nullptr;
313 #ifdef ENABLE_SMART_CONFIG
314  SmartConfigDelegate smartConfigCallback = nullptr;
315 #endif
316 #ifdef ENABLE_WPS
317  WPSConfigDelegate wpsConfigCallback = nullptr;
318 #endif
319 };
320 
328 extern StationClass& WifiStation;
329 
A class to make it easier to handle and pass around IP addresses.
Definition: IpAddress.h:43
AP not found.
Definition: Station.h:35
Getting SSID & password.
Definition: Station.h:52
#define WPS_STATUS_MAP(XX)
Definition: Station.h:66
Find channel.
Definition: Station.h:51
Got IP address.
Definition: Station.h:37
Connection failed.
Definition: Station.h:36
ESP Touch and Air Kiss.
Definition: Station.h:45
StationClass & WifiStation
Global instance of WiFi station object.
Wait.
Definition: Station.h:50
WiFi station class.
Definition: Station.h:107
The String class.
Definition: WString.h:136
String password
AP Password.
Definition: Station.h:61
String toString(WpsStatus status)
SmartConfigEvent
Smart configuration event.
Definition: Station.h:49
bool isLocal(IpAddress address)
Determine if the given address is on the same subnet.
Definition: Station.h:233
A network hardware (MAC) address.
Definition: MacAddress.h:38
MacAddress bssid
AP BSSID.
Definition: Station.h:63
WpsStatus
WiFi WPS callback status.
Definition: Station.h:73
Smart Config callback information.
Definition: Station.h:58
Definition: Station.h:42
String ssid
AP SSID.
Definition: Station.h:60
SmartConfigType
Smart configuration type.
Definition: Station.h:41
#define SMING_DEPRECATED
Definition: sming_attr.h:30
StationConnectionStatus
WiFi station connection states.
Definition: Station.h:31
bool compare(const IpAddress &addr, const IpAddress &mask) const
Definition: IpAddress.h:150
Connection idle.
Definition: Station.h:32
ESP Touch.
Definition: Station.h:43
bool bssidSet
true if connection should match both SSID and BSSID
Definition: Station.h:62
Air Kiss.
Definition: Station.h:44
virtual ~StationClass()
Definition: Station.h:110
Link established.
Definition: Station.h:53
Wrong password.
Definition: Station.h:34
SmartConfigType type
Type of configuration underway.
Definition: Station.h:59
Connecting.
Definition: Station.h:33
Link-over.
Definition: Station.h:54
XX(name, extensionStart, mime)