Skip to content

Commit bbaed29

Browse files
committed
Merge pull request #1323 from Links2004/WiFi
rework WiFi
2 parents 058bd19 + db4076f commit bbaed29

16 files changed

+2075
-1353
lines changed

cores/esp8266/Arduino.h

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ extern "C" {
3737
#include "binary.h"
3838
#include "esp8266_peri.h"
3939
#include "twi.h"
40+
#include "core_esp8266_features.h"
4041

4142
#define HIGH 0x1
4243
#define LOW 0x0
@@ -247,8 +248,12 @@ void optimistic_yield(uint32_t interval_us);
247248
#include "Updater.h"
248249
#include "debug.h"
249250

251+
#ifndef _GLIBCXX_VECTOR
252+
// arduino is not compatible with std::vector
250253
#define min(a,b) ((a)<(b)?(a):(b))
251254
#define max(a,b) ((a)>(b)?(a):(b))
255+
#endif
256+
252257
#define _min(a,b) ((a)<(b)?(a):(b))
253258
#define _max(a,b) ((a)>(b)?(a):(b))
254259

cores/esp8266/IPAddress.h

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ class IPAddress: public Printable {
5656
bool operator==(const IPAddress& addr) const {
5757
return _address.dword == addr._address.dword;
5858
}
59+
bool operator==(uint32_t addr) const {
60+
return _address.dword == addr;
61+
}
5962
bool operator==(const uint8_t* addr) const;
6063

6164
// Overloaded index operator to allow getting and setting individual octets of the address

cores/esp8266/core_esp8266_features.h

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#define CORE_HAS_LIBB64
2929
#define CORE_HAS_BASE64_CLASS
3030

31+
#define WIFI_HAS_EVENT_CALLBACK
32+
3133

3234
#endif
3335

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* This sketch shows the WiFi event usage
3+
*
4+
*/
5+
6+
#include <ESP8266WiFi.h>
7+
8+
const char* ssid = "your-ssid";
9+
const char* password = "your-password";
10+
11+
12+
void WiFiEvent(WiFiEvent_t event) {
13+
Serial.printf("[WiFi-event] event: %d\n", event);
14+
15+
switch(event) {
16+
case WIFI_EVENT_STAMODE_GOT_IP:
17+
Serial.println("WiFi connected");
18+
Serial.println("IP address: ");
19+
Serial.println(WiFi.localIP());
20+
break;
21+
case WIFI_EVENT_STAMODE_DISCONNECTED:
22+
Serial.println("WiFi lost connection");
23+
break;
24+
}
25+
}
26+
27+
void setup() {
28+
Serial.begin(115200);
29+
30+
// delete old config
31+
WiFi.disconnect(true);
32+
33+
delay(1000);
34+
35+
WiFi.onEvent(WiFiEvent);
36+
37+
WiFi.begin(ssid, password);
38+
39+
Serial.println();
40+
Serial.println();
41+
Serial.println("Wait for WiFi... ");
42+
}
43+
44+
45+
void loop() {
46+
delay(1000);
47+
}
48+

0 commit comments

Comments
 (0)