Browse Source

Merge branch 'DanielR92-nrf_info' into development03

pull/498/head
lumapu 2 years ago
parent
commit
f0014e8c70
  1. 51
      src/.vscode/settings.json
  2. 1
      src/CHANGES.md
  3. 21
      src/app.cpp
  4. 16
      src/hm/hmRadio.h
  5. 1
      src/utils/scheduler.h
  6. 24
      src/web/html/system.html
  7. 10
      src/web/webApi.cpp
  8. 2
      src/wifi/ahoywifi.h
  9. 2
      tools/rpi/hoymiles/__main__.py

51
src/.vscode/settings.json

@ -24,6 +24,55 @@
"typeinfo": "cpp",
"string": "cpp",
"istream": "cpp",
"ostream": "cpp"
"ostream": "cpp",
"array": "cpp",
"atomic": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"list": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"map": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"regex": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"limits": "cpp",
"new": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"cinttypes": "cpp"
},
}

1
src/CHANGES.md

@ -5,3 +5,4 @@
* refactored get NTP time #483
* generate `bin.gz` only for 1M device ESP8285
* fix calcSunrise was not called every day
* incresed number of allowed characters for MQTT user, broker and password

21
src/app.cpp

@ -27,6 +27,7 @@ void app::setup() {
ah::Scheduler::setup();
resetSystem();
mSettings.setup();
mSettings.getPtr(mConfig);
DPRINTLN(DBG_INFO, F("Settings valid: ") + String((mSettings.getValid()) ? F("true") : F("false")));
@ -35,7 +36,7 @@ void app::setup() {
everySec(std::bind(&app::tickSecond, this));
every(std::bind(&app::tickSend, this), mConfig->nrf.sendInterval);
#if !defined(AP_ONLY)
once(std::bind(&app::tickNtpUpdate), 2);
once(std::bind(&app::tickNtpUpdate, this), 2);
if((mConfig->sun.lat) && (mConfig->sun.lon)) {
mCalculatedTimezoneOffset = (int8_t)((mConfig->sun.lon >= 0 ? mConfig->sun.lon + 7.5 : mConfig->sun.lon - 7.5) / 15) * 3600;
once(std::bind(&app::tickCalcSunrise, this), 5);
@ -45,7 +46,6 @@ void app::setup() {
mSys = new HmSystemType();
mSys->enableDebug();
mSys->setup(mConfig->nrf.amplifierPower, mConfig->nrf.pinIrq, mConfig->nrf.pinCe, mConfig->nrf.pinCs);
mSys->addInverters(&mConfig->inst);
#if !defined(AP_ONLY)
mMqtt.setup(&mConfig->mqtt, mConfig->sys.deviceName, mVersion, mSys, &mTimestamp, &mSunrise, &mSunset);
@ -53,16 +53,23 @@ void app::setup() {
mWifi.setup(mConfig, &mTimestamp);
mPayload.setup(mSys);
mPayload.enableSerialDebug(mConfig->serial.debug);
#if !defined(AP_ONLY)
if (mConfig->mqtt.broker[0] > 0) {
if(mSys->Radio.isChipConnected()) {
mSys->addInverters(&mConfig->inst);
mPayload.setup(mSys);
mPayload.enableSerialDebug(mConfig->serial.debug);
}
else
DPRINTLN(DBG_WARN, F("WARNING! your NRF24 module can't be reached, check the wiring"));
// when WiFi is in client mode, then enable mqtt broker
if ((mConfig->mqtt.broker[0] > 0) && (WiFi.getMode() == WIFI_STA)) {
mMqtt.setup(&mConfig->mqtt, mConfig->sys.deviceName, mVersion, mSys, &mTimestamp, &mSunrise, &mSunset);
mPayload.addListener(std::bind(&PubMqttType::payloadEventListener, &mMqtt, std::placeholders::_1));
everySec(std::bind(&PubMqttType::tickerSecond, &mMqtt));
everyMin(std::bind(&PubMqttType::tickerMinute, &mMqtt));
mMqtt.setSubscriptionCb(std::bind(&app::mqttSubRxCb, this, std::placeholders::_1));
}
#endif
setupLed();
mWeb = new web(this, mConfig, &mStat, mVersion);

16
src/hm/hmRadio.h

@ -99,7 +99,7 @@ class HmRadio {
DPRINTLN(DBG_VERBOSE, F("hmRadio.h:setup"));
pinMode(irq, INPUT_PULLUP);
mBufCtrl = ctrl;
uint32_t dtuSn = 0x87654321;
uint32_t chipID = 0; // will be filled with last 3 bytes of MAC
@ -192,7 +192,7 @@ class HmRadio {
uint8_t setDefaultChannels(void) {
//DPRINTLN(DBG_VERBOSE, F("hmRadio.h:setDefaultChannels"));
mTxChIdx = 2; // Start TX with 40
mRxChIdx = 0; // Start RX with 03
mRxChIdx = 0; // Start RX with 03
return mRfChLst[mTxChIdx];
}
@ -213,7 +213,7 @@ class HmRadio {
uint16_t crc = ah::crc16(&mTxBuf[10], cnt);
mTxBuf[10 + cnt++] = (crc >> 8) & 0xff;
mTxBuf[10 + cnt++] = (crc ) & 0xff;
// crc over all
mTxBuf[10 + cnt] = ah::crc8(mTxBuf, 10 + cnt);
@ -296,6 +296,14 @@ class HmRadio {
return mNrf24.isChipConnected();
}
rf24_datarate_e getDataRate(void) {
return mNrf24.getDataRate();
}
bool isPVariant(void) {
return mNrf24.isPVariant();
}
uint32_t mSendCnt;
@ -361,7 +369,7 @@ class HmRadio {
uint8_t mTxChIdx;
uint8_t mRfChLst[RF_CHANNELS];
uint8_t mRxChIdx;
uint16_t mRxLoopCnt;

1
src/utils/scheduler.h

@ -42,7 +42,6 @@ namespace ah {
mUptime = 0;
mTimestamp = 0;
mPrevMillis = millis();
mDiffFraq = 0;
}
void loop(void) {

24
src/web/html/system.html

@ -19,6 +19,7 @@
<div id="wrapper">
<div id="content">
<div><ul id="info"></ul></div>
<div><ul id="radio"></ul></div>
<div id="system"></div>
</div>
</div>
@ -59,11 +60,34 @@
}
}
function parseRadio(obj) {
const pa = ["MIN", "LOW", "HIGH", "MAX"];
const datarate = ["1 MBps", "2 MBps", "250 kbps"];
var ul = document.getElementById("radio");
let data;
var li = document.createElement("li");
li.appendChild(document.createTextNode("nrf24l01" + (obj["isPVariant"] ? "+ " : "") + (obj["isconnected"] ? "is connected " : "is not connected ")));
ul.appendChild(li);
if(obj["isconnected"]) {
var li = document.createElement("li");
li.appendChild(document.createTextNode("Datarate: " + datarate[obj["DataRate"]]));
ul.appendChild(li);
var li = document.createElement("li");
li.appendChild(document.createTextNode("Power Level: " + pa[obj["power_level"]]));
ul.appendChild(li);
}
}
function parse(obj) {
if(null != obj) {
parseMenu(obj["menu"]);
parseSys(obj["system"]);
parseSysInfo(obj["system"]);
parseRadio(obj["system"]["radio"]);
var e = document.getElementById("system");
e.innerHTML = obj["html"];

10
src/web/webApi.cpp

@ -174,6 +174,9 @@ void webApi::getSysInfo(JsonObject obj) {
obj[F("sketch_total")] = ESP.getFreeSketchSpace();
obj[F("sketch_used")] = ESP.getSketchSize() / 1024; // in kb
getRadio(obj.createNestedObject(F("radio")));
#if defined(ESP32)
obj[F("heap_total")] = ESP.getHeapSize();
obj[F("chip_revision")] = ESP.getChipRevision();
@ -318,6 +321,9 @@ void webApi::getPinout(JsonObject obj) {
//-----------------------------------------------------------------------------
void webApi::getRadio(JsonObject obj) {
obj[F("power_level")] = mConfig->nrf.amplifierPower;
obj[F("isconnected")] = mApp->mSys->Radio.isChipConnected();
obj[F("DataRate")] = mApp->mSys->Radio.getDataRate();
obj[F("isPVariant")] = mApp->mSys->Radio.isPVariant();
}
@ -373,6 +379,7 @@ void webApi::getMenu(JsonObject obj) {
void webApi::getIndex(JsonObject obj) {
getMenu(obj.createNestedObject(F("menu")));
getSysInfo(obj.createNestedObject(F("system")));
getRadio(obj.createNestedObject(F("radio")));
getStatistics(obj.createNestedObject(F("statistics")));
obj["refresh_interval"] = mConfig->nrf.sendInterval;
@ -395,6 +402,9 @@ void webApi::getIndex(JsonObject obj) {
JsonArray warn = obj.createNestedArray(F("warnings"));
if(!mApp->mSys->Radio.isChipConnected())
warn.add(F("your NRF24 module can't be reached, check the wiring and pinout"));
else if(!mApp->mSys->Radio.isPVariant())
warn.add(F("your NRF24 module have not a plus(+), please check!"));
if((!mApp->mqttIsConnected()) && (String(mConfig->mqtt.broker).length() > 0))
warn.add(F("MQTT is not connected"));

2
src/wifi/ahoywifi.h

@ -22,7 +22,7 @@ class ahoywifi {
void setup(settings_t *config, uint32_t *utcTimestamp);
void loop(void);
void getNtpTime(void);
bool getNtpTime(void);
void scanAvailNetworks(void);
void getAvailNetworks(JsonObject obj);

2
tools/rpi/hoymiles/__main__.py

@ -62,7 +62,7 @@ class SunsetHandler:
tomorrow = now + timedelta(days=1)
nextSunrise = self.suntimes.riseutc(tomorrow)
self.nextSunset = self.suntimes.setutc(tomorrow)
time_to_sleep = int((nextSunrise - datetime.now()).total_seconds())
time_to_sleep = int((nextSunrise - datetime.utcnow()).total_seconds())
logging.info (f'Waiting for sunrise at {nextSunrise} UTC ({time_to_sleep} seconds)')
if time_to_sleep > 0:
time.sleep(time_to_sleep)

Loading…
Cancel
Save