Wi-Fi HTTPS with a certificate
What this example shows
Downloading an image over HTTPS while checking the website certificate. You give the library a certificate with applyHttpsCertificate(), and it uses that certificate when it downloads. In the sketch the certificate is the one for https://varipass.org, and the image is neowise_mono.bmp from that site.
You need your Wi-Fi name (ssid) and password (password). No API key is needed.
Example code
Trimmed from Inkplate10_HTTPS_With_Certificate.ino: the file header comment is removed, and so is the second half of setup(), which tries to load an image from a different website to show that it fails because the certificate does not match that site. The rest is unchanged. ssid and password are placeholders that you replace.
// Next 3 lines are a precaution, you can ignore those, and the example would also work without them
#if !defined(ARDUINO_INKPLATE10) && !defined(ARDUINO_INKPLATE10V2)
#error "Wrong board selection for this example, please select e-radionica Inkplate10 or Soldered Inkplate10 in the boards menu."
#endif
#include "Inkplate.h" //Include Inkplate library to the sketch
Inkplate display(INKPLATE_1BIT); // Create an object on Inkplate library and also set library into 1 Bit mode (BW)
const char ssid[] = ""; // Your WiFi SSID
const char *password = ""; // Your WiFi password
//This is the certificate for the website https://varipass.org
const char* certificate = \
"-----BEGIN CERTIFICATE-----\n" \
"MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw\n" \
"TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh\n" \
"cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4\n" \
"WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu\n" \
"ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY\n" \
"MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc\n" \
"h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+\n" \
"0TM8ukj13X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Hb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7Ur\n" \
"TkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC\n" \
"jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc\n" \
"oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq\n" \
"4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA\n" \
"mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d\n" \
"emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=\n" \
"-----END CERTIFICATE-----\n";
void setup()
{
display.begin(); // Init Inkplate library (you should call this function ONLY ONCE)
display.clearDisplay(); // Clear frame buffer of display
display.display(); // Put clear image on display
display.print("Connecting to WiFi...");
display.partialUpdate();
display.connectWiFi(ssid, password);
while (!display.isConnected())
{
delay(500);
display.print(".");
display.partialUpdate();
}
display.println("\nWiFi OK! Downloading...");
display.partialUpdate();
//Apply the certificate previously defined
display.applyHttpsCertificate(certificate);
//Here we will draw the image using a valid certificate. Photo taken by: Roberto Fernandez
if (!display.image.draw("https://varipass.org/neowise_mono.bmp", 0, 0, false, true))
{
// If is something failed (wrong filename or wrong bitmap format), write error message on the screen.
// REMEMBER! You can only use Windows Bitmap file with color depth of 1, 4, 8 or 24 bits with no compression!
display.println("Image open error");
display.display();
}
display.display();
display.disconnect();
}
void loop()
{
// Nothing...
}
Functions used
Inkplate(uint8_t mode)returns NoneCreates the display object. The mode picks how pixels are stored: `INKPLATE_1BIT` is black and white, which is what the sketches on this page use.
ReturnsConstructor; no return value.
Parameters
| Type | Name | Description |
|---|---|---|
uint8_t | mode | Display mode, INKPLATE_1BIT here. |
display.begin()returns voidInitializes the Inkplate library and its peripherals and clears the frame buffer. Call it once in `setup()`; later calls are ignored.
ReturnsNothing.
display.clearDisplay()returns voidClears the frame buffer. The screen itself does not change until you call `display()` or `partialUpdate()`.
ReturnsNothing.
display.display(bool _leaveOn = 0)returns voidSends the frame buffer to the e-paper panel and refreshes it.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
bool | _leaveOn | Optional. If set to 1, the panel supply stays on after the refresh. Defaults to 0. |
display.print(value)returns size_tPrints text or a number at the cursor, like `Serial.print()`. The display class inherits it from the Arduino `Print` class (through Adafruit GFX). The text appears after the next `display()` or `partialUpdate()`.
ReturnsNumber of bytes written.
Parameters
| Type | Name | Description |
|---|---|---|
various | value | A string, character or number to print. |
display.partialUpdate(bool _forced = false, bool leaveOn = false)returns uint32_tRefreshes only the parts of the screen that changed, without a full refresh. Works in black and white mode only.
ReturnsNumber of pixels that changed from black to white.
Parameters
| Type | Name | Description |
|---|---|---|
bool | _forced | For advanced use with deep sleep. Defaults to false. |
bool | leaveOn | If true, the panel supply stays on after the update. Defaults to false. |
display.connectWiFi(const char *ssid, const char *pass, int timeout = WIFI_TIMEOUT, bool printToSerial = false)returns boolConnects Inkplate to a Wi-Fi network in station mode and waits for the connection. `WIFI_TIMEOUT` is 23 seconds.
Returns`true` if connected, `false` if the timeout passed first.
Parameters
| Type | Name | Description |
|---|---|---|
const char * | ssid | Name of the Wi-Fi network. |
const char * | pass | Password of the Wi-Fi network. |
int | timeout | Timeout in seconds. Defaults to 23. |
bool | printToSerial | If true, prints progress to the serial port. Call Serial.begin() first. Defaults to false. |
display.isConnected()returns boolChecks whether Inkplate is connected to a Wi-Fi network.
Returns`true` if connected, `false` if not.
delay(unsigned long ms)returns voidPauses the sketch for the given number of milliseconds. Arduino core function.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
unsigned long | ms | Time to wait in milliseconds. |
display.println(value)returns size_tSame as `print()`, then moves the cursor to the start of the next line. Comes from the Arduino `Print` class.
ReturnsNumber of bytes written.
Parameters
| Type | Name | Description |
|---|---|---|
various | value | Optional. A string, character or number to print. |
display.applyHttpsCertificate(const char *certificate)returns voidStores a certificate that the library then uses to check the website when it downloads over HTTPS. Without one, the library connects over HTTPS without checking the certificate.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
const char * | certificate | The certificate as a PEM text string. |
display.image.draw(const char *path, int x, int y, bool dither = 1, bool invert = 0)returns boolDraws an image from a URL (`http://` or `https://`) or from the SD card, picking the decoder from the file extension: BMP/DIB, JPG/JPEG or PNG. Call `display()` afterwards to show it.
Returns`true` if the image was drawn, `false` if it was not.
Parameters
| Type | Name | Description |
|---|---|---|
const char * | path | URL or file path of the image. |
int | x | X position of the image top-left corner. |
int | y | Y position of the image top-left corner. |
bool | dither | If true, dithers the image. Defaults to true. |
bool | invert | If true, swaps black and white. Defaults to false. |
display.disconnect()returns voidTurns the Wi-Fi radio off.
ReturnsNothing.
What to expect
The display prints "Connecting to WiFi...", adds a dot every half second until it is connected, then prints "WiFi OK! Downloading...". After that it draws the image from varipass.org at the top-left corner of the screen. If the image cannot be drawn, it prints "Image open error".
The example comments say only a Windows bitmap with 1, 4, 8 or 24 bits of color depth and no compression works. The full example also tries a second image from another website and prints "This image wont load as the certificate is invalid", because the certificate only fits varipass.org.