← Back to Forum
General Discussions
ESP32 communication with dweet.cc by non-secure https
by johannk · 18/07/25 22:54
During initial test I recognized that every HTTP-call to dweet.cc ended in HTTP-ErrorCode 302 which have the meaning "requested resource has been temporarily moved to a different URL".
The request is redirected to an httpS-url and my ESP32 is not prepared to work with HTTPS which needs certificates and so on.
During my search for a solution I found a post on randomnerdtutorials.com with the title esp32-https-requests-wificlientsecure-without-certificate

Based on this example I built following function for my ESP32 which is able to send data to dweet.cc and also retrieve data from dweet.cc.
Please consider: Although we use HTTPS, this is NOT a tap-proof communication channel!

I hope that this example can show you, how to communicate with dweet.cc in an easy way.

<code>
---- code begin -------
#ifdef ESP32 // if we have an ESP32
#include <HTTPClient.h> //
#include <WiFiClientSecure.h> // we include the necessary lib
#else // if NON-ESP32 (e.g. ESP8266
#include <ESP8266HTTPClient.h> //
#include <WiFiClientSecureBearSSL.h> // we include the necessary lib
#endif // end ifdef ESP32

WiFiClientSecure HttpS_Client; //Declare client object for HTTPS-Client

#define GLBBUFMEDLA_SIZE 512 // Size of glbBuf_medla
char glbBuf_medla [GLBBUFMEDLA_SIZE + 1]; // Buffer medium large A (512 bytes plus NUL terminator)



/////////////////////////////////////////////////////////////////////////////////////////////////
// Function for INsecure HTTPS-GET-Request without certificate (e.g. call to dweet.cc)
//
// if UrlData is provided this procedure adds a '?' and append the datastring to GET-Url
// if AnswBufSize <= 0 or AnswerBuffer is NULL the GET Request will fire and forget
// ReturnValue > 0 = Number of received bytes
// < 0 = Error occured
//
// Example-call:
// AnswBytes = HttpsReqInsecure( /*callHost*/ "dweet.cc",
// /*callURL*/ "https://dweet.cc/dweet/for/MyThingName",
// /*UrlData*/ "HostN=TEST01&V=V_1.99z&Param1=111",
// /*AnswBufSize*/ GLBBUFMEDLA_SIZE,
// /*AnswBufAdr*/ glbBuf_medla
// );
//
// based on example of: https://randomnerdtutorials.com/esp32-https-requests/#esp32-https-requests-wificlientsecure-without-certificate
//
int HttpsReqInsecure( char *callHost, char *callURL, char *UrlData = NULL, int AnswBufSize = 0, char *AnswBufAdr = NULL) {
int RetVal = 0; // for return-value
#if INCL_HTTPCLIENT_DEBUG
Serial.print(F("\nDEBUG HttpsReqInsecure: AnswBufSize="));
Serial.print(AnswBufSize);
Serial.print(" AnswBufAdr is ");
Serial.print( (AnswBufSize == NULL) ? "NULL" : "NOT null");
#endif // INCL_HTTPCLIENT_DEBUG
HttpS_Client.setInsecure(); // HTTPS without certificate
if (!HttpS_Client.connect(callHost, 443)) { // connect to server on port 443 failed
Serial.print(F("\nConnection failed to "));
Serial.print(callHost);
} // end if connect to server on port 443 failed
else { // when connection successful
#if INCL_HTTPCLIENT_DEBUG
Serial.print(F("\nConnected to server "));
Serial.print(callHost);
Serial.print(F("\nSend GET-Request: "));
Serial.print (callURL);
#endif // INCL_HTTPCLIENT_DEBUG

HttpS_Client.print ("GET " );
HttpS_Client.print (callURL );
if ( UrlData != NULL ) { // if we have to add prameterdata zu URL
HttpS_Client.print ("?" ); // append question mark as delimiter
HttpS_Client.print (UrlData ); // append url data
} // end if we have to add prameterdata zu URL
HttpS_Client.println( " HTTP/1.0"); // append end of message
HttpS_Client.print ("Host: "); // append host information
HttpS_Client.println(callHost); // append host information
HttpS_Client.println("Connection: close"); // append param that host should close connection
HttpS_Client.println(); // send necessary final LF

// if requested we check for response:

if (AnswBufSize > 0 && AnswBufAdr != NULL ) { // If we should collect an answer
memset(AnswBufAdr, 0, sizeof(AnswBufSize) ); // clear returnbuffer
while (HttpS_Client.connected() && RetVal < AnswBufSize) { // while server connection and buffer not full
while (HttpS_Client.available() && RetVal < AnswBufSize) { // as long data are available
AnswBufAdr[RetVal++] = HttpS_Client.read(); // read byte by byte into return-buffere
} // end while data available
} // end while
#if INCL_HTTPCLIENT_DEBUG
Serial.print(F("\nReceived bytes:"));
Serial.println(RetVal);
Serial.println(AnswBufAdr);
#endif // INCL_HTTPCLIENT_DEBUG
} // end If we should collect an answer
else { // when we should NOT collect the answer (like fire and forget)
#if INCL_HTTPCLIENT_DEBUG
Serial.print(F("\nAnswer not collected !"));
#endif // INCL_HTTPCLIENT_DEBUG
RetVal = -10; // we use RetVal as work-integer
while (HttpS_Client.connected() && RetVal < 0 ) { // while server still connected (max nn ms)
delay(100); // wait a little bit
RetVal++; // increment counter
} // end while server still connected (max nn ms)
RetVal = 0;
} // end when we should NOT collect the answer
} // end when connection successful
HttpS_Client.stop(); // stops client
return RetVal;
} // end HttpsReqInsecure(.....)
---- code end -------
</code>
💬 Replies (0)

No replies yet. Be the first to reply!

Reply