diff --git a/MqttClient.cpp b/MqttClient.cpp index 9a0e6dc..f7f40f4 100644 --- a/MqttClient.cpp +++ b/MqttClient.cpp @@ -48,6 +48,12 @@ String MqttConfig::exec(String params) { *out << " about a minute" << endl; *out << endl; res = "done"; + } else if (params.equalsIgnoreCase("enable")) { + mc->m_enabled = true; + *out << "Query timers enabled" << endl; + } else if (params.equalsIgnoreCase("disable")) { + mc->m_enabled = false; + *out << "Query timers disabled" << endl; } else if (params.equalsIgnoreCase("show")) { // show the whole configuration *out << "Clients:" << endl; @@ -190,7 +196,8 @@ Metro secondTick = Metro(1000); MqttClient::MqttClient(RequestSender *meterBusMaster) : m_mqttConfig(this), m_client(), m_meterBusMaster(meterBusMaster), m_mqttClient(m_client), - m_disconnectState(3), m_disconnectTime(millis()), m_uptime(0), m_deviceIdx(0) + m_disconnectState(3), m_disconnectTime(millis()), m_uptime(0), m_deviceIdx(0), + m_enabled(true) { } @@ -266,7 +273,6 @@ void MqttClient::begin(CmdServer *cmdServer) { configRead(CONFIG_DEVICES, sizeof(m_mbusDevTuple), (char*)m_mbusDevTuple); configRead(CONFIG_BROKER, sizeof(m_mqttBroker), (char*)m_mqttBroker); - m_mqttClient = PubSubClient(m_mqttBroker, MQTT_PORT, callback, m_client); } @@ -333,15 +339,19 @@ void MqttClient::exec() { Serial << "no MQTT connection, message lost: " << msg << endl; } - for (uint8_t i = 0; i < NUM_OF_DEVICES; i++) { - if ((m_mbusDevTuple[i].address != 0) && (m_mbusDevTuple[i].timer != 0)) { - m_mbusDevTuple[i].timer -= 1; -// if (m_mbusDevTuple[i].timer == 0) { -// Serial << "Device " << m_mbusDevTuple[i].token << " ready for request" << endl; -// } else { -// Serial << "Device " << m_mbusDevTuple[i].token << " not ready for request, timer: " << m_mbusDevTuple[i].timer << endl; -// } + if (m_enabled) { + for (uint8_t i = 0; i < NUM_OF_DEVICES; i++) { + if ((m_mbusDevTuple[i].address != 0) && (m_mbusDevTuple[i].timer != 0)) { + m_mbusDevTuple[i].timer -= 1; + // if (m_mbusDevTuple[i].timer == 0) { + // Serial << "Device " << m_mbusDevTuple[i].token << " ready for request" << endl; + // } else { + // Serial << "Device " << m_mbusDevTuple[i].token << " not ready for request, timer: " << m_mbusDevTuple[i].timer << endl; + // } + } } + } else { + Serial << "Query timers disabled" << endl; } //Serial << "while in" << endl; diff --git a/MqttClient.h b/MqttClient.h index a23c1b0..ad6eb90 100644 --- a/MqttClient.h +++ b/MqttClient.h @@ -57,6 +57,7 @@ private: uint32_t m_disconnectTime; uint32_t m_uptime; uint8_t m_deviceIdx; + bool m_enabled; mbusDevTuple_t m_mbusDevTuple[NUM_OF_DEVICES]; }; diff --git a/info.cpp b/info.cpp index 0c24f4b..49948b6 100644 --- a/info.cpp +++ b/info.cpp @@ -16,7 +16,7 @@ String InfoCmd::exec(String params) { *out << "Meterbus Hub" << endl; *out << "Project/Repo: NetMeterBusMaster2" << endl; - *out << "Repo Tag: First_MQTT" << endl; + *out << "Repo Tag: Second_MQTT" << endl; return "done"; }