From f8de34fb974cae0c8d8048a7766e29b876adf9e8 Mon Sep 17 00:00:00 2001 From: Mit4el Date: Mon, 22 May 2023 20:28:16 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=BE=D0=B4=D1=83=D0=BB=D1=8C=20GoogleSh?= =?UTF-8?q?eet,=20=D0=A3=D1=82=D0=BE=D1=87=D0=BD=D0=B8=D0=BB=20=D0=BF?= =?UTF-8?q?=D0=BB=D0=B0=D1=82=D1=84=D0=BE=D1=80=D0=BC=D1=83=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20esp=5F2mb?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_svelte/myProfile.json | 4 + myProfile.json | 4 + platformio.ini | 4 +- src/modules/sensors/A02Distance/modinfo.json | 2 +- src/modules/sensors/Acs712/modinfo.json | 2 +- .../virtual/GoogleSheet/GoogleSheet.cpp | 89 +++++++++++++++++++ src/modules/virtual/GoogleSheet/modinfo.json | 51 +++++++++++ 7 files changed, 152 insertions(+), 4 deletions(-) create mode 100644 src/modules/virtual/GoogleSheet/GoogleSheet.cpp create mode 100644 src/modules/virtual/GoogleSheet/modinfo.json diff --git a/data_svelte/myProfile.json b/data_svelte/myProfile.json index 7432922b..0afa0549 100644 --- a/data_svelte/myProfile.json +++ b/data_svelte/myProfile.json @@ -34,6 +34,10 @@ "path": "src/modules/virtual/Cron", "active": true }, + { + "path": "src/modules/virtual/GoogleSheet", + "active": false + }, { "path": "src/modules/virtual/Loging", "active": true diff --git a/myProfile.json b/myProfile.json index 7432922b..0afa0549 100644 --- a/myProfile.json +++ b/myProfile.json @@ -34,6 +34,10 @@ "path": "src/modules/virtual/Cron", "active": true }, + { + "path": "src/modules/virtual/GoogleSheet", + "active": false + }, { "path": "src/modules/virtual/Loging", "active": true diff --git a/platformio.ini b/platformio.ini index 7f1d6593..18a9163f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -79,7 +79,7 @@ build_flags = -Desp8266_2mb="esp8266_2mb" framework = arduino board = d1_wroom_02 board_build.ldscript = eagle.flash.2m1m.ld -platform = espressif8266 +platform = espressif8266 @4.2.0 monitor_filters = esp8266_exception_decoder upload_speed = 921600 monitor_speed = 115200 @@ -100,7 +100,7 @@ build_flags = -Desp8266_2mb_ota="esp8266_2mb_ota" framework = arduino board = d1_wroom_02 board_build.ldscript = eagle.flash.2m256.ld -platform = espressif8266 +platform = espressif8266 @4.2.0 monitor_filters = esp8266_exception_decoder upload_speed = 921600 monitor_speed = 115200 diff --git a/src/modules/sensors/A02Distance/modinfo.json b/src/modules/sensors/A02Distance/modinfo.json index 2bee177d..bc6a494a 100644 --- a/src/modules/sensors/A02Distance/modinfo.json +++ b/src/modules/sensors/A02Distance/modinfo.json @@ -15,7 +15,7 @@ ], "about": { "authorName": "Bubnov Mikhail", - "authorContact": "https://t.me/Mitchel", + "authorContact": "https://t.me/Mit4bmw", "authorGit": "https://github.com/Mit4el", "exampleURL": "https://iotmanager.org/wiki", "specialThanks": "", diff --git a/src/modules/sensors/Acs712/modinfo.json b/src/modules/sensors/Acs712/modinfo.json index a3540924..5a38c88b 100644 --- a/src/modules/sensors/Acs712/modinfo.json +++ b/src/modules/sensors/Acs712/modinfo.json @@ -21,7 +21,7 @@ ], "about": { "authorName": "Bubnov Mikhail", - "authorContact": "https://t.me/Mitchel", + "authorContact": "https://t.me/Mit4bmw", "authorGit": "https://github.com/Mit4el", "exampleURL": "https://iotmanager.org/wiki", "specialThanks": "", diff --git a/src/modules/virtual/GoogleSheet/GoogleSheet.cpp b/src/modules/virtual/GoogleSheet/GoogleSheet.cpp new file mode 100644 index 00000000..dcf446cb --- /dev/null +++ b/src/modules/virtual/GoogleSheet/GoogleSheet.cpp @@ -0,0 +1,89 @@ + +#include "Global.h" +#include "classes/IoTItem.h" + +String URL = "https://script.google.com/macros/s/"; +long interval; + +class GoogleSheet : public IoTItem +{ +private: + String id; + String logid; + String scid = ""; + String shname = ""; + bool init = false; +public: + GoogleSheet(String parameters) : IoTItem(parameters) + { + jsonRead(parameters, F("id"), id); + jsonRead(parameters, F("logid"), logid); + jsonRead(parameters, F("scid"), scid); + jsonRead(parameters, F("shname"), shname); + jsonRead(parameters, F("int"), interval); + interval = interval * 1000 * 60; // приводим к милисекундам + } + + void doByInterval() + { + if (WiFi.status() == WL_CONNECTED) + { + String value = getItemValue(logid); + String urlFinal = URL + scid + "/exec?"+"sheet=" + shname + "&id=" + logid + "&value=" + value; + if (!init){ init=true; urlFinal = urlFinal + "&init=1";} + + HTTPClient http; +#if defined ESP8266 + WiFiClientSecure client; + client.setInsecure(); + if (!http.begin(client, urlFinal)) + { +#elif defined ESP32 + WiFiClient client; + if (!http.begin(urlFinal)) + { +#endif + SerialPrint("I", F("GoogleSheet"), "connection failed "); + } + http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS); + http.addHeader("Content-Type", "application/x-www-form-urlencoded"); + int httpCode = http.GET(); + String payload = http.getString(); + SerialPrint("<-", F("GoogleSheet"), "URL: " + urlFinal); + SerialPrint("->", F("GoogleSheet"), "URL: " + urlFinal + ", server: " + httpCode); + if (httpCode > 0) + { + SerialPrint("->", F("GoogleSheet"), "msg from server: " + (String)payload.c_str()); + } + http.end(); + } + } + + void loop() + { + if (enableDoByInt) + { + currentMillis = millis(); + difference = currentMillis - prevMillis; + if (difference >= interval) + { + prevMillis = millis(); + this->doByInterval(); + } + } + } + ~GoogleSheet(){}; +}; + +void *getAPI_GoogleSheet(String subtype, String param) +{ + + if (subtype == F("GoogleSheet")) + { + return new GoogleSheet(param); + } + else + { + return nullptr; + } +} diff --git a/src/modules/virtual/GoogleSheet/modinfo.json b/src/modules/virtual/GoogleSheet/modinfo.json new file mode 100644 index 00000000..d6fb0c8d --- /dev/null +++ b/src/modules/virtual/GoogleSheet/modinfo.json @@ -0,0 +1,51 @@ +{ + "menuSection": "Виртуальные элементы", + "configItem": [ + { + "global": 0, + "name": "GoogleSheet", + "type": "Reading", + "subtype": "GoogleSheet", + "id": "sheet", + "widget": "nil", + "page": "", + "descr": "", + "int": 5, + "logid": "id", + "scid": "Script_ID", + "shname": "Logger" + } + ], + "about": { + "authorName": "Bubnov Mikhail", + "authorContact": "https://t.me/Mit4bmw", + "authorGit": "https://github.com/Mit4el", + "exampleURL": "https://iotmanager.org/wiki", + "specialThanks": "", + "moduleName": "GoogleSheet", + "moduleVersion": "1.0", + "usedRam": { + "esp32_4mb": 10, + "esp8266_4mb": 10 + }, + "title": "Логирование в Google таблицы", + "moduleDesc": "Расширение позволяющее логировать любую величину в Google таблицы. Инструкция https://drive.google.com/file/d/1VuI06arObNfH3rsOSHKww1tyhfgqXd9F/view?usp=sharing", + "propInfo": { + "int": "Интервал логирования в минутах", + "logid": "ID величины которую будем логировать", + "scid": "Идентификатор развертывания Google Apps (script id)", + "shname": "Наименование листа в таблице (sheet name)" + } + }, + "defActive": false, + "usedLibs": { + "esp32_4mb": [], + "esp8266_4mb": [], + "esp8266_1mb": [], + "esp8266_1mb_ota": [], + "esp8285_1mb": [], + "esp8285_1mb_ota": [], + "esp8266_2mb": [], + "esp8266_2mb_ota": [] + } +} \ No newline at end of file