2017-10-19 20:21:02 +00:00
|
|
|
# ESPUI
|
2019-02-26 15:15:37 +00:00
|
|
|
|
2019-03-24 17:10:21 +00:00
|
|
|
![ESPUI](https://github.com/s00500/ESPUI/blob/master/docs/ui_complete.png) //
|
|
|
|
TODO: Update Logo
|
2017-10-19 20:25:37 +00:00
|
|
|
|
2019-02-26 15:15:37 +00:00
|
|
|
ESPUI is a simple library to make a web user interface for your projects using
|
|
|
|
the **ESP8266** or the **ESP32** It uses web sockets and lets you create,
|
|
|
|
control, and update elements on your GUI through multiple devices like phones
|
|
|
|
and tablets.
|
|
|
|
|
|
|
|
ESPUI uses simple Arduino-style syntax for creating a solid, functioning user
|
|
|
|
interface without too much boilerplate code.
|
2017-10-19 20:21:02 +00:00
|
|
|
|
2019-02-26 15:15:37 +00:00
|
|
|
So if you either don't know how or just don't want to waste time: this is your
|
|
|
|
simple solution user interface without the need of internet connectivity or any
|
|
|
|
additional servers.
|
2017-10-19 20:21:02 +00:00
|
|
|
|
2019-03-24 17:10:21 +00:00
|
|
|
The Library runs fine on any kind of ESP8266 and ESP32 (NodeMCU Boards, usw)
|
2017-10-19 20:21:02 +00:00
|
|
|
|
2019-02-26 15:15:37 +00:00
|
|
|
# Important notes
|
2017-10-19 20:21:02 +00:00
|
|
|
|
2019-03-24 17:10:21 +00:00
|
|
|
THIS IS THE 2.0.0 DEVELOPMENT BRANCH, NOT GUARANTIED TO WORK
|
2019-03-24 14:37:37 +00:00
|
|
|
|
|
|
|
**Roadmap for 2.0.0:**
|
|
|
|
|
2019-03-24 15:06:35 +00:00
|
|
|
- ArduinoJSON 6.10.0 Support ✅
|
2019-03-24 15:15:30 +00:00
|
|
|
- Tabs by @eringerli ISSUE #45 ✅
|
|
|
|
- remove black line without tabs ✅
|
2019-03-26 15:22:21 +00:00
|
|
|
- API changes by @eringerli ✅
|
2019-03-24 18:18:53 +00:00
|
|
|
- less updateControl functions ✅
|
2019-03-26 15:22:21 +00:00
|
|
|
- proper wrappers for all create/update actions ✅
|
2019-03-24 15:08:05 +00:00
|
|
|
- OptionList by @eringerli
|
2019-03-26 15:22:21 +00:00
|
|
|
- Min Max on slider by @eringerli ✅
|
|
|
|
- Public Access to ESPAsyncServer
|
2019-03-24 14:37:37 +00:00
|
|
|
- Accelerometer Widget
|
2019-03-26 15:22:21 +00:00
|
|
|
- Graph Widget
|
|
|
|
-
|
|
|
|
- Cleanup Example, DNS and autojoin
|
2019-03-24 17:10:21 +00:00
|
|
|
- Cleanup and extend Documentation
|
|
|
|
- Number field ✅
|
|
|
|
- Text field ✅
|
|
|
|
- Data directory ✅
|
2019-03-24 15:06:35 +00:00
|
|
|
- Graph Usage
|
|
|
|
- Accelerometer
|
|
|
|
- Slider
|
|
|
|
- OptionList
|
|
|
|
- Tab usage
|
2019-03-24 15:06:42 +00:00
|
|
|
- Verbosity setting
|
2017-10-19 20:21:02 +00:00
|
|
|
|
2019-03-26 15:22:21 +00:00
|
|
|
## OLD Roadmap :
|
|
|
|
|
|
|
|
- Datagraph output -> _WIP_
|
|
|
|
- Number min and max value
|
|
|
|
- proper return value (as int and not as string) for slider
|
|
|
|
|
2019-03-24 18:18:53 +00:00
|
|
|
## Changelog for functions:
|
|
|
|
|
|
|
|
- split pad into pad and padWithCenter
|
|
|
|
- Cleaned order or parameters on switch
|
|
|
|
- cleaned order of parameters on pad
|
|
|
|
- Changes all numbers to actually be numbers (slider value, number value, min
|
|
|
|
and max)
|
|
|
|
|
2017-11-13 10:17:58 +00:00
|
|
|
## Dependencies
|
2019-02-26 15:15:37 +00:00
|
|
|
|
2017-11-13 10:17:58 +00:00
|
|
|
This library is dependent on the following libraries to function properly.
|
2017-12-01 16:22:14 +00:00
|
|
|
|
|
|
|
- [ESPAsyncWebserver](https://github.com/me-no-dev/ESPAsyncWebServer)
|
2019-03-24 17:10:21 +00:00
|
|
|
- [ArduinoJson](https://github.com/bblanchon/ArduinoJson) (Last tested with
|
|
|
|
version 6.10.0) **Plus for ESP8266**
|
2019-02-26 15:15:37 +00:00
|
|
|
|
2017-12-01 16:22:14 +00:00
|
|
|
- [ESPAsyncTCP](https://github.com/me-no-dev/ESPAsyncTCP)
|
|
|
|
|
|
|
|
**Additionally necessary for ESP32**
|
2017-10-19 20:21:02 +00:00
|
|
|
|
2019-02-26 15:15:37 +00:00
|
|
|
- [AsyncTCP](https://github.com/me-no-dev/AsyncTCP)
|
2017-10-19 20:21:02 +00:00
|
|
|
|
2017-11-13 10:17:58 +00:00
|
|
|
## How to Install
|
2017-05-18 23:08:17 +00:00
|
|
|
|
2017-11-13 10:17:58 +00:00
|
|
|
Make sure all the dependencies are installed, then install like so:
|
2017-05-18 23:08:17 +00:00
|
|
|
|
2019-02-26 15:15:37 +00:00
|
|
|
#### Directly Through Arduino IDE (_recommended_)
|
2017-05-18 23:08:17 +00:00
|
|
|
|
2019-02-26 15:15:37 +00:00
|
|
|
You can find this Library in the Arduino IDE library manager Go to Sketch >
|
|
|
|
Include Library > Library Manager > Search for "ESPUI" > Install
|
2017-05-18 23:08:17 +00:00
|
|
|
|
2017-11-13 10:17:58 +00:00
|
|
|
#### Manual Install
|
2017-05-18 23:08:17 +00:00
|
|
|
|
2019-02-26 15:15:37 +00:00
|
|
|
For Windows: Download the
|
|
|
|
[Repository](https://github.com/s00500/ESPUI/archive/master.zip) and extract the
|
|
|
|
.zip in Documents>Arduino>Libraries>{Place "ESPUI" folder Here}
|
2017-05-18 23:08:17 +00:00
|
|
|
|
2019-02-26 15:15:37 +00:00
|
|
|
For Linux: Download the
|
|
|
|
[Repository](https://github.com/s00500/ESPUI/archive/master.zip) and extract the
|
|
|
|
.zip in Sketchbook/Libraries/{Place "ESPUI" folder Here}
|
2017-05-18 23:08:17 +00:00
|
|
|
|
2019-02-26 15:15:37 +00:00
|
|
|
For macOs: Download the
|
|
|
|
[Repository](https://github.com/s00500/ESPUI/archive/master.zip) and extract the
|
|
|
|
.zip in ~/Documents/Arduino/libraries/{Place "ESPUI" folder Here}
|
2017-05-18 23:08:17 +00:00
|
|
|
|
2017-11-13 10:17:58 +00:00
|
|
|
#### Manually through IDE
|
2017-05-18 23:08:17 +00:00
|
|
|
|
2019-02-26 15:15:37 +00:00
|
|
|
Download the [Repository](https://github.com/s00500/ESPUI/archive/master.zip),
|
|
|
|
Go to Sketch>Include Library>Add .zip Library> Select the Downloaded .zip File.
|
2017-05-18 23:08:17 +00:00
|
|
|
|
2018-05-27 09:41:52 +00:00
|
|
|
## Getting started
|
2017-05-18 23:08:17 +00:00
|
|
|
|
2019-03-24 17:10:21 +00:00
|
|
|
ESPUI serves several files to the browser to build up its web interface. This
|
|
|
|
can be achieved in 2 ways: _PROGMEM_ or _SPIFFS_
|
2017-11-29 13:36:19 +00:00
|
|
|
|
2019-02-26 15:15:37 +00:00
|
|
|
_When `ESPUI.begin()` is called the default is serving files from Memory and
|
|
|
|
ESPUI should work out of the box!_
|
2018-05-27 09:41:52 +00:00
|
|
|
|
2019-03-24 17:10:21 +00:00
|
|
|
**OPTIONAL:** But if this causes your program to _use too much memory_ you can
|
|
|
|
burn the files into the SPIFFS filesystem on the ESP. There are now two ways to
|
|
|
|
do this: you can either use the ESP file upload tool or you use the library
|
|
|
|
function `ESPUI.prepareFileSystem()`
|
2018-05-27 09:41:52 +00:00
|
|
|
|
2019-02-26 15:15:37 +00:00
|
|
|
#### Simple filesystem preparation (_recommended_)
|
2017-11-29 13:36:19 +00:00
|
|
|
|
2019-02-26 15:15:37 +00:00
|
|
|
Just open the example sketch **prepareFileSystem** and run it on the ESP, (give
|
|
|
|
it up to 30 seconds, you can see the status on the Serial Monitor), The library
|
|
|
|
will create all needed files. Congratulations, you are done, from now on you
|
|
|
|
just need to to this again when there is a library update, or when you want to
|
|
|
|
use another chip :-) Now you can upload your normal sketch, when you do not call
|
|
|
|
the `ESPUI.prepareFileSystem()` function the compiler will strip out all the
|
2019-03-24 17:10:21 +00:00
|
|
|
unnecessary strings that are already saved in the chip's filesystem and you have
|
|
|
|
more program memory to work with.
|
2017-05-18 23:08:17 +00:00
|
|
|
|
2017-10-19 20:21:02 +00:00
|
|
|
## User interface Elements
|
2019-02-26 15:15:37 +00:00
|
|
|
|
|
|
|
- Label (updateable)
|
|
|
|
- Button
|
|
|
|
- Switch (updateable)
|
|
|
|
- Control pad
|
|
|
|
- Control pad with center button
|
|
|
|
- Slider
|
|
|
|
- Text Input (updateable)
|
|
|
|
- Numberinput (updateable)
|
|
|
|
|
|
|
|
Checkout the example for the usage
|
|
|
|
|
2018-05-27 09:41:52 +00:00
|
|
|
## Available colors:
|
|
|
|
|
|
|
|
- COLOR_TURQUOISE
|
|
|
|
- COLOR_EMERALD
|
|
|
|
- COLOR_PETERRIVER
|
|
|
|
- COLOR_WETASPHALT
|
|
|
|
- COLOR_SUNFLOWER
|
|
|
|
- COLOR_CARROT
|
|
|
|
- COLOR_ALIZARIN
|
|
|
|
- COLOR_NONE
|
2017-05-18 23:31:51 +00:00
|
|
|
|
2017-05-18 23:08:17 +00:00
|
|
|
## Documentation
|
|
|
|
|
2019-02-26 15:15:37 +00:00
|
|
|
The heart of ESPUI is
|
|
|
|
[ESPAsyncWebserver](https://github.com/me-no-dev/ESPAsyncWebServer). ESPUI's
|
|
|
|
frontend is based on [Skeleton CSS](http://getskeleton.com/) and jQuery-like
|
|
|
|
lightweight [zepto.js](https://zeptojs.com/) for Handling Click Events Etc. The
|
|
|
|
communication between the _ESP32_ and the client browser works using web
|
|
|
|
sockets. ESPUI does not need network access and can be used in standalone access
|
|
|
|
point mode. All assets are loaded from the internal SPIFFS filesystem of the
|
|
|
|
ESP32.
|
|
|
|
|
|
|
|
This section will explain in detail how the Library is to be used from the
|
|
|
|
Arduino code side. As of now the Facilino blocks are not implemented. In the
|
|
|
|
arduino setup() routine the interface can be customised by adding UI Elements.
|
|
|
|
This is done by calling the corresponding library methods on the Library object
|
|
|
|
ESPUI. Eg: `ESPUI.button(“button”, &myCallback);` creates a button in the
|
|
|
|
interface that calls the “myCallback” function when changed. All buttons and
|
|
|
|
items call their callback whenever there is a state change from them. This means
|
|
|
|
the button will call the callback when it is pressed and also again when it is
|
|
|
|
released. To separate different events an integer number with the event name is
|
|
|
|
passed to the callback function that can be handled in a `switch(){}case{}`
|
|
|
|
statement. Here is an overview of the currently implemented different elements
|
|
|
|
of the UI library:
|
2017-11-13 10:02:15 +00:00
|
|
|
|
2017-11-13 10:17:58 +00:00
|
|
|
#### Button
|
2017-11-13 10:02:15 +00:00
|
|
|
|
|
|
|
![Buttons](https://github.com/s00500/ESPUI/blob/master/docs/ui_button.png)
|
|
|
|
|
2019-02-26 15:15:37 +00:00
|
|
|
Buttons have a name and a callback value. They have one event for press and one
|
|
|
|
for release.
|
2017-11-13 10:02:15 +00:00
|
|
|
|
2017-11-13 10:17:58 +00:00
|
|
|
#### Switch
|
2017-11-13 10:02:15 +00:00
|
|
|
|
|
|
|
![Switches](https://github.com/s00500/ESPUI/blob/master/docs/ui_switches.png)
|
|
|
|
|
2019-02-26 15:15:37 +00:00
|
|
|
Switches sync their state on all connected devices. This means when you change
|
|
|
|
their value they change visibly on all tablets or computers that currently
|
|
|
|
display the interface. They also have two types of events: one for turning on
|
|
|
|
and one for turning off.
|
2017-11-13 10:02:15 +00:00
|
|
|
|
2017-11-13 10:17:58 +00:00
|
|
|
#### Buttonpad
|
2017-11-13 10:02:15 +00:00
|
|
|
|
|
|
|
![control pads](https://github.com/s00500/ESPUI/blob/master/docs/ui_controlpad.png)
|
|
|
|
|
2019-02-26 15:15:37 +00:00
|
|
|
Button pads come in two flavours: with or without a center button. They are very
|
|
|
|
useful for con-trolling all kinds of movements of vehicles or also of course our
|
|
|
|
walking robots. They use a single callback per pad and have 8 or 10 different
|
|
|
|
event types to differentiate the button actions.
|
2017-11-13 10:02:15 +00:00
|
|
|
|
2017-11-13 10:17:58 +00:00
|
|
|
#### Labels
|
2017-11-13 10:02:15 +00:00
|
|
|
|
|
|
|
![labels](https://github.com/s00500/ESPUI/blob/master/docs/ui_labels.png)
|
|
|
|
|
2019-02-26 15:15:37 +00:00
|
|
|
Labels are a nice tool to get information from the robot to the user interface.
|
|
|
|
This can be done to show states, values of sensors and configuration parameters.
|
|
|
|
To send data from the code use `ESP.print(labelId, “Text”);` . Labels get a name
|
|
|
|
on creation and a initial value. The name is not changeable once the UI
|
|
|
|
initialised.
|
2017-11-13 10:17:58 +00:00
|
|
|
|
2019-02-26 15:15:37 +00:00
|
|
|
Labels automatically wrap your text. If you want them to have multiple lines use
|
|
|
|
the normal `<br>` tag in the string you print to the label
|
2018-05-27 09:41:52 +00:00
|
|
|
|
2017-11-29 10:35:54 +00:00
|
|
|
#### Slider
|
|
|
|
|
2018-05-27 10:01:06 +00:00
|
|
|
![labels](https://github.com/s00500/ESPUI/blob/master/docs/ui_slider.png)
|
|
|
|
|
2019-02-26 15:15:37 +00:00
|
|
|
The Slider can be used to slide through a value from 1 to 100. Slides provide
|
|
|
|
realtime data, are touch compatible and can be used to for example control a
|
|
|
|
Servo. The current value is shown while the slider is dragged in a little bubble
|
2019-03-26 15:22:21 +00:00
|
|
|
over the handle. In the Callback the slider does not return an int but a String.
|
|
|
|
Use the .toInt
|
2017-11-29 10:35:54 +00:00
|
|
|
|
2019-03-24 17:10:21 +00:00
|
|
|
#### Number Input
|
|
|
|
|
|
|
|
TODO: Add image
|
|
|
|
|
|
|
|
The numberinput can be used to directly input numbers to your program. You can
|
|
|
|
enter a Value into it and when you are done with your change it is sent to the
|
|
|
|
ESP.
|
|
|
|
|
|
|
|
#### Text Input
|
|
|
|
|
|
|
|
TODO: Add image
|
|
|
|
|
|
|
|
The textinput works very similar like the number input but with a string. You
|
|
|
|
can enter a String into it and when you are done with your change it is sent to
|
|
|
|
the ESP.
|
|
|
|
|
|
|
|
#### Using Tabs
|
|
|
|
|
|
|
|
TODO: Add image
|
|
|
|
|
|
|
|
// TODO: add Text for tabs
|
|
|
|
|
2017-12-01 16:22:14 +00:00
|
|
|
#### Initialisation of the UI
|
2017-11-13 10:02:15 +00:00
|
|
|
|
2019-02-26 15:15:37 +00:00
|
|
|
After all the elements are configured you can use `ESPUI.begin(“Some Title”);`
|
|
|
|
to start the UI interface. (Or `ESPUI.beginSPIFFS(“Some Title”);` respectively)
|
|
|
|
Make sure you setup a working network connection or AccesPoint **before** (See
|
|
|
|
example). The web interface can then be used from multiple devices at once and
|
|
|
|
also shows an connection status in the top bar. The library is designed to be
|
|
|
|
easy to use and can still be extended with a lot of more functionality.
|
2017-11-13 10:02:15 +00:00
|
|
|
|
2019-03-24 17:10:21 +00:00
|
|
|
#### Log output
|
|
|
|
|
|
|
|
ESPUI has several different log levels. You can set them using the
|
|
|
|
`ESPUI.setVerbosity(Verbosity::VerboseJSON)` function.
|
|
|
|
|
|
|
|
Loglevels are:
|
|
|
|
|
|
|
|
- Verbosity::Quiet (default)
|
|
|
|
- Verbosity::Verbose
|
|
|
|
- Verbosity::VerboseJSON
|
|
|
|
|
|
|
|
// TODO: Add some more notes here
|
|
|
|
|
2018-05-27 09:41:52 +00:00
|
|
|
# Notes for Development
|
2018-11-24 23:32:23 +00:00
|
|
|
|
2019-03-24 17:10:21 +00:00
|
|
|
If you want to work on the HTML/CSS/JS files, do make changes in the `data`
|
|
|
|
directory. When you need to transfer that code to the ESP, run
|
|
|
|
`tools/prepare_static_ui_sources.py -a` (this script needs python3 with the
|
2019-02-26 15:15:37 +00:00
|
|
|
modules htmlmin, jsmin and csscompressor). This will generate a) minified files
|
|
|
|
next to the original files to be uploaded with the ESP32 sketch data uploader
|
|
|
|
mentioned above and b) the C header files in `src` that contain the minified and
|
|
|
|
gzipped HTML/CSS/JS data (which are used by the **prepareFileSystem** example
|
|
|
|
sketch or when they are served from PROGMEM; see above in the section "Getting
|
|
|
|
started"). Alternatively, you can duplicate the `examples/gui` directory and
|
|
|
|
work on the copy. Then specify the `--source` and `--target` arguments to the
|
|
|
|
`prepare_static_ui_sources.py` script (run the script without arguments for
|
|
|
|
help).
|
|
|
|
|
|
|
|
If you don't have a python environment, you need to minify and gzip the
|
|
|
|
HTML/CSS/JS files manually. I wrote a little useful jsfiddle for this,
|
|
|
|
[see here](https://jsfiddle.net/s00500/yvLbhuuv/).
|
|
|
|
|
|
|
|
If you change something in HTML/CSS/JS and want to create a pull request, please
|
|
|
|
do include the minified versions and corresponding C header files in your
|
|
|
|
commits.
|
2018-05-27 09:41:52 +00:00
|
|
|
|
2017-05-18 23:08:17 +00:00
|
|
|
# Contribute
|
2019-02-26 15:15:37 +00:00
|
|
|
|
|
|
|
Liked this Library? You can **support** me by sending me a :coffee:
|
|
|
|
[Coffee](https://paypal.me/lukasbachschwell/3).
|
2019-03-24 17:10:21 +00:00
|
|
|
|
|
|
|
Otherwise I really welcome **Pull Requests**.
|