|
|
@ -33,23 +33,16 @@ void app::setup() { |
|
|
|
resetSystem(); |
|
|
|
esp_task_wdt_reset(); |
|
|
|
|
|
|
|
mSettings.setup(); |
|
|
|
mSettings.getPtr(mConfig); |
|
|
|
mSettings.setup(mConfig); |
|
|
|
ah::Scheduler::setup(mConfig->inst.startWithoutTime); |
|
|
|
DPRINT(DBG_INFO, F("Settings valid: ")); |
|
|
|
DSERIAL.flush(); |
|
|
|
if (mSettings.getValid()) |
|
|
|
DBGPRINTLN(F("true")); |
|
|
|
else |
|
|
|
DBGPRINTLN(F("false")); |
|
|
|
DBGPRINTLN(mConfig->valid ? F("true") : F("false")); |
|
|
|
|
|
|
|
esp_task_wdt_reset(); |
|
|
|
|
|
|
|
mNrfRadio.setup(&mConfig->serial.debug, &mConfig->serial.privacyLog, &mConfig->serial.printWholeTrace, &mConfig->nrf); |
|
|
|
#if defined(ESP32) |
|
|
|
if(mConfig->cmt.enabled) { |
|
|
|
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); |
|
|
|
} |
|
|
|
mCmtRadio.setup(&mConfig->serial.debug, &mConfig->serial.privacyLog, &mConfig->serial.printWholeTrace, &mConfig->cmt, mConfig->sys.region); |
|
|
|
#endif |
|
|
|
|
|
|
|
#ifdef ETHERNET |
|
|
@ -57,16 +50,16 @@ void app::setup() { |
|
|
|
mNetwork = static_cast<AhoyNetwork*>(new AhoyEthernet()); |
|
|
|
#else |
|
|
|
mNetwork = static_cast<AhoyNetwork*>(new AhoyWifi()); |
|
|
|
#endif // ETHERNET
|
|
|
|
#endif |
|
|
|
mNetwork->setup(mConfig, &mTimestamp, [this](bool gotIp) { this->onNetwork(gotIp); }, [this](bool gotTime) { this->onNtpUpdate(gotTime); }); |
|
|
|
mNetwork->begin(); |
|
|
|
|
|
|
|
esp_task_wdt_reset(); |
|
|
|
|
|
|
|
mCommunication.setup(&mTimestamp, &mConfig->serial.debug, &mConfig->serial.privacyLog, &mConfig->serial.printWholeTrace); |
|
|
|
mCommunication.addPayloadListener(std::bind(&app::payloadEventListener, this, std::placeholders::_1, std::placeholders::_2)); |
|
|
|
mCommunication.addPayloadListener([this] (uint8_t cmd, Inverter<> *iv) { payloadEventListener(cmd, iv); }); |
|
|
|
#if defined(ENABLE_MQTT) |
|
|
|
mCommunication.addPowerLimitAckListener([this] (Inverter<> *iv) { mMqtt.setPowerLimitAck(iv); }); |
|
|
|
mCommunication.addPowerLimitAckListener([this] (Inverter<> *iv) { mMqtt.setPowerLimitAck(iv); }); |
|
|
|
#endif |
|
|
|
mSys.setup(&mTimestamp, &mConfig->inst, this); |
|
|
|
for (uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) { |
|
|
@ -81,7 +74,6 @@ void app::setup() { |
|
|
|
esp_task_wdt_reset(); |
|
|
|
|
|
|
|
// when WiFi is in client mode, then enable mqtt broker
|
|
|
|
#if !defined(AP_ONLY) |
|
|
|
#if defined(ENABLE_MQTT) |
|
|
|
mMqttEnabled = (mConfig->mqtt.broker[0] > 0); |
|
|
|
if (mMqttEnabled) { |
|
|
@ -90,7 +82,6 @@ void app::setup() { |
|
|
|
mCommunication.addAlarmListener([this](Inverter<> *iv) { mMqtt.alarmEvent(iv); }); |
|
|
|
} |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
setupLed(); |
|
|
|
|
|
|
|
esp_task_wdt_reset(); |
|
|
@ -126,9 +117,7 @@ void app::setup() { |
|
|
|
|
|
|
|
#if defined(ENABLE_SIMULATOR) |
|
|
|
mSimulator.setup(&mSys, &mTimestamp, 0); |
|
|
|
mSimulator.addPayloadListener([this](uint8_t cmd, Inverter<> *iv) { |
|
|
|
payloadEventListener(cmd, iv); |
|
|
|
}); |
|
|
|
mSimulator.addPayloadListener([this](uint8_t cmd, Inverter<> *iv) { payloadEventListener(cmd, iv); }); |
|
|
|
#endif /*ENABLE_SIMULATOR*/ |
|
|
|
|
|
|
|
esp_task_wdt_reset(); |
|
|
@ -142,8 +131,7 @@ void app::loop(void) { |
|
|
|
mNrfRadio.loop(); |
|
|
|
|
|
|
|
#if defined(ESP32) |
|
|
|
if(mConfig->cmt.enabled) |
|
|
|
mCmtRadio.loop(); |
|
|
|
mCmtRadio.loop(); |
|
|
|
#endif |
|
|
|
|
|
|
|
ah::Scheduler::loop(); |
|
|
|