mirror of
https://github.com/lumapu/ahoy.git
synced 2025-08-06 09:58:23 +02:00
Ethernet + Wifi fully functional
This commit is contained in:
parent
054683fe87
commit
6045cbb31b
8 changed files with 94 additions and 19 deletions
|
@ -253,6 +253,12 @@ class app : public IApp, public ah::Scheduler {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(ETHERNET)
|
||||||
|
bool isWiredConnection() override {
|
||||||
|
return mNetwork->isWiredConnection();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void lock(bool fromWeb) override {
|
void lock(bool fromWeb) override {
|
||||||
mProtection->lock(fromWeb);
|
mProtection->lock(fromWeb);
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,10 @@ class IApp {
|
||||||
virtual uint32_t getMqttRxCnt() = 0;
|
virtual uint32_t getMqttRxCnt() = 0;
|
||||||
virtual uint32_t getMqttTxCnt() = 0;
|
virtual uint32_t getMqttTxCnt() = 0;
|
||||||
|
|
||||||
|
#if defined(ETHERNET)
|
||||||
|
virtual bool isWiredConnection() = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
virtual void lock(bool fromWeb) = 0;
|
virtual void lock(bool fromWeb) = 0;
|
||||||
virtual char *unlock(const char *clientIp, bool loginFromWeb) = 0;
|
virtual char *unlock(const char *clientIp, bool loginFromWeb) = 0;
|
||||||
virtual void resetLockTimeout(void) = 0;
|
virtual void resetLockTimeout(void) = 0;
|
||||||
|
|
|
@ -34,6 +34,18 @@ class AhoyEthernet : public AhoyWifi {
|
||||||
ETH.setHostname(mConfig->sys.deviceName);
|
ETH.setHostname(mConfig->sys.deviceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getIp(void) {
|
||||||
|
if(Mode::WIRELESS == mMode)
|
||||||
|
return AhoyWifi::getIp();
|
||||||
|
else
|
||||||
|
return ETH.localIP().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isWiredConnection() {
|
||||||
|
return (Mode::WIRED == mMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
void OnEvent(WiFiEvent_t event) {
|
void OnEvent(WiFiEvent_t event) {
|
||||||
switch(event) {
|
switch(event) {
|
||||||
case SYSTEM_EVENT_STA_CONNECTED:
|
case SYSTEM_EVENT_STA_CONNECTED:
|
||||||
|
@ -41,6 +53,9 @@ class AhoyEthernet : public AhoyWifi {
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
case ARDUINO_EVENT_ETH_CONNECTED:
|
case ARDUINO_EVENT_ETH_CONNECTED:
|
||||||
if(NetworkState::CONNECTED != mStatus) {
|
if(NetworkState::CONNECTED != mStatus) {
|
||||||
|
if(ARDUINO_EVENT_ETH_CONNECTED == event)
|
||||||
|
WiFi.disconnect();
|
||||||
|
|
||||||
mStatus = NetworkState::CONNECTED;
|
mStatus = NetworkState::CONNECTED;
|
||||||
DPRINTLN(DBG_INFO, F("Network connected"));
|
DPRINTLN(DBG_INFO, F("Network connected"));
|
||||||
setStaticIp();
|
setStaticIp();
|
||||||
|
@ -106,14 +121,6 @@ class AhoyEthernet : public AhoyWifi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String getIp(void) {
|
|
||||||
if(Mode::WIRELESS == mMode)
|
|
||||||
return AhoyWifi::getIp();
|
|
||||||
else
|
|
||||||
return ETH.localIP().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void setStaticIp() override {
|
void setStaticIp() override {
|
||||||
setupIp([this](IPAddress ip, IPAddress gateway, IPAddress mask, IPAddress dns1, IPAddress dns2) -> bool {
|
setupIp([this](IPAddress ip, IPAddress gateway, IPAddress mask, IPAddress dns1, IPAddress dns2) -> bool {
|
||||||
if(Mode::WIRELESS == mMode)
|
if(Mode::WIRELESS == mMode)
|
||||||
|
|
|
@ -84,6 +84,10 @@ class AhoyNetwork {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual bool isWiredConnection() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool isApActive() {
|
bool isApActive() {
|
||||||
return mAp.isEnabled();
|
return mAp.isEnabled();
|
||||||
}
|
}
|
||||||
|
|
|
@ -432,6 +432,10 @@ class RestApi {
|
||||||
#endif
|
#endif
|
||||||
getMqttInfo(obj.createNestedObject(F("mqtt")));
|
getMqttInfo(obj.createNestedObject(F("mqtt")));
|
||||||
|
|
||||||
|
#if defined(ETHERNET)
|
||||||
|
getEthernetInfo(obj.createNestedObject(F("eth")));
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
obj[F("chip_revision")] = ESP.getChipRevision();
|
obj[F("chip_revision")] = ESP.getChipRevision();
|
||||||
obj[F("chip_model")] = ESP.getChipModel();
|
obj[F("chip_model")] = ESP.getChipModel();
|
||||||
|
@ -824,6 +828,10 @@ class RestApi {
|
||||||
obj[F("irq")] = mConfig->sys.eth.pinIrq;
|
obj[F("irq")] = mConfig->sys.eth.pinIrq;
|
||||||
obj[F("reset")] = mConfig->sys.eth.pinRst;
|
obj[F("reset")] = mConfig->sys.eth.pinRst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void getEthernetInfo(JsonObject obj) {
|
||||||
|
obj[F("wired")] = (bool)mApp->isWiredConnection();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void getRadioNrf(JsonObject obj) {
|
void getRadioNrf(JsonObject obj) {
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
const data = ["sdk", "cpu_freq", "chip_revision", "device_name",
|
const data = ["sdk", "cpu_freq", "chip_revision", "device_name",
|
||||||
"chip_model", "chip_cores", "esp_type", "mac", "wifi_rssi", "wifi_channel", "ts_uptime",
|
"chip_model", "chip_cores", "esp_type", "mac", "wifi_rssi", "wifi_channel", "ts_uptime",
|
||||||
"flash_size", "sketch_used", "heap_total", "heap_free", "heap_frag",
|
"flash_size", "sketch_used", "heap_total", "heap_free", "heap_frag",
|
||||||
"max_free_blk", "version", "modules", "env", "core_version", "reboot_reason"];
|
"max_free_blk", "version", "modules", "env", "core_version", "reboot_reason", "is_eth_con"];
|
||||||
|
|
||||||
lines = [];
|
lines = [];
|
||||||
for (const [key, value] of Object.entries(obj)) {
|
for (const [key, value] of Object.entries(obj)) {
|
||||||
|
@ -111,6 +111,19 @@
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*IF_ETHERNET*/
|
||||||
|
function parseEthernet(obj) {
|
||||||
|
lines = tr("{#CONNECTION_TYPE}", ((obj.wired) ? "{#WIRED}" : "{#WIFI}"));
|
||||||
|
|
||||||
|
document.getElementById("info").append(
|
||||||
|
headline("{#NETWORK}"),
|
||||||
|
ml("table", {class: "table"},
|
||||||
|
ml("tbody", {}, lines)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
/*ENDIF_ETHERNET*/
|
||||||
|
|
||||||
function parseIndex(obj) {
|
function parseIndex(obj) {
|
||||||
if(obj.ts_sunrise > 0) {
|
if(obj.ts_sunrise > 0) {
|
||||||
document.getElementById("info").append(
|
document.getElementById("info").append(
|
||||||
|
@ -138,10 +151,13 @@
|
||||||
meta.content = obj.refresh + "; URL=" + obj.refresh_url;
|
meta.content = obj.refresh + "; URL=" + obj.refresh_url;
|
||||||
document.getElementsByTagName('head')[0].appendChild(meta);
|
document.getElementsByTagName('head')[0].appendChild(meta);
|
||||||
} else if(null != obj.system) {
|
} else if(null != obj.system) {
|
||||||
parseRadio(obj.system);
|
parseRadio(obj.system)
|
||||||
parseMqtt(obj.system.mqtt);
|
parseMqtt(obj.system.mqtt)
|
||||||
parseSysInfo(obj.system);
|
/*IF_ETHERNET*/
|
||||||
getAjax('/api/index', parseIndex);
|
parseEthernet(obj.system.eth)
|
||||||
|
/*ENDIF_ETHERNET*/
|
||||||
|
parseSysInfo(obj.system)
|
||||||
|
getAjax('/api/index', parseIndex)
|
||||||
}
|
}
|
||||||
document.getElementById("html").innerHTML = obj.html;
|
document.getElementById("html").innerHTML = obj.html;
|
||||||
}
|
}
|
||||||
|
|
|
@ -907,6 +907,26 @@
|
||||||
"token": "COMMUNICATING",
|
"token": "COMMUNICATING",
|
||||||
"en": "communicating",
|
"en": "communicating",
|
||||||
"de": "aktiv"
|
"de": "aktiv"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"token": "NETWORK",
|
||||||
|
"en": "Network",
|
||||||
|
"de": "Netzwerk"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"token": "CONNECTION_TYPE",
|
||||||
|
"en": "connection",
|
||||||
|
"de": "Verbindung"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"token": "WIRED",
|
||||||
|
"en": "ethernet cable",
|
||||||
|
"de": "Netzwerkkabel"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"token": "WIFI",
|
||||||
|
"en": "WiFi",
|
||||||
|
"de": "WiFi"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
|
@ -162,18 +162,14 @@ class Web {
|
||||||
mUploadFp.write(data, len);
|
mUploadFp.write(data, len);
|
||||||
if (final) {
|
if (final) {
|
||||||
mUploadFp.close();
|
mUploadFp.close();
|
||||||
#if !defined(ETHERNET)
|
|
||||||
char pwd[PWD_LEN];
|
char pwd[PWD_LEN];
|
||||||
strncpy(pwd, mConfig->sys.stationPwd, PWD_LEN); // backup WiFi PWD
|
strncpy(pwd, mConfig->sys.stationPwd, PWD_LEN); // backup WiFi PWD
|
||||||
#endif
|
|
||||||
if (!mApp->readSettings("/tmp.json")) {
|
if (!mApp->readSettings("/tmp.json")) {
|
||||||
mUploadFail = true;
|
mUploadFail = true;
|
||||||
DPRINTLN(DBG_ERROR, F("upload JSON error!"));
|
DPRINTLN(DBG_ERROR, F("upload JSON error!"));
|
||||||
} else {
|
} else {
|
||||||
LittleFS.remove("/tmp.json");
|
LittleFS.remove("/tmp.json");
|
||||||
#if !defined(ETHERNET)
|
|
||||||
strncpy(mConfig->sys.stationPwd, pwd, PWD_LEN); // restore WiFi PWD
|
strncpy(mConfig->sys.stationPwd, pwd, PWD_LEN); // restore WiFi PWD
|
||||||
#endif
|
|
||||||
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) {
|
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) {
|
||||||
if((mConfig->inst.iv[i].serial.u64 != 0) && (mConfig->inst.iv[i].serial.u64 < 138999999999)) { // hexadecimal
|
if((mConfig->inst.iv[i].serial.u64 != 0) && (mConfig->inst.iv[i].serial.u64 < 138999999999)) { // hexadecimal
|
||||||
mConfig->inst.iv[i].serial.u64 = ah::Serial2u64(String(mConfig->inst.iv[i].serial.u64).c_str());
|
mConfig->inst.iv[i].serial.u64 = ah::Serial2u64(String(mConfig->inst.iv[i].serial.u64).c_str());
|
||||||
|
@ -322,10 +318,18 @@ class Web {
|
||||||
}
|
}
|
||||||
|
|
||||||
void onIndex(AsyncWebServerRequest *request, bool checkAp = true) {
|
void onIndex(AsyncWebServerRequest *request, bool checkAp = true) {
|
||||||
|
#if !defined(ETHERNET)
|
||||||
if(mApp->isApActive() && checkAp) {
|
if(mApp->isApActive() && checkAp) {
|
||||||
onWizard(request);
|
onWizard(request);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
// show wizard only if ethernet is not configured
|
||||||
|
if(mApp->isApActive() && checkAp && !mConfig->sys.eth.enabled) {
|
||||||
|
onWizard(request);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
getPage(request, PROT_MASK_INDEX, index_html, index_html_len);
|
getPage(request, PROT_MASK_INDEX, index_html, index_html_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -432,6 +436,13 @@ class Web {
|
||||||
}
|
}
|
||||||
|
|
||||||
void onWizard(AsyncWebServerRequest *request) {
|
void onWizard(AsyncWebServerRequest *request) {
|
||||||
|
#if defined(ETHERNET)
|
||||||
|
if(mConfig->sys.eth.enabled) {
|
||||||
|
getPage(request, PROT_MASK_INDEX, index_html, index_html_len);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
AsyncWebServerResponse *response = request->beginResponse_P(200, F("text/html; charset=UTF-8"), wizard_html, wizard_html_len);
|
AsyncWebServerResponse *response = request->beginResponse_P(200, F("text/html; charset=UTF-8"), wizard_html, wizard_html_len);
|
||||||
response->addHeader(F("Content-Encoding"), "gzip");
|
response->addHeader(F("Content-Encoding"), "gzip");
|
||||||
response->addHeader(F("content-type"), "text/html; charset=UTF-8");
|
response->addHeader(F("content-type"), "text/html; charset=UTF-8");
|
||||||
|
@ -449,13 +460,12 @@ class Web {
|
||||||
char buf[20] = {0};
|
char buf[20] = {0};
|
||||||
|
|
||||||
// general
|
// general
|
||||||
#if !defined(ETHERNET)
|
|
||||||
if (request->arg("ssid") != "")
|
if (request->arg("ssid") != "")
|
||||||
request->arg("ssid").toCharArray(mConfig->sys.stationSsid, SSID_LEN);
|
request->arg("ssid").toCharArray(mConfig->sys.stationSsid, SSID_LEN);
|
||||||
if (request->arg("pwd") != "{PWD}")
|
if (request->arg("pwd") != "{PWD}")
|
||||||
request->arg("pwd").toCharArray(mConfig->sys.stationPwd, PWD_LEN);
|
request->arg("pwd").toCharArray(mConfig->sys.stationPwd, PWD_LEN);
|
||||||
mConfig->sys.isHidden = (request->arg("hidd") == "on");
|
mConfig->sys.isHidden = (request->arg("hidd") == "on");
|
||||||
#endif /* !defined(ETHERNET) */
|
|
||||||
if (request->arg("ap_pwd") != "")
|
if (request->arg("ap_pwd") != "")
|
||||||
request->arg("ap_pwd").toCharArray(mConfig->sys.apPwd, PWD_LEN);
|
request->arg("ap_pwd").toCharArray(mConfig->sys.apPwd, PWD_LEN);
|
||||||
if (request->arg("device") != "")
|
if (request->arg("device") != "")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue