From 8efd1a15789e8a653600e3509c2a09aa496fe4a1 Mon Sep 17 00:00:00 2001 From: IoT Manager <67171972+IoTManagerProject@users.noreply.github.com> Date: Sun, 8 Oct 2023 19:01:51 +0200 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B1=D0=B0=D0=B3=D0=B0=20=D0=BC?= =?UTF-8?q?=D0=BE=D0=B4=D1=83=D0=BB=D1=8F=20http=20get?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/exec/HttpGet/HttpGet.cpp | 65 ++++++++++------------------ 1 file changed, 22 insertions(+), 43 deletions(-) diff --git a/src/modules/exec/HttpGet/HttpGet.cpp b/src/modules/exec/HttpGet/HttpGet.cpp index 180d9099..269cedd5 100644 --- a/src/modules/exec/HttpGet/HttpGet.cpp +++ b/src/modules/exec/HttpGet/HttpGet.cpp @@ -1,18 +1,12 @@ #include "Global.h" #include "classes/IoTItem.h" -class HttpGet : public IoTItem -{ -public: - HttpGet(String parameters) : IoTItem(parameters) - { - } - - void sendHttpPOST(String url, String msg) - { - if (isNetworkActive()) - { +class HttpGet : public IoTItem { + public: + HttpGet(String parameters) : IoTItem(parameters) {} + void sendHttpPOST(String url, String msg) { + if (isNetworkActive()) { WiFiClient client; HTTPClient http; http.begin(client, url); @@ -23,26 +17,23 @@ public: SerialPrint("<-", F("HttpPOST"), "URL: " + url + ", msg: " + msg); SerialPrint("->", F("HttpPOST"), "URL: " + url + ", server: " + httpResponseCode); - if (httpResponseCode > 0) - { + if (httpResponseCode > 0) { value.valS = payload; + value.isDecimal = false; SerialPrint("->", F("HttpPOST"), "msg from server: " + (String)payload.c_str()); - value.valS = payload; regEvent(value.valS, "HttpGet"); } http.end(); } } - void sendHttpGET(String url) - { + + void sendHttpGET(String url) { WiFiClient client; HTTPClient http; #if defined ESP8266 - if (!http.begin(client, url)) - { + if (!http.begin(client, url)) { #elif defined ESP32 - if (!http.begin(url)) - { + if (!http.begin(url)) { #endif SerialPrint("I", F("HttpGet"), "connection failed "); @@ -52,31 +43,23 @@ public: String payload = http.getString(); SerialPrint("<-", F("HttpGET"), "URL: " + url); SerialPrint("->", F("HttpGET"), "URL: " + url + ", server: " + httpResponseCode); - if (httpResponseCode > 0) - { + if (httpResponseCode > 0) { value.valS = payload; + value.isDecimal = false; SerialPrint("->", F("HttpGET"), "msg from server: " + (String)payload.c_str()); - value.valS = payload; regEvent(value.valS, "HttpGet"); } http.end(); } - IoTValue execute(String command, std::vector ¶m) - { - if (param.size() > 0) - { - if (command == "get") - { - if (param.size()) - { + IoTValue execute(String command, std::vector ¶m) { + if (param.size() > 0) { + if (command == "get") { + if (param.size()) { sendHttpGET(param[0].valS); } - } - else if (command == "post") - { - if (param.size()) - { + } else if (command == "post") { + if (param.size()) { sendHttpPOST(param[0].valS, param[1].valS); } } @@ -87,14 +70,10 @@ public: ~HttpGet(){}; }; -void *getAPI_HttpGet(String subtype, String param) -{ - if (subtype == F("HttpGet")) - { +void *getAPI_HttpGet(String subtype, String param) { + if (subtype == F("HttpGet")) { return new HttpGet(param); - } - else - { + } else { return nullptr; } } \ No newline at end of file