diff --git a/code/espurna/alexa.cpp b/code/espurna/alexa.cpp index 93c8e8a7..e06d06b4 100644 --- a/code/espurna/alexa.cpp +++ b/code/espurna/alexa.cpp @@ -19,6 +19,9 @@ Copyright (C) 2016-2019 by Xose Pérez #include "web.h" #include "ws.h" +#include +#include + struct alexa_queue_element_t { unsigned char device_id; bool state; diff --git a/code/espurna/alexa.h b/code/espurna/alexa.h index 5f89d9b5..f1a4ed4a 100644 --- a/code/espurna/alexa.h +++ b/code/espurna/alexa.h @@ -12,9 +12,6 @@ Copyright (C) 2016-2019 by Xose Pérez #if ALEXA_SUPPORT -#include -#include - bool alexaEnabled(); void alexaSetup(); diff --git a/code/espurna/api.cpp b/code/espurna/api.cpp index e4d946d0..7bf76a9f 100644 --- a/code/espurna/api.cpp +++ b/code/espurna/api.cpp @@ -18,6 +18,9 @@ Copyright (C) 2016-2019 by Xose Pérez #include "web.h" #include "rpc.h" +#include +#include + struct web_api_t { explicit web_api_t(const String& key, api_get_callback_f getFn, api_put_callback_f putFn) : key(key), diff --git a/code/espurna/api.h b/code/espurna/api.h index 5350a8d9..7474b55b 100644 --- a/code/espurna/api.h +++ b/code/espurna/api.h @@ -24,9 +24,6 @@ String apiKey(); #include -#include -#include - using api_get_callback_f = std::function; using api_put_callback_f = std::function ; diff --git a/code/espurna/influxdb.cpp b/code/espurna/influxdb.cpp index bca7a8d7..354d7fc9 100644 --- a/code/espurna/influxdb.cpp +++ b/code/espurna/influxdb.cpp @@ -20,6 +20,8 @@ Copyright (C) 2017-2019 by Xose Pérez #include "ws.h" #include "libs/AsyncClientHelpers.h" +#include + const char InfluxDb_http_success[] = "HTTP/1.1 204"; const char InfluxDb_http_template[] PROGMEM = "POST /write?db=%s&u=%s&p=%s HTTP/1.1\r\nHost: %s:%u\r\nContent-Length: %d\r\n\r\n"; diff --git a/code/espurna/influxdb.h b/code/espurna/influxdb.h index 6e8e0ade..91eca82d 100644 --- a/code/espurna/influxdb.h +++ b/code/espurna/influxdb.h @@ -10,8 +10,6 @@ Copyright (C) 2017-2019 by Xose Pérez #if INFLUXDB_SUPPORT -#include - bool idbSend(const char * topic, unsigned char id, const char * payload); bool idbSend(const char * topic, const char * payload); bool idbEnabled(); diff --git a/code/espurna/libs/AsyncClientHelpers.h b/code/espurna/libs/AsyncClientHelpers.h index ed732ffc..91d43786 100644 --- a/code/espurna/libs/AsyncClientHelpers.h +++ b/code/espurna/libs/AsyncClientHelpers.h @@ -4,8 +4,6 @@ #pragma once -#include - enum class AsyncClientState { Disconnected, Connecting, diff --git a/code/espurna/mqtt.cpp b/code/espurna/mqtt.cpp index 2b5b0838..d6dadbe7 100644 --- a/code/espurna/mqtt.cpp +++ b/code/espurna/mqtt.cpp @@ -26,6 +26,17 @@ Updated secure client support by Niek van der Maas < mail at niekvandermaas dot #include "libs/AsyncClientHelpers.h" #include "libs/SecureClientHelpers.h" +#if MQTT_LIBRARY == MQTT_LIBRARY_ASYNCMQTTCLIENT + #include + #include +#elif MQTT_LIBRARY == MQTT_LIBRARY_ARDUINOMQTT + #include +#elif MQTT_LIBRARY == MQTT_LIBRARY_PUBSUBCLIENT + #include +#endif + +// ----------------------------------------------------------------------------- + #if MQTT_LIBRARY == MQTT_LIBRARY_ASYNCMQTTCLIENT AsyncMqttClient _mqtt; diff --git a/code/espurna/mqtt.h b/code/espurna/mqtt.h index b4ba6359..7ad4f479 100644 --- a/code/espurna/mqtt.h +++ b/code/espurna/mqtt.h @@ -21,15 +21,6 @@ using mqtt_msg_t = std::pair; // topic, payload #if MQTT_SUPPORT -#if MQTT_LIBRARY == MQTT_LIBRARY_ASYNCMQTTCLIENT - #include - #include -#elif MQTT_LIBRARY == MQTT_LIBRARY_ARDUINOMQTT - #include -#elif MQTT_LIBRARY == MQTT_LIBRARY_PUBSUBCLIENT - #include -#endif - void mqttRegister(mqtt_callback_f callback); String mqttTopic(const char * magnitude, bool is_set); diff --git a/code/espurna/ota.h b/code/espurna/ota.h index 713100f7..8ce6f4d1 100644 --- a/code/espurna/ota.h +++ b/code/espurna/ota.h @@ -8,9 +8,6 @@ OTA MODULE #include "espurna.h" -#include -#include - #if OTA_WEB_SUPPORT void otaWebSetup(); @@ -25,7 +22,6 @@ void arduinoOtaSetup(); #if OTA_CLIENT == OTA_CLIENT_ASYNCTCP -#include void otaClientSetup(); #endif // OTA_CLIENT == OTA_CLIENT_ASYNCTCP diff --git a/code/espurna/ota_arduinoota.cpp b/code/espurna/ota_arduinoota.cpp index 8a32ae71..61a15f97 100644 --- a/code/espurna/ota_arduinoota.cpp +++ b/code/espurna/ota_arduinoota.cpp @@ -13,6 +13,8 @@ Copyright (C) 2016-2019 by Xose Pérez #include "system.h" #include "ws.h" +#include + // TODO: allocate ArduinoOTAClass on-demand, stop using global instance void _arduinoOtaConfigure() { diff --git a/code/espurna/ota_asynctcp.cpp b/code/espurna/ota_asynctcp.cpp index abf46d01..0bc92cdb 100644 --- a/code/espurna/ota_asynctcp.cpp +++ b/code/espurna/ota_asynctcp.cpp @@ -20,7 +20,6 @@ Copyright (C) 2016-2019 by Xose Pérez #if TERMINAL_SUPPORT || OTA_MQTT_SUPPORT #include -#include #include "mqtt.h" #include "system.h" @@ -29,6 +28,10 @@ Copyright (C) 2016-2019 by Xose Pérez #include "libs/URL.h" +#include + +#include + const char OTA_REQUEST_TEMPLATE[] PROGMEM = "GET %s HTTP/1.1\r\n" "Host: %s\r\n" diff --git a/code/espurna/telnet.cpp b/code/espurna/telnet.cpp index bc3bbe13..dd3cf7a7 100644 --- a/code/espurna/telnet.cpp +++ b/code/espurna/telnet.cpp @@ -25,6 +25,56 @@ Updated to use WiFiServer and support reverse connections by Niek van der Maas < #include "board.h" #include "ws.h" +#if TELNET_SERVER == TELNET_SERVER_ASYNC + +#include + +struct AsyncBufferedClient { + public: + constexpr static const size_t BUFFERS_MAX = 5; + using buffer_t = std::vector; + + AsyncBufferedClient(AsyncClient* client); + + size_t write(char c); + size_t write(const char* data, size_t size=0); + + void flush(); + size_t available(); + + bool connect(const char *host, uint16_t port); + void close(bool now = false); + bool connected(); + + private: + void _addBuffer(); + + static void _trySend(AsyncBufferedClient* client); + static void _s_onAck(void* client_ptr, AsyncClient*, size_t, uint32_t); + static void _s_onPoll(void* client_ptr, AsyncClient* client); + + std::unique_ptr _client; + std::list _buffers; +}; + +using TTelnetServer = AsyncServer; + +#if TELNET_SERVER_ASYNC_BUFFERED + using TTelnetClient = AsyncBufferedClient; +#else + using TTelnetClient = AsyncClient; +#endif // TELNET_SERVER_ASYNC_BUFFERED + +#elif TELNET_SERVER == TELNET_SERVER_WIFISERVER + +using TTelnetServer = WiFiServer; +using TTelnetClient = WiFiClient; + +#else +#error "TELNET_SERVER value was not properly set" +#endif + + TTelnetServer _telnetServer(TELNET_PORT); std::unique_ptr _telnetClients[TELNET_MAX_CLIENTS]; diff --git a/code/espurna/telnet.h b/code/espurna/telnet.h index a9c13182..5756d623 100644 --- a/code/espurna/telnet.h +++ b/code/espurna/telnet.h @@ -16,55 +16,6 @@ Copyright (C) 2017-2019 by Xose Pérez #include #include -#if TELNET_SERVER == TELNET_SERVER_ASYNC - -#include - -struct AsyncBufferedClient { - public: - constexpr static const size_t BUFFERS_MAX = 5; - using buffer_t = std::vector; - - AsyncBufferedClient(AsyncClient* client); - - size_t write(char c); - size_t write(const char* data, size_t size=0); - - void flush(); - size_t available(); - - bool connect(const char *host, uint16_t port); - void close(bool now = false); - bool connected(); - - private: - void _addBuffer(); - - static void _trySend(AsyncBufferedClient* client); - static void _s_onAck(void* client_ptr, AsyncClient*, size_t, uint32_t); - static void _s_onPoll(void* client_ptr, AsyncClient* client); - - std::unique_ptr _client; - std::list _buffers; -}; - -using TTelnetServer = AsyncServer; - -#if TELNET_SERVER_ASYNC_BUFFERED - using TTelnetClient = AsyncBufferedClient; -#else - using TTelnetClient = AsyncClient; -#endif // TELNET_SERVER_ASYNC_BUFFERED - -#elif TELNET_SERVER == TELNET_SERVER_WIFISERVER - -using TTelnetServer = WiFiServer; -using TTelnetClient = WiFiClient; - -#else -#error "TELNET_SERVER value was not properly set" -#endif - constexpr unsigned char TELNET_IAC = 0xFF; constexpr unsigned char TELNET_XEOF = 0xEC; diff --git a/code/espurna/web.cpp b/code/espurna/web.cpp index 0b0ecfde..7d35950e 100644 --- a/code/espurna/web.cpp +++ b/code/espurna/web.cpp @@ -14,12 +14,19 @@ Copyright (C) 2016-2019 by Xose Pérez #include #include -#include - #include "system.h" #include "utils.h" #include "ntp.h" +#include +#include +#include +#include + +#include +#include +#include + #if WEB_EMBEDDED #if WEBUI_IMAGE == WEBUI_IMAGE_SMALL diff --git a/code/espurna/web.h b/code/espurna/web.h index fb5995d4..96a31b1b 100644 --- a/code/espurna/web.h +++ b/code/espurna/web.h @@ -16,13 +16,7 @@ Copyright (C) 2016-2019 by Xose Pérez #include #include -#include -#include #include -#include -#include -#include -#include struct AsyncWebPrintConfig { const char* const mimeType;