-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lwip2: fix static address management (#4677)
+ interactive example (for debugging)
- Loading branch information
Showing
9 changed files
with
131 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
|
||
/* | ||
Interactive script meant for debugging only | ||
Run it on serial console and keep this source file opened for the list of commands | ||
Please configure SSID, PSK and IPAddresses below to fit with your network | ||
Released to public domain | ||
*/ | ||
|
||
#include "ESP8266WiFi.h" | ||
#include "user_interface.h" | ||
|
||
const char SSID[] = "open"; | ||
const char PSK[] = ""; | ||
|
||
IPAddress staticip(192, 168, 1, 123); | ||
IPAddress gateway(192, 168, 1, 254); | ||
IPAddress subnet(255, 255, 255, 0); | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
Serial.setDebugOutput(true); | ||
|
||
WiFi.mode(WIFI_STA); | ||
WiFi.begin(SSID, PSK); | ||
Serial.println("connecting"); | ||
while (WiFi.status() != WL_CONNECTED) { | ||
delay(500); | ||
Serial.print("."); | ||
} | ||
Serial.println(); | ||
Serial.println(WiFi.localIP()); | ||
Serial.print( | ||
"WL_IDLE_STATUS = 0\n" | ||
"WL_NO_SSID_AVAIL = 1\n" | ||
"WL_SCAN_COMPLETED = 2\n" | ||
"WL_CONNECTED = 3\n" | ||
"WL_CONNECT_FAILED = 4\n" | ||
"WL_CONNECTION_LOST = 5\n" | ||
"WL_DISCONNECTED = 6\n" | ||
); | ||
} | ||
|
||
void WiFiOn() { | ||
wifi_fpm_do_wakeup(); | ||
wifi_fpm_close(); | ||
wifi_set_opmode(STATION_MODE); | ||
wifi_station_connect(); | ||
} | ||
|
||
void WiFiOff() { | ||
wifi_station_disconnect(); | ||
wifi_set_opmode(NULL_MODE); | ||
wifi_set_sleep_type(MODEM_SLEEP_T); | ||
wifi_fpm_open(); | ||
wifi_fpm_do_sleep(0xFFFFFFF); | ||
} | ||
|
||
void loop() { | ||
#define TEST(name, var, varinit, func) \ | ||
static decltype(func) var = (varinit); \ | ||
if ((var) != (func)) { var = (func); Serial.printf("**** %s: ", name); Serial.println(var); } | ||
|
||
#define DO(x...) Serial.println(F( #x )); x; break | ||
|
||
TEST("Free Heap", freeHeap, 0, ESP.getFreeHeap()); | ||
TEST("WiFiStatus", status, WL_IDLE_STATUS, WiFi.status()); | ||
TEST("STA-IP", localIp, (uint32_t)0, WiFi.localIP()); | ||
TEST("AP-IP", apIp, (uint32_t)0, WiFi.softAPIP()); | ||
|
||
switch (Serial.read()) { | ||
case 'F': DO(WiFiOff()); | ||
case 'N': DO(WiFiOn()); | ||
case '1': DO(WiFi.mode(WIFI_AP)); | ||
case '2': DO(WiFi.mode(WIFI_AP_STA)); | ||
case '3': DO(WiFi.mode(WIFI_STA)); | ||
case 'R': DO(if (((GPI >> 16) & 0xf) == 1) ESP.reset() /* else must hard reset */); | ||
case 'd': DO(WiFi.disconnect()); | ||
case 'b': DO(WiFi.begin()); | ||
case 'B': DO(WiFi.begin(SSID, PSK)); | ||
case 'r': DO(WiFi.reconnect()); | ||
case 'c': DO(wifi_station_connect()); | ||
case 'a': DO(WiFi.setAutoReconnect(false)); | ||
case 'A': DO(WiFi.setAutoReconnect(true)); | ||
case 'n': DO(WiFi.setSleepMode(WIFI_NONE_SLEEP)); | ||
case 'l': DO(WiFi.setSleepMode(WIFI_LIGHT_SLEEP)); | ||
case 'm': DO(WiFi.setSleepMode(WIFI_MODEM_SLEEP)); | ||
case 's': DO(WiFi.config(staticip, gateway, subnet)); | ||
case 'D': DO(wifi_station_dhcpc_start()); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule builder
updated
7 files
+6 −6 | Makefile.arduino | |
+24 −32 | glue-esp/lwip-esp.c | |
+13 −3 | glue-lwip/arduino/lwipopts.h | |
+16 −0 | glue-lwip/lwip-git.c | |
+1 −0 | glue/glue.h | |
+10 −0 | glue/gluedebug.h | |
+15 −10 | makefiles/Makefile.build-lwip2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// generated by makefiles/make-lwip2-hash | ||
#ifndef LWIP_HASH_H | ||
#define LWIP_HASH_H | ||
#define LWIP_HASH_STR "STABLE-2_0_3_RELEASE/glue:arduino-2.4.1" | ||
#define LWIP_HASH_STR "STABLE-2_0_3_RELEASE/glue:arduino-2.4.1-7-g2b827f8" | ||
#endif // LWIP_HASH_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76a14b1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
edit from maintainer: moved to #4792
This commit "lwip2: fix static address management (#4677)" breaks the "WiFi.status()" command after a "WiFi.disconnect()" and "WiFi.begin(ssid,pw)".
(Specifically, the "WiFi.status()==WL_CONNECTED" never returns true after the 1st successful connection & disconnection.)
ie. "git checkout 758b0bd" WORKS
but "git checkout 76a14b1" FAILS
My setup is Arduino-IDE using Github-ESP8266 code, with a D1-Mini-ESP8266
Test code is show below:
const char* ssid="your_ssid"; const char* pw="your_password"; // details for your router
#include <ESP8266WiFi.h>
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA); delay(5);
WiFi.disconnect(); delay(5); // disconnect any existing [WIFI_STA] connection
delay(3000); Serial.println(); Serial.println("TEST SKETCH");
if (Connect_wifi()) Disconnect_wifi(); // this works fine
Serial.println("Please wait until 2nd try..."); delay(5000);
if (Connect_wifi()) Disconnect_wifi(); // this fails to report "connected"
WiFi.disconnect(); delay(5); // disconnect any still existing [WIFI_STA] connection
Serial.println("Test END");
}
void Disconnect_wifi() {
delay(2000); Serial.print("Disconnecting from router="); Serial.println(WiFi.disconnect());
}
boolean Connect_wifi() {
Serial.print("Connecting to router ");
WiFi.begin(ssid,pw);
byte x=0, y=0, Wstatus_old=99;
boolean success;
do {
byte Wstatus=WiFi.status();
if (Wstatus_old!=Wstatus) {Wstatus_old=Wstatus; Serial.print(Wstatus);}
y++; if (y==250) {y=0; x++; Serial.print(".");}
success=(Wstatus==WL_CONNECTED);
delay(4);
} while ((x<20) and !success ); // try for 20seconds
if (success) Serial.println(" connected OK"); else Serial.println(" FAILED (but the router actually says apparently connected OK!)");
return success;
}
void loop() {}