Обновление GoogleSheet

This commit is contained in:
Mit4el
2023-07-08 00:15:40 +03:00
parent cb969e75b9
commit af0f7a219b
2 changed files with 23 additions and 22 deletions

View File

@@ -2,8 +2,6 @@
#include "Global.h"
#include "classes/IoTItem.h"
String URL = F("https://script.google.com/macros/s/");
class GoogleSheet : public IoTItem
{
private:
@@ -14,7 +12,10 @@ private:
// bool init = false;
int interval = 1;
// long interval;
String URL = ("http://iotmanager.org/projects/google.php?/macros/s/"); // F("https://script.google.com/macros/s/");
String urlFinal;
HTTPClient http;
WiFiClient client;
public:
GoogleSheet(String parameters) : IoTItem(parameters)
@@ -101,30 +102,29 @@ public:
if (!send)
return; // Не отправляем просто накапливаем данные
/* if (!init)
{
init = true;
urlFinal = urlFinal + "&init=1";
}
*/
HTTPClient http;
/* if (!init)
{
init = true;
urlFinal = urlFinal + "&init=1";
}
*/
// HTTPClient http;
#if defined ESP8266
WiFiClientSecure client;
client.setInsecure();
// WiFiClient client;
// client.setInsecure();
if (!http.begin(client, urlFinal))
{
#elif defined ESP32
WiFiClient client;
// WiFiClient client;
if (!http.begin(urlFinal))
{
#endif
{
SerialPrint("I", F("GoogleSheet"), F("connection failed"));
}
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS); // HTTPC_STRICT_FOLLOW_REDIRECTS HTTPC_FORCE_FOLLOW_REDIRECTS
// http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS); // HTTPC_STRICT_FOLLOW_REDIRECTS HTTPC_FORCE_FOLLOW_REDIRECTS
http.addHeader(F("Content-Type"), F("application/x-www-form-urlencoded"));
int httpCode = http.GET();
// String payload = http.getString();
String payload = http.getString();
SerialPrint("<-", F("GoogleSheet"), "URL: " + urlFinal);
SerialPrint("->", F("GoogleSheet"), "server: " + (String)httpCode); /*"URL: " + urlFinal + */
@@ -133,7 +133,7 @@ public:
SerialPrint("->", F("GoogleSheet"), "msg from server: " + (String)payload.c_str());
}
*/
http.end();
// http.end();
// Обнуляем данные в запросе, так как все отправили
urlFinal = URL + scid + F("/exec?") + F("sheet=") + shname;
};
@@ -153,7 +153,7 @@ public:
return nullptr;
};
~GoogleSheet(){};
~GoogleSheet() { http.end(); };
};
void *getAPI_GoogleSheet(String subtype, String param)

View File

@@ -12,7 +12,7 @@
"descr": "",
"int": 5,
"logid": "",
"scid": "Script_ID",
"scid": "",
"shname": "Logger"
}
],
@@ -21,7 +21,7 @@
"authorContact": "https://t.me/Mit4bmw",
"authorGit": "https://github.com/Mit4el",
"exampleURL": "https://iotmanager.org/wiki",
"specialThanks": "",
"specialThanks": "@AVAKS",
"moduleName": "GoogleSheet",
"moduleVersion": "1.0",
"usedRam": {
@@ -40,7 +40,7 @@
"funcInfo": [
{
"name": "logGoogle",
"descr": "Использовать не чаще раз в минуту! Логирование элементов по их идентификатору в GoogleSheet, указывать через запятую, от одного до N (проверено на 16шт)",
"descr": "Использовать не чаще раз в минуту! Логирование элементов в GoogleSheet, ID элементов указывать через запятую, от одного до N (проверено на 16шт). В данной функции поиск элементов идет по их значению, если несколько элементов с одинаковым значение, может быть не правильно указан его id в Таблице.",
"params": [
"id Идентификатор 1-го элеменета",
"id Идентификатор N-го элеменета"
@@ -59,6 +59,7 @@
"defActive": false,
"usedLibs": {
"esp32_4mb": [],
"esp32s2_4mb": []
"esp32s2_4mb": [],
"esp8266_4mb": []
}
}