supla-device
Loading...
Searching...
No Matches
esp_web_server.h
1/*
2 Copyright (C) AC SOFTWARE SP. Z O.O.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15*/
16
17#ifndef SRC_SUPLA_NETWORK_ESP_WEB_SERVER_H_
18#define SRC_SUPLA_NETWORK_ESP_WEB_SERVER_H_
19
20#include <supla/network/html_output_buffer.h>
21#include <supla/network/web_sender.h>
22#include <supla/network/web_server.h>
23#if defined(ESP8266)
24#include <ESP8266WebServer.h>
25#define ESPWebServer ESP8266WebServer
26#elif defined(ESP32)
27#include <WebServer.h>
28#define ESPWebServer WebServer
29#else
30#error "Missing implementation for this target"
31#endif
32
33#include <supla/element.h>
34
35namespace Supla {
36
37class EspSender : public Supla::WebSender {
38 public:
39 explicit EspSender(::ESPWebServer *req);
40 ~EspSender();
41 void send(const char *, int) override;
42
43 protected:
44 static bool flushChunk(void *context, const char *buf, int size);
45 ::ESPWebServer *reqHandler;
46 HtmlOutputBuffer outputBuffer;
47};
48
49class EspWebServer : public Supla::WebServer, public Supla::Element {
50 public:
51 explicit EspWebServer(HtmlGenerator *generator = nullptr);
52 virtual ~EspWebServer();
53 void start() override;
54 void stop() override;
55 void iterateAlways() override;
56
57 bool handlePost(bool beta = false);
58 ::ESPWebServer *getServerPtr();
59 char *getSendBufPtr() const;
60
61 bool dataSaved = false;
62
63 protected:
64 ::ESPWebServer server;
65 bool started = false;
66 char *sendBuf = nullptr;
67};
68
69}; // namespace Supla
70
71#endif // SRC_SUPLA_NETWORK_ESP_WEB_SERVER_H_
Base class for all elements of SuplaDevice.
Definition element.h:37
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition esp_web_server.cpp:252
Definition html_generator.h:35
Definition html_output_buffer.h:28
Definition web_sender.h:175
Definition web_server.h:44