From 2bfb6467e0bf2325eead0db9353965e4d47cd0ce Mon Sep 17 00:00:00 2001 From: lumapu Date: Tue, 30 Aug 2022 15:35:36 +0200 Subject: [PATCH 1/4] * fix #195: used trim() to remove leading and trailing spaces, added maxlength attr to input field * started to work on #209: added another timer for NTP update after configurable interval (default 12h) --- tools/esp8266/app.cpp | 12 +++++++++++- tools/esp8266/app.h | 2 ++ tools/esp8266/config.h | 7 +++++-- tools/esp8266/html/h/index_html.h | 4 ---- tools/esp8266/html/h/setup_html.h | 4 ---- tools/esp8266/html/h/style_css.h | 4 ---- tools/esp8266/html/h/visualization_html.h | 4 ---- tools/esp8266/html/setup.html | 2 +- tools/esp8266/web.cpp | 4 +++- 9 files changed, 22 insertions(+), 21 deletions(-) delete mode 100644 tools/esp8266/html/h/index_html.h delete mode 100644 tools/esp8266/html/h/setup_html.h delete mode 100644 tools/esp8266/html/h/style_css.h delete mode 100644 tools/esp8266/html/h/visualization_html.h diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index c5989562..f97a6b9d 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -64,6 +64,13 @@ void app::loop(void) { } } + if(checkTicker(&mNtpRefreshTicker, mNtpRefreshInterval)) { + if(!apActive) { + mTimestamp = mWifi->getNtpTime(); + DPRINTLN(DBG_INFO, "[NTP]: " + getDateTimeStr(mTimestamp)); + } + } + mSys->Radio.loop(); @@ -655,7 +662,10 @@ const char* app::getFieldStateClass(uint8_t fieldId) { void app::resetSystem(void) { mUptimeSecs = 0; mUptimeTicker = 0xffffffff; - mUptimeInterval = 1000; + mUptimeInterval = 1000; // [ms] + + mNtpRefreshTicker = 0xffffffff; + mNtpRefreshInterval = NTP_REFRESH_INTERVAL; // [ms] #ifdef AP_ONLY mTimestamp = 1; diff --git a/tools/esp8266/app.h b/tools/esp8266/app.h index 0ccefe7f..48dbc1ed 100644 --- a/tools/esp8266/app.h +++ b/tools/esp8266/app.h @@ -225,6 +225,8 @@ class app { uint16_t mUptimeInterval; uint32_t mUptimeSecs; uint8_t mHeapStatCnt; + uint32_t mNtpRefreshTicker; + uint32_t mNtpRefreshInterval; bool mWifiSettingsValid; diff --git a/tools/esp8266/config.h b/tools/esp8266/config.h index e27a2e09..ab633f9a 100644 --- a/tools/esp8266/config.h +++ b/tools/esp8266/config.h @@ -72,12 +72,15 @@ // threshold of minimum power on which the inverter is marked as inactive #define INACT_PWR_THRESH 3 -// default ntp server uri +// default NTP server uri #define DEF_NTP_SERVER_NAME "pool.ntp.org" -// default ntp server port +// default NTP server port #define DEF_NTP_PORT 8888 +// NTP refresh interval in ms (default 12h) +#define NTP_REFRESH_INTERVAL 12 * 3600 * 1000 + // default mqtt interval #define MQTT_INTERVAL 60 diff --git a/tools/esp8266/html/h/index_html.h b/tools/esp8266/html/h/index_html.h deleted file mode 100644 index c6f769ce..00000000 --- a/tools/esp8266/html/h/index_html.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef __INDEX_HTML_H__ -#define __INDEX_HTML_H__ -const char index_html[] PROGMEM = "Index - {DEVICE}

AHOY - {DEVICE}

Visualization

Setup

Uptime:

Statistics:

Every {TS}seconds the values are updated

This project was started from this discussion. (Mikrocontroller.net)
New updates can be found on Github: https://github.com/grindylow/ahoy

Please report issues using the feature provided by Github

Discuss with us on Discord

Creative Commons - https://creativecommons.org/licenses/by-nc-sa/3.0/de/
Check the licenses which are published on https://github.com/grindylow/ahoyas well

© 2022

Update Firmware

AHOY :: {VERSION}

Reboot

Git SHA: {BUILD}

"; -#endif /*__INDEX_HTML_H__*/ diff --git a/tools/esp8266/html/h/setup_html.h b/tools/esp8266/html/h/setup_html.h deleted file mode 100644 index 6309ef25..00000000 --- a/tools/esp8266/html/h/setup_html.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef __SETUP_HTML_H__ -#define __SETUP_HTML_H__ -const char setup_html[] PROGMEM = "Setup - {DEVICE}

Setup

ERASE SETTINGS (not WiFi)
Device Host Name
WiFi

Enter the credentials to your prefered WiFi station. After rebooting the device tries to connect with this information.

Inverter{INVERTERS}

General

NTP Server
MQTT
System Config

Pinout (Wemos)

{PINOUT}

Radio (NRF24L01+)

Serial Console



Home

Update Firmware

AHOY - {VERSION}

Factory Reset

Reboot

"; -#endif /*__SETUP_HTML_H__*/ diff --git a/tools/esp8266/html/h/style_css.h b/tools/esp8266/html/h/style_css.h deleted file mode 100644 index 24f50e79..00000000 --- a/tools/esp8266/html/h/style_css.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef __STYLE_CSS_H__ -#define __STYLE_CSS_H__ -const char style_css[] PROGMEM = "h1 {margin:0;padding:20pt;font-size:22pt;color:#fff;background-color:#006ec0;display:block;text-transform:uppercase;}html, body {font-family:Arial;margin:0;padding:0;}p {text-align:justify;font-size:13pt;}p.lic, p.lic a {font-size:8pt;color:#999;}.des {margin-top:20px;font-size:13pt;color:#006ec0;}.s_active, .s_collapsible:hover {background-color:#006ec0;}.s_content {display:none;overflow:hidden;}.s_collapsible {background-color:#044e86;color:white;cursor:pointer;padding:18px;width:100%;border:none;text-align:left;outline:none;font-size:15px;margin-bottom:4px;}.subdes {font-size:12pt;color:#006ec0;margin-left:7px;}.subsubdes {font-size:12pt;color:#006ec0;margin:0 0 7px 12px;}.hide {display:none;}a:link, a:visited {text-decoration:none;font-size:13pt;color:#006ec0;}a:hover, a:focus {color:#f00;}a.erase {background-color:#006ec0;color:#fff;padding:7px;display:inline-block;margin-top:30px;}#content {padding:15px 15px 60px 15px;}#footer {position:fixed;bottom:0px;height:45px;background-color:#006ec0;width:100%;border-top:5px solid #fff;}#footer p, #footer a {color:#fff;padding:0 7px 0 7px;font-size:10pt !important;}div.content {background-color:#fff;padding-bottom:65px;overflow:auto;}input, select {padding:7px;font-size:13pt;}input.text, select {width:70%;box-sizing:border-box;margin-bottom:10px;border:1px solid #ccc;}input.sh {max-width:150px !important;margin-right:10px;}input.btn {background-color:#006ec0;color:#fff;border:0px;float:right;margin:10px 0 30px;text-transform:uppercase;}input.cb {margin-bottom:20px;}label {width:20%;display:inline-block;font-size:12pt;padding-right:10px;margin:10px 0px 0px 15px;vertical-align:top;}fieldset {margin-bottom:15px;}.left {float:left;}.right {float:right;}div.ch-iv {width:100%;background-color:#32b004;display:inline-block;margin-bottom:15px;padding-bottom:20px;overflow:auto;}div.ch {width:220px;min-height:350px;background-color:#006ec0;display:inline-block;margin:0 10px 15px 10px;overflow:auto;padding-bottom:20px;}div.ch .value, div.ch .info, div.ch .head, div.ch-iv .value, div.ch-iv .info, div.ch-iv .head {color:#fff;display:block;width:100%;text-align:center;}.subgrp {float:left;width:220px;}div.ch .unit, div.ch-iv .unit {font-size:19px;margin-left:10px;}div.ch .value, div.ch-iv .value {margin-top:20px;font-size:24px;}div.ch .info, div.ch-iv .info {margin-top:3px;font-size:10px;}div.ch .head {background-color:#003c80;padding:10px 0 10px 0;}div.ch-iv .head {background-color:#1c6800;padding:10px 0 10px 0;}div.iv {max-width:960px;margin-bottom:40px;}div.ts {font-size:13px;background-color:#ddd;border-top:7px solid #999;padding:7px;}div.modpwr, div.modname {width:70%;display:inline-block;}#note {margin:50px 10px 10px 10px;padding-top:10px;width:100%;border-top:1px solid #bbb;}@media(max-width:500px) {div.ch .unit, div.ch-iv .unit {font-size:18px;}div.ch {width:170px;min-height:100px }.subgrp {width:180px;}}"; -#endif /*__STYLE_CSS_H__*/ diff --git a/tools/esp8266/html/h/visualization_html.h b/tools/esp8266/html/h/visualization_html.h deleted file mode 100644 index b70bc5b2..00000000 --- a/tools/esp8266/html/h/visualization_html.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef __VISUALIZATION_HTML_H__ -#define __VISUALIZATION_HTML_H__ -const char visualization_html[] PROGMEM = "Index - {DEVICE}

AHOY - {DEVICE}

Every {TS}seconds the values are updated

© 2022

Home

AHOY :: {VERSION}

"; -#endif /*__VISUALIZATION_HTML_H__*/ diff --git a/tools/esp8266/html/setup.html b/tools/esp8266/html/setup.html index d3f2ee39..5be9e9d7 100644 --- a/tools/esp8266/html/setup.html +++ b/tools/esp8266/html/setup.html @@ -102,7 +102,7 @@
MQTT - + diff --git a/tools/esp8266/web.cpp b/tools/esp8266/web.cpp index 0d933142..1bd12af5 100644 --- a/tools/esp8266/web.cpp +++ b/tools/esp8266/web.cpp @@ -384,7 +384,9 @@ void web::showSave(void) { // mqtt if(mWeb->arg("mqttAddr") != "") { - mWeb->arg("mqttAddr").toCharArray(mConfig->mqtt.broker, MQTT_ADDR_LEN); + String addr = mWeb->arg("mqttAddr"); + addr.trim(); + addr.toCharArray(mConfig->mqtt.broker, MQTT_ADDR_LEN); mWeb->arg("mqttUser").toCharArray(mConfig->mqtt.user, MQTT_USER_LEN); mWeb->arg("mqttPwd").toCharArray(mConfig->mqtt.pwd, MQTT_PWD_LEN); mWeb->arg("mqttTopic").toCharArray(mConfig->mqtt.topic, MQTT_TOPIC_LEN); From b67cd033d251746212dfef12a6222689cad8ddf6 Mon Sep 17 00:00:00 2001 From: lumapu Date: Tue, 30 Aug 2022 15:49:33 +0200 Subject: [PATCH 2/4] fix #209 --- tools/esp8266/app.cpp | 18 ++++++++---------- tools/esp8266/app.h | 1 + 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index f97a6b9d..be78d6a5 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -53,14 +53,11 @@ void app::loop(void) { mWebInst->loop(); if(checkTicker(&mUptimeTicker, mUptimeInterval)) { - mUptimeSecs++; - if(0 != mTimestamp) - mTimestamp++; - else { - if(!apActive) { - mTimestamp = mWifi->getNtpTime(); - DPRINTLN(DBG_INFO, "[NTP]: " + getDateTimeStr(mTimestamp)); - } + if(millis() - mPrevMillis >= 1000) { + mPrevMillis += 1000; + mUptimeSecs++; + if(0 != mTimestamp) + mTimestamp++; } } @@ -662,9 +659,10 @@ const char* app::getFieldStateClass(uint8_t fieldId) { void app::resetSystem(void) { mUptimeSecs = 0; mUptimeTicker = 0xffffffff; - mUptimeInterval = 1000; // [ms] + mUptimeInterval = 500; // [ms] + mPrevMillis = 0; - mNtpRefreshTicker = 0xffffffff; + mNtpRefreshTicker = 0; mNtpRefreshInterval = NTP_REFRESH_INTERVAL; // [ms] #ifdef AP_ONLY diff --git a/tools/esp8266/app.h b/tools/esp8266/app.h index 48dbc1ed..b7fd462b 100644 --- a/tools/esp8266/app.h +++ b/tools/esp8266/app.h @@ -224,6 +224,7 @@ class app { uint32_t mUptimeTicker; uint16_t mUptimeInterval; uint32_t mUptimeSecs; + uint32_t mPrevMillis; uint8_t mHeapStatCnt; uint32_t mNtpRefreshTicker; uint32_t mNtpRefreshInterval; From 11fdb4c8228ef9ebde440ea2ebb11840437cb671 Mon Sep 17 00:00:00 2001 From: lumapu Date: Tue, 30 Aug 2022 21:24:35 +0200 Subject: [PATCH 3/4] fix action (directory was missing - needs to be created automatically now) --- tools/esp8266/html/convert.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/esp8266/html/convert.py b/tools/esp8266/html/convert.py index 98027b2f..dadaf92d 100755 --- a/tools/esp8266/html/convert.py +++ b/tools/esp8266/html/convert.py @@ -2,6 +2,8 @@ import re import sys import os +from pathlib import Path + def convert2Header(inFile): fileType = inFile.split(".")[1] define = inFile.split(".")[0].upper() @@ -12,8 +14,10 @@ def convert2Header(inFile): print("ok") outName = "html/" + "h/" + inFileVarName + ".h" inFile = "html/" + inFile + Path("html/h").mkdir(exist_ok=True) else: outName = "h/" + inFileVarName + ".h" + Path("h").mkdir(exist_ok=True) f = open(inFile, "r") data = f.read().replace('\n', '') From 10d6fcc698a0e52168e242af04768b94ed45920b Mon Sep 17 00:00:00 2001 From: lumapu Date: Tue, 30 Aug 2022 21:33:05 +0200 Subject: [PATCH 4/4] badge test --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2411a7f2..c7f2b4f0 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +![actions/workflows/compile_esp8266.yml](../../actions/workflows/compile_esp8266.yml/badge.svg) ![actions/workflows/compile_development.yml](../../actions/workflows/compile_development.yml/badge.svg) + ![Logo](https://github.com/grindylow/ahoy/blob/main/doc/logo1_small.png?raw=true) # ahoy @@ -9,7 +11,7 @@ Click on the link below you are interested in. There you will find further explanations on how to proceed. (*Note: It is still under construction!*) ##### Most updated section -- [ESP8266](tools/esp8266/) that includes an web interface ![](../../actions/workflows/compile_esp8266.yml/badge.svg) +- [ESP8266](tools/esp8266/) that includes an web interface ##### will be updated as needed - [Arduino Nano](tools/nano/NRF24_SendRcv/)