NetMeterbusMaster/MqttClient.h

70 lines
1.5 KiB
C
Raw Permalink Normal View History

2015-05-08 23:40:36 +02:00
/*
* MqttClient.h
*
* Created on: 08.05.2015
* Author: wn
*/
#ifndef MQTTCLIENT_H_
#define MQTTCLIENT_H_
#include <Ethernet.h>
#include <PubSubClient.h>
#include "mBusDialog.h"
2015-05-09 16:31:49 +02:00
#include <Metro.h>
2015-05-11 22:36:58 +02:00
#include "cmd.h"
2015-05-08 23:40:36 +02:00
2015-06-10 21:07:58 +02:00
#define NUM_OF_DEVICES 20
2015-05-29 22:38:24 +02:00
#define MAX_LEN_OF_NAME 16
2015-05-09 16:31:49 +02:00
typedef struct {
2015-05-09 20:26:31 +02:00
uint8_t token;
2015-05-29 22:38:24 +02:00
char name[MAX_LEN_OF_NAME+1];
2015-05-09 16:31:49 +02:00
uint8_t address;
uint16_t queryPeriod;
uint16_t timer;
} mbusDevTuple_t;
2015-05-08 23:40:36 +02:00
2015-05-11 22:36:58 +02:00
class MqttClient;
class MqttConfig : public Cmd {
public:
MqttConfig(MqttClient *mqttClient) : m_mqttClient(mqttClient) {};
virtual String getCmdName() { return "MQ"; }
virtual String getHelp() { return "MQTT Client Config"; }
virtual String exec(String params);
private:
MqttClient *m_mqttClient;
};
2015-05-08 23:40:36 +02:00
class MqttClient : public ResponseCallback {
public:
MqttClient(RequestSender *meterBusMaster);
2015-05-11 22:36:58 +02:00
void begin(CmdServer *cmdServer);
2015-05-08 23:40:36 +02:00
void exec();
2015-05-29 22:38:24 +02:00
virtual void sendResponse(uint8_t *responseBuffer, uint16_t responseBufferLength, uint8_t token, char *name);
2017-01-07 19:08:53 +01:00
virtual void sendError(uint8_t code, uint16_t errorCount, uint16_t loopDisabledCount, uint8_t token, char *name);
2015-05-11 22:36:58 +02:00
friend class MqttConfig;
2015-05-08 23:40:36 +02:00
private:
2015-05-11 22:36:58 +02:00
MqttConfig m_mqttConfig;
char m_mqttBroker[64];
2015-05-08 23:40:36 +02:00
EthernetClient m_client;
RequestSender *m_meterBusMaster;
2015-05-09 00:08:54 +02:00
PubSubClient m_mqttClient;
2015-05-08 23:40:36 +02:00
uint8_t m_disconnectState;
uint32_t m_disconnectTime;
2015-05-09 17:45:17 +02:00
uint32_t m_uptime;
2015-05-09 20:26:31 +02:00
uint8_t m_deviceIdx;
2015-08-14 22:44:52 +02:00
bool m_enabled;
2017-01-04 17:57:52 +01:00
uint16_t m_errorCount;
2017-01-07 19:08:53 +01:00
uint16_t m_loopDisabledCount;
2015-05-09 16:31:49 +02:00
mbusDevTuple_t m_mbusDevTuple[NUM_OF_DEVICES];
2015-05-08 23:40:36 +02:00
};
#endif /* MQTTCLIENT_H_ */