# MKR1000: Failing to send a GET request using WIFI101

**URL:** <https://forum.arduino.cc/t/mkr1000-failing-to-send-a-get-request-using-wifi101/1080775>\
**Category:** MKR 1000 WiFi\
**Created:** [January 22, 2023, 8:01am UTC](https://forum.arduino.cc/t/mkr1000-failing-to-send-a-get-request-using-wifi101/1080775 "2023-01-22T08:01:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![iforire](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/iforire/32/1108275_2.png) [@iforire](https://forum.arduino.cc/u/iforire)\
**Post date:** [January 22, 2023, 8:01am UTC](https://forum.arduino.cc/t/mkr1000-failing-to-send-a-get-request-using-wifi101/1080775/1 "2023-01-22T08:01:17Z")

</div>

Hello everyone,

i've been trying to send a GET request to fill a Google Sheets directly by WIFI using WIFI101 but I can't find the error in my code or in the way i'm doing it.  
I used a tutorial on youtube to do that (sorry can't find it at the moment), it was working on a MKR1010 but then I had to convert it to MKR1000 (using Wifi101 instead of Wifinina), I managed to solve some problems but not the last one.  
The typical Wifi101 example code for sending a Google request is working.  
But the code below does not work (I've tried port = 443 and 80, i've been on forum and posts, and tried things without sucess until now):

```arduino

#include <SPI.h>
#include <WiFi101.h>
#include "Arduino.h"
#include <Wire.h>
#include "arduino_secrets.h" 

///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) // your network key index number
int status = WL_IDLE_STATUS; // the WiFi radio's status
const char host[] = "script.google.com";

const int httpsPort = 80;  
WiFiClient client;
String GAS_ID = SECRET_GAS;

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(115200);
  // check for the WiFi module:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  
  // attempt to connect to WiFi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WEP network, SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }

  // once you are connected :
  Serial.print("You're connected to the network");
  printWiFiStatus();

}

void loop() {

  uint16_t co2 = 800;
  float temperature = 25;
  float humidity = 100;
  String Temp = "Temperature : " + String(temperature) + " °C";
  String Humi = "Humidity : " + String(humidity) + " %";
  String strco2 = "CO2 : " + String(co2) + " ppm";
  Serial.println(Temp);
  Serial.println(Humi);
  Serial.println(strco2);
  sendData(temperature, humidity, co2);
  delay(10000);
}

void sendData(float tem, float hum, uint16_t coo) {
  Serial.println("==========");
  Serial.print("connecting to ");
  Serial.println(host);
  //----------------------------------------Connect to Google host
 if (!client.connect(host, httpsPort)) {
    Serial.println("connection failed");
    return;
  }
  //----------------------------------------
  //----------------------------------------Processing data and sending data
  String string_temperature = String(tem);
  // String string_temperature = String(tem, DEC); 
  String string_humidity = String(hum); 
  String string_co2 = String(coo);
  String url = "/macros/s/" + GAS_ID + "/exec?temperature=" + string_temperature + "&humidity=" + string_humidity + "&co2=" + string_co2;
  Serial.print("requesting URL: ");
  Serial.println(url);

client.print(String("GET ") + url + " HTTP/1.1\r\n" +
         "Host: " + host + "\r\n" +
         "Connection: close\r\n\r\n");
Serial.print(String("GET ") + url + " HTTP/1.1\r\n" +
         "Host: " + host + "\r\n" +
         "Connection: close\r\n\r\n");

  while (client.available()) {
    char c = client.read();
    Serial.write(c);
  }  
  //----------------------------------------

  //----------------------------------------Checking whether the data was sent successfully or not
  while (client.connected()) {
    String line = client.readStringUntil('\n');
    Serial.println(line);
    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.print("reply was : ");
  Serial.println(line);
  Serial.println("closing connection");
  Serial.println("==========");
  Serial.println();
  //----------------------------------------
}

void printWiFiStatus() {

  // print the SSID of the network you're attached to:

  Serial.print("SSID: ");

  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:

  IPAddress ip = WiFi.localIP();

  Serial.print("IP Address: ");

  Serial.println(ip);

  // print the received signal strength:

  long rssi = WiFi.RSSI();

  Serial.print("signal strength (RSSI):");

  Serial.print(rssi);

  Serial.println(" dBm");
}

void printWifiData() {
  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  Serial.println(ip);

}

```

Here is what I get from the client.read that I've added to have some info

> HTTP/1.1 301 Moved Permanently

> Content-Type: text/html; charset=UTF-8

> Cache-Control: no-cache, no-store, max-age=0, must-revalidate

> Pragma: no-cache

> Expires: Mon, 01 Jan 1990 00:00:00 GMT

> Date: Sun, 22 Jan 2023 07:57:54 GMT

> Location: [https://script.google.com/macros/s/XXX](https://script.google.com/macros/s/XXX)  
> X-Content-Type-Options: nosniff

> X-Frame-Options: SAMEORIGIN

> Content-Security-Policy: frame-ancestors 'self'

> X-XSS-Protection: 1; mode=block

> Server: GSE

> Accept-Ranges: none

> Vary: Accept-Encoding

> Connection: close

> Transfer-Encoding: chunked

> headers received  
> esp8266/Arduino CI has failed  
> reply was : 15a

> closing connection

---

<div class="post-metadata">

**Author:** ![Juraj](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/juraj/32/238785_2.png) [@Juraj](https://forum.arduino.cc/u/Juraj)\
**Post date:** [January 22, 2023, 10:09am UTC](https://forum.arduino.cc/t/mkr1000-failing-to-send-a-get-request-using-wifi101/1080775/2 "2023-01-22T10:09:40Z")

</div>

the site doesn't accept unsecure connection.  
use WiFiSSLClient and port 443

---

<div class="post-metadata">

**Author:** ![iforire](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/iforire/32/1108275_2.png) [@iforire](https://forum.arduino.cc/u/iforire)\
**Post date:** [January 22, 2023, 10:19am UTC](https://forum.arduino.cc/t/mkr1000-failing-to-send-a-get-request-using-wifi101/1080775/3 "2023-01-22T10:19:45Z")

</div>

Thanks!  
But it does not work...  
Now, it cannot connect to the server ([script.google.com](http://script.google.com)), while it was poossible using WifiClient (with either port 80 or port 443...).

Also, i've tried the simple example replacing WifiClient by WifiSSLClient and the port to 443, it does not work also

---

<div class="post-metadata">

**Author:** ![iforire](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/iforire/32/1108275_2.png) [@iforire](https://forum.arduino.cc/u/iforire)\
**Post date:** [January 22, 2023, 7:57pm UTC](https://forum.arduino.cc/t/mkr1000-failing-to-send-a-get-request-using-wifi101/1080775/4 "2023-01-22T19:57:10Z")

</div>

Still investigating...  
i've tested many combinations of WiFiClient // WiFiSSLClient // client.connect() // client.conectSSL with no sucess.  
i've added the domain "[script.google.com](http://script.google.com)" to the SSL root certificates of the MKR1000 board, it can now connect to the server as previously without the SSL, but still cannot send the request.  
If anyone has a clue, I'll be glad to hear 😉  
Thanks  
Have a great week

---

<div class="post-metadata">

**Author:** ![iforire](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/iforire/32/1108275_2.png) [@iforire](https://forum.arduino.cc/u/iforire)\
**Post date:** [January 25, 2023, 9:15pm UTC](https://forum.arduino.cc/t/mkr1000-failing-to-send-a-get-request-using-wifi101/1080775/5 "2023-01-25T21:15:43Z")

</div>

Still testing here...  
I found that post with a similar problem:

> [@HTTPS with MKR1000](https://forum.arduino.cc/t/https-with-mkr1000/604099/19):
>
> there is some SSL related fix in the GitHub repo

They solved it using the WiFiSSLClient\_BearSSL library.  
I tried without any sucess...  
I've modified line 317 of WiFi.cpp. I've added the website in the SSL certificate using the Wifi101 updater (but when I close and reopen again, i cannot see the website i'm trying to connect to...).  
And it does not work, impossible to connect to the server.  
Any other libraries you think I could try for my MKR1000? (I've also tried HTPPSClient and ArduyinoHttpsClient, not working also...)  
Thanks!

---

<div class="post-metadata">

**Author:** ![iforire](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/iforire/32/1108275_2.png) [@iforire](https://forum.arduino.cc/u/iforire)\
**Post date:** [January 28, 2023, 7:52am UTC](https://forum.arduino.cc/t/mkr1000-failing-to-send-a-get-request-using-wifi101/1080775/6 "2023-01-28T07:52:58Z")

</div>

I've found that in the "Rezad first" post of this section of the forum (yes, I probably should have read this first...soeey!):

> **Q: I installed a certificate but I cannot establish an HTTPS connection.**  
> A: Check if the certificate is loaded and is SHA 256. The 348 is still not yet supported. Comodo for example has certificate SHA-348 with RSA encryption

I don't know what it means exactly.  
Since I would like to connect to "[script.google.com](http://script.google.com)", should this server has a SHA 256 certificate? If not, will that be impossible to connect to it using a MKR 1000? Or could I create one by some means?  
Thank you

---

<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:** [July 27, 2023, 7:53am UTC](https://forum.arduino.cc/t/mkr1000-failing-to-send-a-get-request-using-wifi101/1080775/7 "2023-07-27T07:53:39Z")

</div>

Closed on July 27, 2023, 7:53am UTC

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