works better now

This commit is contained in:
hg
2015-05-09 23:48:09 +02:00
parent 79cc72826c
commit 424d9d2a6e
3 changed files with 30 additions and 28 deletions

View File

@ -65,8 +65,8 @@ void MqttClient::sendResponse(uint8_t *responseBuffer, uint16_t responseBufferLe
buf << "\"}}";
if (m_disconnectState == 0) {
Serial << "publishing " << strbuf << endl;
Serial << "length: " << buf.length() << endl;
//Serial << "publishing " << strbuf << endl;
//Serial << "length: " << buf.length() << endl;
m_mqttClient.publish("MeterbusHub.Measurement", strbuf);
} else {
Serial << "no MQTT connection, message lost: " << endl <<
@ -78,8 +78,8 @@ void MqttClient::sendError(uint8_t code, uint8_t token) {
String msg = String("{ \"metadata\": { \"device\": \"MeterbusHub\", \"error\": ")
+ code + String(", \"token\": ") + token + String(" }, \"data\": { \"uptime\": ") + m_uptime + String("}}");
if (m_disconnectState == 0) {
Serial << "publishing " << msg << endl;
Serial << "length: " << msg.length() << endl;
//Serial << "publishing " << msg << endl;
//Serial << "length: " << msg.length() << endl;
m_mqttClient.publish("MeterbusHub.Measurement", (char*)msg.c_str());
} else {
Serial << "no MQTT connection, message lost: " << msg << endl;
@ -130,7 +130,7 @@ void MqttClient::exec() {
//Serial << "*** c" << endl;
if (secondTick.check() == 1) {
m_uptime++;
Serial << "Tick " << m_uptime << endl;
//Serial << "Tick " << m_uptime << endl;
// String msg = String("{ \"metadata\": { \"device\": \"MeterbusHub\" }, \"data\": { \"uptime\": ") + m_uptime + String("}}");
// if (m_disconnectState == 0) {
@ -142,11 +142,11 @@ void MqttClient::exec() {
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_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;
// }
}
}
@ -170,7 +170,7 @@ void MqttClient::exec() {
}
break;
} else {
Serial << "Trying " << m_deviceIdx << ", " << m_mbusDevTuple[m_deviceIdx].token << endl;
//Serial << "Trying " << m_deviceIdx << ", " << m_mbusDevTuple[m_deviceIdx].token << endl;
m_deviceIdx++;
if (m_deviceIdx >= NUM_OF_DEVICES) {
m_deviceIdx = 0;