# ESP8266 not connecting to script.google.com

**URL:** <https://forum.arduino.cc/t/esp8266-not-connecting-to-script-google-com/581148>\
**Category:** Programming\
**Created:** [March 21, 2019, 1:53pm UTC](https://forum.arduino.cc/t/esp8266-not-connecting-to-script-google-com/581148 "2019-03-21T13:53:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![SwarlatDee](https://avatars.discourse-cdn.com/v4/letter/s/5fc32e/32.png) [@SwarlatDee](https://forum.arduino.cc/u/SwarlatDee)\
**Post date:** [March 21, 2019, 1:53pm UTC](https://forum.arduino.cc/t/esp8266-not-connecting-to-script-google-com/581148/1 "2019-03-21T13:53:12Z")

</div>

Hello, many thanks for your insight.

I have a project with ESP8266

I am trying to log some sensor data from my Arduino + ultrasonic Sensor to google spreadsheet.

I'm using Arduino uno+ LOLIN(WEMOS) D1 R2 Mini Board as my ESP8266 wifi module.

I am using my mobile hotspot to connect to the internet but it keeps telling me "connection failed" meaning it doesn't connect to [script.google.com](http://script.google.com).

It connects to the internet and gives me an IP but doesn't connect to [script.google.com](http://script.google.com)

Can anyone in the house look at my Arduino code and see if you can help me, please.

This is my arduino code

```cpp
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <WiFiClient.h>
#include <Servo.h>  //servo library

#define trigPin A5
#define echoPin A4

Servo myservo;      

const char* ssid = "<my ssid>";    
const char* password = "<my password>";     
const char* host = "script.google.com";
const int httpsPort = 443;
// Use WiFiClientSecure class to create TLS connection
WiFiClientSecure client;
// SHA1 fingerprint of the certificate, don't care with your GAS service
const char* fingerprint = "46 B2 C3 44 9C 59 09 8B 01 B6 F8 BD 4C FB 00 74 91 2F EF F6";
String GAS_ID = "AKfycbwBPnixqq0_-wXyuMImLLKN0QvtnR3peWpFbifYFkWue_BagmrC";  // Replace by your GAS service id          !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

int trigPin = A5; 
int echoPin = A4; 
float pingTime;  
float targetDistance; 
float speedOfSound = 343; 

void setup()
{

  Serial.begin(115200);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  

  //connecting to internet
  Serial.print("connecting to ");
  Serial.println(ssid);
  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()
{
  digitalWrite(trigPin, LOW); 
  delayMicroseconds(2000); 
  digitalWrite(trigPin, HIGH); 
  delayMicroseconds(15); 
  digitalWrite(trigPin, LOW); 
  delayMicroseconds(10); //Delay in high state

  pingTime = pulseIn(echoPin, HIGH);  
  pingTime = pingTime / 1000000; 
  targetDistance = speedOfSound * pingTime; 
  targetDistance = targetDistance / 2; 
  targetDistance = targetDistance * 100; 
  Serial.print("DATA,TIME,");
  Serial.println(targetDistance );
  delay(1000);
  sendData(targetDistance);

  delay(2000);
}

// Function for Send data into Google Spreadsheet
void sendData(float targetDistance)
{
  Serial.print("connecting to ");
  Serial.println(host);
  if (!client.connect(host, httpsPort)) {
    Serial.println("connection failed");
    return;
  }

  if (client.verify(fingerprint, host)) {
    Serial.println("certificate matches");
  } else {
    Serial.println("certificate doesn't match");
  }
  String string_distance =  String(targetDistance, DEC);
  String url = "/macros/s/" + GAS_ID + "/exec?distance=" + string_distance;
  Serial.print("requesting URL: ");
  Serial.println(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");
      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");
}

```

[  
  ![](http://forum.arduino.cc/index.php?action=dlattach;topic=605076.0;attach=300384;image)  
 ](http://forum.arduino.cc/index.php?action=dlattach;topic=605076.0;attach=300384;image)

Moderator edit:  
`</mark> <mark>[code]</mark> <mark>`

`</mark> <mark>[/code]</mark> <mark>`  
tags added.

 ![Screenshot error message.png](https://europe1.discourse-cdn.com/arduino/original/4X/0/e/6/0e61b8ee88259d47fd24f977474c4189efca1ab6.png)

---

<div class="post-metadata">

**Author:** ![Thee\_Captain](https://avatars.discourse-cdn.com/v4/letter/t/73ab20/32.png) [@Thee\_Captain](https://forum.arduino.cc/u/Thee_Captain)\
**Post date:** [March 21, 2019, 1:58pm UTC](https://forum.arduino.cc/t/esp8266-not-connecting-to-script-google-com/581148/2 "2019-03-21T13:58:29Z")

</div>

You are attempting to connect HTTPS, do you have the correct CA certificate or fingerprint for your server you are making the request of?

If this is the issue, I would get everything working on port 80 first, then move on to your secure request after that.

---

<div class="post-metadata">

**Author:** ![Coding\_Badly](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@Coding\_Badly](https://forum.arduino.cc/u/Coding_Badly)\
**Post date:** [March 21, 2019, 3:11pm UTC](https://forum.arduino.cc/t/esp8266-not-connecting-to-script-google-com/581148/3 "2019-03-21T15:11:36Z")

</div>

@SwarlatDee, do not cross-post. Other thread removed.

@SwarlatDee, do not hijack. Do not cross-post. Other post removed.

---

<div class="post-metadata">

**Author:** ![ed1500](https://avatars.discourse-cdn.com/v4/letter/e/e9a140/32.png) [@ed1500](https://forum.arduino.cc/u/ed1500)\
**Post date:** [June 16, 2019, 12:22pm UTC](https://forum.arduino.cc/t/esp8266-not-connecting-to-script-google-com/581148/4 "2019-06-16T12:22:15Z")

</div>

I dont think th fingerprint is the problem here. As you can see from the code, the error is generated before the fingerprint is verified.  
You may try to include client.setInsecure();

If that gets it to work, you may still expect the error: "esp8266/Arduino CI has failed" just ignore that. The condition that error tests for is not correct

---

<div class="post-metadata">

**Author:** ![AndreCigna](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@AndreCigna](https://forum.arduino.cc/u/AndreCigna)\
**Post date:** [April 15, 2021, 12:41pm UTC](https://forum.arduino.cc/t/esp8266-not-connecting-to-script-google-com/581148/5 "2021-04-15T12:41:15Z")

</div>

I had the same problem. You only have to downgrade the esp8266 version at 2.4.2 from the Board Manager

---

<div class="post-metadata">

**Author:** ![arjun\_chaurasiya](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@arjun\_chaurasiya](https://forum.arduino.cc/u/arjun_chaurasiya)\
**Post date:** [May 4, 2021, 5:41pm UTC](https://forum.arduino.cc/t/esp8266-not-connecting-to-script-google-com/581148/6 "2021-05-04T17:41:05Z")

</div>

hey, thanks man  
I got it working on my nodemcu esp12e with certificate not matching but data uploading to google sheet.

---

<div class="post-metadata">

**Author:** ![AndreCigna](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@AndreCigna](https://forum.arduino.cc/u/AndreCigna)\
**Post date:** [May 4, 2021, 5:53pm UTC](https://forum.arduino.cc/t/esp8266-not-connecting-to-script-google-com/581148/7 "2021-05-04T17:53:50Z")

</div>

no worries:) also in my project the certificate doesn't match but it works in any case

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [September 1, 2021, 5:54pm UTC](https://forum.arduino.cc/t/esp8266-not-connecting-to-script-google-com/581148/8 "2021-09-01T17:54:26Z")

</div>

Closed on September 1, 2021, 5:54pm UTC

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.
