My Project
Loading...
Searching...
No Matches
MattzoMQTTSubscriber.h
Go to the documentation of this file.
1#pragma once
2
3#include <Arduino.h>
4
5// PubSubClient library by Nick O'Leary
6// Install via the built-in Library Manager of the Arduino IDE
7// Tested with Version V2.8.0
8#include <PubSubClient.h>
9
10// WiFi library for ESP-32
11#include "MCMQTTConfiguration.h"
12#include <Ethernet.h>
13#include <EthernetUdp.h>
14#include <WiFi.h>
15
16// MQTT task priority.
17#define MQTT_TASK_PRIORITY 2
18
19// MQTT handle message task core ID.
20#define MQTT_HANDLE_MESSAGE_TASK_COREID 1
21
22// The size of the MQTT task stack specified as the number of bytes.
23#define MQTT_TASK_STACK_DEPTH 3072
24
25// Number of message received the MQTT queue can hold before we start dropping them.
26// Please note the more messages allowed to be queued, the more (heap) memory we consume.
27#define MQTT_INCOMING_QUEUE_LENGTH 100
28
29// Number of message to send the MQTT queue can hold before we start dropping them.
30// Please note the more messages allowed to be queued, the more (heap) memory we consume.
31#define MQTT_OUTGOING_QUEUE_LENGTH 1000
32
33#define MQTT_UNINITIALIZED -10
34
35extern WiFiClient wifiSubscriberClient;
36extern PubSubClient mqttSubscriberClient;
37
42{
43 public:
44 // Public static members
45
46 // Incoming MQTT message queue.
47 static QueueHandle_t IncomingQueue;
48
53
58
64 static uint8_t TaskPriority;
65
71 static int8_t CoreID;
72
76 static uint32_t StackDepth;
77
82 static uint16_t MaxBufferSize;
83
84 // Methods
85
89 static void Setup(MCMQTTConfiguration *config, void (*MQTThandler)(const char *message));
90
91 // Returns the current MQTT connection status.
92 static int GetStatus();
93
94 // All code that should be handled in the Loop
95 static void Loop();
96
97 //pointer to hanler function
98 static void (*handler)(const char *message);
99 private:
100 static MCMQTTConfiguration *_config;
101 static char _subscriberName[60];
102 static bool _setupCompleted;
103
104 // Time of the last sent ping.
105 static unsigned long lastPing;
106
107 // Callback used to put received message on a queue.
108 static void mqttCallback(char *topic, byte *payload, unsigned int length);
109
114 static void sendMessage(char *topic, const char *message);
115
119 static void reconnect();
120
125 static void taskLoop(void *parm);
126};
WiFiClient wifiSubscriberClient
Definition MattzoMQTTSubscriber.cpp:6
PubSubClient mqttSubscriberClient
Definition MattzoMQTTSubscriber.cpp:9
Class used to publish messages to an MQTT broker.
Definition MattzoMQTTSubscriber.h:42
static uint16_t MaxBufferSize
The maximum message size, including header, specified as the number of bytes. Messages larger than th...
Definition MattzoMQTTSubscriber.h:82
static void Loop()
Definition MattzoMQTTSubscriber.cpp:121
static uint32_t StackDepth
The size of the task stack specified as the number of bytes.
Definition MattzoMQTTSubscriber.h:76
static int GetStatus()
Definition MattzoMQTTSubscriber.cpp:45
static int ReconnectDelayInMilliseconds
Reconnect delay in milliseconds. This configures the delay between reconnect attempts.
Definition MattzoMQTTSubscriber.h:52
static QueueHandle_t IncomingQueue
Definition MattzoMQTTSubscriber.h:47
static uint8_t TaskPriority
The priority at which the task should run. Systems that include MPU support can optionally create tas...
Definition MattzoMQTTSubscriber.h:64
static int8_t CoreID
If the value is tskNO_AFFINITY, the created task is not pinned to any CPU, and the scheduler can run ...
Definition MattzoMQTTSubscriber.h:71
static void Setup(MCMQTTConfiguration *config, void(*MQTThandler)(const char *message))
Setup the MQTT Subscriber.
Definition MattzoMQTTSubscriber.cpp:10
static int HandleMessageDelayInMilliseconds
Send message delay in milliseconds. This configures the delay between send message attempts.
Definition MattzoMQTTSubscriber.h:57
static void(* handler)(const char *message)
Definition MattzoMQTTSubscriber.h:98
Definition MCMQTTConfiguration.h:3