From 98c9eb7a0437f10d1a3f2675cdca40deb2a5eaa0 Mon Sep 17 00:00:00 2001 From: luc Date: Fri, 8 Apr 2016 17:49:21 +0200 Subject: [PATCH] sync with devt branch --- .travis.yml | 22 +- README.md | 218 +++++++----------- TODO.txt | 5 + keywords.txt => docs/keywords.txt | 0 esp8266/config.cpp | 26 ++- esp8266/config.h | 14 +- esp8266/data/404.tpl | 2 +- esp8266/data/header.inc | 2 +- esp8266/data/restart.tpl | 2 +- esp8266/data/system.tpl | 4 +- esp8266/data/tags.json | 4 + esp8266/esp8266.ino | 33 ++- esp8266/webinterface.cpp | 53 +++-- esp8266/wifi.cpp | 99 ++++---- esp8266/wifi.h | 1 - {Davinci => images/Davinci}/Capture.PNG | Bin {Davinci => images/Davinci}/backside.jpg | Bin {Davinci => images/Davinci}/board.jpg | Bin .../Davinci}/boardconnected.jpg | Bin davinci.png => images/Davinci/davinci.png | Bin {Davinci => images/Davinci}/screen.jpg | Bin Wires.png => images/HW/Wires.png | Bin WiresESP12E.png => images/HW/WiresESP12E.png | Bin {RADDS => images/RADDS}/Capture.PNG | Bin {RADDS => images/RADDS}/RADDS.png | Bin {RADDS => images/RADDS}/screen.jpg | Bin Page1.png => images/UI/Page1.png | Bin Page2.png => images/UI/Page2.png | Bin Page3.png => images/UI/Page3.png | Bin Page4.png => images/UI/Page4.png | Bin Page5-2.png => images/UI/Page5-2.png | Bin Page6.png => images/UI/Page6.png | Bin Page7.png => images/UI/Page7.png | Bin Page8.png => images/UI/Page8.png | Bin files.png => images/UI/files.png | Bin page5.png => images/UI/page5.png | Bin 36 files changed, 228 insertions(+), 257 deletions(-) create mode 100644 TODO.txt rename keywords.txt => docs/keywords.txt (100%) create mode 100644 esp8266/data/tags.json rename {Davinci => images/Davinci}/Capture.PNG (100%) rename {Davinci => images/Davinci}/backside.jpg (100%) rename {Davinci => images/Davinci}/board.jpg (100%) rename {Davinci => images/Davinci}/boardconnected.jpg (100%) rename davinci.png => images/Davinci/davinci.png (100%) rename {Davinci => images/Davinci}/screen.jpg (100%) rename Wires.png => images/HW/Wires.png (100%) rename WiresESP12E.png => images/HW/WiresESP12E.png (100%) rename {RADDS => images/RADDS}/Capture.PNG (100%) rename {RADDS => images/RADDS}/RADDS.png (100%) rename {RADDS => images/RADDS}/screen.jpg (100%) rename Page1.png => images/UI/Page1.png (100%) rename Page2.png => images/UI/Page2.png (100%) rename Page3.png => images/UI/Page3.png (100%) rename Page4.png => images/UI/Page4.png (100%) rename Page5-2.png => images/UI/Page5-2.png (100%) rename Page6.png => images/UI/Page6.png (100%) rename Page7.png => images/UI/Page7.png (100%) rename Page8.png => images/UI/Page8.png (100%) rename files.png => images/UI/files.png (100%) rename page5.png => images/UI/page5.png (100%) diff --git a/.travis.yml b/.travis.yml index a5b7633d..374f9024 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,27 +11,15 @@ before_install: before_script: - "export DISPLAY=:99.0" - sleep 3 # give xvfb some time to start - - wget http://downloads.arduino.cc/arduino-1.6.5-linux64.tar.xz - - tar xf arduino-1.6.5-linux64.tar.xz - - mv arduino-1.6.5 $HOME/arduino_ide + - wget http://downloads.arduino.cc/arduino-1.6.8-linux64.tar.xz + - tar xf arduino-1.6.8-linux64.tar.xz + - mv arduino-1.6.8 $HOME/arduino_ide - cd $HOME/arduino_ide/hardware - mkdir esp8266com - cd esp8266com - - wget https://github.com/esp8266/Arduino/releases/download/2.1.0/esp8266-2.1.0.zip - - unzip esp8266-2.1.0.zip - - mv esp8266-2.1.0 esp8266 - - wget http://arduino.esp8266.com/versions/2.1.0/package_esp8266com_index.json - - mkdir esp8266/package - - mv package_esp8266com_index.json esp8266/package/package_esp8266com_index.template.json + - git clone https://github.com/esp8266/Arduino.git esp8266 - cd esp8266/tools - python get.py - - cd .. - - head -11 ./platform.txt > pt.txt - - echo 'runtime.tools.xtensa-lx106-elf-gcc.path={runtime.platform.path}/tools/xtensa-lx106-elf' >> pt.txt - - echo 'runtime.tools.esptool.path={runtime.platform.path}/tools/esptool' >> pt.txt - - tail -110 ./platform.txt >> pt.txt - - rm -fr platform.txt - - mv pt.txt platform.txt script: @@ -41,7 +29,7 @@ script: - arduino --board esp8266com:esp8266:generic --save-prefs - arduino --get-pref sketchbook.path - build_sketch esp8266/esp8266.ino - + notifications: email: on_success: change diff --git a/README.md b/README.md index b6e0111f..e3b224b1 100644 --- a/README.md +++ b/README.md @@ -1,63 +1,45 @@ # ESP8266 +Firmware for ESP8266 used with 3D printer using [arduino core version](https://github.com/esp8266/Arduino) +This firmware allows not only to have a cheap bridge between Wifi and serial, but also to have a web UI to configure wifi, to monitor 3D printer and even control it, and to make things easy, +UI is fully customizable without reflashing FW. +Firmware should work with any 3D printer firmware (repetier/marlin/etc..) if serial connection has correct setup. +I currently use it with my personnal flavor of [repetier for Due based boards](https://github.com/luc-github/Repetier-Firmware-0.92). +Please use ESP with at least 1M flash, for ESP with 512K there is limited version [here](https://github.com/luc-github/ESP8266/tree/ESP-512K-64KSPIFFS) -[![Join the chat at https://gitter.im/luc-github/ESP8266](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/luc-github/ESP8266?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -FW for ESP8266 used with 3D printer -Development version: -Arduino ide 1.6.5 with stable 2.1.0 from ESP8266 : [![Build Status](https://travis-ci.org/luc-github/ESP8266.svg?branch=master)](https://travis-ci.org/luc-github/ESP8266) -Stable version: -Arduino ide 1.6.5 with stable 2.0.0 from ESP8266, please use https://github.com/luc-github/ESP8266/releases/tag/v0.5.1 +Stable version: +Arduino ide 1.6.5 with stable [2.0.0](http://arduino.esp8266.com/versions/2.1.0/package_esp8266com_index.json) from ESP8266, please use https://github.com/luc-github/ESP8266/releases/tag/v0.5.1 -Both version seems having instability if compiled/flashed under linux (https://github.com/luc-github/ESP8266/issues/64) - so consider to use windows to compile/flash until core is fixed. +Development version: +Arduino ide 1.6.8 with git from ESP8266 : [![Build Status](https://travis-ci.org/luc-github/ESP8266.svg?branch=master)](https://travis-ci.org/luc-github/ESP8266) -##Description -Thanks to @disneysw for bringing this module idea -Thanks to @lkarlslund for suggestion about independant reset using GPIO2 -Thanks to all contributors (treepleks, j0hnlittle , and feedbacks owners) +[All releases](https://github.com/luc-github/ESP8266/wiki) -Have a bridge configurable by web (implemented) and optionally by printer (not yet implemented) -Have a front end to know what is the wifi status (implemented) or know what is the print status (not yet implemented) - this part can be optional and removed by compilation directive if no need +:question:Any question ?[![Join the chat at https://gitter.im/luc-github/ESP8266](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/luc-github/ESP8266?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +:exclamation:Any issue ? [submit ticket](https://github.com/luc-github/ESP8266/issues) -Should be compatible with reprap printer (Marlin FW/Repetier FW) as soon as you can make both serial to communicate. +:warning: All versions seem having instability if compiled/flashed under linux (https://github.com/luc-github/ESP8266/issues/64), so consider to use windows to compile/flash until core is fixed. -Current release listed here: https://github.com/luc-github/ESP8266/wiki +:+1:Thanks +* to @disneysw for bringing this module idea +* to @lkarlslund for suggestion about independant reset using GPIO2 +* to all contributors (treepleks, j0hnlittle, all feedbacks owners and donations) -Master is using 2.1.0 of https://github.com/esp8266/arduino -use http://arduino.esp8266.com/versions/2.1.0/package_esp8266com_index.json in arduino 1.6.5 IDE preferences +Every support is welcome: [PayPal – The safer, easier way to pay online.](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Y8FFE7NA4LJWQ) +Especially if need to buy new modules for testing. -If you use an ESP with 512K flash like ESP01 please go here : https://github.com/luc-github/ESP8266/tree/ESP-512K-64KSPIFFS, it is dedicated to low memory device. -If you use an ESP with more than 512K flash please use master. - -##Hardware connection ---Use GPIO2 to ground to reset all settings in hard way - 2-6 sec after boot / not before!! Set GPIO2 to ground before boot change boot mode and go to special boot that do not reach FW. Currently boot take 10 sec - giving 8 seconds to connect GPIO2 to GND and do an hard recovery for settings ---Use GPIO0 to ground to be in update mode ---Use a switch to reset/disable module -For ESP01: -
- -For ESP12E: -
-
-For Davinci Board:
-
- -##Development -Currently using [Arduino IDE 1.6.5](http://arduino.cc/en/Main/Software) with the esp8266 module from board manager added from [github.com/esp8266/Arduino](https://github.com/esp8266/Arduino) -please use 2.1.0 relased version (http://arduino.esp8266.com/versions/2.1.0/package_esp8266com_index.json) -staging version (http://arduino.esp8266.com/staging/package_esp8266com_index.json) is not yet stable neither compatible with current master please check dev branch https://github.com/luc-github/ESP8266/tree/devt - -Additionnaly: ---Use minimal css from http://getbootstrap.com/examples/theme/ - -##Flash the Module -*Tools: ---Use IDE to upload directly (latest version of board manager module generate one binary) --- to flash the htm files present in data directory you need to use another tool, installation and usage is explained here: https://github.com/esp8266/Arduino/blob/master/doc/filesystem.md -Once flashed you also can use the web updater to flash new FW in System Configuration Page - -*Connection ---Connect GPIO0 to ground to be in update mode - -

Do not flash Printer fw with ESP connected - it bring troubles, at least on DaVinci

+##Features +* Serial/Wifi bridge using configurable port 8888, here to enable/disable [TCP_IP_DATA_FEATURE](https://github.com/luc-github/ESP8266/blob/master/esp8266/config.h) +* Use GPIO2 to ground to reset all settings in hard way - 2-6 sec after boot / not before!! Set GPIO2 to ground before boot change boot mode and go to special boot that do not reach FW. Currently boot take 10 sec - giving 8 seconds to connect GPIO2 to GND and do an hard recovery for settings, here to enable/disable [RECOVERY_FEATURE](https://github.com/luc-github/ESP8266/blob/master/esp8266/config.h) +* Wifi configuration by web browser (Station or Access point) +* Authentication for sensitive pages, here to enable/disable [AUTHENTICATION_FEATURE](https://github.com/luc-github/ESP8266/blob/master/esp8266/config.h) +* Update firmware by web browser, here to enable/disable [WEB_UPDATE_FEATURE](https://github.com/luc-github/ESP8266/blob/master/esp8266/config.h) +* Control ESP module using commands on serial or data port, here to enable/disable [SERIAL_COMMAND_FEATURE](https://github.com/luc-github/ESP8266/blob/master/esp8266/config.h) +* UI fully constomizable without reflashing FW using html templates, [keywords](https://raw.githubusercontent.com/luc-github/ESP8266/master/docs/keywords.txt) and html files/images +* Captive portal in Access point mode which redirect all unknow call to main page, here to enable/disable [CAPTIVE_PORTAL_FEATURE](https://github.com/luc-github/ESP8266/blob/master/esp8266/config.h) +* mDNS which allows to key the name defined in web browser and connect only with bonjour installed on computer, here to enable/disable [MDNS_FEATURE](https://github.com/luc-github/ESP8266/blob/master/esp8266/config.h) +* SSDP, this feature is a discovery protocol, supported on Windows out of the box, here to enable/disable [SSDP_FEATURE](https://github.com/luc-github/ESP8266/blob/master/esp8266/config.h) +* Printer monitoring / control (temperatures/speed/jog/list SDCard content/launch,pause or stop a print/etc...), here to enable/disable [MONITORING_FEATURE/INFO_MSG_FEATURE/ERROR_MSG_FEATURE/STATUS_MSG_FEATURE](https://github.com/luc-github/ESP8266/blob/master/esp8266/config.h) +* Fail safe mode (Access point)is enabled if cannot connect to defined station at boot. ##Web configuration *Wifi Mode : Access point / Client station @@ -89,62 +71,34 @@ Password: admin These are the pages defined using template: Home page : -
+
System Configuration Page: -
+
Access Point Configuration Page: -
+
Client Configuration Page: -
+
Printer Status Page for 64K SPIFFS, due to limited space available no fancy: -
+
Printer Status Page for more than 64K SPIFFS, fancy one: -
+
Extra Settings Page, for web UI and for printer: -
+
Change password Page: -
+
Login Page: -
+
the template files are stored on SPIFFS: -
-and uploaded using [IDE](http://arduino.esp8266.com/versions/1.6.5-1160-gef26c5f/doc/reference.html#file-system) -The list of keywords can be find here : https://github.com/luc-github/ESP8266/blob/master/keywords.txt -Any files on SPIFFS can be called on web interface without having the path hard coded - this give more flexibility, favicon.ico is a good example of it. -So UI is kind of separated from FW which allow easier modifications. For this a light file manager is available in extra settings page, it allows to upload/download/delete files. as SPIFFS is flat filesystem no directory management is necessary so it is very simple. +
+and uploaded using [pluggin IDE](http://esp8266.github.io/Arduino/versions/2.1.0/doc/filesystem.html#uploading-files-to-file-system) +Any files on SPIFFS can be called on web interface without having the path hard coded, this give more flexibility, favicon.ico is a good example of it. +So UI is kind of separated from FW which allow easier modifications. For this a light file manager is available in extra settings page, it allows to upload/download/delete files. +Because SPIFFS is flat filesystem, no directory management is necessary, so it is very simple. Additionally 404.tpl (the page not found) and restart.tpl(restart page when applying changes) are not mandatory, a fail safe version is embeded if they are not present. -Currently, I tested on ESP01 using 64K SPIFFS ( please use data directory content accordingly due to space limitation) and NodeMCU 1.0 1M SPIFFS. -##Modifying and Testing tpl files -To help to visualize tpl modifications a local tool has been created by [j0hnlittle](https://github.com/j0hnlittle) to avoid to upload everytime your tpl files just to see the results of your modifications -It is a python script (2.7+) located in tools directory, launch it: python server.py, then open browser: http://localhost:8080 -It will display the web ui and allow some navigation +##Direct commands: -##Protocol for discovery -*mDNS : on Station mode only with bonjour installed on computer (done) -*SSDP : on Station and AP mode (done) -*Captive portal : on AP mode only (done) - -##Basic Authentification -Can be disabled in FW -default user: admin -default password: admin - -#OTA support -Currently only web update is supported not telnet one - -##Commands/msg from/to serial(not fully implemented): -*from module to printer by serial communication - -M117 [Message], Error/status message from module (done) - -Send Wifi settings [AP/STATION,SSID,DHC/STATIC,IP,MASK,GW,STATUS,MAC ADDRESSS, BAUD?], ]Module configuration without password - -*from host to printer on port 8888 (implemented) - - bridge from TCP/IP to Serial and vice-versa (done) - -*from printer/host to module (not fully implemented) - -request configuration/status - -set AP/STATION,SSID,PASSSWORD,DHC/STATIC,IP,MASK,GW,BAUD from serial -restart module from host/printer: [ESP888]RESTART -Get IP (only printer see answer): [ESP111]M117 -reset EEPROM and restart: [ESP444]RESET @@ -157,44 +111,50 @@ Currently only web update is supported not telnet one -IP Static: [ESP104]STATIC -IP DHCP: [ESP104]DHCP +##Installation +* For stable: +Please use [Arduino IDE 1.6.5](http://arduino.cc/en/Main/Software) with the esp8266 module from board manager use 2.0.0 stable version (not 2.1.0 it has bugs) by adding in your preferences http://arduino.esp8266.com/stable/package_esp8266com_index.json + +* For development: +Please use [Arduino IDE 1.6.8](http://arduino.cc/en/Main/Software) and [git version of esp8266 module](http://esp8266.github.io/Arduino/versions/2.1.0/doc/installing.html#using-git-version) + +* To flash the module : +Use IDE to upload directly (latest version of board manager module generate one binary) +* To flash the html files present in data directory you need to use another tool, installation and usage is explained [here](https://github.com/esp8266/Arduino/blob/master/doc/filesystem.md#uploading-files-to-file-system) +Once flashed you also can use the web updater to flash new FW in System Configuration Page or go to settings to change html files + +

:warning:Do not flash Printer fw with ESP connected - it bring troubles, at least on DaVinci

+ +##Contribution/customization +To modifying and Testing tpl files a local tool has been created by [j0hnlittle](https://github.com/j0hnlittle) to avoid to upload everytime your tpl files just to see the results of your modifications. It is a python script (2.7+) located in tools directory, launch it: python server.py, then open browser: http://localhost:8080 +It will display the web ui and allow some navigation + +To style the code before pushing PR please use [astyle --style=otbs *.h *.cpp *.ino](http://astyle.sourceforge.net/) + +Feedback/suggestion/discussions are always welcome -##Front End (implemented) ---Display printer status (done) ---Display temperatures (done) ---Display positions/flow/speed (done) ---Display print progress if any (done) ---List SDCard Content (done) ---Launch a Print (done) ---Stop/Pause a Print (done) ---Emergency Stop (done) ---Jog control / custom commands (done) + +##Result of ESP12E on Davinci +I use a proto board to connect ESP12E socket, one micro switch for recovery, one jumper for normal usage/ flash, I did not put hardware switch. +
+Connected to Davinci: +
+The back cover: +
+The screen when connected to AP: +
+The settings: +
+##Result of ESP12E on Due/RADDS + the rendering on screen when connection to AP is done: +
+ The settings: +
+ + ##TODO -- Close open topics -- Do testing (a lot) -- UI Improvement ---Printer EEPROM management (Canceled/Postponed for next stage) - -##Result of ESP12E on Davinci -I use a proto board to connect ESP12E socket, one micro switch for recovery, one jumper for normal usage/ flash, I did not put hardware switch. -
-Connected to Davinci: -
-The back cover: -
-The screen when connected to AP: -
-The settings: -
- -##Result of ESP12E on Due/RADDS - Use Serial1 for communications -
- the rendering on screen when connection to AP is done: -
- The settings: -
- -##Donation: -Every support is welcome: [PayPal – The safer, easier way to pay online.](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Y8FFE7NA4LJWQ) -Especially if need to buy new modules for testing. +-- Printer EEPROM management diff --git a/TODO.txt b/TODO.txt new file mode 100644 index 00000000..8b50ccf1 --- /dev/null +++ b/TODO.txt @@ -0,0 +1,5 @@ +TODO +MONITORING_FEATURE : temperatures +INFO_MSG_FEATURE +ERROR_MSG_FEATURE +STATUS_MSG_FEATURE diff --git a/keywords.txt b/docs/keywords.txt similarity index 100% rename from keywords.txt rename to docs/keywords.txt diff --git a/esp8266/config.cpp b/esp8266/config.cpp index f09639a9..4aac9af2 100644 --- a/esp8266/config.cpp +++ b/esp8266/config.cpp @@ -236,6 +236,7 @@ void CONFIG::print_config() { //use biggest size for buffer char sbuf[MAX_PASSWORD_LENGTH+1]; + uint8_t ipbuf[4]; byte bbuf=0; int ibuf=0; if (CONFIG::read_byte(EP_WIFI_MODE, &bbuf )) { @@ -257,7 +258,6 @@ void CONFIG::print_config() } else { Serial.println(F("Error reading SSID")); } - //if (CONFIG::read_string(EP_PASSWORD, sbuf , MAX_PASSWORD_LENGTH))Serial.println(sbuf); if (CONFIG::read_byte(EP_IP_MODE, &bbuf )) { Serial.print(F("IP Mode: ")); @@ -272,23 +272,23 @@ void CONFIG::print_config() Serial.println(F("Error reading IP mode")); } - if (CONFIG::read_buffer(EP_IP_VALUE,(byte *)sbuf , IP_LENGTH)) { + if (CONFIG::read_buffer(EP_IP_VALUE,(byte *)ipbuf , IP_LENGTH)) { Serial.print(F("IP: ")); - Serial.println(wifi_config.ip2str((byte *)sbuf)); + Serial.println(IPAddress(ipbuf).toString()); } else { Serial.println(F("Error reading IP")); } - if (CONFIG::read_buffer(EP_MASK_VALUE, (byte *)sbuf , IP_LENGTH)) { + if (CONFIG::read_buffer(EP_MASK_VALUE, (byte *)ipbuf , IP_LENGTH)) { Serial.print(F("Subnet: ")); - Serial.println(wifi_config.ip2str((byte *)sbuf)); + Serial.println(IPAddress(ipbuf).toString()); } else { Serial.println(F("Error reading subnet")); } - if (CONFIG::read_buffer(EP_GATEWAY_VALUE, (byte *)sbuf , IP_LENGTH)) { + if (CONFIG::read_buffer(EP_GATEWAY_VALUE, (byte *)ipbuf , IP_LENGTH)) { Serial.print(F("Gateway: ")); - Serial.println(wifi_config.ip2str((byte *)sbuf)); + Serial.println(IPAddress(ipbuf).toString()); } else { Serial.println(F("Error reading gateway")); } @@ -443,5 +443,17 @@ void CONFIG::print_config() Serial.println(F("Enabled")); #else Serial.println(F("Disabled")); +#endif + Serial.print(F("Pin 2 Recovery: ")); +#ifdef RECOVERY_FEATURE + Serial.println(F("Enabled")); +#else + Serial.println(F("Disabled")); +#endif + Serial.print(F("Authentication: ")); +#ifdef AUTHENTICATION_FEATURE + Serial.println(F("Enabled")); +#else + Serial.println(F("Disabled")); #endif } diff --git a/esp8266/config.h b/esp8266/config.h index 4a8058c9..a0a3b5b7 100644 --- a/esp8266/config.h +++ b/esp8266/config.h @@ -21,7 +21,7 @@ //comment to disable //MDNS_FEATURE: this feature allow type the name defined //in web browser by default: http:\\esp8266.local and connect -#define MDNS_FEATURE +//#define MDNS_FEATURE //SSDD_FEATURE: this feature is a discovery protocol, supported on Windows out of the box #define SSDP_FEATURE @@ -41,16 +41,16 @@ //TCP_IP_DATA_FEATURE: allow to connect serial from TCP/IP #define TCP_IP_DATA_FEATURE +//RECOVERY_FEATURE: allow to use GPIO2 pin as hardware reset for EEPROM, add 8s to boot time to let user to jump GPIO2 to GND +#define RECOVERY_FEATURE + #ifndef CONFIG_h #define CONFIG_h #include #include "wifi.h" -extern "C" { -#include "user_interface.h" -} //version and sources location -#define FW_VERSION "0.6.0" +#define FW_VERSION "0.6.1" #define REPOSITORY "https://github.com/luc-github/ESP8266" @@ -99,8 +99,8 @@ const byte DEFAULT_MASK_VALUE[] = {255, 255, 255, 0}; #define DEFAULT_GATEWAY_VALUE DEFAULT_IP_VALUE const long DEFAULT_BAUD_RATE = 9600; const char M117_[] PROGMEM = "M117 "; -#define DEFAULT_PHY_MODE PHY_MODE_11G -#define DEFAULT_SLEEP_MODE MODEM_SLEEP_T +#define DEFAULT_PHY_MODE WIFI_PHY_MODE_11G +#define DEFAULT_SLEEP_MODE WIFI_MODEM_SLEEP #define DEFAULT_CHANNEL 11 #define DEFAULT_AUTH_TYPE AUTH_WPA_PSK #define DEFAULT_SSID_VISIBLE 1 diff --git a/esp8266/data/404.tpl b/esp8266/data/404.tpl index a4672d77..c4e4f2e8 100644 --- a/esp8266/data/404.tpl +++ b/esp8266/data/404.tpl @@ -7,7 +7,7 @@

if not redirected, click here

- + \n\n\n\n\n"; -const char PAGE_RESTART [] PROGMEM ="\n\nRestarting... \n\n\n
Restarting, please wait....\n
\n\n
\n\n\n\n"; +const char PAGE_404 [] PROGMEM ="\n\nRedirecting... \n\n\n
Unknown page - you will be redirected...\n

\nif not redirected, click here\n

\n\n\n\n
\n\n\n\n"; +const char PAGE_RESTART [] PROGMEM ="\n\nRestarting... \n\n\n
Restarting, please wait....\n
\n\n
\n\n\n\n"; const char RESTARTCMD [] PROGMEM =""; const char VALUE_11B[] PROGMEM = "11b"; const char VALUE_11N[] PROGMEM = "11n"; @@ -339,9 +339,10 @@ char * intTostr(int value) bool processTemplate(const char * filename, STORESTRINGS_CLASS & KeysList , STORESTRINGS_CLASS & ValuesList ) { if(KeysList.size() != ValuesList.size()) { //Sanity check + Serial.print("Error"); return false; } - + LinkedList myFileList = LinkedList(); String buffer2send; String bufferheader(F("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: ")); @@ -480,6 +481,7 @@ bool processTemplate(const char * filename, STORESTRINGS_CLASS & KeysList , ST //send header with calculated size header_sent=true; web_interface->WebServer.sendContent(bufferheader); + } //send data web_interface->WebServer.sendContent(buffer2send); @@ -521,6 +523,7 @@ bool processTemplate(const char * filename, STORESTRINGS_CLASS & KeysList , ST } //send data web_interface->WebServer.sendContent(buffer2send); + } } //if we end size calculation loop @@ -701,6 +704,13 @@ void ProcessNoAlert(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesLi //root insterface void handle_web_interface_root() +{ + static const char HOME_PAGE [] PROGMEM = "HTTP/1.1 301 OK\r\nLocation: /HOME\r\nCache-Control: no-cache\r\n\r\n"; + web_interface->WebServer.sendContent_P(HOME_PAGE); +} + +//root insterface +void handle_web_interface_home() { String stmp; long lstatus; @@ -861,7 +871,7 @@ void handle_web_interface_root() //IP stmp = "$IP_CONNECTED["+String(client_counter)+"]$"; KeysList.add(stmp.c_str()); - ValuesList.add(wifi_config.ip2str((byte *)&station->ip)); + ValuesList.add(IPAddress((const uint8_t *)&station->ip).toString().c_str()); //increment counter client_counter++; //go next record @@ -940,13 +950,13 @@ void handle_web_interface_root() if (wifi_get_ip_info(SOFTAP_IF,&info)) { //IP address KeysList.add(FPSTR(KEY_AP_IP)); - ValuesList.add(wifi_config.ip2str(info.ip.addr)); + ValuesList.add(IPAddress((const uint8_t *)&(info.ip.addr)).toString().c_str()); //GW address KeysList.add(FPSTR(KEY_AP_GW)); - ValuesList.add(wifi_config.ip2str(info.gw.addr)); + ValuesList.add(IPAddress((const uint8_t *)&(info.gw.addr)).toString().c_str()); //Sub Net Mask KeysList.add(FPSTR(KEY_AP_SUBNET)); - ValuesList.add(wifi_config.ip2str(info.netmask.addr)); + ValuesList.add(IPAddress((const uint8_t *)&(info.netmask.addr)).toString().c_str()); } else { //IP address KeysList.add(FPSTR(KEY_AP_IP)); @@ -1022,7 +1032,6 @@ void handle_web_interface_root() ValuesList.add(""); //Firmware & Free Mem, at the end to reflect situation GetFreeMem(KeysList, ValuesList); - //process the template file and provide list of variables processTemplate("/home.tpl", KeysList , ValuesList); //need to clean to speed up memory recovery @@ -1525,22 +1534,23 @@ void handle_web_interface_configAP() } //IP for static IP if (!CONFIG::read_buffer(EP_IP_VALUE,ip_sav , IP_LENGTH) ) { - sIP=wifi_config.ip2str((byte *)DEFAULT_IP_VALUE); + sIP=IPAddress((const uint8_t *)DEFAULT_IP_VALUE).toString(); + } else { - sIP=wifi_config.ip2str(ip_sav); + sIP=IPAddress((const uint8_t *)ip_sav).toString(); } //GW for static IP if (!CONFIG::read_buffer(EP_GATEWAY_VALUE,gw_sav , IP_LENGTH) ) { - sGW=wifi_config.ip2str((byte *)DEFAULT_GATEWAY_VALUE); + sGW=IPAddress((const uint8_t *)DEFAULT_GATEWAY_VALUE).toString(); } else { - sGW=wifi_config.ip2str(gw_sav); + sGW=IPAddress((const uint8_t *)gw_sav).toString(); } //Subnet for static IP if (!CONFIG::read_buffer(EP_MASK_VALUE,msk_sav , IP_LENGTH) ) { - sMask=wifi_config.ip2str((byte *)DEFAULT_MASK_VALUE); + sMask=IPAddress((const uint8_t *)DEFAULT_MASK_VALUE).toString(); } else { - sMask=wifi_config.ip2str(msk_sav); + sMask=IPAddress((const uint8_t *)msk_sav).toString(); } } @@ -1839,21 +1849,21 @@ void handle_web_interface_configSTA() } //IP for static IP if (!CONFIG::read_buffer(EP_IP_VALUE,ip_sav , IP_LENGTH) ) { - sIP=wifi_config.ip2str((byte *)DEFAULT_IP_VALUE); + sIP=IPAddress((const uint8_t *)DEFAULT_IP_VALUE).toString(); } else { - sIP=wifi_config.ip2str(ip_sav); + sIP=IPAddress((const uint8_t *)ip_sav).toString(); } //GW for static IP if (!CONFIG::read_buffer(EP_GATEWAY_VALUE,gw_sav , IP_LENGTH) ) { - sGW=wifi_config.ip2str((byte *)DEFAULT_GATEWAY_VALUE); + sGW=IPAddress((const uint8_t *)DEFAULT_GATEWAY_VALUE).toString(); } else { - sGW=wifi_config.ip2str(gw_sav); + sGW=IPAddress((const uint8_t *)gw_sav).toString(); } //Subnet for static IP if (!CONFIG::read_buffer(EP_MASK_VALUE,msk_sav , IP_LENGTH) ) { - sMask=wifi_config.ip2str((byte *)DEFAULT_MASK_VALUE); + sMask=IPAddress((const uint8_t *)DEFAULT_MASK_VALUE).toString(); } else { - sMask=wifi_config.ip2str(msk_sav); + sMask=IPAddress((const uint8_t *)msk_sav).toString(); } } //Display values @@ -2534,7 +2544,7 @@ void handleSDFileList() //and handle not registred path void handle_not_found() { - static const char NOT_AUTH_NF [] PROGMEM = "HTTP/1.1 301 OK\r\nLocation: /\r\nCache-Control: no-cache\r\n\r\n"; + static const char NOT_AUTH_NF [] PROGMEM = "HTTP/1.1 301 OK\r\nLocation: /HOME\r\nCache-Control: no-cache\r\n\r\n"; if (!web_interface->is_authenticated()) { web_interface->WebServer.sendContent_P(NOT_AUTH_NF); @@ -2833,6 +2843,7 @@ WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port):WebServer(port) { //init what will handle "/" WebServer.on("/",HTTP_ANY, handle_web_interface_root); + WebServer.on("/HOME",HTTP_ANY, handle_web_interface_home); WebServer.on("/CONFIGSYS",HTTP_ANY, handle_web_interface_configSys); WebServer.on("/CONFIGAP",HTTP_ANY, handle_web_interface_configAP); WebServer.on("/CONFIGSTA",HTTP_ANY, handle_web_interface_configSTA); diff --git a/esp8266/wifi.cpp b/esp8266/wifi.cpp index 3349aec2..0ef3dcf1 100644 --- a/esp8266/wifi.cpp +++ b/esp8266/wifi.cpp @@ -25,14 +25,13 @@ #ifdef MDNS_FEATURE #include #endif -extern "C" { -#include "user_interface.h" -} #ifdef CAPTIVE_PORTAL_FEATURE #include extern DNSServer dnsServer; #endif - +extern "C" { +#include "user_interface.h" +} WIFI_CONFIG::WIFI_CONFIG() { iweb_port=DEFAULT_WEB_PORT; @@ -65,8 +64,9 @@ const char * WIFI_CONFIG::get_default_hostname() return hostname; } -//no strtok so this is simplified version -//return number of part +//helper to convert string to IP +//do not use IPAddress.fromString() because lack of check point and error result +//return number of parts byte WIFI_CONFIG::split_ip (const char * ptr,byte * part) { if (strlen(ptr)>15 || strlen(ptr)< 7) { @@ -112,16 +112,7 @@ char * WIFI_CONFIG::mac2str(uint8_t mac [WL_MAC_ADDR_LENGTH]) return macstr; } -//just simple helper to convert IP address to string -char * WIFI_CONFIG::ip2str(IPAddress Ip ) -{ - static char ipstr [16]; - if (0>sprintf(ipstr, "%i.%i.%i.%i",Ip[0],Ip[1],Ip[2],Ip[3])) { - strcpy (ipstr, "0.0.0.0"); - } - return ipstr; -} - +//safe setup if no connection void WIFI_CONFIG::Safe_Setup() { #ifdef CAPTIVE_PORTAL_FEATURE @@ -153,24 +144,52 @@ bool WIFI_CONFIG::Setup() int wstatus; IPAddress currentIP; byte bflag=0; - + byte bmode=0; + //system_update_cpu_freq(SYS_CPU_160MHZ); //set the sleep mode if (!CONFIG::read_byte(EP_SLEEP_MODE, &bflag )) { return false; } - wifi_set_sleep_type ((sleep_type_t)bflag); + WiFi.setSleepMode ((WiFiSleepType_t)bflag); sleep_mode=bflag; //AP or client ? - if (!CONFIG::read_byte(EP_WIFI_MODE, &bflag ) || !CONFIG::read_string(EP_SSID, sbuf , MAX_SSID_LENGTH) ||!CONFIG::read_string(EP_PASSWORD, pwd , MAX_PASSWORD_LENGTH)) { + if (!CONFIG::read_byte(EP_WIFI_MODE, &bmode ) || !CONFIG::read_string(EP_SSID, sbuf , MAX_SSID_LENGTH) ||!CONFIG::read_string(EP_PASSWORD, pwd , MAX_PASSWORD_LENGTH)) { return false; } if (!CONFIG::read_string(EP_HOSTNAME, hostname , MAX_HOSTNAME_LENGTH)) { strcpy(hostname,get_default_hostname()); } - //disconnect if connected - WiFi.disconnect(); + //DHCP or Static IP ? + if (!CONFIG::read_byte(EP_IP_MODE, &bflag )) { + return false; + } + if (bflag==STATIC_IP_MODE) { + byte ip_buf[4]; + //get the IP + if (!CONFIG::read_buffer(EP_IP_VALUE,ip_buf , IP_LENGTH)) { + return false; + } + IPAddress local_ip (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]); + //get the gateway + if (!CONFIG::read_buffer(EP_GATEWAY_VALUE,ip_buf , IP_LENGTH)) { + return false; + } + IPAddress gateway (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]); + //get the mask + if (!CONFIG::read_buffer(EP_MASK_VALUE,ip_buf , IP_LENGTH)) { + return false; + } + IPAddress subnet (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]); + //apply according active wifi mode + if (bmode==AP_MODE) { + WiFi.softAPConfig( local_ip, gateway, subnet); + } else { + WiFi.config( local_ip, gateway, subnet); + } + } //this is AP mode - if (bflag==AP_MODE) { + if (bmode==AP_MODE) { + WiFi.enableSTA(true); //setup Soft AP WiFi.mode(WIFI_AP); WiFi.softAP(sbuf, pwd); @@ -178,7 +197,7 @@ bool WIFI_CONFIG::Setup() if (!CONFIG::read_byte(EP_PHY_MODE, &bflag )) { return false; } - wifi_set_phy_mode((phy_mode_t)bflag); + WiFi.setPhyMode((WiFiPhyMode_t)bflag); //get current config struct softap_config apconfig; wifi_softap_get_config(&apconfig); @@ -206,6 +225,7 @@ bool WIFI_CONFIG::Setup() delay(1000); } } else { + WiFi.enableAP(false); //setup station mode WiFi.mode(WIFI_STA); WiFi.begin(sbuf, pwd); @@ -214,7 +234,7 @@ bool WIFI_CONFIG::Setup() if (!CONFIG::read_byte(EP_PHY_MODE, &bflag )) { return false; } - wifi_set_phy_mode((phy_mode_t)bflag); + WiFi.setPhyMode((WiFiPhyMode_t)bflag); delay(500); byte i=0; //try to connect @@ -244,34 +264,7 @@ bool WIFI_CONFIG::Setup() WiFi.hostname(hostname); } - //DHCP or Static IP ? - if (!CONFIG::read_byte(EP_IP_MODE, &bflag )) { - return false; - } - if (bflag==STATIC_IP_MODE) { - byte ip_buf[4]; - //get the IP - if (!CONFIG::read_buffer(EP_IP_VALUE,ip_buf , IP_LENGTH)) { - return false; - } - IPAddress local_ip (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]); - //get the gateway - if (!CONFIG::read_buffer(EP_GATEWAY_VALUE,ip_buf , IP_LENGTH)) { - return false; - } - IPAddress gateway (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]); - //get the mask - if (!CONFIG::read_buffer(EP_MASK_VALUE,ip_buf , IP_LENGTH)) { - return false; - } - IPAddress subnet (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]); - //apply according active wifi mode - if (wifi_get_opmode()==WIFI_AP || wifi_get_opmode()==WIFI_AP_STA) { - WiFi.softAPConfig( local_ip, gateway, subnet); - } else { - WiFi.config( local_ip, gateway, subnet); - } - } + #ifdef MDNS_FEATURE // Set up mDNS responder: if (!mdns.begin(hostname)) { @@ -281,7 +274,7 @@ bool WIFI_CONFIG::Setup() } #endif //Get IP - if (wifi_get_opmode()==WIFI_STA) { + if (WiFi.getMode()==WIFI_STA) { currentIP=WiFi.localIP(); } else { currentIP=WiFi.softAPIP(); diff --git a/esp8266/wifi.h b/esp8266/wifi.h index 7b90c894..38ea51c3 100644 --- a/esp8266/wifi.h +++ b/esp8266/wifi.h @@ -44,7 +44,6 @@ public: bool Setup(); void Safe_Setup(); char * mac2str(uint8_t mac [WL_MAC_ADDR_LENGTH]); - char * ip2str(IPAddress Ip ); byte split_ip (const char * ptr,byte * part); const char * get_default_hostname(); const char * get_hostname(); diff --git a/Davinci/Capture.PNG b/images/Davinci/Capture.PNG similarity index 100% rename from Davinci/Capture.PNG rename to images/Davinci/Capture.PNG diff --git a/Davinci/backside.jpg b/images/Davinci/backside.jpg similarity index 100% rename from Davinci/backside.jpg rename to images/Davinci/backside.jpg diff --git a/Davinci/board.jpg b/images/Davinci/board.jpg similarity index 100% rename from Davinci/board.jpg rename to images/Davinci/board.jpg diff --git a/Davinci/boardconnected.jpg b/images/Davinci/boardconnected.jpg similarity index 100% rename from Davinci/boardconnected.jpg rename to images/Davinci/boardconnected.jpg diff --git a/davinci.png b/images/Davinci/davinci.png similarity index 100% rename from davinci.png rename to images/Davinci/davinci.png diff --git a/Davinci/screen.jpg b/images/Davinci/screen.jpg similarity index 100% rename from Davinci/screen.jpg rename to images/Davinci/screen.jpg diff --git a/Wires.png b/images/HW/Wires.png similarity index 100% rename from Wires.png rename to images/HW/Wires.png diff --git a/WiresESP12E.png b/images/HW/WiresESP12E.png similarity index 100% rename from WiresESP12E.png rename to images/HW/WiresESP12E.png diff --git a/RADDS/Capture.PNG b/images/RADDS/Capture.PNG similarity index 100% rename from RADDS/Capture.PNG rename to images/RADDS/Capture.PNG diff --git a/RADDS/RADDS.png b/images/RADDS/RADDS.png similarity index 100% rename from RADDS/RADDS.png rename to images/RADDS/RADDS.png diff --git a/RADDS/screen.jpg b/images/RADDS/screen.jpg similarity index 100% rename from RADDS/screen.jpg rename to images/RADDS/screen.jpg diff --git a/Page1.png b/images/UI/Page1.png similarity index 100% rename from Page1.png rename to images/UI/Page1.png diff --git a/Page2.png b/images/UI/Page2.png similarity index 100% rename from Page2.png rename to images/UI/Page2.png diff --git a/Page3.png b/images/UI/Page3.png similarity index 100% rename from Page3.png rename to images/UI/Page3.png diff --git a/Page4.png b/images/UI/Page4.png similarity index 100% rename from Page4.png rename to images/UI/Page4.png diff --git a/Page5-2.png b/images/UI/Page5-2.png similarity index 100% rename from Page5-2.png rename to images/UI/Page5-2.png diff --git a/Page6.png b/images/UI/Page6.png similarity index 100% rename from Page6.png rename to images/UI/Page6.png diff --git a/Page7.png b/images/UI/Page7.png similarity index 100% rename from Page7.png rename to images/UI/Page7.png diff --git a/Page8.png b/images/UI/Page8.png similarity index 100% rename from Page8.png rename to images/UI/Page8.png diff --git a/files.png b/images/UI/files.png similarity index 100% rename from files.png rename to images/UI/files.png diff --git a/page5.png b/images/UI/page5.png similarity index 100% rename from page5.png rename to images/UI/page5.png