mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-12 08:26:38 +02:00
Meine anpassungen wegen
MQTT Intervall MQTT Test MQTT Subscribe muss nur nach dem MQTT Connect nicht bei jedem Connect Check
This commit is contained in:
parent
6276957b22
commit
4dc64eb2d7
2 changed files with 28 additions and 6 deletions
|
@ -165,6 +165,8 @@ void app::setup(uint32_t timeout) {
|
|||
mMqtt.setup(mqttAddr, mqttTopic, mqttUser, mqttPwd, mqttDevName, mqttPort);
|
||||
mMqtt.mClient->setCallback(std::bind(&app::cbMqtt, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
||||
mMqttTicker = 0;
|
||||
// für mqtt test
|
||||
mMqttTicker = mMqttInterval -10;
|
||||
|
||||
mSerialTicker = 0;
|
||||
|
||||
|
@ -363,8 +365,12 @@ void app::loop(void) {
|
|||
}
|
||||
}
|
||||
snprintf(val, 10, "%ld", millis()/1000);
|
||||
sendMqttDiscoveryConfig();
|
||||
// sendMqttDiscoveryConfig();
|
||||
mMqtt.sendMsg("uptime", val);
|
||||
|
||||
// für einfacheren Test mit MQTT, den MQTT abschnitt in 10 Sekunden wieder ausführen
|
||||
mMqttTicker = mMqttInterval -10;
|
||||
|
||||
}
|
||||
|
||||
if(mSerialValues) {
|
||||
|
@ -488,6 +494,9 @@ bool app::buildPayload(uint8_t id) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::processPayload(bool retransmit) {
|
||||
|
||||
boolean doMQTT = false;
|
||||
|
||||
DPRINTLN(DBG_VERBOSE, F("app::processPayload"));
|
||||
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
|
||||
Inverter<> *iv = mSys->getInverterByPos(id);
|
||||
|
@ -544,11 +553,23 @@ void app::processPayload(bool retransmit) {
|
|||
yield();
|
||||
}
|
||||
iv->doCalculations();
|
||||
doMQTT = true;
|
||||
|
||||
}
|
||||
}
|
||||
yield();
|
||||
}
|
||||
}
|
||||
|
||||
// ist MQTT aktiviert und es wurden Daten vom einem oder mehreren WR aufbereitet ( doMQTT = true)
|
||||
// dann die den mMqttTicker auf mMqttIntervall -2 setzen, also
|
||||
// MQTT aussenden in 2 sek aktivieren
|
||||
// dies sollte noch über einen Schalter im Setup aktivier / deaktivierbar gemacht werden
|
||||
if( (mMqttInterval != 0xffff) && doMQTT ) {
|
||||
++mMqttTicker = mMqttInterval -2;
|
||||
DPRINT(DBG_DEBUG, F("MQTTticker auf Intervall -2 sec ")) ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -121,13 +121,14 @@ class mqtt {
|
|||
else
|
||||
mClient->connect(mDevName);
|
||||
}
|
||||
}
|
||||
// ein Subscribe ist nur nach einem connect notwendig
|
||||
char topic[MQTT_TOPIC_LEN + 13 ]; // "/devcontrol/#" --> + 6 byte
|
||||
// ToDo: "/devcontrol/#" is hardcoded
|
||||
snprintf(topic, MQTT_TOPIC_LEN + 13, "%s/devcontrol/#", mTopic);
|
||||
DPRINTLN(DBG_INFO, F("subscribe to ") + String(topic));
|
||||
mClient->subscribe(topic); // subscribe to mTopic + "/devcontrol/#"
|
||||
}
|
||||
}
|
||||
|
||||
WiFiClient mEspClient;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue