mirror of
https://github.com/lumapu/ahoy.git
synced 2025-06-10 14:41:37 +02:00
fixed MQTT crash during boot if no MQTT was set
added #318 status LED support
This commit is contained in:
parent
ca8142e781
commit
700c5c71e4
8 changed files with 99 additions and 28 deletions
|
@ -44,15 +44,17 @@ class mqtt {
|
|||
mClient->setBufferSize(MQTT_MAX_PACKET_SIZE);
|
||||
}
|
||||
|
||||
void setCallback(MQTT_CALLBACK_SIGNATURE){
|
||||
void setCallback(MQTT_CALLBACK_SIGNATURE) {
|
||||
mClient->setCallback(callback);
|
||||
}
|
||||
|
||||
void sendMsg(const char *topic, const char *msg) {
|
||||
//DPRINTLN(DBG_VERBOSE, F("mqtt.h:sendMsg"));
|
||||
char top[64];
|
||||
snprintf(top, 64, "%s/%s", mCfg->topic, topic);
|
||||
sendMsg2(top, msg, false);
|
||||
if(mAddressSet) {
|
||||
char top[64];
|
||||
snprintf(top, 64, "%s/%s", mCfg->topic, topic);
|
||||
sendMsg2(top, msg, false);
|
||||
}
|
||||
}
|
||||
|
||||
void sendMsg2(const char *topic, const char *msg, boolean retained) {
|
||||
|
@ -61,12 +63,14 @@ class mqtt {
|
|||
reconnect();
|
||||
if(mClient->connected())
|
||||
mClient->publish(topic, msg, retained);
|
||||
mTxCnt++;
|
||||
}
|
||||
mTxCnt++;
|
||||
}
|
||||
|
||||
bool isConnected(bool doRecon = false) {
|
||||
//DPRINTLN(DBG_VERBOSE, F("mqtt.h:isConnected"));
|
||||
if(!mAddressSet)
|
||||
return false;
|
||||
if(doRecon && !mClient->connected())
|
||||
reconnect();
|
||||
return mClient->connected();
|
||||
|
@ -74,9 +78,11 @@ class mqtt {
|
|||
|
||||
void loop() {
|
||||
//DPRINT(F("m"));
|
||||
if(!mClient->connected())
|
||||
reconnect();
|
||||
mClient->loop();
|
||||
if(mAddressSet) {
|
||||
if(!mClient->connected())
|
||||
reconnect();
|
||||
mClient->loop();
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t getTxCnt(void) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue