Skip to content

Commit 7968d38

Browse files
Merge pull request #17 from KipK/wifi_connection-issue
Some network changes ( missing push event at IP change, Active scan, connect best signal AP )
2 parents 784d454 + 4242971 commit 7968d38

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

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/net_manager.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "lcd.h"
55
#include "espal.h"
66
#include "time_man.h"
7+
#include "event.h"
78

89
#include "LedManagerTask.h"
910

@@ -90,7 +91,6 @@ void NetManagerTask::wifiStartAccessPoint()
9091

9192
WiFi.enableAP(true);
9293
WiFi.enableSTA(true); // Needed for scanning
93-
9494
WiFi.softAPConfig(_apIP, _apIP, _apNetMask);
9595

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

157157
WiFi.hostname(esp_hostname.c_str());
158158
WiFi.setSleep(WIFI_PS_NONE);
159+
WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN);
160+
WiFi.setSortMethod(WIFI_CONNECT_AP_BY_SIGNAL);
159161
WiFi.begin(esid.c_str(), epass.c_str());
160162

161163
_clientRetryTime = millis() + WIFI_CLIENT_RETRY_TIMEOUT;
@@ -164,7 +166,7 @@ void NetManagerTask::wifiClientConnect()
164166
void NetManagerTask::wifiScanNetworks(WiFiScanCompleteCallback callback)
165167
{
166168
if(WiFi.scanComplete() != WIFI_SCAN_RUNNING) {
167-
WiFi.scanNetworks(true, false, true);
169+
WiFi.scanNetworks(true, false, false);
168170
}
169171
_scanCompleteCallbacks.push_back(callback);
170172
}
@@ -206,6 +208,12 @@ void NetManagerTask::wifiOnStationModeConnected(const WiFiEventStationModeConnec
206208
void NetManagerTask::wifiOnStationModeGotIP(const WiFiEventStationModeGotIP &event)
207209
{
208210
haveNetworkConnection(WiFi.localIP());
211+
StaticJsonDocument<128> doc;
212+
doc["wifi_client_connected"] = (int)net.isWifiClientConnected();
213+
doc["eth_connected"] = (int)net.isWiredConnected();
214+
doc["net_connected"] = (int)net.isWifiClientConnected();
215+
doc["ipaddress"] = net.getIp();
216+
event_send(doc);
209217

210218
// Clear any error state
211219
_clientDisconnects = 0;
@@ -517,6 +525,7 @@ void NetManagerTask::setup()
517525
MDNS.addServiceTxt("openevse", "tcp", "type", buildenv.c_str());
518526
MDNS.addServiceTxt("openevse", "tcp", "version", currentfirmware.c_str());
519527
MDNS.addServiceTxt("openevse", "tcp", "id", ESPAL.getLongId());
528+
520529
}
521530
}
522531

@@ -793,4 +802,4 @@ bool NetManagerTask::isWiredConnected()
793802
#else
794803
return false;
795804
#endif
796-
}
805+
}

src/net_manager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class NetManagerTask : public MicroTasks::Task
172172
NetManagerTask(LcdTask &lcd, LedManagerTask &led, TimeManager &time);
173173

174174
void begin();
175-
175+
176176
void wifiScan();
177177

178178
void wifiStart();
@@ -183,7 +183,7 @@ class NetManagerTask : public MicroTasks::Task
183183
void wifiTurnOnAp();
184184

185185
void wifiScanNetworks(WiFiScanCompleteCallback callback);
186-
186+
187187
bool isConnected();
188188
bool isWifiClientConnected();
189189
bool isWiredConnected();

src/web_server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ void handleNotFound(MongooseHttpServerRequest *request)
10331033
DBUG("NOT_FOUND: ");
10341034
dumpRequest(request);
10351035

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

0 commit comments

Comments
 (0)