2024-01-16 04:22:41 +00:00
|
|
|
#pragma once
|
|
|
|
#include <ESPMegaIoT.hpp>
|
2024-02-10 07:26:41 +00:00
|
|
|
/**
|
|
|
|
* @brief A class that create a variable that exists on other devices and can be accessed remotely
|
|
|
|
*
|
|
|
|
* This class is used to create a variable that exists on other devices and can be accessed remotely.
|
|
|
|
* Supports setting and getting values from the variable.
|
|
|
|
* Also support value request.
|
|
|
|
*/
|
2024-01-16 04:22:41 +00:00
|
|
|
class RemoteVariable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RemoteVariable();
|
|
|
|
~RemoteVariable();
|
2024-02-09 10:48:43 +00:00
|
|
|
void begin(size_t size, const char* topic, ESPMegaIoT* iot);
|
|
|
|
void begin(size_t size, const char* topic, ESPMegaIoT* iot, bool useValueRequest, const char* valueRequestTopic);
|
|
|
|
void setValue(const char* value);
|
|
|
|
void enableSetValue(const char* setValueTopic);
|
2024-01-16 04:22:41 +00:00
|
|
|
void subscribe();
|
2024-01-16 05:48:06 +00:00
|
|
|
void requestValue();
|
2024-01-16 04:22:41 +00:00
|
|
|
char* getValue();
|
|
|
|
private:
|
2024-01-16 05:48:06 +00:00
|
|
|
void mqtt_callback(char* topic, char* payload);
|
2024-01-16 04:22:41 +00:00
|
|
|
ESPMegaIoT* iot;
|
2024-02-09 10:48:43 +00:00
|
|
|
const char* topic;
|
2024-01-16 04:22:41 +00:00
|
|
|
char* value;
|
|
|
|
size_t size;
|
2024-01-16 05:48:06 +00:00
|
|
|
bool useValueRequest;
|
2024-02-09 10:48:43 +00:00
|
|
|
const char* valueRequestTopic;
|
2024-01-16 05:48:06 +00:00
|
|
|
bool useSetValue;
|
2024-02-09 10:48:43 +00:00
|
|
|
const char* setValueTopic;
|
2024-01-16 04:22:41 +00:00
|
|
|
};
|