mirror of
https://github.com/lumapu/ahoy.git
synced 2025-06-14 00:21:44 +02:00
0.8.1030001-zero
Merge branch 'development03' into zero-export
This commit is contained in:
commit
a86a55e9de
35 changed files with 1394 additions and 1322 deletions
110
src/app.cpp
110
src/app.cpp
|
@ -57,17 +57,15 @@ void app::setup() {
|
|||
mCmtRadio.setup(&mConfig->serial.debug, &mConfig->serial.privacyLog, &mConfig->serial.printWholeTrace, mConfig->cmt.pinSclk, mConfig->cmt.pinSdio, mConfig->cmt.pinCsb, mConfig->cmt.pinFcsb, mConfig->sys.region);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ETHERNET
|
||||
delay(1000);
|
||||
mEth.setup(mConfig, &mTimestamp, [this](bool gotIp) { this->onNetwork(gotIp); }, [this](bool gotTime) { this->onNtpUpdate(gotTime); });
|
||||
mNetwork = static_cast<AhoyNetwork*>(new AhoyEthernet());
|
||||
#else
|
||||
mNetwork = static_cast<AhoyNetwork*>(new AhoyWifi());
|
||||
#endif // ETHERNET
|
||||
|
||||
#if !defined(ETHERNET)
|
||||
mWifi.setup(mConfig, &mTimestamp, [this](bool gotIp) { this->onNetwork(gotIp); }, [this](bool gotTime) { this->onNtpUpdate(gotTime); });
|
||||
#if !defined(AP_ONLY)
|
||||
everySec(std::bind(&ahoywifi::tickWifiLoop, &mWifi), "wifiL");
|
||||
#endif
|
||||
#endif /* defined(ETHERNET) */
|
||||
mNetwork->setup(mConfig, &mTimestamp, [this](bool gotIp) { this->onNetwork(gotIp); }, [this](bool gotTime) { this->onNtpUpdate(gotTime); });
|
||||
mNetwork->begin();
|
||||
|
||||
esp_task_wdt_reset();
|
||||
|
||||
|
@ -116,7 +114,7 @@ void app::setup() {
|
|||
#if defined(ENABLE_MQTT)
|
||||
mMqttEnabled = (mConfig->mqtt.broker[0] > 0);
|
||||
if (mMqttEnabled) {
|
||||
mMqtt.setup(&mConfig->mqtt, mConfig->sys.deviceName, mVersion, &mSys, &mTimestamp, &mUptime);
|
||||
mMqtt.setup(this, &mConfig->mqtt, mConfig->sys.deviceName, mVersion, &mSys, &mTimestamp, &mUptime);
|
||||
mMqtt.setSubscriptionCb(std::bind(&app::mqttSubRxCb, this, std::placeholders::_1));
|
||||
mCommunication.addAlarmListener([this](Inverter<> *iv) { mMqtt.alarmEvent(iv); });
|
||||
}
|
||||
|
@ -205,7 +203,6 @@ void app::loop(void) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::onNetwork(bool gotIp) {
|
||||
DPRINTLN(DBG_INFO, F("onNetwork"));
|
||||
mNetworkConnected = gotIp;
|
||||
ah::Scheduler::resetTicker();
|
||||
regularTickers(); //reinstall regular tickers
|
||||
|
@ -213,12 +210,6 @@ void app::onNetwork(bool gotIp) {
|
|||
mMqttReconnect = true;
|
||||
mSunrise = 0; // needs to be set to 0, to reinstall sunrise and ivComm tickers!
|
||||
once(std::bind(&app::tickNtpUpdate, this), 2, "ntp2");
|
||||
#if !defined(ETHERNET)
|
||||
if (WIFI_AP == WiFi.getMode()) {
|
||||
mMqttEnabled = false;
|
||||
}
|
||||
everySec(std::bind(&ahoywifi::tickWifiLoop, &mWifi), "wifiL");
|
||||
#endif /* !defined(ETHERNET) */
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -226,6 +217,7 @@ void app::regularTickers(void) {
|
|||
DPRINTLN(DBG_DEBUG, F("regularTickers"));
|
||||
everySec(std::bind(&WebType::tickSecond, &mWeb), "webSc");
|
||||
everySec([this]() { mProtection->tickSecond(); }, "prot");
|
||||
everySec([this]() {mNetwork->tickNetworkLoop(); }, "net");
|
||||
|
||||
// Plugins
|
||||
#if defined(PLUGIN_DISPLAY)
|
||||
|
@ -300,26 +292,14 @@ void app::updateNtp(void) {
|
|||
void app::tickNtpUpdate(void) {
|
||||
uint32_t nxtTrig = 5; // default: check again in 5 sec
|
||||
|
||||
#if defined(ETHERNET)
|
||||
if (!mNtpReceived)
|
||||
mEth.updateNtpTime();
|
||||
else
|
||||
mNtpReceived = false;
|
||||
#else
|
||||
if (!mNtpReceived)
|
||||
mWifi.updateNtpTime();
|
||||
else
|
||||
mNtpReceived = false;
|
||||
#endif
|
||||
if (!mNtpReceived)
|
||||
mNetwork->updateNtpTime();
|
||||
else {
|
||||
nxtTrig = mConfig->ntp.interval * 60; // check again in configured interval
|
||||
mNtpReceived = false;
|
||||
}
|
||||
|
||||
updateNtp();
|
||||
nxtTrig = mConfig->ntp.interval * 60; // check again in 12h
|
||||
|
||||
// immediately start communicating
|
||||
if (mSendFirst) {
|
||||
mSendFirst = false;
|
||||
once(std::bind(&app::tickSend, this), 1, "senOn");
|
||||
}
|
||||
|
||||
mMqttReconnect = false;
|
||||
|
||||
|
@ -476,39 +456,17 @@ 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);
|
||||
});
|
||||
|
||||
if(!sendIv(iv))
|
||||
notAvail = false;
|
||||
// Plugin ZeroExport
|
||||
// #if defined(PLUGIN_ZEROEXPORT)
|
||||
// TODO: aufräumen
|
||||
// TODO: aufr<66>umen
|
||||
// if(mConfig->nrf.enabled || mConfig->cmt.enabled) {
|
||||
// mZeroExport.loop();
|
||||
// zeroexport();
|
||||
// }
|
||||
// #endif
|
||||
// Plugin ZeroExport - Ende
|
||||
}
|
||||
}
|
||||
|
||||
if(mAllIvNotAvail != notAvail)
|
||||
|
@ -518,6 +476,37 @@ void app::tickSend(void) {
|
|||
updateLed();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool app::sendIv(Inverter<> *iv) {
|
||||
if(NULL == iv)
|
||||
return true;
|
||||
|
||||
if(!iv->config->enabled)
|
||||
return true;
|
||||
|
||||
if(!iv->commEnabled) {
|
||||
DPRINT_IVID(DBG_INFO, iv->id);
|
||||
DBGPRINTLN(F("no communication to the inverter (night time)"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!iv->radio->isChipConnected())
|
||||
return true;
|
||||
|
||||
bool notAvail = true;
|
||||
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;
|
||||
|
@ -614,7 +603,6 @@ void app::resetSystem(void) {
|
|||
mTimestamp = 1;
|
||||
#endif
|
||||
|
||||
mSendFirst = true;
|
||||
mAllIvNotAvail = true;
|
||||
|
||||
mSunrise = 0;
|
||||
|
@ -690,7 +678,7 @@ void app::updateLed(void) {
|
|||
#if defined(PLUGIN_ZEROEXPORT)
|
||||
void app::zeroexport() {
|
||||
return;
|
||||
// TODO: aufräumen
|
||||
// TODO: aufr<EFBFBD>umen
|
||||
// TODO: umziehen nach loop
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue