ESPMegaPRO-v3-SDK/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/RemoteVariable.hpp

32 lines
1.1 KiB
C++

#pragma once
#include <ESPMegaIoT.hpp>
/**
* @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.
*/
class RemoteVariable
{
public:
RemoteVariable();
~RemoteVariable();
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);
void subscribe();
void requestValue();
char* getValue();
private:
void mqtt_callback(char* topic, char* payload);
ESPMegaIoT* iot;
const char* topic;
char* value;
size_t size;
bool useValueRequest;
const char* valueRequestTopic;
bool useSetValue;
const char* setValueTopic;
};