Closed Twilight-Logic closed 2 years ago
I realised after I had submitted this issue that the original project written by Andreas, and which I based mine on, was developed on the ESP8266, but I was using an ESP32. It is stated that this HTTPSDirect library works on both platforms. Looking at the source code it can be seen that it places a wrapper around many of the original WiFiSecureClient functions and with some minor differences, the syntax is essentially the same on both platforms, so no reason why it shouldn't. That led me to wonder whether the problem might be platform specific. I therefore purchased an ESP8266 to test with which arrived today. I had to make some minor adjustments to the sketch, for example to use ESP8266 versions of libraries, for example the
#ifdef ESP8266
#include <ESP8266WiFi.h>
#include <LittleFS.h>
#include <ESP8266mDNS.h>
#define LDR A0
#endif
#ifdef ESP32
#include <WiFi.h>
#include <LITTLEFS.h>
#include <ESPmDNS.h>
#define LDR 35
#endif
The remainder of the code remained the same. I then compiled, uploaded and tested both Andreas project and my own project code on the ESP8266. Both ran as expected and connected to the Google App Script resource without error and I was able to read events from my calendar.
Evidently then, the problem is related to the ESP32 platform and some difference between the implementations of the ESP8266 and ESP32 versions of the WiFi library, specifically the WiFiClientSecure module. Same code. The ESP8266 version works, the ESP32 version generates the SSL error. For some reason I had assumed that it would just work identically on both.
I have raised an issue on Esspresiffs ESP32 library GitHub repository.
The project has been on the backburner for some time now and I recently came back to it. It turns out that I was using an old version of the ESP32 SDK. It came to my attention recently that the URL to use to obtain the ESP32 board package has changed to:
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
I don't know when that change took place, but I updated the URL and downloaded the updated board library. I no longer get the above error.
Incidentally, in order to use the library on the ESP32, I also added the following change in HTTPSRedirect.h:
I then replaced the two instances of "ESP8266" (createGetRequest & createPOSTRequest) in HTTPSredirect.cpp to "WIFIMCU", for example:
void HTTPSRedirect::createGetRequest(const String& url, const char* host){
_Request = String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"User-Agent: " + WIFIMCU + "\r\n" +
(_keepAlive ? "" : "Connection: close\r\n") +
"\r\n\r\n";
return;
}
This should make no functional difference. It just sends the corresponding User-Agent string to the ESP board board used.
This issue can now be closed.
I have been trying to interface with Google App Script using this library to read my calendar. I am following the examples I have found online. I have published my Google script as a web app and it returns the desired result in the browser on the PC. However, I cannot get the same result on the ESP32.
This is the particular project I am following and on which I have based the code in my sketch. Admittedly the author of this project is using an ESP8266 but there are a number of other very similar examples of the use of the HTTPSRedirect library online: https://github.com/SensorsIot/Reminder-with-Google-Calender/tree/master/ReminderV2
The function that is called from setup() function and makes and initial connection to the Google host works fine but shows the following warning when the log level is set to 'debug':
[I][ssl_client.cpp:127] start_ssl_client(): WARNING: Skipping SSL Verification. INSECURE!
This is to be expected since the sketch includes a call to the .setInsecure() method. However, the second function that is called from void loop() does not work and hangs at the GET request. I see the following error returned:
[E][ssl_client.cpp:36] _handle_error(): [data_to_read():287]: (-29184) SSL - An invalid SSL record was received
I have checked that the URL is being formed correctly and also tried adding delays but this has made no difference. Unfortunately I can't get past this point.
The full output in serial monitor looks like this:
I have tried ESP32 library versions 1.0.4, 1.0.5 and 1.0.6. I had to remove the .setInsecure() line to make it compile with library version 1.0.4. I attempted to add the Google CA certificates at one point, but couldn't get this to work either. I think at least two certificates are required but am not sure how to add multiple certificates? Since none of the examples online seem to have any certificates included, I figured this ought not to be necessary so gave up on the idea and commented out the added lines.
Upload of complete sketch: Calendar-Clock.zip