Browse Source

Merge branch 'development03' of https://github.com/lumapu/ahoy into development03

pull/470/head^2
lumapu 2 years ago
parent
commit
4fd3cd8ca9
  1. 10
      scripts/getVersion.py
  2. 4
      src/publisher/pubMqtt.h
  3. 4
      src/utils/helper.cpp
  4. 1
      src/utils/helper.h
  5. 6
      src/web/webApi.cpp
  6. 4
      src/web/webApi.h

10
scripts/getVersion.py

@ -1,4 +1,6 @@
import os import os
import shutil
import gzip
from datetime import date from datetime import date
def genOtaBin(path): def genOtaBin(path):
@ -24,6 +26,11 @@ def genOtaBin(path):
with open(path + "ota.bin", "wb") as f: with open(path + "ota.bin", "wb") as f:
f.write(bytearray(arr)) f.write(bytearray(arr))
# write gzip firmware file
def gzip_bin(bin_file, gzip_file):
with open(bin_file,"rb") as fp:
with gzip.open(gzip_file, "wb", compresslevel = 9) as f:
shutil.copyfileobj(fp, f)
def readVersion(path, infile): def readVersion(path, infile):
f = open(path + infile, "r") f = open(path + infile, "r")
@ -48,16 +55,19 @@ def readVersion(path, infile):
src = path + ".pio/build/esp8266-release/firmware.bin" src = path + ".pio/build/esp8266-release/firmware.bin"
dst = path + "firmware/" + versionout dst = path + "firmware/" + versionout
os.rename(src, dst) os.rename(src, dst)
gzip_bin(dst, dst + ".gz")
versionout = version[:-1] + "_esp8266_1m_" + sha + ".bin" versionout = version[:-1] + "_esp8266_1m_" + sha + ".bin"
src = path + ".pio/build/esp8285-release/firmware.bin" src = path + ".pio/build/esp8285-release/firmware.bin"
dst = path + "firmware/" + versionout dst = path + "firmware/" + versionout
os.rename(src, dst) os.rename(src, dst)
gzip_bin(dst, dst + ".gz")
versionout = version[:-1] + "_esp32_" + sha + ".bin" versionout = version[:-1] + "_esp32_" + sha + ".bin"
src = path + ".pio/build/esp32-wroom32-release/firmware.bin" src = path + ".pio/build/esp32-wroom32-release/firmware.bin"
dst = path + "firmware/" + versionout dst = path + "firmware/" + versionout
os.rename(src, dst) os.rename(src, dst)
gzip_bin(dst, dst + ".gz")
# other ESP32 bin files # other ESP32 bin files
src = path + ".pio/build/esp32-wroom32-release/" src = path + ".pio/build/esp32-wroom32-release/"

4
src/publisher/pubMqtt.h

@ -388,7 +388,7 @@ class PubMqtt {
} }
snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/ch%d/%s", iv->config->name, rec->assign[i].ch, fields[rec->assign[i].fieldId]); snprintf(topic, 32 + MAX_NAME_LENGTH, "%s/ch%d/%s", iv->config->name, rec->assign[i].ch, fields[rec->assign[i].fieldId]);
snprintf(val, 40, "%.3f", iv->getValue(i, rec)); snprintf(val, 40, "%g", ah::round3(iv->getValue(i, rec)));
publish(topic, val, retained); publish(topic, val, retained);
// calculate total values for RealTimeRunData_Debug // calculate total values for RealTimeRunData_Debug
@ -437,7 +437,7 @@ class PubMqtt {
break; break;
} }
snprintf(topic, 32 + MAX_NAME_LENGTH, "total/%s", fields[fieldId]); snprintf(topic, 32 + MAX_NAME_LENGTH, "total/%s", fields[fieldId]);
snprintf(val, 40, "%.3f", total[i]); snprintf(val, 40, "%g", ah::round3(total[i]));
publish(topic, val, true); publish(topic, val, true);
} }
} }

4
src/utils/helper.cpp

@ -26,4 +26,8 @@ namespace ah {
else else
snprintf(str, 16, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); snprintf(str, 16, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
} }
double round3(double value) {
return (int)(value * 1000 + 0.5) / 1000.0;
}
} }

1
src/utils/helper.h

@ -14,6 +14,7 @@
namespace ah { namespace ah {
void ip2Arr(uint8_t ip[], const char *ipStr); void ip2Arr(uint8_t ip[], const char *ipStr);
void ip2Char(uint8_t ip[], char *str); void ip2Char(uint8_t ip[], char *str);
double round3(double value);
} }
#endif /*__HELPER_H__*/ #endif /*__HELPER_H__*/

6
src/web/webApi.cpp

@ -448,7 +448,7 @@ void webApi::getLive(JsonObject obj) {
JsonObject obj2 = invArr.createNestedObject(); JsonObject obj2 = invArr.createNestedObject();
obj2[F("name")] = String(iv->config->name); obj2[F("name")] = String(iv->config->name);
obj2[F("channels")] = iv->channels; obj2[F("channels")] = iv->channels;
obj2[F("power_limit_read")] = round3(iv->actPowerLimit); obj2[F("power_limit_read")] = ah::round3(iv->actPowerLimit);
obj2[F("last_alarm")] = String(iv->lastAlarmMsg); obj2[F("last_alarm")] = String(iv->lastAlarmMsg);
obj2[F("ts_last_success")] = rec->ts; obj2[F("ts_last_success")] = rec->ts;
@ -457,7 +457,7 @@ void webApi::getLive(JsonObject obj) {
obj2[F("ch_names")][0] = "AC"; obj2[F("ch_names")][0] = "AC";
for (uint8_t fld = 0; fld < sizeof(list); fld++) { for (uint8_t fld = 0; fld < sizeof(list); fld++) {
pos = (iv->getPosByChFld(CH0, list[fld], rec)); pos = (iv->getPosByChFld(CH0, list[fld], rec));
ch0[fld] = (0xff != pos) ? round3(iv->getValue(pos, rec)) : 0.0; ch0[fld] = (0xff != pos) ? ah::round3(iv->getValue(pos, rec)) : 0.0;
obj[F("ch0_fld_units")][fld] = (0xff != pos) ? String(iv->getUnit(pos, rec)) : notAvail; obj[F("ch0_fld_units")][fld] = (0xff != pos) ? String(iv->getUnit(pos, rec)) : notAvail;
obj[F("ch0_fld_names")][fld] = (0xff != pos) ? String(iv->getFieldName(pos, rec)) : notAvail; obj[F("ch0_fld_names")][fld] = (0xff != pos) ? String(iv->getFieldName(pos, rec)) : notAvail;
} }
@ -474,7 +474,7 @@ void webApi::getLive(JsonObject obj) {
case 4: pos = (iv->getPosByChFld(j, FLD_YT, rec)); break; case 4: pos = (iv->getPosByChFld(j, FLD_YT, rec)); break;
case 5: pos = (iv->getPosByChFld(j, FLD_IRR, rec)); break; case 5: pos = (iv->getPosByChFld(j, FLD_IRR, rec)); break;
} }
cur[k] = (0xff != pos) ? round3(iv->getValue(pos, rec)) : 0.0; cur[k] = (0xff != pos) ? ah::round3(iv->getValue(pos, rec)) : 0.0;
if(1 == j) { if(1 == j) {
obj[F("fld_units")][k] = (0xff != pos) ? String(iv->getUnit(pos, rec)) : notAvail; obj[F("fld_units")][k] = (0xff != pos) ? String(iv->getUnit(pos, rec)) : notAvail;
obj[F("fld_names")][k] = (0xff != pos) ? String(iv->getFieldName(pos, rec)) : notAvail; obj[F("fld_names")][k] = (0xff != pos) ? String(iv->getFieldName(pos, rec)) : notAvail;

4
src/web/webApi.h

@ -59,10 +59,6 @@ class webApi {
bool setCtrl(JsonObject jsonIn, JsonObject jsonOut); bool setCtrl(JsonObject jsonIn, JsonObject jsonOut);
bool setSetup(JsonObject jsonIn, JsonObject jsonOut); bool setSetup(JsonObject jsonIn, JsonObject jsonOut);
double round3(double value) {
return (int)(value * 1000 + 0.5) / 1000.0;
}
AsyncWebServer *mSrv; AsyncWebServer *mSrv;
app *mApp; app *mApp;

Loading…
Cancel
Save