1

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

15
  • It's not possible to open that link, please provide the Apps Script code as part of your question Commented Jan 23, 2020 at 11:45
  • The link is private and needs a Google account. Ask your friend to publish the web app as "Anyone, even anonymous" can access. Else you'd need your arduino to handle oauth and send authorization headers. Commented Jan 23, 2020 at 12:24
  • you didn't call client.connect. after GET goes only the url without host and port. remove all includes except of #include <ESP8266WiFi.h>. delete WiFiServer server(80); Commented Jan 23, 2020 at 12:26
  • @albertovielma, excuse me, the link is now working. Sorry, my mistake Commented Jan 23, 2020 at 15:56
  • @Juraj, as you see I tried your suggestion (I added the code in the main question) but doesn't work. Any idea? Commented Jan 24, 2020 at 7:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.