SensESP 2.7.2
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
signalk_put_request.h
Go to the documentation of this file.
1#ifndef _signalk_put_request_H_
2#define _signalk_put_request_H_
3
4#include <ArduinoJson.h>
5
6#include <functional>
7#include <map>
8
11
12namespace sensesp {
13
20class SKRequest {
21 public:
35 std::function<void(DynamicJsonDocument&)> callback,
36 uint32_t timeout = 5000);
37
43
44 protected:
53
56 static std::map<String, PendingRequest*> request_map;
57
60 static void remove_request(String request_id);
61
64 static PendingRequest* get_request(String request_id);
65};
66
75class SKPutRequestBase : public SKRequest, public Configurable {
76 public:
85 uint32_t timeout = 5000);
86
87 // For reading and writing the configuration
88 virtual void get_configuration(JsonObject& doc) override;
89 virtual bool set_configuration(const JsonObject& config) override;
90 virtual String get_config_schema() override;
91
96
102 bool request_pending();
103
104 protected:
108 void send_put_request();
109
115
121
125};
126
133template <typename T>
134class SKPutRequest : public SKPutRequestBase, public ValueConsumer<T> {
135 public:
149
150 virtual void set_input(T new_value, uint8_t input_channel = 0) override {
152 return;
153 }
154 if (!request_pending()) {
155 this->value = new_value;
157 } else {
158 debugW("Ignoring PUT request (previous request still outstanding)");
159 }
160 };
161
162 virtual void set_put_value(JsonObject& put_data) override {
163 put_data["value"] = value;
164 };
165
166 protected:
169};
170
175
176} // namespace sensesp
177
178#endif
An object that is capable of having configuration data that can be set remotely using a RESTful API,...
Construct a new transform based on a single function.
A base class for all template variations of the PUT request class SKPutRequest. This base class keeps...
virtual void set_put_value(JsonObject &put_data)=0
virtual bool set_configuration(const JsonObject &config) override
virtual String get_config_schema() override
virtual void get_configuration(JsonObject &doc) override
virtual void on_response(DynamicJsonDocument &response)
Used to send requests to the server to change the value of the specified path to a specific value acc...
virtual void set_input(T new_value, uint8_t input_channel=0) override
SKPutRequest(String sk_path, String config_path="", bool ignore_duplicates=true, uint32_t timeout=5000)
virtual void set_put_value(JsonObject &put_data) override
std::function< void(DynamicJsonDocument &)> callback
A base class for all objects that are capable of sending "requests" to the SignalK server (and option...
static void handle_response(DynamicJsonDocument &response)
static std::map< String, PendingRequest * > request_map
static String send_request(DynamicJsonDocument &request, std::function< void(DynamicJsonDocument &)> callback, uint32_t timeout=5000)
static PendingRequest * get_request(String request_id)
static void remove_request(String request_id)
A base class for piece of code (like a transform) that accepts data for input. ValueConsumers can acc...
#define debugW(fmt,...)
Definition local_debug.h:49
SKPutRequest< int > IntSKPutRequest
SKPutRequest< bool > BoolSKPutRequest
SKPutRequest< float > FloatSKPutRequest
SKPutRequest< String > StringSKPutRequest