my friend made a google script, and gave me this link: https://script.google.com/macros/s/AKfycbxxWwU59sp_rF9C6phVIFSdLF6IIM83hFRWUrrJyVI8TdY6F-t1/exec
If you click you will se "52" in your browser. Now I want to create a script in Arduino that can receive this value and use it in order to adjust the amount of light of a LED (code below is without LED part).
I wrote a code:
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiClientSecure.h>
const char* ssid = "TabletS3";
const char* password = "123456789";
//https://script.google.com/macros/s/AKfycbxxWwU59sp_rF9C6phVIFSdLF6IIM83hFRWUrrJyVI8TdY6F-t1/exec
WiFiServer server(80);
//String GAS_ID = "AKfycbxxWwU59sp_rF9C6phVIFSdLF6IIM83hFRWUrrJyVI8TdY6F-t1"; // Replace by your GAS service id
const char* host = "script.google.com";
const int httpsPort = 443;
const char* fingerprint = "46 B2 C3 44 9C 59 09 8B 01 B6 F8 BD 4C FB 00 74 91 2F EF F6";
WiFiClientSecure client;
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
}
void loop() {
String url = "https://script.google.com/macros/s/AKfycbxxWwU59sp_rF9C6phVIFSdLF6IIM83hFRWUrrJyVI8TdY6F-t1/exec";
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
//"User-Agent: BuildFailureDetectorESP8266\r\n" +
"Connection: close\r\n\r\n");
Serial.println("Response:");
while (client.connected())
{
String line = client.readStringUntil('\r');
Serial.print(line);
client.flush();
}
delay(10000);
}
but I can't read value "52" on Serial Monitor. Where is the mistake?
Thanks in advance, RR
After your insight I tried this:
#include <ESP8266WiFi.h>
//#include <DNSServer.h>
//#include <ESP8266WebServer.h>
//#include <WiFiClientSecure.h>
const char* ssid = "TabletS3";
const char* password = "123456789";
//https://script.google.com/macros/s/AKfycbxxWwU59sp_rF9C6phVIFSdLF6IIM83hFRWUrrJyVI8TdY6F-t1/exec
//WiFiServer server(80);
//String GAS_ID = "AKfycbxxWwU59sp_rF9C6phVIFSdLF6IIM83hFRWUrrJyVI8TdY6F-t1"; // Replace by your GAS service id
const char* host = "script.google.com";
const int httpsPort = 443;
const char* fingerprint = "46 B2 C3 44 9C 59 09 8B 01 B6 F8 BD 4C FB 00 74 91 2F EF F6";
WiFiClientSecure client;
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
}
void loop() {
String url = "https://script.google.com/macros/s/AKfycbxxWwU59sp_rF9C6phVIFSdLF6IIM83hFRWUrrJyVI8TdY6F-t1/exec";
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"User-Agent: BuildFailureDetectorESP8266\r\n" +
"Connection: close\r\n\r\n");
Serial.println("request sent");
while (client.connected()) {
String line = client.readStringUntil('\n');
if (line == "\r") {
Serial.println("headers received");
break;
}
}
String line = client.readStringUntil('\n');
if (line.startsWith("{\"state\":\"success\"")) {
Serial.println("esp8266/Arduino CI successfull!");
} else {
Serial.println("esp8266/Arduino CI has failed");
}
Serial.println("reply was:");
Serial.println("==========");
Serial.println(line);
Serial.println("==========");
Serial.println("closing connection");
delay(10000);
}
But doesn't catch nothing