Skip to content

Commit aa7fab5

Browse files
authored
Merge pull request #533 from jeremypoulter/wifi_connection-issue
Re-work of the network manager
2 parents 59fcb68 + 0537e30 commit aa7fab5

File tree

11 files changed

+711
-339
lines changed

11 files changed

+711
-339
lines changed

platformio.ini

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ lib_deps =
3838
jeremypoulter/[email protected]
3939
jeremypoulter/[email protected]
4040
jeremypoulter/[email protected]
41-
jeremypoulter/[email protected].2
41+
jeremypoulter/[email protected].3
4242
4343
4444
lib_ignore = WebSockets ; ArduinoOcpp: don't compile built-in WS library
@@ -60,6 +60,8 @@ debug_flags =
6060
#-D ENABLE_DEBUG_TESLA_CLIENT
6161
#-D ENABLE_DEBUG_LIMIT
6262
#-D ENABLE_PROFILE
63+
#-D ENABLE_NOISY_PROFILE
64+
#-D ENABLE_DEBUG_MICROTASKS
6365
src_build_flags =
6466
# -D ARDUINOJSON_USE_LONG_LONG
6567
# -D ENABLE_ASYNC_WIFI_SCAN
@@ -114,13 +116,13 @@ build_flags =
114116
${common.build_flags}
115117
#upload_port = openevse.local
116118
upload_speed = 921600
117-
monitor_speed = 115200
118119
extra_scripts = ${common.extra_scripts}
119120
board_build.partitions = ${common.build_partitions}
120121
#platform_packages =
121122
# ; use a special branch
122123
# framework-arduinoespressif32 @ https://github.com/marcovannoord/arduino-esp32.git#idf-release/v4.0
123124
# platformio/framework-arduinoespressif32 @ ~3.10006.0
125+
monitor_speed = 115200
124126
monitor_filters =
125127
esp32_exception_decoder
126128

@@ -248,7 +250,6 @@ build_flags =
248250
-D DEBUG_PORT=Serial
249251
-D RAPI_PORT=Serial2
250252
-D ENABLE_WIRED_ETHERNET
251-
-D RANDOM_SEED_CHANNEL=1
252253
# https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/examples/ETH_LAN8720/ETH_LAN8720.ino
253254

254255
[env:openevse_esp32-gateway-f]
@@ -266,7 +267,7 @@ build_flags =
266267
-D DEBUG_PORT=Serial
267268
-D RAPI_PORT=Serial2
268269
-D ENABLE_WIRED_ETHERNET
269-
-D RANDOM_SEED_CHANNEL=1
270+
-D RESET_ETH_PHY_ON_BOOT=1
270271
-D RX2=16
271272
-D TX2=32
272273
board_build.extra_flags = "-DARDUINO_ESP32_GATEWAY=\'F\'"
@@ -278,7 +279,6 @@ upload_speed = 921600
278279
extends = env:openevse_esp32-gateway-f
279280
build_flags =
280281
${env:openevse_esp32-gateway-f.build_flags}
281-
-D RESET_ETH_PHY_ON_BOOT=1
282282
board_build.extra_flags = "-DARDUINO_ESP32_GATEWAY=\'E\'"
283283

284284
[env:openevse_esp32-gateway-e_dev]
@@ -309,7 +309,6 @@ build_flags =
309309
-D DEBUG_PORT=Serial
310310
-D RAPI_PORT=Serial2
311311
-D ENABLE_WIRED_ETHERNET
312-
-D RANDOM_SEED_CHANNEL=1
313312
-D RESET_ETH_PHY_ON_BOOT=1
314313
upload_speed = 921600
315314

src/app_config.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "emonesp.h"
22
#include "espal.h"
33
#include "divert.h"
4+
#include "net_manager.h"
45
#include "mqtt.h"
56
#include "ocpp.h"
67
#include "tesla_client.h"
@@ -393,3 +394,6 @@ config_reset() {
393394
LittleFS.format();
394395
config_load_settings();
395396
}
397+
398+
399+

src/emonesp.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
#endif
5252

5353
#ifndef WIFI_CLIENT_RETRY_TIMEOUT
54-
#define WIFI_CLIENT_RETRY_TIMEOUT (5 * 60 * 1000)
54+
#define WIFI_CLIENT_RETRY_TIMEOUT (10 * 1000)
5555
#endif
5656

5757
#ifndef WIFI_CLIENT_DISCONNECTS_BEFORE_AP
@@ -61,11 +61,15 @@
6161
// Used to change the ADC channel used for seeding the rndom number generator
6262
// Should be set to an unconnected pin
6363
#ifndef RANDOM_SEED_CHANNEL
64-
#if WIFI_BUTTON != 0 && (!defined(WIFI_LED) || WIFI_LED != 0)
65-
#define RANDOM_SEED_CHANNEL 0
66-
#else
67-
#define RANDOM_SEED_CHANNEL 1
68-
#endif
64+
#ifdef ESP32
65+
#define RANDOM_SEED_CHANNEL 14
66+
#else
67+
#if WIFI_BUTTON != 0 && (!defined(WIFI_LED) || WIFI_LED != 0)
68+
#define RANDOM_SEED_CHANNEL 0
69+
#else
70+
#define RANDOM_SEED_CHANNEL 1
71+
#endif
72+
#endif
6973
#endif
7074

7175
#ifndef HAL_ID_ENCODING_BASE

src/input.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ void input_setup()
186186
{
187187
case OPENEVSE_WIFI_MODE_AP:
188188
case OPENEVSE_WIFI_MODE_AP_DEFAULT:
189-
net_wifi_turn_on_ap();
189+
net.wifiTurnOnAp();
190190
break;
191191
case OPENEVSE_WIFI_MODE_CLIENT:
192-
net_wifi_turn_off_ap();
192+
net.wifiTurnOffAp();
193193
break;
194194
}
195195
});

src/main.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ Scheduler scheduler(evse);
7070
ManualOverride manual(evse);
7171
DivertTask divert(evse);
7272

73+
NetManagerTask net(lcd, ledManager, timeManager);
74+
7375
RapiSender &rapiSender = evse.getSender();
7476

7577
unsigned long Timer1; // Timer for events once every 30 seconds
@@ -137,7 +139,7 @@ void setup()
137139
ledManager.begin(evse);
138140

139141
// Initialise the WiFi
140-
net_setup();
142+
net.begin();
141143
DBUGF("After net_setup: %d", ESPAL.getFreeHeap());
142144

143145
// Initialise Mongoose networking library
@@ -177,7 +179,6 @@ loop() {
177179
Profile_End(Mongoose, 10);
178180

179181
web_server_loop();
180-
net_loop();
181182
ota_loop();
182183
rapiSender.loop();
183184

@@ -216,7 +217,7 @@ loop() {
216217
}
217218
}
218219

219-
if(net_is_connected())
220+
if(net.isConnected())
220221
{
221222
if (config_tesla_enabled()) {
222223
teslaClient.loop();
@@ -288,7 +289,7 @@ class SystemRestart : public MicroTasks::Alarm
288289
void Trigger()
289290
{
290291
DBUGLN("Restarting...");
291-
net_wifi_disconnect();
292+
net.wifiStop();
292293
ESPAL.reset();
293294
}
294295
} systemRestartAlarm;
@@ -336,4 +337,4 @@ void handle_serial()
336337
DEBUG_PORT.printf("{\"code\":200,\"msg\":\"%s\"}\n", config_modified ? "done" : "no change");
337338
}
338339
}
339-
}
340+
}

src/mqtt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ mqtt_connect()
271271
doc["id"] = ESPAL.getLongId();
272272
doc["name"] = esp_hostname;
273273
doc["mqtt"] = mqtt_topic;
274-
doc["http"] = "http://"+ipaddress+"/";
274+
doc["http"] = "http://"+net.getIp()+"/";
275275

276276
// Once connected, publish an announcement..
277277
String announce = "";

0 commit comments

Comments
 (0)