mirror of
https://github.com/lumapu/ahoy.git
synced 2025-04-29 10:16:21 +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
|
||||
}
|
||||
|
||||
#if defined(ETHERNET)
|
||||
bool isWiredConnection() override {
|
||||
return mNetwork->isWiredConnection();
|
||||
}
|
||||
#endif
|
||||
|
||||
void lock(bool fromWeb) override {
|
||||
mProtection->lock(fromWeb);
|
||||
}
|
||||
|
|
|
@ -57,6 +57,10 @@ class IApp {
|
|||
virtual uint32_t getMqttRxCnt() = 0;
|
||||
virtual uint32_t getMqttTxCnt() = 0;
|
||||
|
||||
#if defined(ETHERNET)
|
||||
virtual bool isWiredConnection() = 0;
|
||||
#endif
|
||||
|
||||
virtual void lock(bool fromWeb) = 0;
|
||||
virtual char *unlock(const char *clientIp, bool loginFromWeb) = 0;
|
||||
virtual void resetLockTimeout(void) = 0;
|
||||
|
|
|
@ -34,6 +34,18 @@ class AhoyEthernet : public AhoyWifi {
|
|||
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) {
|
||||
switch(event) {
|
||||
case SYSTEM_EVENT_STA_CONNECTED:
|
||||
|
@ -41,6 +53,9 @@ class AhoyEthernet : public AhoyWifi {
|
|||
[[fallthrough]];
|
||||
case ARDUINO_EVENT_ETH_CONNECTED:
|
||||
if(NetworkState::CONNECTED != mStatus) {
|
||||
if(ARDUINO_EVENT_ETH_CONNECTED == event)
|
||||
WiFi.disconnect();
|
||||
|
||||
mStatus = NetworkState::CONNECTED;
|
||||
DPRINTLN(DBG_INFO, F("Network connected"));
|
||||
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 {
|
||||
setupIp([this](IPAddress ip, IPAddress gateway, IPAddress mask, IPAddress dns1, IPAddress dns2) -> bool {
|
||||
if(Mode::WIRELESS == mMode)
|
||||
|
|
|
@ -84,6 +84,10 @@ class AhoyNetwork {
|
|||
return false;
|
||||
}
|
||||
|
||||
virtual bool isWiredConnection() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isApActive() {
|
||||
return mAp.isEnabled();
|
||||
}
|
||||
|
|
|
@ -432,6 +432,10 @@ class RestApi {
|
|||
#endif
|
||||
getMqttInfo(obj.createNestedObject(F("mqtt")));
|
||||
|
||||
#if defined(ETHERNET)
|
||||
getEthernetInfo(obj.createNestedObject(F("eth")));
|
||||
#endif
|
||||
|
||||
#if defined(ESP32)
|
||||
obj[F("chip_revision")] = ESP.getChipRevision();
|
||||
obj[F("chip_model")] = ESP.getChipModel();
|
||||
|
@ -824,6 +828,10 @@ class RestApi {
|
|||
obj[F("irq")] = mConfig->sys.eth.pinIrq;
|
||||
obj[F("reset")] = mConfig->sys.eth.pinRst;
|
||||
}
|
||||
|
||||
void getEthernetInfo(JsonObject obj) {
|
||||
obj[F("wired")] = (bool)mApp->isWiredConnection();
|
||||
}
|
||||
#endif
|
||||
|
||||
void getRadioNrf(JsonObject obj) {
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
const data = ["sdk", "cpu_freq", "chip_revision", "device_name",
|
||||
"chip_model", "chip_cores", "esp_type", "mac", "wifi_rssi", "wifi_channel", "ts_uptime",
|
||||
"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 = [];
|
||||
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) {
|
||||
if(obj.ts_sunrise > 0) {
|
||||
document.getElementById("info").append(
|
||||
|
@ -138,10 +151,13 @@
|
|||
meta.content = obj.refresh + "; URL=" + obj.refresh_url;
|
||||
document.getElementsByTagName('head')[0].appendChild(meta);
|
||||
} else if(null != obj.system) {
|
||||
parseRadio(obj.system);
|
||||
parseMqtt(obj.system.mqtt);
|
||||
parseSysInfo(obj.system);
|
||||
getAjax('/api/index', parseIndex);
|
||||
parseRadio(obj.system)
|
||||
parseMqtt(obj.system.mqtt)
|
||||
/*IF_ETHERNET*/
|
||||
parseEthernet(obj.system.eth)
|
||||
/*ENDIF_ETHERNET*/
|
||||
parseSysInfo(obj.system)
|
||||
getAjax('/api/index', parseIndex)
|
||||
}
|
||||
document.getElementById("html").innerHTML = obj.html;
|
||||
}
|
||||
|
|
|
@ -907,6 +907,26 @@
|
|||
"token": "COMMUNICATING",
|
||||
"en": "communicating",
|
||||
"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);
|
||||
if (final) {
|
||||
mUploadFp.close();
|
||||
#if !defined(ETHERNET)
|
||||
char pwd[PWD_LEN];
|
||||
strncpy(pwd, mConfig->sys.stationPwd, PWD_LEN); // backup WiFi PWD
|
||||
#endif
|
||||
if (!mApp->readSettings("/tmp.json")) {
|
||||
mUploadFail = true;
|
||||
DPRINTLN(DBG_ERROR, F("upload JSON error!"));
|
||||
} else {
|
||||
LittleFS.remove("/tmp.json");
|
||||
#if !defined(ETHERNET)
|
||||
strncpy(mConfig->sys.stationPwd, pwd, PWD_LEN); // restore WiFi PWD
|
||||
#endif
|
||||
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
|
||||
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) {
|
||||
#if !defined(ETHERNET)
|
||||
if(mApp->isApActive() && checkAp) {
|
||||
onWizard(request);
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -432,6 +436,13 @@ class Web {
|
|||
}
|
||||
|
||||
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);
|
||||
response->addHeader(F("Content-Encoding"), "gzip");
|
||||
response->addHeader(F("content-type"), "text/html; charset=UTF-8");
|
||||
|
@ -449,13 +460,12 @@ class Web {
|
|||
char buf[20] = {0};
|
||||
|
||||
// general
|
||||
#if !defined(ETHERNET)
|
||||
if (request->arg("ssid") != "")
|
||||
request->arg("ssid").toCharArray(mConfig->sys.stationSsid, SSID_LEN);
|
||||
if (request->arg("pwd") != "{PWD}")
|
||||
request->arg("pwd").toCharArray(mConfig->sys.stationPwd, PWD_LEN);
|
||||
mConfig->sys.isHidden = (request->arg("hidd") == "on");
|
||||
#endif /* !defined(ETHERNET) */
|
||||
|
||||
if (request->arg("ap_pwd") != "")
|
||||
request->arg("ap_pwd").toCharArray(mConfig->sys.apPwd, PWD_LEN);
|
||||
if (request->arg("device") != "")
|
||||
|
|
Loading…
Add table
Reference in a new issue