From 4e84527a4fd7b17b9516cb622d6f09ce48bcbb9d Mon Sep 17 00:00:00 2001 From: hg Date: Sun, 10 May 2015 18:32:11 +0200 Subject: [PATCH] some fixes --- MqttClient.cpp | 19 ++++++++++--------- meterBusMaster.cpp | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/MqttClient.cpp b/MqttClient.cpp index d54df2c..206158f 100644 --- a/MqttClient.cpp +++ b/MqttClient.cpp @@ -13,7 +13,7 @@ #include -byte MQTT_BROKER[] = { 192, 168, 75, 1 }; +byte MQTT_BROKER[] = { 172, 16, 2, 16 }; const uint16_t MQTT_PORT = 1883; @@ -67,7 +67,7 @@ void MqttClient::sendResponse(uint8_t *responseBuffer, uint16_t responseBufferLe if (m_disconnectState == 0) { //Serial << "publishing " << strbuf << endl; //Serial << "length: " << buf.length() << endl; - m_mqttClient.publish("MeterbusHub.Measurement", strbuf); + m_mqttClient.publish("MeterbusHub/Measurement", strbuf); } else { Serial << "no MQTT connection, message lost: " << endl << strbuf << endl; @@ -80,7 +80,7 @@ void MqttClient::sendError(uint8_t code, uint8_t token) { if (m_disconnectState == 0) { //Serial << "publishing " << msg << endl; //Serial << "length: " << msg.length() << endl; - m_mqttClient.publish("MeterbusHub.Measurement", (char*)msg.c_str()); + m_mqttClient.publish("MeterbusHub/Measurement", (char*)msg.c_str()); } else { Serial << "no MQTT connection, message lost: " << msg << endl; } @@ -119,6 +119,7 @@ void MqttClient::exec() { m_disconnectTime = millis(); m_disconnectState = 0; } else { + Serial << "no success" << endl; m_disconnectState = 1; } break; @@ -132,12 +133,12 @@ void MqttClient::exec() { m_uptime++; //Serial << "Tick " << m_uptime << endl; -// String msg = String("{ \"metadata\": { \"device\": \"MeterbusHub\" }, \"data\": { \"uptime\": ") + m_uptime + String("}}"); -// if (m_disconnectState == 0) { -// m_mqttClient.publish("MeterbusHub.Heartbeat", (char*)msg.c_str()); -// } else { -// Serial << "no MQTT connection, message lost: " << msg << endl; -// } + String msg = String("{ \"metadata\": { \"device\": \"MeterbusHub\" }, \"data\": { \"uptime\": ") + m_uptime + String("}}"); + if (m_disconnectState == 0) { + m_mqttClient.publish("MeterbusHub/Heartbeat", (char*)msg.c_str()); + } else { + 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)) { diff --git a/meterBusMaster.cpp b/meterBusMaster.cpp index a58b56d..317db06 100644 --- a/meterBusMaster.cpp +++ b/meterBusMaster.cpp @@ -173,7 +173,7 @@ void MeterBusMaster::prepareResponse(bool err, uint8_t in) { static int16_t expectedChars = -1; static uint8_t state = 0; - //Serial << "r1" << endl; + //Serial << "r0" << endl; if (err) { //Serial << "r1" << endl; if (m_responseCallback != 0) {