Skip to content

Commit

Permalink
Merge pull request #533 from jeremypoulter/wifi_connection-issue
Browse files Browse the repository at this point in the history
Re-work of the network manager
  • Loading branch information
glynhudson authored Mar 8, 2023
2 parents 59fcb68 + 0537e30 commit aa7fab5
Show file tree
Hide file tree
Showing 11 changed files with 711 additions and 339 deletions.
11 changes: 5 additions & 6 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ lib_deps =
jeremypoulter/OpenEVSE@0.0.12
jeremypoulter/ESPAL@0.0.3
jeremypoulter/StreamSpy@0.0.1
jeremypoulter/MicroTasks@0.0.2
jeremypoulter/MicroTasks@0.0.3
matth-x/ArduinoOcpp@0.2.0
matth-x/ArduinoOcppMongoose@0.0.1
lib_ignore = WebSockets ; ArduinoOcpp: don't compile built-in WS library
Expand All @@ -60,6 +60,8 @@ debug_flags =
#-D ENABLE_DEBUG_TESLA_CLIENT
#-D ENABLE_DEBUG_LIMIT
#-D ENABLE_PROFILE
#-D ENABLE_NOISY_PROFILE
#-D ENABLE_DEBUG_MICROTASKS
src_build_flags =
# -D ARDUINOJSON_USE_LONG_LONG
# -D ENABLE_ASYNC_WIFI_SCAN
Expand Down Expand Up @@ -114,13 +116,13 @@ build_flags =
${common.build_flags}
#upload_port = openevse.local
upload_speed = 921600
monitor_speed = 115200
extra_scripts = ${common.extra_scripts}
board_build.partitions = ${common.build_partitions}
#platform_packages =
# ; use a special branch
# framework-arduinoespressif32 @ https://github.com/marcovannoord/arduino-esp32.git#idf-release/v4.0
# platformio/framework-arduinoespressif32 @ ~3.10006.0
monitor_speed = 115200
monitor_filters =
esp32_exception_decoder

Expand Down Expand Up @@ -248,7 +250,6 @@ build_flags =
-D DEBUG_PORT=Serial
-D RAPI_PORT=Serial2
-D ENABLE_WIRED_ETHERNET
-D RANDOM_SEED_CHANNEL=1
# https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/examples/ETH_LAN8720/ETH_LAN8720.ino

[env:openevse_esp32-gateway-f]
Expand All @@ -266,7 +267,7 @@ build_flags =
-D DEBUG_PORT=Serial
-D RAPI_PORT=Serial2
-D ENABLE_WIRED_ETHERNET
-D RANDOM_SEED_CHANNEL=1
-D RESET_ETH_PHY_ON_BOOT=1
-D RX2=16
-D TX2=32
board_build.extra_flags = "-DARDUINO_ESP32_GATEWAY=\'F\'"
Expand All @@ -278,7 +279,6 @@ upload_speed = 921600
extends = env:openevse_esp32-gateway-f
build_flags =
${env:openevse_esp32-gateway-f.build_flags}
-D RESET_ETH_PHY_ON_BOOT=1
board_build.extra_flags = "-DARDUINO_ESP32_GATEWAY=\'E\'"

[env:openevse_esp32-gateway-e_dev]
Expand Down Expand Up @@ -309,7 +309,6 @@ build_flags =
-D DEBUG_PORT=Serial
-D RAPI_PORT=Serial2
-D ENABLE_WIRED_ETHERNET
-D RANDOM_SEED_CHANNEL=1
-D RESET_ETH_PHY_ON_BOOT=1
upload_speed = 921600

Expand Down
4 changes: 4 additions & 0 deletions src/app_config.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "emonesp.h"
#include "espal.h"
#include "divert.h"
#include "net_manager.h"
#include "mqtt.h"
#include "ocpp.h"
#include "tesla_client.h"
Expand Down Expand Up @@ -393,3 +394,6 @@ config_reset() {
LittleFS.format();
config_load_settings();
}



16 changes: 10 additions & 6 deletions src/emonesp.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#endif

#ifndef WIFI_CLIENT_RETRY_TIMEOUT
#define WIFI_CLIENT_RETRY_TIMEOUT (5 * 60 * 1000)
#define WIFI_CLIENT_RETRY_TIMEOUT (10 * 1000)
#endif

#ifndef WIFI_CLIENT_DISCONNECTS_BEFORE_AP
Expand All @@ -61,11 +61,15 @@
// Used to change the ADC channel used for seeding the rndom number generator
// Should be set to an unconnected pin
#ifndef RANDOM_SEED_CHANNEL
#if WIFI_BUTTON != 0 && (!defined(WIFI_LED) || WIFI_LED != 0)
#define RANDOM_SEED_CHANNEL 0
#else
#define RANDOM_SEED_CHANNEL 1
#endif
#ifdef ESP32
#define RANDOM_SEED_CHANNEL 14
#else
#if WIFI_BUTTON != 0 && (!defined(WIFI_LED) || WIFI_LED != 0)
#define RANDOM_SEED_CHANNEL 0
#else
#define RANDOM_SEED_CHANNEL 1
#endif
#endif
#endif

#ifndef HAL_ID_ENCODING_BASE
Expand Down
4 changes: 2 additions & 2 deletions src/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ void input_setup()
{
case OPENEVSE_WIFI_MODE_AP:
case OPENEVSE_WIFI_MODE_AP_DEFAULT:
net_wifi_turn_on_ap();
net.wifiTurnOnAp();
break;
case OPENEVSE_WIFI_MODE_CLIENT:
net_wifi_turn_off_ap();
net.wifiTurnOffAp();
break;
}
});
Expand Down
11 changes: 6 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ Scheduler scheduler(evse);
ManualOverride manual(evse);
DivertTask divert(evse);

NetManagerTask net(lcd, ledManager, timeManager);

RapiSender &rapiSender = evse.getSender();

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

// Initialise the WiFi
net_setup();
net.begin();
DBUGF("After net_setup: %d", ESPAL.getFreeHeap());

// Initialise Mongoose networking library
Expand Down Expand Up @@ -177,7 +179,6 @@ loop() {
Profile_End(Mongoose, 10);

web_server_loop();
net_loop();
ota_loop();
rapiSender.loop();

Expand Down Expand Up @@ -216,7 +217,7 @@ loop() {
}
}

if(net_is_connected())
if(net.isConnected())
{
if (config_tesla_enabled()) {
teslaClient.loop();
Expand Down Expand Up @@ -288,7 +289,7 @@ class SystemRestart : public MicroTasks::Alarm
void Trigger()
{
DBUGLN("Restarting...");
net_wifi_disconnect();
net.wifiStop();
ESPAL.reset();
}
} systemRestartAlarm;
Expand Down Expand Up @@ -336,4 +337,4 @@ void handle_serial()
DEBUG_PORT.printf("{\"code\":200,\"msg\":\"%s\"}\n", config_modified ? "done" : "no change");
}
}
}
}
2 changes: 1 addition & 1 deletion src/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ mqtt_connect()
doc["id"] = ESPAL.getLongId();
doc["name"] = esp_hostname;
doc["mqtt"] = mqtt_topic;
doc["http"] = "http://"+ipaddress+"/";
doc["http"] = "http://"+net.getIp()+"/";

// Once connected, publish an announcement..
String announce = "";
Expand Down
Loading

0 comments on commit aa7fab5

Please sign in to comment.