{"id":122070,"date":"2023-01-19T14:49:31","date_gmt":"2023-01-19T14:49:31","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=122070"},"modified":"2023-01-19T14:49:33","modified_gmt":"2023-01-19T14:49:33","slug":"esp8266-nodemcu-https-requests","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-https-requests\/","title":{"rendered":"ESP8266 NodeMCU HTTPS Requests (Arduino IDE)"},"content":{"rendered":"\n<p>In this guide, you&#8217;ll learn how to make HTTPS requests with the ESP8266 NodeMCU board. We&#8217;ll introduce you to some HTTPS fundamental concepts and provide several examples: HTTPS requests without certificate, with fingerprint and with certificate.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Requests.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 NodeMCU HTTPS requests Arduino IDE Core\" class=\"wp-image-122256\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Requests.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Requests.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Requests.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Requests.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<p>We have a similar tutorial for the ESP32 board:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-https-requests\/\">ESP32 HTTPS Requests<\/a><\/li><\/ul>\n\n\n\n<p><strong>Table of Contents<\/strong><\/p>\n\n\n\n<p>Throughout this article, we&#8217;ll cover the following subjects:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"#what-is-https\">What is HTTPS?<\/a><ul><li><a href=\"#why-https-esp8266\">Why do you need HTTPS with the ESP8266?<\/a><\/li><\/ul><\/li><li><a href=\"#tls-ssl-certificates\">SSL\/TLS Certificates<\/a><ul><li><a href=\"#certificate-chain\">Certificate Chain<\/a><\/li><li><a href=\"#certification-expiration-date\">Certificates Expiration Date<\/a><\/li><\/ul><\/li><li><a href=\"#getting-server-certificate\">Getting a Server&#8217;s Certificate using Google Chrome<\/a><\/li><li><a href=\"#ESP8266-https-requests\">HTTPS Requests with the ESP8266<\/a><ul><li><a href=\"#esp8266-https-requests-no-certificate\">ESP8266 HTTPS Requests &#8211; No certificate<\/a><\/li><li><a href=\"#esp8266-https-requests-fingerprint\">ESP8266 HTTPS Requests &#8211; Fingerprint<\/a><\/li><li><a href=\"#esp8266-https-requests-root-certificate\">ESP8266 HTTPS Requests &#8211; Root Certificate<\/a><\/li><li><a href=\"#esp8266-https-requests-root-store\">ESP8266 HTTPS Requests &#8211; Root Store<\/a><\/li><\/ul><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-https\">Introduction<\/h2>\n\n\n\n<p>To understand how to make HTTPS requests with the ESP8266, it&#8217;s better to be familiar with some fundamental concepts that we&#8217;ll explain next. We also recommend taking a look at the following article:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-https-ssl-tls\/\">ESP32\/ESP8266 with HTTPS and SSL\/TLS Encryption: Basic Concepts<\/a><\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"what-is-https\">What is HTTPS?<\/h3>\n\n\n\n<p>HTTPS is the secure version of the HTTP protocol, hence the \u201cS\u201d, which stands for secure.<\/p>\n\n\n\n<p>HTTP is a protocol to transfer data over the internet. When that data is encrypted with SSL\/TLS, it\u2019s called HTTPS.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"500\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/HTTP-vs-HTTPS.png?resize=750%2C500&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"HTTP vs HTTPS protocol\" class=\"wp-image-121260\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/HTTP-vs-HTTPS.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/HTTP-vs-HTTPS.png?resize=300%2C200&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>To simplify, HTTPS is just the HTTP protocol but with encrypted data using SSL\/TLS.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"why-https-esp8266\">Why do you need HTTPS with the ESP8266?<\/h3>\n\n\n\n<p>Using HTTPS ensures the following:<\/p>\n\n\n\n<p><strong>1) Encryption<\/strong>: all traffic between the ESP8266 and a server will be encrypted\u2014no one can spy on your requests and passwords, they will only see gibberish.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"308\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Encrypted-Communication_ESP8266-encryption-with-server.png?resize=750%2C308&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 HTTPS requests encrypted\" class=\"wp-image-122258\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Encrypted-Communication_ESP8266-encryption-with-server.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Encrypted-Communication_ESP8266-encryption-with-server.png?resize=300%2C123&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>When using the ESP8266 libraries to make HTTPS requests, they take care of encryption and decryption of the messages.<\/p>\n\n\n\n<p><strong>2) Server trust (identification):<\/strong> when using HTTPS, via TLS\/SSL certificates, you ensure you are connected to the server you would expect\u2014this means, you always know to who you are connected to.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"472\" height=\"163\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/SSL-TLS-certificate_SSL-certificate.png?resize=472%2C163&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"SSL\/TLS Certificate valid\" class=\"wp-image-121504\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/SSL-TLS-certificate_SSL-certificate.png?w=472&amp;quality=100&amp;strip=all&amp;ssl=1 472w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/SSL-TLS-certificate_SSL-certificate.png?resize=300%2C104&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 472px) 100vw, 472px\" \/><\/figure><\/div>\n\n\n<p>To make sure we are connected to the right server, we need to check the server certificate on the ESP8266 or the server fingerprint. This means we need to download the server certificate or fingerprint and hard code it on our sketch so that we can check if we&#8217;re actually connected to the server we are expecting.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"tls-ssl-certificates\">TLS\/SSL Certificates<\/h3>\n\n\n\n<p>SSL certificates are issued by legitimate <strong>Certificate Authorities<\/strong>. One of the most known is LetsEncrypt. Certificate Authorities confirm the identity of the certificate owner and provide proof that the certificate is valid.&nbsp;The certificate also contains the server&#8217;s public key for asymmetrically encrypted communication with a client.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"351\" height=\"163\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/TLS-SSL-Certificate-Public-Key.png?resize=351%2C163&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"TLS SSL Certificate Public Key\" class=\"wp-image-121506\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/TLS-SSL-Certificate-Public-Key.png?w=351&amp;quality=100&amp;strip=all&amp;ssl=1 351w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/TLS-SSL-Certificate-Public-Key.png?resize=300%2C139&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 351px) 100vw, 351px\" \/><\/figure><\/div>\n\n\n<p>When a Certificate Authority issues a certificate, it signs the certificate with its root certificate. This root certificate should be on the database of trusted certificates called a <strong>root store<\/strong>. Your browser and the operating system contain a database of root certificates that they can trust (root store). The following screenshot shows some of the trusted root certificates.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"505\" height=\"467\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/trusted-root-certificates.png?resize=505%2C467&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"trusted root certificates chrome\" class=\"wp-image-121499\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/trusted-root-certificates.png?w=505&amp;quality=100&amp;strip=all&amp;ssl=1 505w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/trusted-root-certificates.png?resize=300%2C277&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 505px) 100vw, 505px\" \/><\/figure><\/div>\n\n\n<p>So, when you connect to a website using your browser, it checks if its certificate was signed by a root certificate that belongs to its root store. New root certificates are added or deleted to the root store with each browser update.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"468\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/HTTPS-browser-valid-certificate.png?resize=750%2C468&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"client server TLS SSL Certificates\" class=\"wp-image-121269\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/HTTPS-browser-valid-certificate.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/HTTPS-browser-valid-certificate.png?resize=300%2C187&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>When you&#8217;re using an ESP8266, you need to upload the certificates that you trust to your board. Usually, you&#8217;ll add only the certificate for the server you&#8217;ll want to connect to. <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"354\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-check-server-certificate_ESP8266-check-server-certificate.png?resize=750%2C354&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 Check server certificate for secure connection\" class=\"wp-image-122259\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-check-server-certificate_ESP8266-check-server-certificate.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-check-server-certificate_ESP8266-check-server-certificate.png?resize=300%2C142&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>But, it&#8217;s also possible to upload a root store to your board to have more options, and don&#8217;t have to worry about searching for a specific website&#8217;s certificate.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"certificate-chain\">Certificate Chain<\/h3>\n\n\n\n<p>An SSL certificate is part of an SSL certificate chain. <strong>What is a certificate chain?<\/strong><\/p>\n\n\n\n<p>A certificate chain includes the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>root certificate (from a Certificate Authority);<\/li><li>one or more intermediate certificates;<\/li><li>the server certificate.<\/li><\/ul>\n\n\n\n<p>The server certificate is what makes your browser show a secure padlock icon when you visit a website. It means the server has a <strong>valid<\/strong> SSL\/TLS certificate and all the connections with the website are encrypted. A valid SSL\/TLS certificate is a certificate trusted by your browser. What makes it trustable?<\/p>\n\n\n\n<p>As we&#8217;ve mentioned previously, SSL\/TLS certificates are issued by Certificate Authorities. However, these authorities don&#8217;t issue certificates directly to websites. They use intermediates that will issue the server certificate (<strong>Certificate Authority<\/strong> &gt; <strong>intermediate certificate<\/strong> &gt; <strong>server certificate<\/strong>). The following screenshot shows an example for the Github website. You can see the certificate hierarchy highlighted with a red rectangle.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"546\" height=\"669\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/certificate-hierarchy-github.png?resize=546%2C669&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"SSL Certificate Chain\" class=\"wp-image-121500\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/certificate-hierarchy-github.png?w=546&amp;quality=100&amp;strip=all&amp;ssl=1 546w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/certificate-hierarchy-github.png?resize=245%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 245w\" sizes=\"(max-width: 546px) 100vw, 546px\" \/><\/figure><\/div>\n\n\n<p>Your browser checks this certificate chain until it finds the root certificate. If that certificate is in the browser&#8217;s root store, then it considers the certificate to be valid. In this case, the DigiCert Global Root CA is in the browser&#8217;s root store. So, it will display the &#8220;secure&#8221; icon on the browser bar.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"456\" height=\"134\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/github-secure-icon.png?resize=456%2C134&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"github secure icon\" class=\"wp-image-121502\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/github-secure-icon.png?w=456&amp;quality=100&amp;strip=all&amp;ssl=1 456w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/github-secure-icon.png?resize=300%2C88&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 456px) 100vw, 456px\" \/><\/figure><\/div>\n\n\n<p>The following diagram shows a high-level overview of how it works.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"395\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/12\/certificate-chain-f_certificate-chain.png?resize=750%2C395&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"certificate chain example\" class=\"wp-image-123943\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/12\/certificate-chain-f_certificate-chain.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/12\/certificate-chain-f_certificate-chain.png?resize=300%2C158&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p><strong>In summary:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>root certificate<\/strong>: it&#8217;s a self-signed certificate issued by a Certificate Authority. The private key of this certificate is used to sign the next certificate in the hierarchy of certificates. Root certificates are loaded in the trust stores of browsers and operating systems.<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>intermediate certificate<\/strong>: it&#8217;s signed by the private key of the root certificate. The public key of the intermediate certificate is the one that signs the server certificate. There can be more than one intermediate certificate.<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>server certificate<\/strong>: this certificate is issued to a specific domain name on a server. It&#8217;s signed by the intermediate certificate public key. If it is valid (trustable certificate chain), the browser displays a secure padlock badge on the search bar next to the website domain.<\/li><\/ul>\n\n\n\n<p>With the ESP8266, to check the validity of a server, you can load any of those certificates: root, intermediate, or server certificate. Instead of the certificate, you can also check the certificate fingerprint. The fingerprint is a hash of the certificate (a unique identifier of the certificate generated from the certificate information).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"certification-expiration-date\">Certificates Expiration Date<\/h3>\n\n\n\n<p>SSL\/TLS certificates have an expiry date. You can check on a browser the expiry date of the certificate for a particular server. The server&#8217;s certificate usually has a short-term validity and the fingerprint validity is even shorter.<\/p>\n\n\n\n<p>So, if you want to use them in your ESP8266 projects, you&#8217;ll need to update your code quite frequently. If you want your code to run for years without worrying, you can use the website&#8217;s root certificate, which usually has a validity of five to ten years or more. However, using the fingerprint might be useful for testing purposes or might be a good option depending on the application.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"getting-server-certificate\">Getting a Server&#8217;s Certificate<\/h2>\n\n\n\n<p>There are different ways to get the server&#8217;s certificate. One of the easiest ways is to download the certificate directly from your browser. You can also use <a href=\"https:\/\/www.openssl.org\/\" target=\"_blank\" rel=\"noopener\">OpenSSL <\/a>and get all the certificate information you need using the command line (we won&#8217;t cover this method in this tutorial). <\/p>\n\n\n\n<p>In this section, you&#8217;ll learn how to get the server&#8217;s certificate. We&#8217;ll generally use the root certificate, but you can use any of the other certificates on the certificate chain\u2014you just need to be aware of the certificate expiry date.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Getting a Server&#8217;s Certificate using Google Chrome<\/h3>\n\n\n\n<p>In this section, we&#8217;ll show you how to get the certificate for a server using Google Chrome (that&#8217;s the web browser we use more often). Instructions for other web browsers should be similar.<\/p>\n\n\n\n<p>The examples we&#8217;ll use later show how to make an HTTPS request to the howmyssl.com website. So, for demonstration purposes, we&#8217;ll show you how to get its root certificate. It is similar for other websites.<\/p>\n\n\n\n<p><strong>How to Get Websites&#8217;s Certificate using Google Chrome?<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Go to the website that you want to get the certificate for.<\/li><\/ol>\n\n\n\n<ol start=\"2\"><li>Click on the padlock icon and then click on <strong>Show connection details<\/strong>.<\/li><\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"719\" height=\"372\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/google-chrome-get-website-certificate-1.png?resize=719%2C372&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Google chrome website certificate ssl\" class=\"wp-image-121512\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/google-chrome-get-website-certificate-1.png?w=719&amp;quality=100&amp;strip=all&amp;ssl=1 719w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/google-chrome-get-website-certificate-1.png?resize=300%2C155&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 719px) 100vw, 719px\" \/><\/figure><\/div>\n\n\n<ol start=\"3\"><li>Then, click on <strong>Show certificate<\/strong>.<\/li><\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"719\" height=\"372\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/google-chrome-get-website-certificate-2.png?resize=719%2C372&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Google chrome website certificate ssl information\" class=\"wp-image-121514\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/google-chrome-get-website-certificate-2.png?w=719&amp;quality=100&amp;strip=all&amp;ssl=1 719w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/google-chrome-get-website-certificate-2.png?resize=300%2C155&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 719px) 100vw, 719px\" \/><\/figure><\/div>\n\n\n<ol start=\"4\"><li>A new window will open with all the information about the website&#8217;s certificate. Click on the <strong>Details<\/strong> tab, make sure you select the root certificate (that&#8217;s what we&#8217;re looking for in this example), then click on <strong>Export&#8230;<\/strong><\/li><\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"546\" height=\"668\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/google-chrome-get-website-certificate-3.png?resize=546%2C668&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Google chrome website certificate ssl details\" class=\"wp-image-121515\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/google-chrome-get-website-certificate-3.png?w=546&amp;quality=100&amp;strip=all&amp;ssl=1 546w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/google-chrome-get-website-certificate-3.png?resize=245%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 245w\" sizes=\"(max-width: 546px) 100vw, 546px\" \/><\/figure><\/div>\n\n\n<ol start=\"5\"><li>Select a place on your computer to save the certificate. Save it on the default format: <span class=\"rnthl rntliteral\">Base64-encoded ASCII, single certificate (*.pem, .crt)<\/span>.  And that&#8217;s it. <\/li><\/ol>\n\n\n\n<p>You can double-click on the certificate file to check its details, including the expiration date.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"405\" height=\"515\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/certificate-information.png?resize=405%2C515&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Google chrome website certificate ssl certificate information expanded\" class=\"wp-image-121517\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/certificate-information.png?w=405&amp;quality=100&amp;strip=all&amp;ssl=1 405w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/certificate-information.png?resize=236%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 236w\" sizes=\"(max-width: 405px) 100vw, 405px\" \/><\/figure><\/div>\n\n\n<p>Open the certificate using Notepad or other similar software. You should get something similar as shown below.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"615\" height=\"805\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/root-certificate-notepad.png?resize=615%2C805&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"SSL certificate notepad\" class=\"wp-image-121518\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/root-certificate-notepad.png?w=615&amp;quality=100&amp;strip=all&amp;ssl=1 615w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/root-certificate-notepad.png?resize=229%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 229w\" sizes=\"(max-width: 615px) 100vw, 615px\" \/><\/figure><\/div>\n\n\n<p id=\"get-fingerprint\"><strong>How to Get a Website&#8217;s Fingerprint using Google Chrome?<\/strong><\/p>\n\n\n\n<p>Getting a website&#8217;s certificate fingerprint is straightforward. Follow the next instructions:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Go to the website that you want to get the fingerprint.<\/li><\/ol>\n\n\n\n<ol start=\"2\"><li>Click on the padlock icon and then click on <strong>Show connection details<\/strong>.<\/li><\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"719\" height=\"372\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/google-chrome-get-website-certificate-1.png?resize=719%2C372&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Google chrome website certificate ssl\" class=\"wp-image-121512\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/google-chrome-get-website-certificate-1.png?w=719&amp;quality=100&amp;strip=all&amp;ssl=1 719w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/google-chrome-get-website-certificate-1.png?resize=300%2C155&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 719px) 100vw, 719px\" \/><\/figure><\/div>\n\n\n<ol start=\"3\"><li>Then, click on <strong>Show certificate<\/strong>.<\/li><\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"719\" height=\"372\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/google-chrome-get-website-certificate-2.png?resize=719%2C372&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Google chrome website certificate ssl certificate is valid\" class=\"wp-image-121514\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/google-chrome-get-website-certificate-2.png?w=719&amp;quality=100&amp;strip=all&amp;ssl=1 719w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/google-chrome-get-website-certificate-2.png?resize=300%2C155&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 719px) 100vw, 719px\" \/><\/figure><\/div>\n\n\n<ol start=\"4\"><li>A new window will open with all the information about the website&#8217;s certificate, including the fingerprints. For the ESP8266 examples, you&#8217;ll use the SHA-1 fingerprint.<\/li><\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"547\" height=\"668\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/website-fingerprint-example.png?resize=547%2C668&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"website fingerprint example\" class=\"wp-image-122261\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/website-fingerprint-example.png?w=547&amp;quality=100&amp;strip=all&amp;ssl=1 547w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/website-fingerprint-example.png?resize=246%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 246w\" sizes=\"(max-width: 547px) 100vw, 547px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"ESP8266-https-requests\">HTTPS Requests with the ESP8266 NodeMCU<\/h2>\n\n\n\n<p>Now that you know all the major important aspects of certificates and how to get a server&#8217;s certificate, let&#8217;s finally take a look at how to make HTTPS requests with the ESP8266 using the Arduino core. We&#8217;ll cover different methods: without a certificate, with the website fingerprint, and with the server&#8217;s root certificate.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"320\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Requests.png?resize=750%2C320&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"HTTPS Requests with the ESP8266 NodeMCU board\" class=\"wp-image-121365\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Requests.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Requests.png?resize=300%2C128&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>You can find different examples showing how to make HTTPS requests with the ESP8266 in the Arduino IDE examples section.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Basic HTTPS Client (<span class=\"rnthl rntliteral\">ESP8266HTTPClient<\/span> library): <strong>File <\/strong>&gt; <strong>Examples<\/strong> &gt; <strong>ESP8266HTTPClient&nbsp;<\/strong>&gt; <strong><a href=\"https:\/\/github.com\/esp8266\/Arduino\/blob\/master\/libraries\/ESP8266HTTPClient\/examples\/BasicHttpsClient\/BasicHttpsClient.ino\" target=\"_blank\" rel=\"noopener\">BasicHTTPSClient<\/a><\/strong><\/li><li>Basic HTTPS Client (<span class=\"rnthl rntliteral\">WiFiClientSecure<\/span> library): <strong>File <\/strong>&gt; <strong>Examples <\/strong>&gt; <strong>ESP8266WiFi <\/strong>&gt; <strong><a href=\"https:\/\/github.com\/esp8266\/Arduino\/tree\/master\/libraries\/ESP8266WiFi\/examples\/HTTPSRequest\" target=\"_blank\" rel=\"noopener\">HTTPSRequest <\/a><\/strong><\/li><\/ul>\n\n\n\n<p>You\u2019ll need to update the certificates and fingerprints to make the examples work. We created several examples based on those. All examples presented make a request to the <a href=\"http:\/\/www.howsmyssl.com\/a\/check\" target=\"_blank\" rel=\"noopener\">www.howsmyssl.com\/a\/check<\/a> website. It returns some information regarding how secure the HTTPS connection is. Let&#8217;s take a look at them.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"esp8266-https-requests-no-certificate\">ESP8266 NodeMCU HTTPS Requests &#8211; No Certificate<\/h3>\n\n\n\n<p>You can make HTTPS requests with the ESP8266 without a certificate and without a fingerprint. The connection will be encrypted, but you&#8217;ll skip the SSL server certificate verification. This means that you won&#8217;t be sure if the server you&#8217;re connected to is really who it claims to be. This situation is useful for testing purposes or to make HTTPS requests to local servers inside your network.<\/p>\n\n\n\n<p>The following code was based on the <a href=\"https:\/\/github.com\/esp8266\/Arduino\/blob\/master\/libraries\/ESP8266HTTPClient\/examples\/BasicHttpsClient\/BasicHttpsClient.ino\" target=\"_blank\" rel=\"noopener\">BasicHttpsClient example<\/a>.<\/p>\n\n\n\n<p>To test the code, simply insert your network credentials and upload the code to your board.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\r\n  Complete project details: https:\/\/RandomNerdTutorials.com\/esp8266-nodemcu-https-requests\/ \r\n  Based on the BasicHTTPSClient.ino Created on: 20.08.2018 (ESP8266 examples)\r\n*\/\r\n\r\n#include &lt;Arduino.h&gt;\r\n#include &lt;ESP8266WiFi.h&gt;\r\n#include &lt;ESP8266HTTPClient.h&gt;\r\n#include &lt;WiFiClientSecureBearSSL.h&gt;\r\n\r\n\/\/ Replace with your network credentials\r\nconst char* ssid = &quot;REPLACE_WITH_YOUR_SSID&quot;;\r\nconst char* password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;\r\n\r\nvoid setup() {\r\n  Serial.begin(115200);\r\n  \/\/Serial.setDebugOutput(true);\r\n\r\n  Serial.println();\r\n  Serial.println();\r\n  Serial.println();\r\n\r\n  \/\/Connect to Wi-Fi\r\n  WiFi.mode(WIFI_STA);\r\n  WiFi.begin(ssid, password);\r\n  Serial.print(&quot;Connecting to WiFi ..&quot;);\r\n  while (WiFi.status() != WL_CONNECTED) {\r\n    Serial.print('.');\r\n    delay(1000);\r\n  }\r\n}\r\n\r\nvoid loop() {\r\n  \/\/ wait for WiFi connection\r\n  if ((WiFi.status() == WL_CONNECTED)) {\r\n\r\n    std::unique_ptr&lt;BearSSL::WiFiClientSecure&gt;client(new BearSSL::WiFiClientSecure);\r\n\r\n    \/\/ Ignore SSL certificate validation\r\n    client-&gt;setInsecure();\r\n    \r\n    \/\/create an HTTPClient instance\r\n    HTTPClient https;\r\n    \r\n    \/\/Initializing an HTTPS communication using the secure client\r\n    Serial.print(&quot;[HTTPS] begin...\\n&quot;);\r\n    if (https.begin(*client, &quot;https:\/\/www.howsmyssl.com\/a\/check&quot;)) {  \/\/ HTTPS\r\n      Serial.print(&quot;[HTTPS] GET...\\n&quot;);\r\n      \/\/ start connection and send HTTP header\r\n      int httpCode = https.GET();\r\n      \/\/ httpCode will be negative on error\r\n      if (httpCode &gt; 0) {\r\n        \/\/ HTTP header has been send and Server response header has been handled\r\n        Serial.printf(&quot;[HTTPS] GET... code: %d\\n&quot;, httpCode);\r\n        \/\/ file found at server\r\n        if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {\r\n          String payload = https.getString();\r\n          Serial.println(payload);\r\n        }\r\n      } else {\r\n        Serial.printf(&quot;[HTTPS] GET... failed, error: %s\\n&quot;, https.errorToString(httpCode).c_str());\r\n      }\r\n\r\n      https.end();\r\n    } else {\r\n      Serial.printf(&quot;[HTTPS] Unable to connect\\n&quot;);\r\n    }\r\n  }\r\n  Serial.println();\r\n  Serial.println(&quot;Waiting 2min before the next round...&quot;);\r\n  delay(120000);\r\n}\r\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP8266\/ESP8266_HTTPS\/ESP8266_BasicHttpsClient_without_Certificate.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">How does the Code Work?<\/h4>\n\n\n\n<p>First, you need to include the required libraries. You need the <span class=\"rnthl rntliteral\">WiFiClientSecureBearSSL<\/span> library to make HTTPS requests.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;Arduino.h&gt;\n#include &lt;ESP8266WiFi.h&gt;\n#include &lt;ESP8266HTTPClient.h&gt;\n#include &lt;WiFiClientSecureBearSSL.h&gt;<\/code><\/pre>\n\n\n\n<p>Insert your network credentials in the following lines.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Replace with your network credentials\nconst char* ssid = \"REPLACE_WITH_YOUR_SSID\";\nconst char* password = \"REPLACE_WITH_YOUR_PASSWORD\";<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, initialize the Serial Monitor and connect the board to your Wi-Fi network.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void setup() {\n  Serial.begin(115200);\n  \/\/ Serial.setDebugOutput(true);\n\n  Serial.println();\n  Serial.println();\n  Serial.println();\n\n  \/\/Connect to Wi-Fi\n  WiFi.mode(WIFI_STA);\n  WiFi.begin(ssid, password);\n  Serial.print(\"Connecting to WiFi ..\");\n  while (WiFi.status() != WL_CONNECTED) {\n    Serial.print('.');\n    delay(1000);\n  }\n<\/code><\/pre>\n\n\n\n<p>The following line creates a new <span class=\"rnthl rntliteral\">WiFiClientSecure<\/span> instance called <span class=\"rnthl rntliteral\">client<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>std::unique_ptr&lt;BearSSL::WiFiClientSecure&gt;client(new BearSSL::WiFiClientSecure);<\/code><\/pre>\n\n\n\n<p>In case you don&#8217;t want to verify the server certificate, use the <span class=\"rnthl rntliteral\">setInsecure()<\/span> method on the <span class=\"rnthl rntliteral\">client<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Ignore SSL certificate validation\nclient-&gt;setInsecure();<\/code><\/pre>\n\n\n\n<p>Create an <span class=\"rnthl rntliteral\">HTTPClient<\/span> instance called <span class=\"rnthl rntliteral\">https<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/create an HTTPClient instance\nHTTPClient https;<\/code><\/pre>\n\n\n\n<p>Initialize the <span class=\"rnthl rntliteral\">https<\/span> client on the host specified using the <span class=\"rnthl rntliteral\">begin()<\/span> method. In this case, we&#8217;re making a request on the following URL: <span class=\"rnthl rntliteral\">https:\/\/www.howsmyssl.com\/a\/check<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code> if (https.begin(*client, \"https:\/\/www.howsmyssl.com\/a\/check\")) {  \/\/ HTTPS<\/code><\/pre>\n\n\n\n<p>Get the server response code.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code> int httpCode = https.GET();<\/code><\/pre>\n\n\n\n<p>If the response code is a positive number, it means the connection was established successfully, so we can read the response payload using the <span class=\"rnthl rntliteral\">getString()<\/span> method on the <span class=\"rnthl rntliteral\">https<\/span> object. Then, we can print the payload in the Serial Monitor. In a practical application, you can do whatever task you need with the ESP8266 depending on the received payload.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>if (https.begin(*client, \"https:\/\/www.howsmyssl.com\/a\/check\")) {  \/\/ HTTPS\n  Serial.print(\"&#091;HTTPS] GET...\\n\");\n  \/\/ start connection and send HTTP header\n  int httpCode = https.GET();\n  \/\/ httpCode will be negative on error\n  if (httpCode &gt; 0) {\n    \/\/ HTTP header has been send and Server response header has been handled\n    Serial.printf(\"&#091;HTTPS] GET... code: %d\\n\", httpCode);\n    \/\/ file found at server\n    if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {\n      String payload = https.getString();\n      Serial.println(payload);\n    }<\/code><\/pre>\n\n\n\n<p>If the response code is a negative number, it means we have an error. We&#8217;ll print the error code.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>else {\n   Serial.printf(\"&#091;HTTPS] GET... failed, error: %s\\n\", https.errorToString(httpCode).c_str());\n}<\/code><\/pre>\n\n\n\n<p>Finally, close the HTTPS connection using the <span class=\"rnthl rntliteral\">end()<\/span> method:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>https.end();<\/code><\/pre>\n\n\n\n<p>This specific example makes a request every two minutes. You should change it depending on your project requirements.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.println(\"Waiting 2min before the next round...\");\ndelay(120000);<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Demonstration<\/h4>\n\n\n\n<p>After uploading the code, open the Serial Monitor at a baud rate of 115200. Press the on-board RST button to start running the newly uploaded code. <\/p>\n\n\n\n<p>You should get something similar as shown in the picture below.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"601\" height=\"292\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Request-Serial-Monitor-1.png?resize=601%2C292&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 HTTPS example demonstration serial monitor\" class=\"wp-image-122274\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Request-Serial-Monitor-1.png?w=601&amp;quality=100&amp;strip=all&amp;ssl=1 601w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Request-Serial-Monitor-1.png?resize=300%2C146&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/><\/figure><\/div>\n\n\n<p>You get the response code 200, which means everything is fine with the request.<\/p>\n\n\n\n<p>If you scroll to the right, you&#8217;ll get the result of how secure the connection is. You should get a &#8220;Probably Okay&#8221;.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"601\" height=\"381\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Request-Serial-Monitor-2.png?resize=601%2C381&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 HTTPS example demonstration serial monitor\" class=\"wp-image-122275\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Request-Serial-Monitor-2.png?w=601&amp;quality=100&amp;strip=all&amp;ssl=1 601w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Request-Serial-Monitor-2.png?resize=300%2C190&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/><\/figure><\/div>\n\n\n<p>Your connection is still encrypted, but with this example, it will skip SSL verification.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"esp8266-https-requests-fingerprint\">ESP8266 NodeMCU HTTPS Requests &#8211; Fingerprint<\/h3>\n\n\n\n<p>You can make HTTPS requests with the ESP8266, and check the server authenticity using the server fingerprint. One of the biggest downsides of using a fingerprint is that its validity is usually pretty short. So, you&#8217;ll need to update your sketch quite often.<\/p>\n\n\n\n<p>Here&#8217;s an example using server verification with the fingerprint. This example is based on the <a href=\"https:\/\/github.com\/esp8266\/Arduino\/blob\/master\/libraries\/ESP8266HTTPClient\/examples\/BasicHttpsClient\/BasicHttpsClient.ino\" target=\"_blank\" rel=\"noreferrer noopener\">BasicHttpsClient example<\/a>. Because the fingerprint changes quite often, you may need to modify the code with the website&#8217;s current fingerprint\u2014<a href=\"#get-fingerprint\">check this section to learn how to get the fingerprint<\/a>.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\r\n  Complete project details: https:\/\/RandomNerdTutorials.com\/esp8266-nodemcu-https-requests\/\r\n  Based on the BasicHTTPSClient.ino Created on: 20.08.2018 (ESP8266 examples)\r\n*\/\r\n\r\n#include &lt;Arduino.h&gt;\r\n#include &lt;ESP8266WiFi.h&gt;\r\n#include &lt;ESP8266HTTPClient.h&gt;\r\n#include &lt;WiFiClientSecureBearSSL.h&gt;\r\n\r\n\/\/ Replace with your network credentials\r\nconst char* ssid = &quot;REPLACE_WITH_YOUR_SSID&quot;;\r\nconst char* password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;\r\n\r\n\/\/ Fingerprint (might need to be updated)\r\nconst uint8_t fingerprint[20] = {0x76, 0x99, 0x2e, 0x6f, 0x04, 0xf4, 0xad, 0x19, 0xba, 0x54, 0xf5, 0x92, 0x50, 0x51, 0x56, 0x2b, 0x86, 0x8b, 0x5a, 0x92};\r\n\r\nvoid setup() {\r\n  Serial.begin(115200);\r\n  \/\/Serial.setDebugOutput(true);\r\n\r\n  Serial.println();\r\n  Serial.println();\r\n  Serial.println();\r\n\r\n  \/\/Connect to Wi-Fi\r\n  WiFi.mode(WIFI_STA);\r\n  WiFi.begin(ssid, password);\r\n  Serial.print(&quot;Connecting to WiFi ..&quot;);\r\n  while (WiFi.status() != WL_CONNECTED) {\r\n    Serial.print('.');\r\n    delay(1000);\r\n  }\r\n}\r\n\r\nvoid loop() {\r\n  \/\/ wait for WiFi connection\r\n  if ((WiFi.status() == WL_CONNECTED)) {\r\n\r\n    std::unique_ptr&lt;BearSSL::WiFiClientSecure&gt;client(new BearSSL::WiFiClientSecure);\r\n\r\n    client-&gt;setFingerprint(fingerprint);\r\n    \/\/ Or, if you happy to ignore the SSL certificate, then use the following line instead:\r\n    \/\/ client-&gt;setInsecure();\r\n\r\n    HTTPClient https;\r\n\r\n    Serial.print(&quot;[HTTPS] begin...\\n&quot;);\r\n    if (https.begin(*client, &quot;https:\/\/www.howsmyssl.com\/a\/check&quot;)) {  \/\/ HTTPS\r\n\r\n      Serial.print(&quot;[HTTPS] GET...\\n&quot;);\r\n      \/\/ start connection and send HTTP header\r\n      int httpCode = https.GET();\r\n\r\n      \/\/ httpCode will be negative on error\r\n      if (httpCode &gt; 0) {\r\n        \/\/ HTTP header has been send and Server response header has been handled\r\n        Serial.printf(&quot;[HTTPS] GET... code: %d\\n&quot;, httpCode);\r\n\r\n        \/\/ file found at server\r\n        if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {\r\n          String payload = https.getString();\r\n          Serial.println(payload);\r\n        }\r\n      } else {\r\n        Serial.printf(&quot;[HTTPS] GET... failed, error: %s\\n&quot;, https.errorToString(httpCode).c_str());\r\n      }\r\n\r\n      https.end();\r\n    } else {\r\n      Serial.printf(&quot;[HTTPS] Unable to connect\\n&quot;);\r\n    }\r\n  }\r\n\r\n  Serial.println();\r\n  Serial.println(&quot;Waiting 2min before the next round...&quot;);\r\n  delay(120000);\r\n}\r\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP8266\/ESP8266_HTTPS\/ESP8266_BasicHttpsClient_Fingerprint.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">How does the Code Work?<\/h4>\n\n\n\n<p>The code in this example is very similar to the previous one but adds the necessary lines to check the server fingerprint. We&#8217;ll just take a quick look at the lines relevant for this example. For a more detailed explanation, <a href=\"#esp8266-https-requests-no-certificate\">check the previous example<\/a>.<\/p>\n\n\n\n<p>First, you need to include the required libraries. You need the <span class=\"rnthl rntliteral\">WiFiClientSecureBearSSL<\/span> library to make HTTPS requests.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;Arduino.h&gt;\n#include &lt;ESP8266WiFi.h&gt;\n#include &lt;ESP8266HTTPClient.h&gt;\n#include &lt;WiFiClientSecureBearSSL.h&gt;<\/code><\/pre>\n\n\n\n<p>Insert your network credentials in the following lines:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Replace with your network credentials\nconst char* ssid = \"REPLACE_WITH_YOUR_SSID\";\nconst char* password = \"REPLACE_WITH_YOUR_PASSWORD\";<\/code><\/pre>\n\n\n\n<p>Insert the server fingerprint in the following line:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Fingerprint for demo URL (might need to be updated)\nconst uint8_t fingerprint&#091;20] = {0x76, 0x99, 0x2e, 0x6f, 0x04, 0xf4, 0xad, 0x19, 0xba, 0x54, 0xf5, 0x92, 0x50, 0x51, 0x56, 0x2b, 0x86, 0x8b, 0x5a, 0x92};<\/code><\/pre>\n\n\n\n<p>In a previous section, we&#8217;ve seen that the fingerprint for the URL we&#8217;ll make the request is:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">76 99 2E 6F 04 F4 AD 19 BA 54 F5 92 50 51 56 2B 86 8B 5A 92<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"547\" height=\"668\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/website-fingerprint-example.png?resize=547%2C668&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"website fingerprint example\" class=\"wp-image-122261\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/website-fingerprint-example.png?w=547&amp;quality=100&amp;strip=all&amp;ssl=1 547w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/website-fingerprint-example.png?resize=246%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 246w\" sizes=\"(max-width: 547px) 100vw, 547px\" \/><\/figure><\/div>\n\n\n<p>So, you must insert it in your code like this:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>const uint8_t fingerprint&#091;20] = {0x76, 0x99, 0x2e, 0x6f, 0x04, 0xf4, 0xad, 0x19, 0xba, 0x54, 0xf5, 0x92, 0x50, 0x51, 0x56, 0x2b, 0x86, 0x8b, 0x5a, 0x92};<\/code><\/pre>\n\n\n\n<p>Because the fingerprint changes frequently, you may need to double-check the current fingerprint. If you&#8217;re making a request on a different URL, you need to <a href=\"#get-fingerprint\">get its fingerprint as described previously<\/a>.<\/p>\n\n\n\n<p>You need to create a <span class=\"rnthl rntliteral\">WiFiClientSecure<\/span> instance called <span class=\"rnthl rntliteral\">client<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>std::unique_ptr&lt;BearSSL::WiFiClientSecure&gt;client(new BearSSL::WiFiClientSecure);<\/code><\/pre>\n\n\n\n<p>To set the server fingerprint, use the <span class=\"rnthl rntliteral\">setFingerpirnt()<\/span> method on the <span class=\"rnthl rntliteral\">client<\/span> and pass the <span class=\"rnthl rntliteral\">fingerprint<\/span> as an argument:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>client-&gt;setFingerprint(fingerprint);<\/code><\/pre>\n\n\n\n<p>Create an <span class=\"rnthl rntliteral\">HTTPClient<\/span> instance called <span class=\"rnthl rntliteral\">https<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/create an HTTPClient instance\nHTTPClient https;<\/code><\/pre>\n\n\n\n<p>Initialize the <span class=\"rnthl rntliteral\">https<\/span> client on the host specified using the <span class=\"rnthl rntliteral\">begin()<\/span> method. In this case, we&#8217;re making a request on the following URL: <span class=\"rnthl rntliteral\">https:\/\/www.howsmyssl.com\/a\/check<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code> if (https.begin(*client, \"https:\/\/www.howsmyssl.com\/a\/check\")) {  \/\/ HTTPS<\/code><\/pre>\n\n\n\n<p>Then, you just need to handle the server response. A response code of 200 means everything went as expected. A response code with a negative number means something went wrong with the request.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code> int httpCode = https.GET();\n\n\/\/ httpCode will be negative on error\nif (httpCode &gt; 0) {\n  \/\/ HTTP header has been send and Server response header has been handled\n  Serial.printf(\"&#091;HTTPS] GET... code: %d\\n\", httpCode);\n\n  \/\/ file found at server\n  if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {\n    String payload = https.getString();\n    Serial.println(payload);\n  }\n} else {\n  Serial.printf(\"&#091;HTTPS] GET... failed, error: %s\\n\", https.errorToString(httpCode).c_str());\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Demonstration<\/h4>\n\n\n\n<p>After uploading the code, open the Serial Monitor at a baud rate of 115200. Press the on-board RST button to start running the newly uploaded code. <\/p>\n\n\n\n<p>You should get something similar as shown in the picture below (exactly like in the previous example).<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"601\" height=\"292\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Request-Serial-Monitor-1.png?resize=601%2C292&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 HTTPS example demonstration serial monitor\" class=\"wp-image-122274\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Request-Serial-Monitor-1.png?w=601&amp;quality=100&amp;strip=all&amp;ssl=1 601w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Request-Serial-Monitor-1.png?resize=300%2C146&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/><\/figure><\/div>\n\n\n<p>You get the response code 200, which means everything is fine with the request.<\/p>\n\n\n\n<p>If you scroll to the right, you&#8217;ll get the result of how secure the connection is. You should get a &#8220;Probably Okay&#8221;.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"601\" height=\"381\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Request-Serial-Monitor-2.png?resize=601%2C381&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 HTTPS example demonstration serial monitor\" class=\"wp-image-122275\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Request-Serial-Monitor-2.png?w=601&amp;quality=100&amp;strip=all&amp;ssl=1 601w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Request-Serial-Monitor-2.png?resize=300%2C190&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/><\/figure><\/div>\n\n\n<p>Your connection is encrypted and you verified the authenticity of the server using the server fingerprint.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"esp8266-https-requests-root-certificate\">ESP8266 NodeMCU HTTPS Requests &#8211; Root Certificate<\/h3>\n\n\n\n<p>In this section, we&#8217;ll show you an example of an HTTPS request using the server root certificate. <\/p>\n\n\n\n<p>Using the server root certificate is a great option because you verify the server SSL certificate, and thus you guarantee you&#8217;re communicating with the right server. Additionally, the root certificate is usually valid for more than five years, which means you don&#8217;t need to constantly update your ESP8266 sketch (unlike the fingerprint method).<\/p>\n\n\n\n<p>We&#8217;re providing an example based on the <span class=\"rnthl rntliteral\">ESP8266_HTTPSRequest<\/span> example, which you can find in your Arduino IDE:&nbsp;<strong>File&nbsp;<\/strong>&gt;&nbsp;<strong>Examples&nbsp;<\/strong>&gt;&nbsp;<strong>ESP8266WiFi&nbsp;<\/strong>&gt;&nbsp;<strong><a href=\"https:\/\/github.com\/esp8266\/Arduino\/tree\/master\/libraries\/ESP8266WiFi\/examples\/HTTPSRequest\" target=\"_blank\" rel=\"noreferrer noopener\">HTTPSRequest<\/a><\/strong>.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\r\n  Complete project details: https:\/\/RandomNerdTutorials.com\/esp8266-nodemcu-https-requests\/\r\n  Based on the example created by Ivan Grokhotkov, 2015 (File &gt; Examples &gt; ESP8266WiFi &gt; HTTPSRequests)\r\n*\/\r\n\r\n#include &lt;ESP8266WiFi.h&gt;\r\n#include &lt;WiFiClientSecure.h&gt;\r\n#include &lt;ESP8266HTTPClient.h&gt;\r\n\r\n\/\/ Root certificate for howsmyssl.com\r\nconst char IRG_Root_X1 [] PROGMEM = R&quot;CERT(\r\n-----BEGIN CERTIFICATE-----\r\nMIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw\r\nTzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh\r\ncmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4\r\nWhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu\r\nZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY\r\nMTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc\r\nh77ct984kIxuPOZXoHj3dcKi\/vVqbvYATyjb3miGbESTtrFj\/RQSa78f0uoxmyF+\r\n0TM8ukj13Xnfs7j\/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U\r\nA5\/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW\r\nT8KOEUt+zwvo\/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm\/ELNKjD+Jo2FR3qyH\r\nB5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ4Q7e2RCOFvu396j3x+UC\r\nB5iPNgiV5+I3lg02dZ77DnKxHZu8A\/lJBdiB3QW0KtZB6awBdpUKD9jf1b0SHzUv\r\nKBds0pjBqAlkd25HN7rOrFleaJ1\/ctaJxQZBKT5ZPt0m9STJEadao0xAH0ahmbWn\r\nOlFuhjuefXKnEgV4We0+UXgVCwOPjdAvBbI+e0ocS3MFEvzG6uBQE3xDk3SzynTn\r\njh8BCNAw1FtxNrQHusEwMFxIt4I7mKZ9YIqioymCzLq9gwQbooMDQaHWBfEbwrbw\r\nqHyGO0aoSCqI3Haadr8faqU9GY\/rOPNk3sgrDQoo\/\/fb4hVC1CLQJ13hef4Y53CI\r\nrU7m2Ys6xt0nUW7\/vGT1M0NPAgMBAAGjQjBAMA4GA1UdDwEB\/wQEAwIBBjAPBgNV\r\nHRMBAf8EBTADAQH\/MB0GA1UdDgQWBBR5tFnme7bl5AFzgAiIyBpY9umbbjANBgkq\r\nhkiG9w0BAQsFAAOCAgEAVR9YqbyyqFDQDLHYGmkgJykIrGF1XIpu+ILlaS\/V9lZL\r\nubhzEFnTIZd+50xx+7LSYK05qAvqFyFWhfFQDlnrzuBZ6brJFe+GnY+EgPbk6ZGQ\r\n3BebYhtF8GaV0nxvwuo77x\/Py9auJ\/GpsMiu\/X1+mvoiBOv\/2X\/qkSsisRcOj\/KK\r\nNFtY2PwByVS5uCbMiogziUwthDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5\r\nORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7Ur\r\nTkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+\/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC\r\njNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc\r\noyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0\/1lvh+wjChP4kqKOJ2qxq\r\n4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U\/t7y0Ff\/9yi0GE44Za4rF2LN9d11TPA\r\nmRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc\/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d\r\nemyPxgcYxn\/eR44\/KJ4EBs+lVDR3veyJm+kXQ99b21\/+jh5Xos1AnX5iItreGCc=\r\n-----END CERTIFICATE-----\r\n)CERT&quot;;\r\n\r\n\/\/ Replace with your network credentials\r\nconst char* ssid = &quot;REPLACE_WITH_YOUR_SSID&quot;;\r\nconst char* password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;\r\n\r\n\/\/ Create a list of certificates with the server certificate\r\nX509List cert(IRG_Root_X1);\r\n\r\nvoid setup() {\r\n  Serial.begin(115200);\r\n  \/\/Serial.setDebugOutput(true);\r\n\r\n  Serial.println();\r\n  Serial.println();\r\n  Serial.println();\r\n\r\n  \/\/Connect to Wi-Fi\r\n  WiFi.mode(WIFI_STA);\r\n  WiFi.begin(ssid, password);\r\n  Serial.print(&quot;Connecting to WiFi ..&quot;);\r\n  while (WiFi.status() != WL_CONNECTED) {\r\n    Serial.print('.');\r\n    delay(1000);\r\n  }\r\n\r\n  \/\/ Set time via NTP, as required for x.509 validation\r\n  configTime(3 * 3600, 0, &quot;pool.ntp.org&quot;, &quot;time.nist.gov&quot;);\r\n\r\n  Serial.print(&quot;Waiting for NTP time sync: &quot;);\r\n  time_t now = time(nullptr);\r\n  while (now &lt; 8 * 3600 * 2) {\r\n    delay(500);\r\n    Serial.print(&quot;.&quot;);\r\n    now = time(nullptr);\r\n  }\r\n  Serial.println(&quot;&quot;);\r\n  struct tm timeinfo;\r\n  gmtime_r(&amp;now, &amp;timeinfo);\r\n  Serial.print(&quot;Current time: &quot;);\r\n  Serial.print(asctime(&amp;timeinfo));\r\n}\r\n\r\nvoid loop() {\r\n  WiFiClientSecure client;\r\n\r\n  \/\/ wait for WiFi connection\r\n  if ((WiFi.status() == WL_CONNECTED)) {\r\n\r\n    client.setTrustAnchors(&amp;cert);\r\n\r\n    HTTPClient https;\r\n\r\n    Serial.print(&quot;[HTTPS] begin...\\n&quot;);\r\n    if (https.begin(client, &quot;https:\/\/www.howsmyssl.com\/a\/check&quot;)) {  \/\/ HTTPS\r\n\r\n      Serial.print(&quot;[HTTPS] GET...\\n&quot;);\r\n      \/\/ start connection and send HTTP header\r\n      int httpCode = https.GET();\r\n\r\n      \/\/ httpCode will be negative on error\r\n      if (httpCode &gt; 0) {\r\n        \/\/ HTTP header has been send and Server response header has been handled\r\n        Serial.printf(&quot;[HTTPS] GET... code: %d\\n&quot;, httpCode);\r\n\r\n        \/\/ file found at server\r\n        if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {\r\n          String payload = https.getString();\r\n          Serial.println(payload);\r\n        }\r\n      } else {\r\n        Serial.printf(&quot;[HTTPS] GET... failed, error: %s\\n&quot;, https.errorToString(httpCode).c_str());\r\n      }\r\n\r\n      https.end();\r\n    } else {\r\n      Serial.printf(&quot;[HTTPS] Unable to connect\\n&quot;);\r\n    }\r\n  }\r\n\r\n  Serial.println();\r\n  Serial.println(&quot;Waiting 2min before the next round...&quot;);\r\n  delay(10000);\r\n}\r\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP8266\/ESP8266_HTTPS\/ESP8266_BasicHttpsClient_Certificate.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>This example does exactly the same thing as the previous ones (makes a request to the www.howsmyssl.com website), but it checks the server certificate. You can make a request to any other website, as long as you get its server certificate.<\/p>\n\n\n\n<p>For this section, you&#8217;ll need the server certificate (<a href=\"#getting-server-certificate\">see this section to learn how to get the server certificate<\/a>).<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">How does the Code Work?<\/h4>\n\n\n\n<p>This example is similar to the previous ones but adds the required lines to check the server certificate.<\/p>\n\n\n\n<p>First, include the required libraries. You&#8217;ll use the <span class=\"rnthl rntliteral\">WiFiClientSecure<\/span> library to make requests using TLS, and the <span class=\"rnthl rntliteral\">ESP8266HTTPClient<\/span> library to make it easy to make the requests.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;ESP8266WiFi.h>\n#include &lt;WiFiClientSecure.h>\n#include &lt;ESP8266HTTPClient.h><\/code><\/pre>\n\n\n\n<p>The server root certificate for the howsmyssl.com website is saved on the <span class=\"rnthl rntliteral\">IRG_Root_X1<\/span> variable.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Root certificate for howsmyssl.com\nconst char IRG_Root_X1 &#091;] PROGMEM = R\"CERT(\n-----BEGIN CERTIFICATE-----\nMIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw\nTzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh\ncmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4\nWhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu\nZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY\nMTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc\nh77ct984kIxuPOZXoHj3dcKi\/vVqbvYATyjb3miGbESTtrFj\/RQSa78f0uoxmyF+\n0TM8ukj13Xnfs7j\/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U\nA5\/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW\nT8KOEUt+zwvo\/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm\/ELNKjD+Jo2FR3qyH\nB5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ4Q7e2RCOFvu396j3x+UC\nB5iPNgiV5+I3lg02dZ77DnKxHZu8A\/lJBdiB3QW0KtZB6awBdpUKD9jf1b0SHzUv\nKBds0pjBqAlkd25HN7rOrFleaJ1\/ctaJxQZBKT5ZPt0m9STJEadao0xAH0ahmbWn\nOlFuhjuefXKnEgV4We0+UXgVCwOPjdAvBbI+e0ocS3MFEvzG6uBQE3xDk3SzynTn\njh8BCNAw1FtxNrQHusEwMFxIt4I7mKZ9YIqioymCzLq9gwQbooMDQaHWBfEbwrbw\nqHyGO0aoSCqI3Haadr8faqU9GY\/rOPNk3sgrDQoo\/\/fb4hVC1CLQJ13hef4Y53CI\nrU7m2Ys6xt0nUW7\/vGT1M0NPAgMBAAGjQjBAMA4GA1UdDwEB\/wQEAwIBBjAPBgNV\nHRMBAf8EBTADAQH\/MB0GA1UdDgQWBBR5tFnme7bl5AFzgAiIyBpY9umbbjANBgkq\nhkiG9w0BAQsFAAOCAgEAVR9YqbyyqFDQDLHYGmkgJykIrGF1XIpu+ILlaS\/V9lZL\nubhzEFnTIZd+50xx+7LSYK05qAvqFyFWhfFQDlnrzuBZ6brJFe+GnY+EgPbk6ZGQ\n3BebYhtF8GaV0nxvwuo77x\/Py9auJ\/GpsMiu\/X1+mvoiBOv\/2X\/qkSsisRcOj\/KK\nNFtY2PwByVS5uCbMiogziUwthDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5\nORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7Ur\nTkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+\/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC\njNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc\noyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0\/1lvh+wjChP4kqKOJ2qxq\n4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U\/t7y0Ff\/9yi0GE44Za4rF2LN9d11TPA\nmRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc\/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d\nemyPxgcYxn\/eR44\/KJ4EBs+lVDR3veyJm+kXQ99b21\/+jh5Xos1AnX5iItreGCc=\n-----END CERTIFICATE-----\n)CERT\";<\/code><\/pre>\n\n\n\n<p>Insert your network credentials in the following lines:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Replace with your network credentials\nconst char* ssid = \"REPLACE_WITH_YOUR_SSID\";\nconst char* password = \"REPLACE_WITH_YOUR_PASSWORD\";<\/code><\/pre>\n\n\n\n<p>Then, you need to create a list of certificates <span class=\"rnthl rntliteral\">cert<\/span> (even if you only have one certificate) with the server certificate you want to use:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Create a list of certificates with the server certificate\nX509List cert(IRG_Root_X1);<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, you need to configure the time on the ESP8266, which is necessary to validate the certificate.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>\/\/ Set time via NTP, as required for x.509 validation\nconfigTime(3 * 3600, 0, \"pool.ntp.org\", \"time.nist.gov\");\n\nSerial.print(\"Waiting for NTP time sync: \");\ntime_t now = time(nullptr);\nwhile (now &lt; 8 * 3600 * 2) {\n  delay(500);\n  Serial.print(\".\");\n  now = time(nullptr);\n}\nSerial.println(\"\");\nstruct tm timeinfo;\ngmtime_r(&amp;now, &amp;timeinfo);\nSerial.print(\"Current time: \");\nSerial.print(asctime(&amp;timeinfo));<\/code><\/pre>\n\n\n\n<p>First, to make an HTTPS request, you need to create a <span class=\"rnthl rntliteral\">WiFiClientSecure<\/span> object.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>WiFiClientSecure client;<\/code><\/pre>\n\n\n\n<p>Then, you need to tell which certificates the client can trust using the <span class=\"rnthl rntliteral\">setTrustAnchors()<\/span> method and passing as an argument the certificate list <span class=\"rnthl rntliteral\">cert<\/span> (in this case, we only added one certificate).<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>client.setTrustAnchors(&amp;cert);<\/code><\/pre>\n\n\n\n<p> From now on, the code is the same as the previous projects.<\/p>\n\n\n\n<p>You need to create an <span class=\"rnthl rntliteral\">HTTPClient<\/span> instance (<span class=\"rnthl rntliteral\">https<\/span>), initialize the https client on the host specified using the <span class=\"rnthl rntliteral\">begin()<\/span> method, and then, handle the server response.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>client.setTrustAnchors(&amp;cert);\n\nHTTPClient https;\n\nSerial.print(\"&#091;HTTPS] begin...\\n\");\nif (https.begin(client, \"https:\/\/www.howsmyssl.com\/a\/check\")) {  \/\/ HTTPS\n\n  Serial.print(\"&#091;HTTPS] GET...\\n\");\n  \/\/ start connection and send HTTP header\n  int httpCode = https.GET();\n\n \n \/\/ httpCode will be negative on error\n  if (httpCode &gt; 0) {\n    \/\/ HTTP header has been send and Server response header has been handled\n    Serial.printf(\"&#091;HTTPS] GET... code: %d\\n\", httpCode);\n\n     \/\/ file found at server\n    if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {\n      String payload = https.getString();\n      Serial.println(payload);\n    }\n  } else {\n    Serial.printf(\"&#091;HTTPS] GET... failed, error: %s\\n\", https.errorToString(httpCode).c_str());\n  }<\/code><\/pre>\n\n\n\n<p>After uploading this code to the ESP8266 board, you should get the same messages on the Serial Monitor as in the previous examples.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"601\" height=\"292\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Request-Serial-Monitor-1.png?resize=601%2C292&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 HTTPS Requests Serial Monitor\" class=\"wp-image-122274\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Request-Serial-Monitor-1.png?w=601&amp;quality=100&amp;strip=all&amp;ssl=1 601w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Request-Serial-Monitor-1.png?resize=300%2C146&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"esp8266-https-requests-root-store\">ESP8266 HTTPS Requests &#8211; Root Store<\/h3>\n\n\n\n<p>Instead of just saving one certificate on the ESP8266, you can save multiple certificates. You can add two, three, or more certificates, and you can even add a root store. As we&#8217;ve seen previously, a root store is a database of root certificates that your browser or operating system can trust.<\/p>\n\n\n\n<p>You can download the entire Mozilla Certificate store, and upload it to your ESP8266 so that it behaves like a browser. So, you&#8217;ll be able to make HTTPS requests securely to any server (that uses TLS) without having to hardcode its certificate.<\/p>\n\n\n\n<p>This article is already quite long, so we&#8217;ll cover this subject in another tutorial (to be published soon). <\/p>\n\n\n\n<p>If you&#8217;re curious about this topic, I recommend taking a look at the ESP8266 Certificate Store official example: <a href=\"https:\/\/github.com\/esp8266\/Arduino\/tree\/master\/libraries\/ESP8266WiFi\/examples\/BearSSL_CertStore\" target=\"_blank\" rel=\"noopener\">BearSSL_CertStore<\/a>. You can also find it on your Arduino IDE: <strong>File <\/strong>&gt; <strong>Examples <\/strong>&gt; <strong>ESP8266WiFi <\/strong>&gt; <strong>BearSSL_CertStore<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this tutorial, you learned how to make HTTPS requests with the ESP8266. <\/p>\n\n\n\n<p>We&#8217;ve shown you different ways to make HTTPS requests with the ESP8266: without a certificate, with a fingerprint, and with a certificate. It&#8217;s also possible to use multiple certificates or a root store\u2014we&#8217;ll cover this subject in a future tutorial. You also learned about the basic concepts of HTTPS protocol and about SSL\/TLS certificates.<\/p>\n\n\n\n<p>Other related tutorials that you may find interesting:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-https-ssl-tls\/\">ESP32\/ESP8266 with HTTPS and SSL\/TLS Encryption: Basic Concepts<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-https-requests\/\">ESP32 HTTPS Requests (Arduino IDE)<\/a><\/li><\/ul>\n\n\n\n<p>We hope you found this tutorial useful. We intend to create more tutorials about HTTPS and secure communication. Let us know in the comments below what you think.<\/p>\n\n\n\n<p>Learn more about the ESP8266 with our resources:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/home-automation-using-esp8266\/\">Home Automation using ESP8266<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/build-web-servers-esp32-esp8266-ebook\/\">Build Web Servers with ESP32 and ESP8266<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/firebase-esp32-esp8266-ebook\/\">Firebase Web App with ESP32 and ESP8266<\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/projects-esp8266\/\">Free ESP8266 Projects and Tutorials\u2026<\/a><\/li><\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, you&#8217;ll learn how to make HTTPS requests with the ESP8266 NodeMCU board. We&#8217;ll introduce you to some HTTPS fundamental concepts and provide several examples: HTTPS requests without &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ESP8266 NodeMCU HTTPS Requests (Arduino IDE)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-https-requests\/#more-122070\" aria-label=\"Read more about ESP8266 NodeMCU HTTPS Requests (Arduino IDE)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":122256,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[265,214,246,300,240,264],"tags":[],"class_list":["post-122070","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp8266-project","category-esp8266","category-esp8266-arduino-ide","category-0-esp8266","category-esp8266-projects","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/11\/ESP8266-HTTPS-Requests.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/122070","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=122070"}],"version-history":[{"count":42,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/122070\/revisions"}],"predecessor-version":[{"id":125650,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/122070\/revisions\/125650"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/122256"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=122070"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=122070"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=122070"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}