Wio Terminal httpCode <= 0

Hello
I trying to connect to https script google site with Wio Terminal, but iit works every now and then
I have “HTTP Status Code: -7”.
See log

00:10:39.243 -> Reading Data From Google Sheet…
00:10:41.680 -> HTTP Status Code: 200
00:10:41.680 -> Payload: 10

00:10:42.664 -> Reading Data From Google Sheet…
00:10:44.493 -> HTTP Status Code: -7
00:10:44.493 -> Error on HTTP request
00:10:45.524 -> Pulsante 1

00:10:45.524 -> Reading Data From Google Sheet…
00:10:48.055 -> HTTP Status Code: -7
00:10:48.055 -> Error on HTTP request

00:10:48.946 -> Reading Data From Google Sheet…
00:10:51.524 -> HTTP Status Code: -7
00:10:51.524 -> Error on HTTP request

00:10:52.602 -> Reading Data From Google Sheet…
00:10:55.321 -> HTTP Status Code: -7
00:10:55.321 -> Error on HTTP request

00:10:56.680 -> https://script.google.com/macros/s/zzz/exec?pulsante=1
00:10:56.680 -> Reading Data From Google Sheet…
00:10:59.305 -> HTTP Status Code: 200
00:10:59.305 -> Payload: 10

my code
#include “rpcWiFi.h”

#include <HTTPClient.h>
[…]

HTTPClient http;
http.setTimeout(3000);
String url = “https://script.google.com/macros/s/” + GOOGLE_SCRIPT_ID + “/exec?pulsante=” + pulsante;
Serial.println(url);
Serial.println(“Reading Data From Google Sheet…”);

if (http.begin(client, url.c_str()),443) { // HTTPS client, url.c_str()
tft.drawString(“Connesso”, 70, 130);
//-----------------------------------------------------------------------------------
//Removes the error “302 Moved Temporarily Error”
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
//-----------------------------------------------------------------------------------
//Get the returning HTTP status code
int httpCode = http.GET();

Serial.print("HTTP Status Code: ");
Serial.println(httpCode);
//-----------------------------------------------------------------------------------
if (httpCode <= 0) {
  Serial.println("Error on HTTP request");
  http.end();
  client.stop();
  tft.drawString("Error on HTTP request", 70, 150);
  return;
}
//-----------------------------------------------------------------------------------
//reading data comming from Google Sheet
String payload = http.getString();
Serial.println("Payload: " + payload);
tft.drawString("Payload: " + payload, 70, 150);
//-----------------------------------------------------------------------------------
if (httpCode == 200) {
  Serial.println("Payload: " + payload);
 
}
//-------------------------------------------------------------------------------------
http.end();

} else {
Serial.printf("[HTTPS] Unable to connect\n");
}
client.stop();

}

thanks

I want to help you perform a reproduction to see if there are any problems, can you tell me where you follow the steps to operate?

Hi,
I’m trying to execute google script
How you can see from the code, I tried to connect with HTTPClient.h library, but I don’t always have the correct answer. I tried also to create a loop and without change code, I have one ok and some errors, one ok and some errors and so on
I don’t understand wath means “HTTP Status Code: -7”

Thanks

I mean what steps did you follow to complete it? If so, can you give me the link to follow the steps? Or have you tried connecting to other websites?

If you are using the HTTPClient library, perhaps you should re-check our tutorial document, this library seems to be obsolete.

Hi
"This library has been deprecated in favor of our rpcWifi library. "
If you see this library in example BasicHttpsClient, they are using “#include <HTTPClient.h>”
I started from this example Seeed_Arduino_rpcWiFi and I tried to connect to script.google.com, but sometimes it works, others don’t

log

00:30:21.727 -> [HTTPS] begin…
00:30:21.727 -> [HTTPS] GET…
00:30:24.298 -> [HTTPS] GET… code: 200
00:30:24.298 -> Hello world!
00:30:24.345 ->
00:30:24.345 -> Waiting 10s before the next round…
00:30:34.351 -> [HTTPS] begin…
00:30:34.351 -> [HTTPS] GET…
00:30:36.477 -> [HTTPS] GET… failed, error: no HTTP server
00:30:36.477 ->
00:30:36.477 -> Waiting 10s before the next round…
00:30:46.457 -> [HTTPS] begin…
00:30:46.457 -> [HTTPS] GET…
00:30:48.555 -> [HTTPS] GET… failed, error: connection refused
00:30:48.555 ->
00:30:48.555 -> Waiting 10s before the next round…
00:30:58.549 -> [HTTPS] begin…
00:30:58.549 -> [HTTPS] GET…
00:31:00.752 -> [HTTPS] GET… failed, error: no HTTP server
00:31:00.752 ->
00:31:00.752 -> Waiting 10s before the next round…
00:31:10.736 -> [HTTPS] begin…
00:31:10.736 -> [HTTPS] GET…
00:31:13.124 -> [HTTPS] GET… code: 200
00:31:13.124 -> Hello world!
00:31:13.170 ->
00:31:13.170 -> Waiting 10s before the next round…

/**
BasicHTTPSClient.ino

Created on: 14.10.2018

*/

#include <rpcWiFi.h>
#include <HTTPClient.h>
#include <WiFiClientSecure.h>

WiFiClientSecure client;

void setup() {

Serial.begin(115200);

Serial.println();
Serial.println();
Serial.println();

WiFi.mode(WIFI_STA);
WiFi.begin("…", “…”);

// wait for WiFi connection
Serial.print(“Waiting for WiFi to connect…”);
while ((WiFi.status() != WL_CONNECTED)) {
Serial.print(".");
}
Serial.println(" connected");
//client.setCACert(test_root_ca);
}

void loop() {
String checkUrl = “https://script.google.com/macros/s/AKfycbyVlx63MncBiza4pWnuHV2U22tunVHcqh-YKlSPT17EQx-n-Jh8H3laEWW_eciqvZ-iSg/exec?pulsante=1”;
if (&client) {
{
// Add a scoping block for HTTPClient https to make sure it is destroyed before WiFiClientSecure *client is
HTTPClient https;
//https.setTimeout(10000);
https.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
Serial.print("[HTTPS] begin…\n");
if (https.begin(client, checkUrl)) { // HTTPS
Serial.print("[HTTPS] GET…\n");
// start connection and send HTTP header
int httpCode = https.GET();

    // httpCode will be negative on error
    if (httpCode > 0) {
      // HTTP header has been send and Server response header has been handled
      Serial.printf("[HTTPS] GET... code: %d\n", httpCode);

      // file found at server
      if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
        String payload = https.getString();
        Serial.println(payload);
      }
    } else {
      Serial.printf("[HTTPS] GET... failed, error: %s\n", https.errorToString(httpCode).c_str());
    }

    https.end();
  } else {
    Serial.printf("[HTTPS] Unable to connect\n");
  }
  // End extra scoping block
}

} else {
Serial.println(“Unable to create client”);
}

Serial.println();
Serial.println(“Waiting 10s before the next round…”);
delay(10000);
}

After testing, I also found the same problem, which is under study to solve it, please wait a moment.

For the sample code we provide:

/**
   BasicHTTPSClient.ino
    Created on: 14.10.2018
*/

#include <Arduino.h>
#include <rpcWiFi.h>
#include <HTTPClient.h>
#include <WiFiClientSecure.h>

const char* test_root_ca = \
                            "-----BEGIN CERTIFICATE-----\n"
                            "MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh\n"
                            "MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n"
                            "d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD\n"
                            "QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT\n"
                            "MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j\n"
                            "b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG\n"
                            "9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB\n"
                            "CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97\n"
                            "nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt\n"
                            "43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P\n"
                            "T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4\n"
                            "gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO\n"
                            "BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR\n"
                            "TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw\n"
                            "DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr\n"
                            "hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg\n"
                            "06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF\n"
                            "PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls\n"
                            "YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk\n"
                            "CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=\n"
                            "-----END CERTIFICATE-----\n";

WiFiClientSecure client;

void setup() {

  Serial.begin(115200);

  Serial.println();
  Serial.println();
  Serial.println();

  WiFi.mode(WIFI_STA);
  WiFi.begin("CHCK", "depot0510");

  // wait for WiFi connection
  Serial.print("Waiting for WiFi to connect...");
  while ((WiFi.status() != WL_CONNECTED)) {
    Serial.print(".");
  }
  Serial.println(" connected");
  client.setCACert(test_root_ca);
}

void loop() {
  if(&client) {
    {
      // Add a scoping block for HTTPClient https to make sure it is destroyed before WiFiClientSecure *client is 
      HTTPClient https;
  
      Serial.print("[HTTPS] begin...\n");
      if (https.begin(client, "https://www.example.com/index.html")) {  // HTTPS
        Serial.print("[HTTPS] GET...\n");
        // start connection and send HTTP header
        int httpCode = https.GET();
  
        // httpCode will be negative on error
        if (httpCode > 0) {
          // HTTP header has been send and Server response header has been handled
          Serial.printf("[HTTPS] GET... code: %d\n", httpCode);
  
          // file found at server
          if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
            String payload = https.getString();
            Serial.println(payload);
          }
        } else {
          Serial.printf("[HTTPS] GET... failed, error: %s\n", https.errorToString(httpCode).c_str());
        }
  
        https.end();
      } else {
        Serial.printf("[HTTPS] Unable to connect\n");
      }
      // End extra scoping block
    }
  
  } else {
    Serial.println("Unable to create client");
  }

  Serial.println();
  Serial.println("Waiting 10s before the next round...");
  delay(10000);
}

After testing, we found that "https.begin(client, "https://www.example.com/index.html")" is only suitable for “https://www.example.com/index.html” This site. If you change the website, you will not be able to connect. Since we are currently in China and cannot connect to the Google network, there is no way to test the connection of Google for you, but we have tested several websites. Removing the client parameter can solve the connection problem well, namely:
https.begin(“URL”)

Hi
thank you for your reply, I had already tried but without “client” it works only with http not with https

Maurizio

Hi
I tried ESP8266HTTPClient.h, but for me It’s not compatible with Wio terminal

I have this error
C:\Users\Maurizio\AppData\Local\Arduino15\packages\Seeeduino\hardware\samd\1.8.2\cores\arduino/main.cpp:40: undefined reference to setup' C:\Users\Maurizio\AppData\Local\Arduino15\packages\Seeeduino\hardware\samd\1.8.2\cores\arduino/main.cpp:43: undefined reference to loop’
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for the card Seeeduino Wio Terminal.

ESP8266HTTPClient is not compatible with wio Terminal, we have our own library, but similar, we can refer to the library description about ESP8266HTTPClient

You can go to understand the syntax of https.begin(). It is understood that not all webpages are allowed to push data and pull data. Many websites need to determine the port number and even the password.

Hi
In October 2021 I booked order 4000086204 and you claim to ship it via RU833237151NL in November. I havent received it.