mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-02-17 04:02:13 +01:00
Change the soft AP behavior so it does not start as fast on ethernet #271
This commit is contained in:
parent
2a3d7aa7e7
commit
632dd3900b
6 changed files with 44 additions and 17 deletions
58
Network.cpp
58
Network.cpp
|
|
@ -1,4 +1,3 @@
|
||||||
#include <Arduino.h>
|
|
||||||
#include <ETH.h>
|
#include <ETH.h>
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <ESPmDNS.h>
|
#include <ESPmDNS.h>
|
||||||
|
|
@ -40,18 +39,21 @@ bool Network::setup() {
|
||||||
}
|
}
|
||||||
void Network::loop() {
|
void Network::loop() {
|
||||||
if(millis() - this->lastEmit > 1500) {
|
if(millis() - this->lastEmit > 1500) {
|
||||||
while(!this->connect()) {
|
|
||||||
// If we lost our connenction
|
|
||||||
connectRetries++;
|
|
||||||
if(connectRetries > 100) {
|
|
||||||
this->openSoftAP();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
sockEmit.loop();
|
|
||||||
}
|
|
||||||
connectRetries = 0;
|
|
||||||
this->lastEmit = millis();
|
this->lastEmit = millis();
|
||||||
|
if(!this->softAPOpened) {
|
||||||
|
while(!this->connect()) {
|
||||||
|
// If we lost our connection
|
||||||
|
connectRetries++;
|
||||||
|
if(connectRetries > 100) {
|
||||||
|
if(!this->connected()) this->openSoftAP();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
sockEmit.loop();
|
||||||
|
}
|
||||||
|
connectRetries = 0;
|
||||||
|
}
|
||||||
this->emitSockets();
|
this->emitSockets();
|
||||||
|
this->lastEmit = millis();
|
||||||
if(!this->connected()) return;
|
if(!this->connected()) return;
|
||||||
}
|
}
|
||||||
if(this->connected() && millis() - this->lastMDNS > 60000) {
|
if(this->connected() && millis() - this->lastMDNS > 60000) {
|
||||||
|
|
@ -113,6 +115,21 @@ void Network::emitSockets(uint8_t num) {
|
||||||
void Network::setConnected(conn_types connType) {
|
void Network::setConnected(conn_types connType) {
|
||||||
this->connType = connType;
|
this->connType = connType;
|
||||||
this->connectTime = millis();
|
this->connectTime = millis();
|
||||||
|
connectRetries = 0;
|
||||||
|
if(this->connType == conn_types::wifi) {
|
||||||
|
if(this->softAPOpened) {
|
||||||
|
WiFi.softAPdisconnect(true);
|
||||||
|
WiFi.mode(WIFI_STA);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(this->connType == conn_types::ethernet) {
|
||||||
|
if(this->softAPOpened) {
|
||||||
|
Serial.println("Disonnecting from SoftAP");
|
||||||
|
WiFi.softAPdisconnect(true);
|
||||||
|
WiFi.mode(WIFI_OFF);
|
||||||
|
}
|
||||||
|
this->wifiFallback = false;
|
||||||
|
}
|
||||||
if(this->connectAttempts == 1) {
|
if(this->connectAttempts == 1) {
|
||||||
Serial.println();
|
Serial.println();
|
||||||
if(this->connType == conn_types::wifi) {
|
if(this->connType == conn_types::wifi) {
|
||||||
|
|
@ -217,8 +234,10 @@ void Network::setConnected(conn_types connType) {
|
||||||
settings.printAvailHeap();
|
settings.printAvailHeap();
|
||||||
}
|
}
|
||||||
bool Network::connectWired() {
|
bool Network::connectWired() {
|
||||||
if(this->connType == conn_types::ethernet) {
|
//if(this->connType == conn_types::ethernet && ETH.linkUp()) {
|
||||||
|
if(ETH.linkUp()) {
|
||||||
this->disconnected = 0;
|
this->disconnected = 0;
|
||||||
|
this->wifiFallback = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(this->connectAttempts > 0) {
|
if(this->connectAttempts > 0) {
|
||||||
|
|
@ -254,7 +273,7 @@ bool Network::connectWired() {
|
||||||
ETH.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE);
|
ETH.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE);
|
||||||
|
|
||||||
uint32_t wait = millis();
|
uint32_t wait = millis();
|
||||||
while(millis() - wait < 7000) {
|
while(millis() - wait < 14000) {
|
||||||
if(this->connected()) return true;
|
if(this->connected()) return true;
|
||||||
delay(500);
|
delay(500);
|
||||||
}
|
}
|
||||||
|
|
@ -377,8 +396,13 @@ bool Network::connectWiFi() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool Network::connect() {
|
bool Network::connect() {
|
||||||
if(settings.connType != conn_types::wifi && settings.connType != conn_types::unset && !this->wifiFallback)
|
if(settings.connType == conn_types::unset) return true;
|
||||||
return this->connectWired();
|
else if(settings.connType == conn_types::ethernet || (settings.connType == conn_types::ethernetpref)) {
|
||||||
|
bool bConnected = this->connectWired();
|
||||||
|
if(!bConnected && settings.connType == conn_types::ethernetpref && settings.WIFI.ssid[0] != '\0')
|
||||||
|
bConnected = this->connectWiFi();
|
||||||
|
return bConnected;
|
||||||
|
}
|
||||||
return this->connectWiFi();
|
return this->connectWiFi();
|
||||||
}
|
}
|
||||||
int Network::getStrengthByMac(const char *macAddr) {
|
int Network::getStrengthByMac(const char *macAddr) {
|
||||||
|
|
@ -444,7 +468,7 @@ bool Network::openSoftAP() {
|
||||||
long startTime = millis();
|
long startTime = millis();
|
||||||
int c = 0;
|
int c = 0;
|
||||||
|
|
||||||
while ((WiFi.status() != WL_CONNECTED))
|
while (!this->connected())
|
||||||
{
|
{
|
||||||
int clients = WiFi.softAPgetStationNum();
|
int clients = WiFi.softAPgetStationNum();
|
||||||
webServer.loop();
|
webServer.loop();
|
||||||
|
|
@ -531,9 +555,11 @@ void Network::networkEvent(WiFiEvent_t event) {
|
||||||
break;
|
break;
|
||||||
case ARDUINO_EVENT_WIFI_AP_STOP:
|
case ARDUINO_EVENT_WIFI_AP_STOP:
|
||||||
Serial.println("WiFi AP Stopped");
|
Serial.println("WiFi AP Stopped");
|
||||||
|
net.softAPOpened = false;
|
||||||
break;
|
break;
|
||||||
case ARDUINO_EVENT_WIFI_AP_START:
|
case ARDUINO_EVENT_WIFI_AP_START:
|
||||||
Serial.println("WiFi AP Started");
|
Serial.println("WiFi AP Started");
|
||||||
|
net.softAPOpened = true;
|
||||||
break;
|
break;
|
||||||
case ARDUINO_EVENT_WIFI_STA_START:
|
case ARDUINO_EVENT_WIFI_STA_START:
|
||||||
if(settings.hostname[0] != '\0') WiFi.setHostname(settings.hostname);
|
if(settings.hostname[0] != '\0') WiFi.setHostname(settings.hostname);
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ class Network {
|
||||||
bool ethStarted = false;
|
bool ethStarted = false;
|
||||||
public:
|
public:
|
||||||
bool wifiFallback = false;
|
bool wifiFallback = false;
|
||||||
|
bool softAPOpened = false;
|
||||||
conn_types connType = conn_types::unset;
|
conn_types connType = conn_types::unset;
|
||||||
bool connected();
|
bool connected();
|
||||||
String ssid;
|
String ssid;
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -2762,7 +2762,7 @@ class Somfy {
|
||||||
pinMaps = [
|
pinMaps = [
|
||||||
{ name: '', maxPins: 39, inputs: [0, 1, 6, 7, 8, 9, 10, 11, 37, 38], outputs: [3, 6, 7, 8, 9, 10, 11, 34, 35, 36, 37, 38, 39] },
|
{ name: '', maxPins: 39, inputs: [0, 1, 6, 7, 8, 9, 10, 11, 37, 38], outputs: [3, 6, 7, 8, 9, 10, 11, 34, 35, 36, 37, 38, 39] },
|
||||||
{ name: 's2', maxPins: 46, inputs: [0, 15, 16, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 45], outputs: [0, 15, 16, 19, 20, 26, 27, 28, 29, 30, 31, 32, 45, 46]},
|
{ name: 's2', maxPins: 46, inputs: [0, 15, 16, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 45], outputs: [0, 15, 16, 19, 20, 26, 27, 28, 29, 30, 31, 32, 45, 46]},
|
||||||
{ name: 's3', maxPins: 48, inputs: [0, 3, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 39, 40, 41, 42, 43, 44], outputs: [0, 3, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 39, 40, 41, 42, 43, 44] },
|
{ name: 's3', maxPins: 48, inputs: [0, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 39, 40, 41, 42, 43], outputs: [0, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 39, 40, 41, 42, 43] },
|
||||||
{ name: 'c3', maxPins: 21, inputs: [11, 12, 13, 14, 15, 16, 17, 18, 19, 20], outputs: [11, 12, 13, 14, 15, 16, 17, 21] }
|
{ name: 'c3', maxPins: 21, inputs: [11, 12, 13, 14, 15, 16, 17, 18, 19, 20], outputs: [11, 12, 13, 14, 15, 16, 17, 21] }
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue