ESP32 HTTPS example / Bitcoin monitor
This is a very simple example of an ESP32 application using HTTPS to extract data via an API on a remote server. This simple configuration cannot, however, validate the authenticity of the remote server without additional steps. But for many non-sensitive applications, this is OK.
It uses the ESP32 library WiFiClientSecure.h for enabling https://xxxxx.yyy URLs.
As a demonstration I have used APIs from two different Bitcoin providers which appear to require HTTPS, not simple HTTP, and seem to work without any other authentication mechanism. That is you do not need any account, API key or give credit card details etc.
I've wrapped up the demonstation for a Cheap Yellow Display (CYD) but, with some hacking, it can have other applications. It is un-polished but works.
Disclaimer: I don't hold any Bitcoins and am using this as a basic test before I use a similar technique to extract data from another site.
Maybe someone finds it interesting or useful.
/*
bitcoin_monitor for Cheap Yellow Display
Demonstrates Minimal HTTPS example for talking to an https:// web site with encryption
but without any of the normal checks for validating the remote server
Demonstrates two APIs that appear to need no account or authorisation key:
coingecko and coinbase
Instructions:
01 Change WLAN credentials
02 Compile for ESP32 Dev Module
See:
https://www.hackster.io/etolocka/bitcoin-monitor-with-crowpanel-5-79-and-gxepd2-1c5f3e
https://randomnerdtutorials.com/esp32-https-requests/
https://docs.coingecko.com/v3.0.1/reference/authentication
https://docs.cdp.coinbase.com/api-reference/v2/introduction
PINOUT CYD
See: https://github.com/witnessmenow/ESP32-Cheap-Yellow-Display/blob/main/PINS.md
TFT (Uses the HSPI)
IO2 TFT_RS AKA: TFT_DC
IO12 TFT_SDO AKA: TFT_MISO
IO13 TFT_SDI AKA: TFT_MOSI
IO14 TFT_SCK
IO15 TFT_CS
IO21 TFT_BL Backlight Also on P3 connector, for some reason
Ver 0.04P 16.02.2026 integrate CYD screen based on ST7789_cyd_V0_04.ino (compile for ESP32)
Author 6v6gt
*/
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include "SPI.h"
#include "Adafruit_GFX.h"
// #include "Adafruit_ILI9341.h"
#include <Adafruit_ST7789.h>
#define TFT_CS 15
#define TFT_RST -1
#define TFT_DC 2
SPIClass hspi = SPIClass(HSPI);
Adafruit_ST7789 tft = Adafruit_ST7789(&hspi, TFT_CS, TFT_DC, TFT_RST); // Adafruit_ST7789(SPIClass *spiClass, int8_t cs, int8_t dc, int8_t rst);
// Change the following parameters to suit your environment
const char* ssid = "your own SSIS";
const char* password = "your own password";
String serverPath1 = "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd,chf";
String serverPath2 = "https://api.coinbase.com/v2/prices/BTC-USD/spot";
WiFiClientSecure* client = new WiFiClientSecure;
void setup() {
Serial.begin(115200);
while (!Serial && millis() < 4000) delay(100); // Wait for Serial Monitor before continuing
Serial.println("\nStarting . . . ");
// tft
pinMode(21, OUTPUT); // backlight CYD
digitalWrite(21, HIGH);
//tft.begin();
tft.init(240, 320); // Init ST7789 240x240
tft.setRotation(1);
tft.invertDisplay(false);
// jsonBuffer.reserve(40960); // est only 16k - overkill - should use a stream method.
// set up WiFi
WiFi.begin(ssid, password);
Serial.println("Connecting to WLAN");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
Serial.print("Wifi RSSI=");
Serial.println(WiFi.RSSI());
}
void loop() {
// Check WiFi connection status
if (WiFi.status() == WL_CONNECTED) {
// WiFiClientSecure* client = new WiFiClientSecure;
if (client) {
// set secure client without certificate
client->setInsecure();
//create an HTTPClient instance
HTTPClient https;
//Initializing an HTTPS communication using the secure client
Serial.print("\n[HTTPS] begin...\n");
// =========================
// coingecko + tft print
// =========================
if (https.begin(*client, serverPath1)) { // HTTPS
Serial.print(">>>coingecko\n");
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) {
// print server response payload
String payload = https.getString();
Serial.println(payload);
JsonDocument doc;
DeserializationError error = deserializeJson(doc, payload);
if (!error) {
float priceUSD = doc["bitcoin"]["usd"];
Serial.print("Bitcoin price USD : ") ;
Serial.println( priceUSD ) ;
// tft
tft.fillScreen(ST77XX_BLACK);
tft.setCursor(10, 20);
tft.setTextSize(3);
tft.setTextColor(ST77XX_YELLOW, ST77XX_BLUE);
tft.println( "Bitcoin" ) ;
tft.setCursor(10, 50);
tft.setTextSize(4);
tft.setTextColor(ST77XX_WHITE, ST77XX_BLACK);
tft.print("$") ;
tft.println( priceUSD ) ;
float priceEuro = doc["bitcoin"]["chf"];
Serial.print("Bitcoin price CHF : ") ;
Serial.println( priceEuro ) ;
}
else {
Serial.println( "ERROR deserializeJson(doc, payload)" ) ;
}
}
} else {
Serial.printf("[HTTPS] GET... failed, error: %s\n", https.errorToString(httpCode).c_str());
}
https.end();
} // if (https.begin)
// =========================
// coinbase
// =========================
if (https.begin(*client, serverPath2)) { // HTTPS
Serial.print(">>>coinbase\n");
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) {
// print server response payload
String payload = https.getString();
Serial.println(payload);
JsonDocument doc;
DeserializationError error = deserializeJson(doc, payload);
if (!error) {
float priceUSD = doc["data"]["amount"];
Serial.print("Bitcoin price USD : ") ;
Serial.println( priceUSD ) ;
}
else {
Serial.println( "ERROR deserializeJson(doc, payload)" ) ;
}
}
} else {
Serial.printf("[HTTPS] GET... failed, error: %s\n", https.errorToString(httpCode).c_str());
}
https.end();
} // if (https.begin)
} // if (client)
}
delay(60000); // 1 minute. not too often or the API may block
Serial.println("") ;
} // loop

