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

32 lines
1.1 KiB
C++
Raw Normal View History

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();
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;
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;
const char* valueRequestTopic;
2024-01-16 05:48:06 +00:00
bool useSetValue;
const char* setValueTopic;
2024-01-16 04:22:41 +00:00
};