Skip to main content

Wi-Fi web server

What this example shows​

Turning Inkplate 10 into its own Wi-Fi access point with a small web page. Connect your phone or computer to the Inkplate network, open the address shown on the screen, type some text into the form and press the button. The text then appears on the e-paper display.

The sketch does not join your home network, so you do not need to enter Wi-Fi credentials. The access point is called "Inkplate 10" with the password "Soldered", set by the two #define lines at the top, and you can change them.

Example code​

Trimmed from Inkplate10_HTTP_Web_Server.ino: the file header comment is removed, the sketch is otherwise unchanged. The page that the browser receives is stored in htmlCode.h, which sits in the same folder and is shown second. Keep both files in one sketch folder.

Select Board
Inkplate10_HTTP_Web_Server.ino
// 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
#include "htmlCode.h" //Include .h file where we stored out html code of our web page
#include <WebServer.h> //Include ESP32 library for Web server
#include <WiFi.h> //Include ESP32 WiFi library
#include <WiFiClient.h> //Include ESP32 WiFi library for AP
#include <uri/UriBraces.h>

#define ssid "Inkplate 10"
#define pass "Soldered"

Inkplate display(INKPLATE_1BIT); // Create an object on Inkplate library and also set library into 1 Bit mode (BW)
WebServer server(80); // Create Web server on port 80 (HTTP port number)

IPAddress serverIP;
String txt;

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.setTextSize(3); // Scale text to be two times bigger then original (5x7 px)
display.setTextColor(BLACK, WHITE); // Set text color to black and background color to white
display.setTextWrap(true); // If text does not fit on screen, send it to new line

WiFi.begin(); // Init. WiFi library
WiFi.mode(WIFI_AP); // Set WiFi to Access point mode
WiFi.softAP(ssid, pass); // Set SSID (WiFi name) and password for Access point

serverIP = WiFi.softAPIP(); // Get the server IP address

server.on("/", handleRoot); // If you open homepage, go to handle root function
server.on(UriBraces("/string/{}"),
handleString); // If you send some text to Inkplate, go to handleString function. Note that {} brackets at
// the end of address. That means that web address has some arguments (our text!).
server.begin(); // Start the web server
updatePaper();
}

void loop()
{
server.handleClient(); // You have to constantly read if there is any new client connected to web server
}

void updateHTML()
{ // This function will send response to client and send HTML code of our web page
server.send(200, "text/html", s);
}

void handleRoot()
{ // This function will send response to client if client open a root (homepage) of our web page
updateHTML();
}

void handleString()
{ // This function will send response to client, send HTML code of web page, get the text from argument sent in web page
// address and refresh screen with new text
txt = server.arg(0);
updateHTML();
updatePaper();
}

void updatePaper()
{ // This function updates screen with new data (text)
display.clearDisplay(); // Clear everything from epaper frame buffer
display.setCursor(20, 40); // Print out instruction on how to connect to Inkplate WiFi and how to open a web page
display.print("Connect to ");
display.print(ssid);
display.println(" WiFi with pass: ");
display.setCursor(240, 100);
display.println(pass);
display.setCursor(100, 150);
display.print("Open Your web browser and open");
display.setCursor(240, 210);
display.print("http://");
display.print(serverIP);
display.println('/');
display.println();
display.fillRect(10, 240, 780, 4, BLACK);
display.println("User text:"); // Print out what user typed in web page
display.print(txt);
display.display(); // Send everything to screen (refresh the screen)
}
Select Board
htmlCode.h
String s = "<head>"
"<title>Soldered Inkplate e-paper display</title>"

"<style type='text/css'>"

"textarea {"
"width: 300px;"
"height: 5em;"
"}"

"textarea {"
" font-size: 150%;"
"}"

"t1 {"
" font-size: 150%;"
" font-weight: bold;"
"}"

"</style>"

"</head>"

"<body><form action='/string/' method='get' target='_self'><t1>Insert string that you want to display:</t1><br><textarea autofocus maxlength = '100' rows = '7' cols = '30' name = 'input1'>Write some text!</textarea><br>"

"<input type='submit' value='Send to display!'></form></body></html>";

Functions used​

Inkplate(uint8_t mode)returns None

Creates 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

TypeNameDescription
uint8_tmodeDisplay mode, INKPLATE_1BIT here.
WebServer(uint16_t port)returns None

Creates a web server on the given port. 80 is the standard HTTP port. Part of the ESP32 Arduino core.

ReturnsDeclaration; no return value.

Parameters

TypeNameDescription
intportTCP port to listen on.
display.begin()returns void

Initializes the Inkplate library and its peripherals and clears the frame buffer. Call it once in `setup()`; later calls are ignored.

ReturnsNothing.

display.clearDisplay()returns void

Clears the frame buffer. The screen itself does not change until you call `display()` or `partialUpdate()`.

ReturnsNothing.

display.display(bool _leaveOn = 0)returns void

Sends the frame buffer to the e-paper panel and refreshes it.

ReturnsNothing.

Parameters

TypeNameDescription
bool_leaveOnOptional. If set to 1, the panel supply stays on after the refresh. Defaults to 0.
display.setTextSize(uint8_t s)returns void

Sets the text scale. 1 is the base size, 2 is twice as big, and so on. The function comes from the Adafruit GFX base class the library builds on.

ReturnsNothing.

Parameters

TypeNameDescription
uint8_tsText scale factor.
display.setTextColor(uint16_t c, uint16_t bg)returns void

Sets the text color and the background color behind it. Comes from the Adafruit GFX base class.

ReturnsNothing.

Parameters

TypeNameDescription
uint16_tcText color.
uint16_tbgBackground color.
display.setTextWrap(bool w)returns void

Chooses whether text that is too long for the screen width wraps to the next line (`true`) or is clipped (`false`). Comes from the Adafruit GFX base class.

ReturnsNothing.

Parameters

TypeNameDescription
boolwtrue to wrap, false to clip.
WiFi.begin()returns wl_status_t

Initializes the Wi-Fi library. With no arguments the example only uses it to start the Wi-Fi stack before switching to access point mode. Part of the ESP32 Arduino core.

ReturnsConnection status.

WiFi.mode(wifi_mode_t mode)returns bool

Sets the Wi-Fi mode. The sketch uses `WIFI_MODE_STA` (join a network), `WIFI_AP` (be an access point) and `WIFI_OFF` (radio off). Part of the ESP32 Arduino core.

Returns`true` if the mode was set.

Parameters

TypeNameDescription
wifi_mode_tmodeThe Wi-Fi mode.
WiFi.softAP(const char *ssid, const char *pass)returns bool

Starts Inkplate as a Wi-Fi access point with the given name and password. Part of the ESP32 Arduino core.

Returns`true` if the access point started.

Parameters

TypeNameDescription
const char *ssidName of the access point.
const char *passPassword of the access point.
WiFi.softAPIP()returns IPAddress

Returns the IP address of Inkplate while it runs as an access point. Part of the ESP32 Arduino core.

ReturnsThe access point IP address.

server.on(const Uri &uri, handler)returns void

Registers a function that runs when a browser requests the given path. `UriBraces` with a path that ends in a braces placeholder matches a path with one argument after `/string/`.

ReturnsNothing.

Parameters

TypeNameDescription
const Uri &uriThe path to handle, as a string or UriBraces.
functionhandlerThe function to call.
UriBraces(const String &uri)returns None

Builds a path matcher where `{}` stands for a part of the address that can change. Included with `uri/UriBraces.h`.

ReturnsConstructor; no return value.

Parameters

TypeNameDescription
const String &uriPath pattern such as /string/{}.
server.begin()returns void

Starts the web server.

ReturnsNothing.

server.handleClient()returns void

Checks for and serves waiting browser requests. Call it often, which the sketch does in `loop()`.

ReturnsNothing.

server.send(int code, const char *content_type, const String &content)returns void

Sends a response to the browser.

ReturnsNothing.

Parameters

TypeNameDescription
intcodeHTTP status code, 200 here.
const char *content_typeContent type, text/html here.
const String &contentThe response body, here the page in htmlCode.h.
server.arg(int i)returns String

Returns the value of the request argument at index `i`.

ReturnsThe argument value.

Parameters

TypeNameDescription
intiIndex of the argument.
display.setCursor(int16_t x, int16_t y)returns void

Sets where the next printed text starts, in pixels from the top-left corner. Comes from the Adafruit GFX base class.

ReturnsNothing.

Parameters

TypeNameDescription
int16_txX position in pixels.
int16_tyY position in pixels.
display.print(value)returns size_t

Prints 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

TypeNameDescription
variousvalueA string, character or number to print.
display.println(value)returns size_t

Same as `print()`, then moves the cursor to the start of the next line. Comes from the Arduino `Print` class.

ReturnsNumber of bytes written.

Parameters

TypeNameDescription
variousvalueOptional. A string, character or number to print.
display.fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)returns void

Draws a filled rectangle. Comes from the Adafruit GFX base class.

ReturnsNothing.

Parameters

TypeNameDescription
int16_txX position of the top-left corner.
int16_tyY position of the top-left corner.
int16_twWidth in pixels.
int16_thHeight in pixels.
uint16_tcolorFill color, for example BLACK.
IPAddress()returns None

Holds an IP address. The sketch stores the access point address in an `IPAddress` variable and prints it on the display. Part of the ESP32 Arduino core.

ReturnsConstructor; no return value.

What to expect​

The display shows instructions: connect to the "Inkplate 10" Wi-Fi with the password "Soldered", then open http:// followed by the access point IP address in your browser. Below a black line, "User text:" is followed by whatever you sent.

In the browser you get a form with a text box (100 characters at most) and a "Send to display!" button. Each time you send, the screen refreshes with your new text.