Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ESP8266WiFi.h"
- #include "HTTPSRedirect.h"
- const char* ssid = "SSID";
- const char* password = "PASSWORD";
- const char* host = "script.google.com";
- const char *url = "/macros/s/ID/exec";
- const int httpsPort = 443;
- void setup() {
- Serial.begin(9600);
- WiFi.mode(WIFI_STA);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("");
- Serial.println("WiFi connected");
- Serial.println("IP address: ");
- Serial.println(WiFi.localIP());
- }
- void loop() {
- HTTPSRedirect* client = new HTTPSRedirect(httpsPort);
- client->setPrintResponseBody(false);
- client->setContentTypeHeader("application/json");
- bool flag = false;
- for (int i=0; i<5; i++){
- int retval = client->connect(host, httpsPort);
- if (retval == 1) {
- flag = true;
- break;
- }
- else
- Serial.println("Connection failed. Retrying...");
- }
- if (!flag){
- Serial.print("Could not connect to server: ");
- Serial.println(host);
- Serial.println("Exiting...");
- return;
- }
- String payload = "{}";
- client->POST(url, host, payload, false);
- String response = client->getResponseBody();
- Serial.print(response);
- delete client;
- client = nullptr;
- delay(5000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement