ESPixelStick Firmware
Firmware for the ESPixelStick
Loading...
Searching...
No Matches
InputMQTT.h
Go to the documentation of this file.
1#pragma once
2/*
3* InputMQTT.h
4*
5* Project: ESPixelStick - An ESP8266 / ESP32 and E1.31 based pixel driver
6* Copyright (c) 2021, 2025 Shelby Merrick
7* http://www.forkineye.com
8*
9* This program is provided free for you to use in any way that you wish,
10* subject to the laws and regulations where you are using it. Due diligence
11* is strongly suggested before using this code. Please give credit where due.
12*
13* The Author makes no warranty of any kind, express or implied, with regard
14* to this program or the documentation contained in this document. The
15* Author shall not be liable in any event for incidental or consequential
16* damages in connection with, or arising out of, the furnishing, performance
17* or use of these programs.
18*
19*/
20
21
22#include "InputCommon.hpp"
23#include "InputEffectEngine.hpp"
25#include <Arduino.h>
26#include <AsyncMqttClient.h>
27
29{
30 public:
31
33 c_InputMgr::e_InputChannelIds NewInputChannelId,
34 c_InputMgr::e_InputType NewChannelType,
35 uint32_t BufferSize);
36
37 virtual ~c_InputMQTT ();
38
39 // functions to be provided by the derived class
40 void Begin ();
41 bool SetConfig (JsonObject& jsonConfig);
42 void GetConfig (JsonObject& jsonConfig);
43 void GetStatus (JsonObject& jsonStatus);
44 void Process ();
45 void GetDriverName (String& sDriverName) { sDriverName = "MQTT"; }
46 void SetBufferInfo (uint32_t BufferSize);
47 void NetworkStateChanged (bool IsConnected); // used by poorly designed rx functions
48
49private:
50#define MQTT_PORT 1883
51
52 AsyncMqttClient mqtt; // MQTT object
53 Ticker mqttTicker; // Ticker to handle MQTT
56
57 // Keep track of last known effect configuration state
59
60 // from original config struct
61 String ip;
62 uint16_t port = MQTT_PORT;
63 String user;
64 String password;
65 String topic;
66#ifdef SUPPORT_SENSOR_DS18B20
67 String TemperatureSensorTopic;
68#endif // def SUPPORT_SENSOR_DS18B20
70 String haprefix = "homeassistant";
71 bool hadisco = true;
72 String lwtTopic;
73
74 const char* ON = "ON";
75 const char* OFF = "OFF";
76 const char* LWT_ONLINE = "online";
77 const char* LWT_OFFLINE = "offline";
78
80
81 void setup ();
82 void onNetworkConnect ();
83 void onNetworkDisconnect ();
84 void validate ();
85 void NetworkStateChanged (bool IsConnected, bool RebootAllowed); // used by poorly designed rx functions
86 void PlayFseq (JsonObject & JsonConfig);
87 void PlayEffect (JsonObject & JsonConfig);
88 void GetEngineConfig (JsonObject & JsonConfig);
89 void GetEffectList (JsonObject & JsonConfig);
90 void StopPlayFileEngine ();
91 void UpdateEffectConfiguration (JsonObject & JsonConfig);
92
93 void load ();
94 void save ();
95
96 bool stateOn = false;
97
99 //
100 // MQTT Section
101 //
103
104 void disconnectFromMqtt ();
105 void connectToMqtt (); // onMqttDisconnect, onWifiConnect
106 void onMqttConnect (bool sessionPresent); // setup
107 void onMqttDisconnect (AsyncMqttClientDisconnectReason reason); // setup
108 void onMqttMessage (char* topic, char* payload, AsyncMqttClientMessageProperties properties, uint32_t len, uint32_t index, uint32_t total); // setup
109 void publishHA (); // updateConfig
110 void publishState (); // onMqttConnect, onMqttMessage, procT, updateConfig
111};
#define MQTT_PORT
Default MQTT port.
Definition InputMQTT.h:50
Definition InputCommon.hpp:27
Definition InputFPPRemotePlayItem.hpp:26
Definition InputMQTT.h:29
bool stateOn
Definition InputMQTT.h:96
void Begin()
set up the operating environment based on the current config (or defaults)
Definition InputMQTT.cpp:100
void GetEffectList(JsonObject &JsonConfig)
Definition InputMQTT.cpp:649
void onMqttMessage(char *topic, char *payload, AsyncMqttClientMessageProperties properties, uint32_t len, uint32_t index, uint32_t total)
Definition InputMQTT.cpp:379
virtual ~c_InputMQTT()
Definition InputMQTT.cpp:66
c_InputFPPRemotePlayItem * pPlayFileEngine
Definition InputMQTT.h:55
Ticker mqttTicker
Definition InputMQTT.h:53
void GetDriverName(String &sDriverName)
get the name for the instantiated driver
Definition InputMQTT.h:45
void PlayEffect(JsonObject &JsonConfig)
Definition InputMQTT.cpp:564
const char * LWT_ONLINE
Definition InputMQTT.h:76
void validateConfiguration()
Definition InputMQTT.cpp:236
bool hadisco
Definition InputMQTT.h:71
void GetConfig(JsonObject &jsonConfig)
Get the current config used by the driver.
Definition InputMQTT.cpp:121
void StopPlayFileEngine()
Definition InputMQTT.cpp:594
void publishHA()
Definition InputMQTT.cpp:681
void disconnectFromMqtt()
Definition InputMQTT.cpp:295
const char * ON
Definition InputMQTT.h:74
void onNetworkDisconnect()
Call from onWiFiDisconnect()
Definition InputMQTT.cpp:261
void validate()
Call from validateConfig()
void publishState()
Definition InputMQTT.cpp:743
const char * LWT_OFFLINE
Definition InputMQTT.h:77
void SetBufferInfo(uint32_t BufferSize)
Definition InputMQTT.cpp:184
c_InputCommon * pEffectsEngine
Definition InputMQTT.h:54
const char * OFF
Definition InputMQTT.h:75
String lwtTopic
Definition InputMQTT.h:72
bool SetConfig(JsonObject &jsonConfig)
Set a new config in the driver.
Definition InputMQTT.cpp:200
void GetStatus(JsonObject &jsonStatus)
Definition InputMQTT.cpp:145
AsyncMqttClient mqtt
Definition InputMQTT.h:52
void connectToMqtt()
Definition InputMQTT.cpp:273
c_InputEffectEngine::MQTTConfiguration_t effectConfig
Definition InputMQTT.h:58
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason)
Definition InputMQTT.cpp:356
void PlayFseq(JsonObject &JsonConfig)
Definition InputMQTT.cpp:481
c_InputMQTT(c_InputMgr::e_InputChannelIds NewInputChannelId, c_InputMgr::e_InputType NewChannelType, uint32_t BufferSize)
Definition InputMQTT.cpp:33
void UpdateEffectConfiguration(JsonObject &JsonConfig)
Definition InputMQTT.cpp:799
void GetEngineConfig(JsonObject &JsonConfig)
Definition InputMQTT.cpp:609
void Process()
Call from loop(), renders Input data.
Definition InputMQTT.cpp:157
uint16_t port
Definition InputMQTT.h:62
String user
Definition InputMQTT.h:63
void setup()
Call from setup()
bool CleanSessionRequired
Definition InputMQTT.h:69
void onNetworkConnect()
Call from onWifiConnect()
Definition InputMQTT.cpp:250
void onMqttConnect(bool sessionPresent)
Definition InputMQTT.cpp:309
String ip
Definition InputMQTT.h:61
String password
Definition InputMQTT.h:64
String topic
Definition InputMQTT.h:65
void NetworkStateChanged(bool IsConnected)
Definition InputMQTT.cpp:772
void load()
Load configuration from File System.
String haprefix
Definition InputMQTT.h:70
void save()
Save configuration to File System.
e_InputType
Definition InputMgr.hpp:71
e_InputChannelIds
Definition InputMgr.hpp:40
Definition InputEffectEngine.hpp:80