message displaying works
This commit is contained in:
@ -11,8 +11,14 @@
|
||||
#include <Ethernet.h>
|
||||
#include <Metro.h>
|
||||
#include <PubSubClient.h>
|
||||
#include "hmi.h"
|
||||
|
||||
|
||||
extern Hmi hmi;
|
||||
|
||||
static const char MESSAGE_TOPIC[] = "IoT/Message/Monitor";
|
||||
static const char ALARM_TOPIC[] = "IoT/Alarm/Monitor";
|
||||
|
||||
|
||||
void callback(char* topic, byte* payload, unsigned int length);
|
||||
|
||||
@ -36,6 +42,37 @@ void callback(char* topic, byte* payload, unsigned int length) {
|
||||
memcpy(buffer, payload, length);
|
||||
*(buffer + length) = 0;
|
||||
Serial << "Received message: " << length << ", " << String(topic) << ", " << String(buffer) << endl;
|
||||
|
||||
if (!(strcmp(topic, MESSAGE_TOPIC) && strcmp(topic, ALARM_TOPIC))) {
|
||||
char *paramPtr = buffer;
|
||||
char *slotStr = 0;
|
||||
char *headerStr = 0;
|
||||
char *bodyStr = 0;
|
||||
if ((paramPtr != 0) && (*paramPtr != 0)){
|
||||
slotStr = strsep(¶mPtr, " ");
|
||||
}
|
||||
if ((paramPtr != 0) && (*paramPtr != 0)){
|
||||
headerStr = strsep(¶mPtr, " ");
|
||||
}
|
||||
if ((paramPtr != 0) && (*paramPtr != 0)){
|
||||
bodyStr = strsep(¶mPtr, " ");
|
||||
}
|
||||
|
||||
if ((slotStr != 0) && (*slotStr != 0) &&
|
||||
(headerStr != 0) && (*headerStr != 0) &&
|
||||
(bodyStr != 0) && (*bodyStr != 0)) {
|
||||
|
||||
uint8_t slot = atoi(slotStr);
|
||||
|
||||
if (! strcmp(topic, ALARM_TOPIC)) {
|
||||
Serial << "Alarm" << endl;
|
||||
} else if (! strcmp(topic, MESSAGE_TOPIC)) {
|
||||
hmi.updateMessage(slot, headerStr, bodyStr);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Serial << "Strange, unknown topic received" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,8 +117,8 @@ void MqttClientNS::exec() {
|
||||
case 3:
|
||||
Serial.println("discState 3");
|
||||
if (mqttClient.connect("Monitor")) {
|
||||
mqttClient.subscribe("IoT/Message/Monitor");
|
||||
mqttClient.subscribe("IoT/Alarm/Monitor");
|
||||
mqttClient.subscribe(MESSAGE_TOPIC);
|
||||
mqttClient.subscribe(ALARM_TOPIC);
|
||||
disconnectTime = millis();
|
||||
disconnectState = 0;
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user