Skip to content

Full autocontained (on SPIFFS) async web server on ESP8266. Written as a Library.

License

Notifications You must be signed in to change notification settings

species5618/FSBrowserNG_5618

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FSBrowserNG

Full autocontained (on SPIFFS) async web server on ESP8266. Written as a Library.

Same features as my FSBrowser sketch but built around AsyncWebServer library and implemented as a library itself. See *.ino file for usage example

Species5618 plans

  • 3 or more specials folders , with callback to toplevel ino code support, to allow main code to send and recieve data from web without editing library

    • json , get and put JSON data back to main code
    • rest , get and put plain text data to main code
    • post , form post handlers
  • Add Config capability reuse JSON capability to store generic config items in JSON files on SPIFFS

  • 2FA login, plan to include a google auithenticator libary so one time password can be used, this feature May be added back into orginal project

  • send email on config change or login

  • send SMS via textlocal or nexmo,

    • may try and support tokenised URL
    • may try and support SSL URLs

Introduction

I wanted to add a standard environment for all my ESP8266 based projects to be able to configure them via web browser to avoid code editing when I need to change some settings like SSID, password, etc.

I found John Lassen's WebConfig project to almost fit my needs. It uses a simple but powerful web interface with dynamic data using microAJAX. I've added some dynamic data using Links2004's WebSockets library.

So, I tried to fork it. Original WebConfig project stores web pages on PROGMEM, but I was recently using SPIFFS on ESP8266 and I think it is a good way to store web content. I found I was not the first to think this when I noticed about FSBrowser example in ESP8266WebServer library.

This example code has a great bonus: a text editor (based on ACE) with syntax highligth that can be used to edit html on board directly. I found a bug on it (already sent to esp8266/Arduino repository) and, when fixed, noticed how usefull this editor is.

My code is a fork of both projects, and has become a start framework for my future projects. Finally i've refactored code to use it as a library, so it is easier to integrate it in a project. See this example to check that only 3 lines are necessary to use it.

I only have to add more HTML data and some funtions to show dynamic data in order to adapt it to any other task.

It has integrated NTP syncronization based on my own NTPClient library, that can be configured via this Web interface too.

Configuration is stored on SPIFFS too, in a JSON file. So, it recovers config during boot.

Implemented OTA Update with Arduino IDE and Web interface.

Web access can be protected with Basic HTTP Authentication.

I use a library called ESPAsyncWebServer. It is much faster than standard ESP8266WebServer library due to its async design.

Notice that Basic HTTP Authentication alone is not suitable to protect data over Internet. It allows recovery of user and password via sniffing and does not encrypt data flow. It is valid to give a first protection and may be a good solution combining it with strong VPN. Take this in account when connecting it to public networks or Internet.

WiFi connection

I've implemented a way to turn ESP8266 into AP mode so I can set WiFi config when prior WiFi is not available. It is done by setting IO pin 4 to high status during boot. This pin is configurable by a #define. in FSWebServerlib.h. You must ensure it is connected to GND to allow it to connect to a router.

AP Mode is also started when loadConfig() finds no config file (config.json). This is so to help first use without needind to hardcode user and password. config.js is generated automatically if needed:

{
	"ssid":"YOUR_SSID",
	"pass":"YOUR_PASSWORD",
	"ip":[192,168,1,4],
	"netmask":[255,255,255,0],
	"gateway":[192,168,1,1],
	"dns":[192,168,1,1],
	"dhcp":1
	,"ntp":"es.pool.ntp.org"
	,"NTPperiod":5
	,"timeZone":10
	,"daylight":1
	,"deviceName":"ESP8266fs"
}

WiFi connection to router is confirmed via LED on IO pin GPIO02 as soon an IP address is got. Same LED is used to confirm AP mode by flashing 3 times. LED ping can be configured in FSWebServerlib.h.

How to use it

After compile and flash into ESP8266 you need to upload SPIFFS data using download tool for Arduino IDE. Check SPIFFS doc for details.

  • http://ip_address/admin.html takes you to main configuration GUI.
  • http://ip_address/edit contains code editor. Any file stored in SPIFFS may be loaded here and saved using CTRL+S command.
  • http://ip_address/update allows remote update through WEB.
  • http://ip_address/ includes an example info page that shows how to get realtime data from ESP. You may change this to adapt to your project.

You may add your own files to SPIFFS to be served by ESP8266. You only need to add some code if you need dynamic data.

FSBrowserNG extends AsyncWebServer class. So, you may use all its methods as usual.

Dependances

This library makes use of other libraries you have to include in your Arduino library folder.

All other libraries used are installed in Arduino ESP8266 framework.

Troubleshooting

If the compiler exits with an error similar to "WebHandlers.cpp:67:64: error: 'strftime' was not declared in this scope", follow these steps:

  • Locate folder /Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include
  • make a copy of time.h and name it _time.h
  • Locate and open ESPAsyncWebServer\src\WebHandlerImpl.h
  • Replace #include <time.h> to #include <_time.h>

see me-no-dev/ESPAsyncWebServer#60

If the ESP8266 Sketch Data Upload fails with an error similar to "Exception in thread "AWT-EventQueue-0" java.lang.IllegalAccessError: tried to access method", replace the ESP8266FS 0.3.0 plugin by the ESP8266FS 0.2.0 plugin.

TODO

  • HTTP Authentication HTTP Basic authentication implemented. Will try to improve to a more secure mechanism.
  • OTA update via web interface MD5 cheching added.
  • MD5 check of uploaded firmware
  • Configuration protection
  • HTTPS (in evaluation). Not possible with ESP8266
  • Integration of editor in admin.html
  • Convert code to classes and try to design a library to add all this functionality easily.
  • 2-Step authentication

About

Full autocontained (on SPIFFS) async web server on ESP8266. Written as a Library.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 41.1%
  • HTML 40.7%
  • JavaScript 16.7%
  • CSS 1.5%