Skip to content

Commit

Permalink
0.8.102
Browse files Browse the repository at this point in the history
* fix MDNS #1538
* improved Wizard
* improved MqTT on devcontrol e.g. set power limit
  • Loading branch information
lumapu committed Apr 1, 2024
1 parent bcc52c7 commit 4d5ae72
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 77 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ src/web/html/tmp/*
src/output.map

/.venv
/scripts/__pycache__/htmlPreprocessorDefines.cpython-311.pyc
2 changes: 2 additions & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
scripts/__pycache__/*
*.pyc
3 changes: 3 additions & 0 deletions src/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
## 0.8.102 - 2024-04-01
* fix NTP for `opendtufusion` #1542
* fix scan WiFi in AP mode
* fix MDNS #1538
* improved Wizard
* improved MqTT on devcontrol e.g. set power limit

## 0.8.101 - 2024-03-28
* updated converter scripts to include all enabled features again (redundant scan of build flags) #1534
Expand Down
55 changes: 32 additions & 23 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,29 +403,7 @@ void app::tickSend(void) {

for (uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) {
Inverter<> *iv = mSys.getInverterByPos(i);
if(NULL == iv)
continue;

if(iv->config->enabled) {
if(!iv->commEnabled) {
DPRINT_IVID(DBG_INFO, iv->id);
DBGPRINTLN(F("no communication to the inverter (night time)"));
continue;
}

if(!iv->radio->isChipConnected())
continue;

if(InverterStatus::OFF != iv->status)
notAvail = false;

iv->tickSend([this, iv](uint8_t cmd, bool isDevControl) {
if(isDevControl)
mCommunication.addImportant(iv, cmd);
else
mCommunication.add(iv, cmd);
});
}
sendIv(iv);
}

if(mAllIvNotAvail != notAvail)
Expand All @@ -435,6 +413,37 @@ void app::tickSend(void) {
updateLed();
}

//-----------------------------------------------------------------------------
bool app::sendIv(Inverter<> *iv) {
bool notAvail = true;
if(NULL == iv)
return notAvail;

if(!iv->config->enabled)
return notAvail;

if(!iv->commEnabled) {
DPRINT_IVID(DBG_INFO, iv->id);
DBGPRINTLN(F("no communication to the inverter (night time)"));
return notAvail;
}

if(!iv->radio->isChipConnected())
return notAvail;

if(InverterStatus::OFF != iv->status)
notAvail = false;

iv->tickSend([this, iv](uint8_t cmd, bool isDevControl) {
if(isDevControl)
mCommunication.addImportant(iv, cmd);
else
mCommunication.add(iv, cmd);
});

return notAvail;
}

//-----------------------------------------------------------------------------
void app:: zeroIvValues(bool checkAvail, bool skipYieldDay) {
Inverter<> *iv;
Expand Down
11 changes: 9 additions & 2 deletions src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ class app : public IApp, public ah::Scheduler {
return mNetwork->getIp();
}

bool isApActive(void) override {
return mNetwork->isApActive();
}

void setRebootFlag() override {
once(std::bind(&app::tickReboot, this), 3, "rboot");
}
Expand Down Expand Up @@ -386,8 +390,10 @@ class app : public IApp, public ah::Scheduler {
bool mNtpReceived = false;
void updateNtp(void);

void triggerTickSend() override {
once(std::bind(&app::tickSend, this), 0, "tSend");
void triggerTickSend(uint8_t id) override {
once([this, id]() {
sendIv(mSys.getInverterByPos(id));
}, 0, "devct");
}

void tickCalcSunrise(void);
Expand All @@ -396,6 +402,7 @@ class app : public IApp, public ah::Scheduler {
void tickSunrise(void);
void tickComm(void);
void tickSend(void);
bool sendIv(Inverter<> *iv);
void tickMinute(void);
void tickZeroValues(void);
void tickMidnight(void);
Expand Down
3 changes: 2 additions & 1 deletion src/appInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class IApp {
virtual bool getWasInCh12to14(void) const = 0;
#endif /* defined(ETHERNET) */
virtual String getIp(void) = 0;
virtual bool isApActive(void) = 0;

virtual uint32_t getUptime() = 0;
virtual uint32_t getTimestamp() = 0;
Expand All @@ -42,7 +43,7 @@ class IApp {
virtual void getSchedulerInfo(uint8_t *max) = 0;
virtual void getSchedulerNames() = 0;

virtual void triggerTickSend() = 0;
virtual void triggerTickSend(uint8_t id) = 0;

virtual bool getRebootRequestState() = 0;
virtual bool getSettingsValid() = 0;
Expand Down
7 changes: 6 additions & 1 deletion src/network/AhoyNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,18 @@ class AhoyNetwork {
return false;
}

bool isApActive() {
return mAp.isEnabled();
}

#if !defined(ETHERNET)
bool getAvailNetworks(JsonObject obj) {
JsonArray nets = obj.createNestedArray(F("networks"));

if(!mScanActive) {
mScanActive = true;
WiFi.disconnect();
if(NetworkState::GOT_IP != mStatus)
WiFi.disconnect();
WiFi.scanNetworks(true, true);
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions src/network/AhoyWifiAp.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class AhoyWifiAp {
if(!mEnabled)
return;

if(WiFi.softAPgetStationNum() > 0)
return;

mDns.stop();
WiFi.softAPdisconnect();
#if defined(ETHERNET)
Expand Down
6 changes: 5 additions & 1 deletion src/network/AhoyWifiEsp32.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,22 @@ class AhoyWifi : public AhoyNetwork {
mConnected = false;
mOnNetworkCB(false);
mAp.enable();
MDNS.end();
}
break;

case NetworkState::CONNECTED:
break;

case NetworkState::GOT_IP:
if(!mConnected) {
if(mAp.isEnabled())
mAp.disable();

if(!mConnected) {
mConnected = true;
ah::welcome(WiFi.localIP().toString(), F("Station"));
MDNS.begin(mConfig->sys.deviceName);
MDNS.addServiceTxt("http", "tcp", "path", "/");
mOnNetworkCB(true);
}
break;
Expand Down
4 changes: 4 additions & 0 deletions src/network/AhoyWifiEsp8266.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class AhoyWifi : public AhoyNetwork {
mConnected = false;
mOnNetworkCB(false);
mAp.enable();
MDNS.end();
}

if (WiFi.softAPgetStationNum() > 0) {
Expand Down Expand Up @@ -93,6 +94,9 @@ class AhoyWifi : public AhoyNetwork {
mConnected = true;
ah::welcome(WiFi.localIP().toString(), F("Station"));
MDNS.begin(mConfig->sys.deviceName);
MDNSResponder::hMDNSService hRes = MDNS.addService(NULL, "http", "tcp", 80);
MDNS.addServiceTxt(hRes, "path", "/");
MDNS.announce();
mOnNetworkCB(true);
}

Expand Down
2 changes: 1 addition & 1 deletion src/web/RestApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ class RestApi {

accepted = iv->setDevControlRequest(ActivePowerContr);
if(accepted)
mApp->triggerTickSend();
mApp->triggerTickSend(iv->id);
} else if(F("dev") == jsonIn[F("cmd")]) {
DPRINTLN(DBG_INFO, F("dev cmd"));
iv->setDevCommand(jsonIn[F("val")].as<int>());
Expand Down
28 changes: 1 addition & 27 deletions src/web/html/setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,9 @@
<div class="col-12 col-sm-3 my-2">{#AP_PWD}</div>
<div class="col-12 col-sm-9"><input type="text" name="ap_pwd" minlength="8" /></div>
</div>
<div class="row mb-3">
<div class="col-12 col-sm-3 my-2">{#SEARCH_NETWORKS}</div>
<div class="col-12 col-sm-9"><input type="button" name="scanbtn" id="scanbtn" class="btn" value="{#BTN_SCAN}" onclick="scan()"/></div>
</div>

<div class="row mb-2 mb-sm-3">
<div class="col-12 col-sm-3 my-2">{#AVAIL_NETWORKS}</div>
<div class="col-12 col-sm-9">
<select name="networks" id="networks" onChange="selNet()">
<option value="-1" selected disabled hidden>{#NETWORK_NOT_SCANNED}</option>
</select>
</div>
</div>
<div class="row mb-2 mb-sm-3">
<div class="col-12 col-sm-3 my-2">SSID</div>
<div class="col-12 col-sm-9"><input type="text" name="ssid"/></div>
<div class="col-12 col-sm-9"><input type="text" name="ssid"/><br/><a href="/wizard">{#SCAN_WIFI}</a></div>
</div>
<div class="row mb-2 mb-sm-3">
<div class="col-12 col-sm-3">{#SSID_HIDDEN}</div>
Expand Down Expand Up @@ -606,12 +593,6 @@
setTimeout(function() {getAjax('/api/index', apiCbNtp2)}, 2000)
}

function scan() {
var obj = {cmd: "scan_wifi", token: "*"}
getAjax("/api/setup", apiCbWifi, "POST", JSON.stringify(obj));
setTimeout(function() {getAjax('/api/setup/networks', listNetworks)}, 5000);
}

function syncTime() {
var obj = {cmd: "sync_ntp", token: "*"}
getAjax("/api/setup", apiCbNtp, "POST", JSON.stringify(obj))
Expand Down Expand Up @@ -1319,13 +1300,6 @@
s.appendChild(opt("-1", "{#NO_NETWORK_FOUND}"));
}

function selNet() {
var s = document.getElementById("networks");
var e = document.getElementsByName("ssid")[0];
if(-1 != s.value)
e.value = s.value;
}

getAjax("/api/setup", parse);
</script>
</body>
Expand Down
9 changes: 5 additions & 4 deletions src/web/html/wizard.html
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
sect("{#WIFI_MANUAL}", ml("input", {id: "man", type: "text"})),
sect("{#WIFI_PASSWORD}", ml("input", {id: "pwd", type: "password"})),
ml("div", {class: "row my-4"}, ml("div", {class: "col a-r"}, ml("input", {type: "button", class:"btn", value: "{#BTN_NEXT}", onclick: () => {saveWifi()}}, null))),
ml("div", {class: "row mt-5"}, ml("div", {class: "col a-c"}, ml("a", {href: "http://192.168.4.1/"}, "{#STOP_WIZARD}")))
ml("div", {class: "row mt-5"}, ml("div", {class: "col a-c"}, ml("a", {href: "http://192.168.4.1/index"}, "{#STOP_WIZARD}")))
])
}
/*ENDIF_ETHERNET*/
Expand All @@ -229,9 +229,9 @@
ml("div", {class: "row"}, ml("div", {class: "col"}, ml("span", {class: "fs-5"}, "{#TEST_CONNECTION}"))),
sect("{#TRY_TO_CONNECT}", ml("span", {id: "state"}, "{#CONNECTING}")),
ml("div", {class: "row my-4"}, ml("div", {class: "col a-r"}, ml("input", {type: "button", class:"btn hide", id: "btn", value: "{#BTN_FINISH}", onclick: () => {redirect()}}, null))),
ml("div", {class: "row mt-5"}, ml("div", {class: "col a-c"}, ml("a", {href: "http://192.168.4.1/"}, "{#STOP_WIZARD}")))
ml("div", {class: "row mt-5"}, ml("div", {class: "col a-c"}, ml("a", {href: "http://192.168.4.1/index"}, "{#STOP_WIZARD}")))
)
v = setInterval(() => {getAjax('/api/setup/getip', printIp)}, 1000);
v = setInterval(() => {getAjax('/api/setup/getip', printIp)}, 300);
}

function redirect() {
Expand Down Expand Up @@ -286,7 +286,8 @@
}

c.append(step1())
v = setInterval(() => {getAjax('/api/setup/networks', nets)}, 1000);
getAjax('/api/setup/networks', nets)
v = setInterval(() => {getAjax('/api/setup/networks', nets)}, 1000)
/*ENDIF_ETHERNET*/

</script>
Expand Down
20 changes: 5 additions & 15 deletions src/web/lang.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
{
"token": "BTN_NEXT",
"en": "next >>",
"de": "prüfen >>"
"de": "pr&uuml;fen >>"
},
{
"token": "BTN_REBOOT",
Expand All @@ -91,7 +91,7 @@
{
"token": "TEST_CONNECTION",
"en": "Test Connection",
"de": "Verbindung wird überprüft"
"de": "Verbindung wird &uuml;berpr&uuml;ft"
},
{
"token": "TRY_TO_CONNECT",
Expand Down Expand Up @@ -259,19 +259,9 @@
"de": "Netzwerke suchen"
},
{
"token": "BTN_SCAN",
"en": "scan",
"de": "Suche starten"
},
{
"token": "AVAIL_NETWORKS",
"en": "Avail Networks",
"de": "Verf&uuml;gbare Netzwerke"
},
{
"token": "NETWORK_NOT_SCANNED",
"en": "not scanned",
"de": "nicht gesucht"
"token": "SCAN_WIFI",
"en": "scan for WiFi networks",
"de": "nach WiFi Netzwerken suchen"
},
{
"token": "SSID_HIDDEN",
Expand Down
9 changes: 7 additions & 2 deletions src/web/web.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class Web {
mConfig = config;

DPRINTLN(DBG_VERBOSE, F("app::setup-on"));
mWeb.on("/", HTTP_GET, std::bind(&Web::onIndex, this, std::placeholders::_1));
mWeb.on("/", HTTP_GET, std::bind(&Web::onIndex, this, std::placeholders::_1, true));
mWeb.on("/index", HTTP_GET, std::bind(&Web::onIndex, this, std::placeholders::_1, false));
mWeb.on("/login", HTTP_ANY, std::bind(&Web::onLogin, this, std::placeholders::_1));
mWeb.on("/logout", HTTP_GET, std::bind(&Web::onLogout, this, std::placeholders::_1));
mWeb.on("/colors.css", HTTP_GET, std::bind(&Web::onColor, this, std::placeholders::_1));
Expand Down Expand Up @@ -319,7 +320,11 @@ class Web {
client->send("hello!", NULL, millis(), 1000);
}

void onIndex(AsyncWebServerRequest *request) {
void onIndex(AsyncWebServerRequest *request, bool checkAp = true) {
if(mApp->isApActive() && checkAp) {
onWizard(request);
return;
}
getPage(request, PROT_MASK_INDEX, index_html, index_html_len);
}

Expand Down

0 comments on commit 4d5ae72

Please sign in to comment.