Skip to content

Commit

Permalink
Merge pull request #17 from KipK/wifi_connection-issue
Browse files Browse the repository at this point in the history
Some network changes (  missing push event at IP change,  Active scan, connect best signal AP )
  • Loading branch information
jeremypoulter authored Feb 27, 2023
2 parents 784d454 + 4242971 commit 7968d38
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
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();
}



15 changes: 12 additions & 3 deletions src/net_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "lcd.h"
#include "espal.h"
#include "time_man.h"
#include "event.h"

#include "LedManagerTask.h"

Expand Down Expand Up @@ -90,7 +91,6 @@ void NetManagerTask::wifiStartAccessPoint()

WiFi.enableAP(true);
WiFi.enableSTA(true); // Needed for scanning

WiFi.softAPConfig(_apIP, _apIP, _apNetMask);

// Create Unique SSID e.g "emonESP_XXXXXX"
Expand Down Expand Up @@ -156,6 +156,8 @@ void NetManagerTask::wifiClientConnect()

WiFi.hostname(esp_hostname.c_str());
WiFi.setSleep(WIFI_PS_NONE);
WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN);
WiFi.setSortMethod(WIFI_CONNECT_AP_BY_SIGNAL);
WiFi.begin(esid.c_str(), epass.c_str());

_clientRetryTime = millis() + WIFI_CLIENT_RETRY_TIMEOUT;
Expand All @@ -164,7 +166,7 @@ void NetManagerTask::wifiClientConnect()
void NetManagerTask::wifiScanNetworks(WiFiScanCompleteCallback callback)
{
if(WiFi.scanComplete() != WIFI_SCAN_RUNNING) {
WiFi.scanNetworks(true, false, true);
WiFi.scanNetworks(true, false, false);
}
_scanCompleteCallbacks.push_back(callback);
}
Expand Down Expand Up @@ -206,6 +208,12 @@ void NetManagerTask::wifiOnStationModeConnected(const WiFiEventStationModeConnec
void NetManagerTask::wifiOnStationModeGotIP(const WiFiEventStationModeGotIP &event)
{
haveNetworkConnection(WiFi.localIP());
StaticJsonDocument<128> doc;
doc["wifi_client_connected"] = (int)net.isWifiClientConnected();
doc["eth_connected"] = (int)net.isWiredConnected();
doc["net_connected"] = (int)net.isWifiClientConnected();
doc["ipaddress"] = net.getIp();
event_send(doc);

// Clear any error state
_clientDisconnects = 0;
Expand Down Expand Up @@ -517,6 +525,7 @@ void NetManagerTask::setup()
MDNS.addServiceTxt("openevse", "tcp", "type", buildenv.c_str());
MDNS.addServiceTxt("openevse", "tcp", "version", currentfirmware.c_str());
MDNS.addServiceTxt("openevse", "tcp", "id", ESPAL.getLongId());

}
}

Expand Down Expand Up @@ -793,4 +802,4 @@ bool NetManagerTask::isWiredConnected()
#else
return false;
#endif
}
}
4 changes: 2 additions & 2 deletions src/net_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class NetManagerTask : public MicroTasks::Task
NetManagerTask(LcdTask &lcd, LedManagerTask &led, TimeManager &time);

void begin();

void wifiScan();

void wifiStart();
Expand All @@ -183,7 +183,7 @@ class NetManagerTask : public MicroTasks::Task
void wifiTurnOnAp();

void wifiScanNetworks(WiFiScanCompleteCallback callback);

bool isConnected();
bool isWifiClientConnected();
bool isWiredConnected();
Expand Down
2 changes: 1 addition & 1 deletion src/web_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ void handleNotFound(MongooseHttpServerRequest *request)
DBUG("NOT_FOUND: ");
dumpRequest(request);

if(net.isWifiModeApOnly()) {
if((net.isWifiModeAp()) {
// Redirect to the home page in AP mode (for the captive portal)
MongooseHttpServerResponseStream *response = request->beginResponseStream();
response->setContentType(CONTENT_TYPE_HTML);
Expand Down

0 comments on commit 7968d38

Please sign in to comment.