Read Value from URL with ESP8266

Hi everyone, my friend made a google script, and gave me this link:

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>   
char ssid[] = "TabletS3";
char password[] = "123456789";
String line =" ";
String url = "";
char url2[] = "";
const char* host = "";

//WiFiClientSecure client;
WiFiClient client;

void setup() {

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {


void loop() {

  if (client.connect(url2,80)) {
    client.println(String("GET ") + url);
    //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");

    line = client.readString();


The Serial print this html indeed of “52”:

HTTP/1.0 400 Bad Request
Content-Type: text/html; charset=UTF-8
Referrer-Policy: no-referrer
Content-Length: 1555
Date: Fri, 24 Jan 2020 15:41:32 GMT

<!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 400 (Bad Request)!!1</title>
    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(// 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(// no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(// no-repeat 0% 0%/100% 100%;-moz-border-image:url(// 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(// no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
  <a href=//><span id=logo aria-label=Google></span></a>
  <p><b>400.</b> <ins>That’s an error.</ins>
  <p>Your client has issued a malformed or illegal request.  <ins>That’s all we know.</ins>

Do I gather that you want to convert the test in the line String into an integer ?

If so, then the String toInt() function will do what you say you want. If that is not what you want then please explain what you want to do

I think there is a mistake in the script because it never return value 52 (or String), it return instead an html that correspond to an error (is reported in the question above)

The key to your issue "Error 400 (Bad Request)!!" is probably the "s" in the below. You might find info in the ESP8266 HTTPS example codes.


Thanks for the answer, following the example I tried this:

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>

const char* ssid = "Riccardo";
const char* password = "Ciao1234";

const char* host = "";
const int httpsPort = 443;

// Use web browser to view and copy
// SHA1 fingerprint of the certificate
const char* fingerprint = "CF 05 98 89 CA FF 8E D8 5E 5C E0 C2 E4 F7 E6 C3 C7 50 DD 5C";

void setup() {
  Serial.print("connecting to ");
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
  Serial.println("WiFi connected");
  Serial.println("IP address: ");

  // Use WiFiClientSecure class to create TLS connection
  WiFiClientSecure client;
  Serial.print("connecting to ");
  if (!client.connect(host, httpsPort)) {
    Serial.println("connection failed");

  if (client.verify(fingerprint, host)) {
    Serial.println("certificate matches");
  } else {
    Serial.println("certificate doesn't match");

  String url = "/macros/s/AKfycbxxWwU59sp_rF9C6phVIFSdLF6IIM83hFRWUrrJyVI8TdY6F-t1/exec";
  Serial.print("requesting URL: ");

  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");
  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("closing connection");

void loop() {

but I received this answer:

connecting to Riccardo
WiFi connected
IP address:
connecting to
certificate doesn't match
requesting URL: /macros/s/AKfycbxxWwU59sp_rF9C6phVIFSdLF6IIM83hFRWUrrJyVI8TdY6F-t1/exec
request sent
headers received
esp8266/Arduino CI has failed
reply was:
closing connection

I did’t change fingerprint, I left the example one
Can’t see never “52”
Any idea?