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,
47 };
48 
56 };
57 
63  bool bssidSet = false;
65 };
66 
67 #define WPS_STATUS_MAP(XX) \
68  XX(Success) \
69  XX(Failed) \
70  XX(Timeout) \
71  XX(WEP)
72 
74 enum class WpsStatus {
75 #define XX(name) name,
77 #undef XX
78 };
79 
80 #define XX(name) constexpr WpsStatus eWPS_##name{WpsStatus::name};
82 #undef XX
83 
84 String toString(WpsStatus status);
85 
90 
98 
105 
109 {
110 public:
114  struct Config {
118  bool autoConnectOnStartup = true;
119  bool save = true;
120  };
121 
122  virtual ~StationClass()
123  {
124  }
125 
131  virtual void enable(bool enabled, bool save = false) = 0;
132 
136  virtual bool isEnabled() const = 0;
137 
144  virtual bool config(const Config& config) = 0;
145 
152  bool config(const String& ssid, const String& password, bool autoConnectOnStartup = true, bool save = true)
153  {
154  Config cfg{
155  .ssid = ssid,
156  .password = password,
157  .autoConnectOnStartup = autoConnectOnStartup,
158  .save = save,
159  };
160  return config(cfg);
161  }
162 
165  virtual bool connect() = 0;
166 
169  virtual bool disconnect() = 0;
170 
174  bool isConnected() const;
175 
179  bool isConnectionFailed() const;
180 
184  virtual StationConnectionStatus getConnectionStatus() const = 0;
185 
189  String getConnectionStatusName() const;
190 
194  virtual bool isEnabledDHCP() const = 0;
195 
199  virtual void enableDHCP(bool enable) = 0;
200 
204  virtual void setHostname(const String& hostname) = 0;
205 
209  virtual String getHostname() const = 0;
210 
214  virtual IpAddress getIP() const = 0;
215 
219  virtual MacAddress getMacAddress() const = 0;
220 
225  String getMAC(char sep = '\0') const;
226 
239  virtual bool setMacAddress(const MacAddress& addr) const = 0;
240 
244  virtual IpAddress getNetworkMask() const = 0;
245 
249  virtual IpAddress getNetworkGateway() const = 0;
250 
254  virtual IpAddress getNetworkBroadcast() const = 0;
255 
261  bool isLocal(IpAddress address)
262  {
263  return address.compare(getIP(), getNetworkMask());
264  }
265 
270  bool setIP(IpAddress address);
271 
278  virtual bool setIP(IpAddress address, IpAddress netmask, IpAddress gateway) = 0;
279 
283  virtual String getSSID() const = 0;
284 
288  virtual MacAddress getBSSID() const = 0;
289 
293  virtual String getPassword() const = 0;
294 
298  virtual int8_t getRssi() const = 0;
299 
303  virtual uint8_t getChannel() const = 0;
304 
309  virtual bool startScan(ScanCompletedDelegate scanCompleted) = 0;
310 
311 #ifdef ENABLE_SMART_CONFIG
312 
318  virtual bool smartConfigStart(SmartConfigType sctype, SmartConfigDelegate callback = nullptr) = 0;
319 
322  virtual void smartConfigStop() = 0;
323 #endif
324 
325 #ifdef ENABLE_WPS
326 
329  virtual bool wpsConfigStart(WPSConfigDelegate callback = nullptr) = 0;
330 
333  virtual void wpsConfigStop() = 0;
334 #endif
335 
336 protected:
337  ScanCompletedDelegate scanCompletedCallback = nullptr;
338 #ifdef ENABLE_SMART_CONFIG
339  SmartConfigDelegate smartConfigCallback = nullptr;
340 #endif
341 #ifdef ENABLE_WPS
342  WPSConfigDelegate wpsConfigCallback = nullptr;
343 #endif
344 };
345 
353 extern StationClass& WifiStation;
354 
A class to make it easier to handle and pass around IP addresses.
Definition: IpAddress.h:44
AP not found.
Definition: Station.h:35
Getting SSID & password.
Definition: Station.h:53
#define WPS_STATUS_MAP(XX)
Definition: Station.h:67
Find channel.
Definition: Station.h:52
String ssid
Service Set to connect to (may be advertised by multiple access points)
Definition: Station.h:115
Got IP address.
Definition: Station.h:37
Connection failed.
Definition: Station.h:36
ESP Touch and Air Kiss.
Definition: Station.h:45
MacAddress bssid
Set this to connect to a specific access point.
Definition: Station.h:117
StationClass & WifiStation
Global instance of WiFi station object.
Wait.
Definition: Station.h:51
WiFi station class.
Definition: Station.h:108
XX(name, extensionStart, mime)
Station configuration passed to config method.
Definition: Station.h:114
The String class.
Definition: WString.h:136
String password
AP Password.
Definition: Station.h:62
String toString(WpsStatus status)
SmartConfigEvent
Smart configuration event.
Definition: Station.h:50
bool isLocal(IpAddress address)
Determine if the given address is on the same subnet.
Definition: Station.h:261
A network hardware (MAC) address.
Definition: MacAddress.h:38
bool config(const String &ssid, const String &password, bool autoConnectOnStartup=true, bool save=true)
Configure WiFi station.
Definition: Station.h:152
MacAddress bssid
AP BSSID.
Definition: Station.h:64
WpsStatus
WiFi WPS callback status.
Definition: Station.h:74
Smart Config callback information.
Definition: Station.h:59
Definition: Station.h:42
String ssid
AP SSID.
Definition: Station.h:61
SmartConfigType
Smart configuration type.
Definition: Station.h:41
StationConnectionStatus
WiFi station connection states.
Definition: Station.h:31
bool compare(const IpAddress &addr, const IpAddress &mask) const
Definition: IpAddress.h:151
Connection idle.
Definition: Station.h:32
String password
Password (if required)
Definition: Station.h:116
ESP Touch.
Definition: Station.h:43
bool bssidSet
true if connection should match both SSID and BSSID
Definition: Station.h:63
ESP Touch version 2.
Definition: Station.h:46
Air Kiss.
Definition: Station.h:44
virtual ~StationClass()
Definition: Station.h:122
Link established.
Definition: Station.h:54
Wrong password.
Definition: Station.h:34
SmartConfigType type
Type of configuration underway.
Definition: Station.h:60
Connecting.
Definition: Station.h:33
Link-over.
Definition: Station.h:55