Skip to content

Commit 76a14b1

Browse files
authored
lwip2: fix static address management (#4677)
+ interactive example (for debugging)
1 parent 758b0bd commit 76a14b1

File tree

9 files changed

+131
-6
lines changed

9 files changed

+131
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
2+
/*
3+
Interactive script meant for debugging only
4+
Run it on serial console and keep this source file opened for the list of commands
5+
Please configure SSID, PSK and IPAddresses below to fit with your network
6+
7+
Released to public domain
8+
*/
9+
10+
#include "ESP8266WiFi.h"
11+
#include "user_interface.h"
12+
13+
const char SSID[] = "open";
14+
const char PSK[] = "";
15+
16+
IPAddress staticip(192, 168, 1, 123);
17+
IPAddress gateway(192, 168, 1, 254);
18+
IPAddress subnet(255, 255, 255, 0);
19+
20+
void setup() {
21+
Serial.begin(115200);
22+
Serial.setDebugOutput(true);
23+
24+
WiFi.mode(WIFI_STA);
25+
WiFi.begin(SSID, PSK);
26+
Serial.println("connecting");
27+
while (WiFi.status() != WL_CONNECTED) {
28+
delay(500);
29+
Serial.print(".");
30+
}
31+
Serial.println();
32+
Serial.println(WiFi.localIP());
33+
Serial.print(
34+
"WL_IDLE_STATUS = 0\n"
35+
"WL_NO_SSID_AVAIL = 1\n"
36+
"WL_SCAN_COMPLETED = 2\n"
37+
"WL_CONNECTED = 3\n"
38+
"WL_CONNECT_FAILED = 4\n"
39+
"WL_CONNECTION_LOST = 5\n"
40+
"WL_DISCONNECTED = 6\n"
41+
);
42+
}
43+
44+
void WiFiOn() {
45+
wifi_fpm_do_wakeup();
46+
wifi_fpm_close();
47+
wifi_set_opmode(STATION_MODE);
48+
wifi_station_connect();
49+
}
50+
51+
void WiFiOff() {
52+
wifi_station_disconnect();
53+
wifi_set_opmode(NULL_MODE);
54+
wifi_set_sleep_type(MODEM_SLEEP_T);
55+
wifi_fpm_open();
56+
wifi_fpm_do_sleep(0xFFFFFFF);
57+
}
58+
59+
void loop() {
60+
#define TEST(name, var, varinit, func) \
61+
static decltype(func) var = (varinit); \
62+
if ((var) != (func)) { var = (func); Serial.printf("**** %s: ", name); Serial.println(var); }
63+
64+
#define DO(x...) Serial.println(F( #x )); x; break
65+
66+
TEST("Free Heap", freeHeap, 0, ESP.getFreeHeap());
67+
TEST("WiFiStatus", status, WL_IDLE_STATUS, WiFi.status());
68+
TEST("STA-IP", localIp, (uint32_t)0, WiFi.localIP());
69+
TEST("AP-IP", apIp, (uint32_t)0, WiFi.softAPIP());
70+
71+
switch (Serial.read()) {
72+
case 'F': DO(WiFiOff());
73+
case 'N': DO(WiFiOn());
74+
case '1': DO(WiFi.mode(WIFI_AP));
75+
case '2': DO(WiFi.mode(WIFI_AP_STA));
76+
case '3': DO(WiFi.mode(WIFI_STA));
77+
case 'R': DO(if (((GPI >> 16) & 0xf) == 1) ESP.reset() /* else must hard reset */);
78+
case 'd': DO(WiFi.disconnect());
79+
case 'b': DO(WiFi.begin());
80+
case 'B': DO(WiFi.begin(SSID, PSK));
81+
case 'r': DO(WiFi.reconnect());
82+
case 'c': DO(wifi_station_connect());
83+
case 'a': DO(WiFi.setAutoReconnect(false));
84+
case 'A': DO(WiFi.setAutoReconnect(true));
85+
case 'n': DO(WiFi.setSleepMode(WIFI_NONE_SLEEP));
86+
case 'l': DO(WiFi.setSleepMode(WIFI_LIGHT_SLEEP));
87+
case 'm': DO(WiFi.setSleepMode(WIFI_MODEM_SLEEP));
88+
case 's': DO(WiFi.config(staticip, gateway, subnet));
89+
case 'D': DO(wifi_station_dhcpc_start());
90+
}
91+
}

tools/sdk/lib/liblwip2.a

12.3 KB
Binary file not shown.

tools/sdk/lib/liblwip2_1460.a

12.3 KB
Binary file not shown.

tools/sdk/lwip2/Makefile

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
all install clean: builder/lwip2-src/README
33
make -C builder -f Makefile.arduino $@
44

5+
latestmaster: downloadmaster install
6+
7+
latestupstream: downloadupstream install
8+
9+
downloadupstream: downloadmaster
10+
cd builder/lwip2-src; git checkout master
11+
12+
downloadmaster: download
13+
cd builder; git checkout master
14+
515
download: builder/lwip2-src/README
616

717
builder/lwip2-src/README:

tools/sdk/lwip2/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
```make install```: download, compile, install lwip2
22

3+
```make latestmaster```: download latest lwip2, compile, install
4+
5+
```make latestupstream```: download latest lwip2 and latest upstream lwIP, compile, install
6+
37
```make download```: download lwIP-2 builder
48

59
```make clean```: clean builder only
@@ -10,4 +14,4 @@ MSS values are in builder/Makefile.arduino
1014

1115
MSS values in boards.txt are only informative
1216

13-
current lwip2 submodule repository: https://github.com/d-a-v/esp82xx-nonos-linklayer/tree/arduino-2.4.0
17+
current lwip2 submodule repository: https://github.com/d-a-v/esp82xx-nonos-linklayer/tree/arduino-2.4.1

tools/sdk/lwip2/include/gluedebug.h

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#ifndef __GLUE_DEBUG_H
33
#define __GLUE_DEBUG_H
44

5+
// this file is commonly included by both sides of the glue
56
/////////////////////////////////////////////////////////////////////////////
67
// user-definable
78

@@ -27,6 +28,15 @@
2728
#define LWIP_DBG_TYPES_ON (LWIP_DBG_ON)
2829
#endif
2930

31+
/////////////////////////////////////////////////////////////////////////////
32+
// packet capture callback from esp side
33+
#include <stdlib.h>
34+
35+
#ifdef __cplusplus
36+
extern "C"
37+
#endif
38+
void (*phy_capture) (int netif_idx, const char* data, size_t len, int out, int success);
39+
3040
/////////////////////////////////////////////////////////////////////////////
3141

3242
#if UDEBUG && UDEBUGSTORE
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// generated by makefiles/make-lwip2-hash
22
#ifndef LWIP_HASH_H
33
#define LWIP_HASH_H
4-
#define LWIP_HASH_STR "STABLE-2_0_3_RELEASE/glue:arduino-2.4.1"
4+
#define LWIP_HASH_STR "STABLE-2_0_3_RELEASE/glue:arduino-2.4.1-7-g2b827f8"
55
#endif // LWIP_HASH_H

tools/sdk/lwip2/include/lwipopts.h

+13-3
Original file line numberDiff line numberDiff line change
@@ -2688,9 +2688,11 @@
26882688
* Return ERR_OK if packet is accepted, any error code otherwise.
26892689
* Payload points to ethernet header!
26902690
*/
2691-
#ifdef __DOXYGEN__
2692-
#define LWIP_HOOK_UNKNOWN_ETH_PROTOCOL(pbuf, netif)
2693-
#endif
2691+
//#ifdef __DOXYGEN__
2692+
//#define LWIP_HOOK_UNKNOWN_ETH_PROTOCOL(pbuf, netif)
2693+
//#endif
2694+
#define LWIP_HOOK_UNKNOWN_ETH_PROTOCOL(pbuf, netif) lwip_unhandled_packet((pbuf), (netif))
2695+
26942696
/**
26952697
* @}
26962698
*/
@@ -3003,4 +3005,12 @@
30033005
#include "lwip-git-hash.h"
30043006
#include <sys/time.h> // settimeofday() + struct timeval
30053007

3008+
// allow to handle special packets (user redefinable)
3009+
struct pbuf;
3010+
struct netif;
3011+
#ifndef LWIP_ERR_T
3012+
#define LWIP_ERR_T s8
3013+
#endif
3014+
LWIP_ERR_T lwip_unhandled_packet (struct pbuf* pbuf, struct netif* netif) __attribute__((weak));
3015+
30063016
#endif // MYLWIPOPTS_H

0 commit comments

Comments
 (0)