works a little bit
This commit is contained in:
parent
f86b389012
commit
472b9628c4
@ -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 {
|
||||
|
@ -13,8 +13,6 @@
|
||||
#include "mBusDialog.h"
|
||||
|
||||
|
||||
const String MQTT_BROKER = "172.16.2.16";
|
||||
const uint16_t MQTT_PORT = 1883;
|
||||
|
||||
class MqttClient : public ResponseCallback {
|
||||
public:
|
||||
@ -25,8 +23,8 @@ public:
|
||||
virtual void sendError(uint8_t code);
|
||||
private:
|
||||
EthernetClient m_client;
|
||||
PubSubClient m_mqttClient;
|
||||
RequestSender *m_meterBusMaster;
|
||||
PubSubClient m_mqttClient;
|
||||
uint8_t m_disconnectState;
|
||||
uint32_t m_disconnectTime;
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "meterBusMaster.h"
|
||||
#include "overCurrentProt.h"
|
||||
#include <Ethernet.h>
|
||||
#include "MqttClient.h"
|
||||
|
||||
|
||||
const uint8_t POWER_LED = 4;
|
||||
@ -23,6 +24,7 @@ static TestCmd testCmd;
|
||||
static Uptime uptime;
|
||||
|
||||
static MeterBusMaster meterBusMaster;
|
||||
static MqttClient mqttClient(&meterBusMaster);
|
||||
// static MeterBusServer meterBusServer(2001, &meterBusMaster);
|
||||
static OverCurrentProt overCurrentProt;
|
||||
|
||||
@ -50,6 +52,7 @@ void setup() {
|
||||
overCurrentProt.begin(&cmdServer);
|
||||
meterBusMaster.begin(&cmdServer);
|
||||
// meterBusServer.begin();
|
||||
mqttClient.begin();
|
||||
|
||||
digitalWrite(POWER_LED, HIGH);
|
||||
}
|
||||
@ -61,4 +64,5 @@ void loop() {
|
||||
overCurrentProt.exec();
|
||||
meterBusMaster.exec();
|
||||
// meterBusServer.exec();
|
||||
mqttClient.exec();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user