works a little bit
This commit is contained in:
@ -8,15 +8,26 @@
|
||||
#include "MqttClient.h"
|
||||
|
||||
#include <PubSubClient.h>
|
||||
#include <PString.h>
|
||||
#include <Streaming.h>
|
||||
|
||||
|
||||
byte MQTT_BROKER[] = { 192, 168, 75, 1 };
|
||||
const uint16_t MQTT_PORT = 1883;
|
||||
|
||||
|
||||
void callback(char* topic, byte* payload, unsigned int length) {
|
||||
char strbuf[256];
|
||||
memset(strbuf, sizeof(strbuf), 0);
|
||||
memcpy(strbuf, payload, length);
|
||||
Serial << "MQTT Message received: " << topic << ", " << strbuf << endl;
|
||||
|
||||
// handle message arrived
|
||||
}
|
||||
|
||||
|
||||
MqttClient::MqttClient(RequestSender *meterBusMaster) :
|
||||
m_client(255), m_meterBusMaster(meterBusMaster), m_mqttClient(MQTT_BROKER, MQTT_PORT, callback, m_client),
|
||||
m_client(), m_meterBusMaster(meterBusMaster), m_mqttClient(MQTT_BROKER, MQTT_PORT, callback, m_client),
|
||||
m_disconnectState(3), m_disconnectTime(millis())
|
||||
{
|
||||
}
|
||||
@ -67,6 +78,8 @@ void MqttClient::exec() {
|
||||
case 3:
|
||||
Serial.println("discState 3");
|
||||
if (m_mqttClient.connect("MeterbusHub")) {
|
||||
Serial << "MQTT connected" << endl;
|
||||
m_mqttClient.subscribe("MeterbusHub.Configuration");
|
||||
m_disconnectTime = millis();
|
||||
m_disconnectState = 0;
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user