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.setup(mqttAddr, mqttTopic, mqttUser, mqttPwd, mqttDevName, mqttPort);
|
||||||
mMqtt.mClient->setCallback(std::bind(&app::cbMqtt, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
mMqtt.mClient->setCallback(std::bind(&app::cbMqtt, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
||||||
mMqttTicker = 0;
|
mMqttTicker = 0;
|
||||||
|
// für mqtt test
|
||||||
|
mMqttTicker = mMqttInterval -10;
|
||||||
|
|
||||||
mSerialTicker = 0;
|
mSerialTicker = 0;
|
||||||
|
|
||||||
|
@ -363,8 +365,12 @@ void app::loop(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
snprintf(val, 10, "%ld", millis()/1000);
|
snprintf(val, 10, "%ld", millis()/1000);
|
||||||
sendMqttDiscoveryConfig();
|
// sendMqttDiscoveryConfig();
|
||||||
mMqtt.sendMsg("uptime", val);
|
mMqtt.sendMsg("uptime", val);
|
||||||
|
|
||||||
|
// für einfacheren Test mit MQTT, den MQTT abschnitt in 10 Sekunden wieder ausführen
|
||||||
|
mMqttTicker = mMqttInterval -10;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mSerialValues) {
|
if(mSerialValues) {
|
||||||
|
@ -488,6 +494,9 @@ bool app::buildPayload(uint8_t id) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::processPayload(bool retransmit) {
|
void app::processPayload(bool retransmit) {
|
||||||
|
|
||||||
|
boolean doMQTT = false;
|
||||||
|
|
||||||
DPRINTLN(DBG_VERBOSE, F("app::processPayload"));
|
DPRINTLN(DBG_VERBOSE, F("app::processPayload"));
|
||||||
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
|
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
|
||||||
Inverter<> *iv = mSys->getInverterByPos(id);
|
Inverter<> *iv = mSys->getInverterByPos(id);
|
||||||
|
@ -544,11 +553,23 @@ void app::processPayload(bool retransmit) {
|
||||||
yield();
|
yield();
|
||||||
}
|
}
|
||||||
iv->doCalculations();
|
iv->doCalculations();
|
||||||
|
doMQTT = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
yield();
|
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,12 +121,13 @@ class mqtt {
|
||||||
else
|
else
|
||||||
mClient->connect(mDevName);
|
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/#"
|
||||||
}
|
}
|
||||||
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;
|
WiFiClient mEspClient;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue