2020-09-07 11:40:01 +02:00
/*
10 _Inkplate_Web_Server example for e - radionica . com Inkplate 6
For this example you will need a micro USB cable , Inkplate 6 and a device with WiFi and Internet brower ( PC , Laptop , Smartphone , . . . ) .
Select " Inkplate 6(ESP32) " from Tools - > Board menu .
Don ' t have " Inkplate 6(ESP32) " option ? Follow our tutorial and add it :
https : //e-radionica.com/en/blog/add-inkplate-6-to-arduino-ide/
This example will show you how you can use Inkplate as a small and simple standlone Web Server .
You need to connect to Inkplate with WiFi and open IP address shown on Inkplate display .
After opening IP address , you will se text box where you can type some text and after that you press " Send to display " .
Text will apper on Inkplate display !
This is just simple example what you can do with it and of course , you can create much more complex stuff .
HINT : You can change WiFi name and password of your Inkplate WIFi Access point by changing ssid and pass in # define macros !
Want to learn more about Inkplate ? Visit www . inkplate . io
Looking to get support ? Write on our forums : http : //forum.e-radionica.com/en/
15 July 2020 by e - radionica . com
*/
2020-09-14 12:07:34 +02:00
# include <WiFi.h> //Include ESP32 WiFi library
# include <WiFiClient.h> //Include ESP32 WiFi library for AP
# include <WebServer.h> //Include ESP32 library for Web server
# 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
2020-09-07 11:40:01 +02:00
2020-09-14 12:07:34 +02:00
# define ssid "Inkplate6"
# define pass "e-radionica"
2020-09-07 11:40:01 +02:00
2020-09-16 11:55:51 +02:00
Inkplate display ( INKPLATE_1BIT ) ; //Create an object on Inkplate library and also set library into 1 Bit mode (BW)
2020-09-14 12:07:34 +02:00
WebServer server ( 80 ) ; //Create Web server on port 80 (HTTP port number)
2020-09-07 11:40:01 +02:00
IPAddress serverIP ;
String txt ;
2020-09-14 12:07:34 +02:00
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
2020-09-07 11:40:01 +02:00
2020-09-14 12:07:34 +02:00
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
2020-09-07 11:40:01 +02:00
2020-09-14 12:07:34 +02:00
serverIP = WiFi . softAPIP ( ) ; //Get the server IP address
2020-09-07 11:40:01 +02:00
2020-09-14 12:07:34 +02:00
server . on ( " / " , handleRoot ) ; //If you open homepage, go to handle root function
server . on ( " /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
2020-09-07 11:40:01 +02:00
updatePaper ( ) ;
}
2020-09-14 12:07:34 +02:00
void loop ( )
{
server . handleClient ( ) ; //You have to constantly read if there is any new client connected to web server
2020-09-07 11:40:01 +02:00
}
2020-09-14 12:07:34 +02:00
void updateHTML ( )
{ //This function will send response to client and send HTML code of our web page
2020-09-07 11:40:01 +02:00
server . send ( 200 , " text/html " , s ) ;
}
2020-09-14 12:07:34 +02:00
void handleRoot ( )
{ //This function will send response to client if client open a root (homepage) of our web page
2020-09-07 11:40:01 +02:00
updateHTML ( ) ;
}
2020-09-14 12:07:34 +02:00
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
2020-09-07 11:40:01 +02:00
txt = server . arg ( 0 ) ;
updateHTML ( ) ;
updatePaper ( ) ;
}
2020-09-14 12:07:34 +02:00
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
2020-09-07 11:40:01 +02:00
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 ) ;
2020-09-14 12:07:34 +02:00
display . println ( " User text: " ) ; //Print out what user typed in web page
2020-09-07 11:40:01 +02:00
display . print ( txt ) ;
2020-09-14 12:07:34 +02:00
display . display ( ) ; //Send everything to screen (refresh the screen)
2020-09-07 11:40:01 +02:00
}