Title: "Error! Not connected to host." when using ISR · Issue #8 · StorageB/Google-Sheets-Logging · GitHub
Open Graph Title: "Error! Not connected to host." when using ISR · Issue #8 · StorageB/Google-Sheets-Logging
X Title: "Error! Not connected to host." when using ISR · Issue #8 · StorageB/Google-Sheets-Logging
Description: Hey, I'm trying to create a kind of stopwatch and for the best responsibility, I use an interrupt, from which the subroutine to send the data is called. (When I was trying the raw example it worked and I used as much as I could from the ...
Open Graph Description: Hey, I'm trying to create a kind of stopwatch and for the best responsibility, I use an interrupt, from which the subroutine to send the data is called. (When I was trying the raw example it worked...
X Description: Hey, I'm trying to create a kind of stopwatch and for the best responsibility, I use an interrupt, from which the subroutine to send the data is called. (When I was trying the raw example it wo...
Opengraph URL: https://github.com/StorageB/Google-Sheets-Logging/issues/8
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"\"Error! Not connected to host.\" when using ISR","articleBody":"Hey, \r\nI'm trying to create a kind of stopwatch and for the best responsibility, I use an interrupt, from which the subroutine to send the data is called.\r\n(When I was trying the raw example it worked and I used as much as I could from the example)\r\nAccording to the serial monitor, the values of my variables seem to be taken along correctly, but when the payload should get posted, it didn't work, and I got this response:\r\n```\r\nPublishing data...\r\n{\"command\": \"insert_row\", \"sheet_name\": \"Tabellenblatt1\", \"values\": \"4,406571,408355\"}\r\nError! Not connected to host.\r\nError while connecting\r\n```\r\nThis is my code: \r\n```\r\n#include \u003cArduino.h\u003e\r\n#include \u003cESP8266WiFi.h\u003e\r\n#include \"HTTPSRedirect.h\"\r\n\r\n#define ON_Board_LED 2\r\n#define BUTTON_PIN 0\r\n\r\nconst char* ssid = \"myWiFi\";\r\nconst char* password = \"myPW\";\r\nconst char *GScriptId = \"my Script-ID\";\r\n\r\n// Enter command (insert_row or append_row) and your Google Sheets sheet name (default is Sheet1):\r\nString payload_base = \"{\\\"command\\\": \\\"insert_row\\\", \\\"sheet_name\\\": \\\"Tabellenblatt1\\\", \\\"values\\\": \";\r\nString payload = \"\";\r\n\r\n// Google Sheets setup (do not edit)\r\nconst char* host = \"script.google.com\";\r\nconst int httpsPort = 443;\r\nconst char* fingerprint = \"\";\r\nString url = String(\"/macros/s/\") + GScriptId + \"/exec\";\r\nHTTPSRedirect* client = nullptr;\r\n\r\n// Declare variables that will be published to Google Sheets\r\nvolatile int run = 0;\r\nvolatile uint64_t time_start = 0;\r\nvolatile uint64_t time_finish = 0;\r\n\r\nvolatile bool running = false;\r\nvolatile uint64_t last_isr;\r\n\r\nvoid ICACHE_RAM_ATTR ISR() {\r\n if (millis() - last_isr \u003e 500) { //bounce-filter\r\n if (!running) {\r\n time_start = millis();\r\n running = true;\r\n last_isr = millis();\r\n } else {\r\n time_finish = millis();\r\n running = false;\r\n run++;\r\n last_isr = millis();\r\n sendData(run, time_start, time_finish);\r\n }\r\n }\r\n}\r\n\r\nvoid setup() {\r\n Serial.begin(9600); \r\n delay(10);\r\n Serial.println('\\n');\r\n \r\n // Connect to WiFi\r\n WiFi.begin(ssid, password); \r\n Serial.print(\"Connecting to \");\r\n Serial.print(ssid); Serial.println(\" ...\");\r\n while (WiFi.status() != WL_CONNECTED) {\r\n delay(1000);\r\n Serial.print(\".\");\r\n }\r\n Serial.println('\\n');\r\n Serial.println(\"Connection established!\"); \r\n Serial.print(\"IP address:\\t\");\r\n Serial.println(WiFi.localIP());\r\n\r\n // Use HTTPSRedirect class to create a new TLS connection\r\n client = new HTTPSRedirect(httpsPort);\r\n client-\u003esetInsecure();\r\n client-\u003esetPrintResponseBody(true);\r\n client-\u003esetContentTypeHeader(\"application/json\");\r\n Serial.print(\"Connecting to \");\r\n Serial.println(host);\r\n\r\n // Try to connect for a maximum of 5 times\r\n bool flag = false;\r\n for (int i=0; i\u003c5; i++){ \r\n int retval = client-\u003econnect(host, httpsPort);\r\n if (retval == 1){\r\n flag = true;\r\n Serial.println(\"Connected\");\r\n break;\r\n }\r\n else\r\n Serial.println(\"Connection failed. Retrying...\");\r\n }\r\n if (!flag){\r\n Serial.print(\"Could not connect to server: \");\r\n Serial.println(host);\r\n return;\r\n }\r\n delete client; // delete HTTPSRedirect object\r\n client = nullptr; // delete HTTPSRedirect object\r\n\r\n pinMode(ON_Board_LED,OUTPUT); //--\u003e On Board LED port Direction output\r\n digitalWrite(ON_Board_LED, HIGH); //--\u003e Turn off Led On Board\r\n attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), ISR, FALLING);\r\n}\r\n\r\nvoid loop() {\r\n if (running) {\r\n digitalWrite(ON_Board_LED, LOW);\r\n } else {\r\n digitalWrite(ON_Board_LED, HIGH);\r\n }\r\n}\r\n\r\nvoid sendData(int run, uint64_t time_star, uint64_t time_finish) {\r\n static bool flag = false;\r\n if (!flag){\r\n client = new HTTPSRedirect(httpsPort);\r\n client-\u003esetInsecure();\r\n flag = true;\r\n client-\u003esetPrintResponseBody(true);\r\n client-\u003esetContentTypeHeader(\"application/json\");\r\n }\r\n if (client != nullptr){\r\n if (!client-\u003econnected()){\r\n client-\u003econnect(host, httpsPort);\r\n }\r\n }\r\n else{\r\n Serial.println(\"Error creating client object!\");\r\n }\r\n \r\n // Create json object string to send to Google Sheets\r\n payload = payload_base + \"\\\"\" + run + \",\" + time_start + \",\" + time_finish + \"\\\"}\";\r\n \r\n // Publish data to Google Sheets\r\n Serial.println(\"Publishing data...\");\r\n Serial.println(payload);\r\n if(client-\u003ePOST(url, host, payload)){ \r\n // do stuff here if publish was successful\r\n }\r\n else{\r\n // do stuff here if publish was not successful\r\n Serial.println(\"Error while connecting\");\r\n }\r\n}\r\n```\r\nI'm grateful for any advice on a better solution, thanks\r\n\r\nHardware: Wemos D1 mini","author":{"url":"https://github.com/franz134","@type":"Person","name":"franz134"},"datePublished":"2022-11-22T15:55:26.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/8/Google-Sheets-Logging/issues/8"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:6b9ac163-0959-4432-bcd3-3a86c2192dc1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ACF6:6C38E:4E1EB7:6EFE48:6A4BCBD1 |
| html-safe-nonce | 07e589bdaa2ed1044d708a62d4756e7a7bf056a5c12beb972f87d6fe13ed7a69 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQ0Y2OjZDMzhFOjRFMUVCNzo2RUZFNDg6NkE0QkNCRDEiLCJ2aXNpdG9yX2lkIjoiNDI2NzYxMDcwMTE1OTk3NTg5MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d14b3c5ec013732ca4ecdc1a24cf78e6dbd78c71db43ac244eeb17bdab4676bd |
| hovercard-subject-tag | issue:1460133939 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/StorageB/Google-Sheets-Logging/8/issue_layout |
| twitter:image | https://opengraph.githubassets.com/eef930ffbac67abb9df6d0a5d0bca044604fd05f695392a772283c2f4d9e4ef5/StorageB/Google-Sheets-Logging/issues/8 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/eef930ffbac67abb9df6d0a5d0bca044604fd05f695392a772283c2f4d9e4ef5/StorageB/Google-Sheets-Logging/issues/8 |
| og:image:alt | Hey, I'm trying to create a kind of stopwatch and for the best responsibility, I use an interrupt, from which the subroutine to send the data is called. (When I was trying the raw example it worked... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | franz134 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 14aa00ce5bdb34d0eefb5facbffd7de9e144c688d8a93ef8df902d5f94b51dd7 |
| turbo-cache-control | no-preview |
| go-import | github.com/StorageB/Google-Sheets-Logging git https://github.com/StorageB/Google-Sheets-Logging.git |
| octolytics-dimension-user_id | 44729718 |
| octolytics-dimension-user_login | StorageB |
| octolytics-dimension-repository_id | 257144994 |
| octolytics-dimension-repository_nwo | StorageB/Google-Sheets-Logging |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 257144994 |
| octolytics-dimension-repository_network_root_nwo | StorageB/Google-Sheets-Logging |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 58b8f89190447502561829f30862aa0a99d53367 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width