diff --git a/.travis.yml b/.travis.yml index 05bda5a3..002c1bc6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,9 +11,9 @@ before_install: before_script: - "export DISPLAY=:99.0" - sleep 3 # give xvfb some time to start - - wget http://downloads.arduino.cc/arduino-1.8.0-linux64.tar.xz - - tar xf arduino-1.8.0-linux64.tar.xz - - mv arduino-1.8.0 $HOME/arduino_ide + - wget http://downloads.arduino.cc/arduino-1.8.4-linux64.tar.xz + - tar xf arduino-1.8.4-linux64.tar.xz + - mv arduino-1.8.4 $HOME/arduino_ide - cd $HOME/arduino_ide/hardware - mkdir esp8266com - cd esp8266com @@ -21,13 +21,22 @@ before_script: - cd esp8266/tools - python get.py - cd .. - - touch pt.txt - - echo 'build.flash_ld=eagle.flash.4m.ld' >> pt.txt - - echo 'build.flash_freq=40' >> pt.txt - - echo 'build.flash_size=4M' >> pt.txt - - cat ./platform.txt >> pt.txt - - rm -fr platform.txt - - mv pt.txt platform.txt + - echo 'build.flash_ld=eagle.flash.4m.ld' >> platform.txt + - echo 'build.flash_freq=40' >> platform.txt + - echo 'build.flash_size=4M' >> platform.txt + - echo 'build.flash_mode=dio' >> platform.txt + - echo 'build.f_cpu=160000000L' >> platform.txt + - sed -i "s/generic.build.f_cpu=80000000L/generic.build.f_cpu=160000000L/g" ./boards.txt + - cd $HOME/arduino_ide/hardware + - mkdir esp32 + - cd esp32 + - git clone https://github.com/espressif/arduino-esp32.git esp32 + - cd esp32/tools + - python get.py + - cd .. + - echo 'build.flash_freq=40m' >> platform.txt + - mv $TRAVIS_BUILD_DIR/libraries/WebServer $HOME/arduino_ide/hardware/esp32/esp32/libraries/ + - mv $TRAVIS_BUILD_DIR/libraries/DNSServer $HOME/arduino_ide/hardware/esp32/esp32/libraries/ script: @@ -37,6 +46,8 @@ script: - arduino --board esp8266com:esp8266:generic --save-prefs - arduino --get-pref sketchbook.path - build_sketch esp3d/esp3d.ino + - arduino --board esp32:esp32:esp32 --save-prefs + - build_sketch esp3d/esp3d.ino notifications: email: diff --git a/README.md b/README.md index d633c41e..c550aa82 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,32 @@ # ESP3D[![Code Climate](https://codeclimate.com/github/luc-github/ESP3D/badges/gpa.svg)](https://codeclimate.com/github/luc-github/ESP3D) -Firmware for ESP8266/ESP8285 used with 3D printer using [arduino core version](https://github.com/esp8266/Arduino) +Firmware for ESP8266/ESP8285 and ESP32 used with 3D printer using [ESP8266 core version](https://github.com/esp8266/Arduino) and [ESP32 core version](https://github.com/espressif/arduino-esp32) + 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/ESP3D/tree/ESP-512K-64KSPIFFS) -Stable version: +Firmware should work with any 3D printer firmware (repetier/marlin/smoothieware using GCODE) if serial connection has a 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). + +The web interface files are present in data directory but UI has it's own repository [ESP3D-WEBUI](https://github.com/luc-github/ESP3D-WEBUI). +* be aware ESP3D-WEBUI is for firmware 0.9.99 minimum - previous released version use tpl files which are no more used. + +Stable version (ESP8266 only): Arduino ide 1.6.5 with stable [2.0.0](http://arduino.esp8266.com/versions/2.0.0/package_esp8266com_index.json) from ESP8266, please use https://github.com/luc-github/ESP3D/releases/tag/v0.5.1 Arduino ide 1.6.8 with stable [2.2.0](http://arduino.esp8266.com/versions/2.2.0/package_esp8266com_index.json) from ESP8266, please use https://github.com/luc-github/ESP3D/releases/tag/v0.6.2 -Development version: -Arduino ide 1.8.0 with git from ESP8266 : [![Build Status](https://travis-ci.org/luc-github/ESP3D.svg?branch=master)](https://travis-ci.org/luc-github/ESP3D) +RC version for 1.0(master branch) very stable but waiting for 2.4 release of ESP8266: +Arduino ide 1.8.4 with git version from ESP8266 or ESP32 : [![Build Status](https://travis-ci.org/luc-github/ESP3D.svg?branch=master)](https://travis-ci.org/luc-github/ESP3D) + +Development version for 2.0 (asyncwebserver branch) pre alpha : +Arduino ide 1.8.4 with git version from ESP8266 or ESP32 : [![Build Status](https://travis-ci.org/luc-github/ESP3D.svg?branch=asyncwebserver)](https://travis-ci.org/luc-github/ESP3D) [All releases](https://github.com/luc-github/ESP3D/wiki) -:question:Any question ? check [Wiki](https://github.com/luc-github/ESP3D/wiki/Install-Instructions) or [![Join the chat at https://gitter.im/luc-github/ESP3D](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/luc-github/ESP3D?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -:exclamation:Any issue ? check [Wiki](https://github.com/luc-github/ESP3D/wiki/Install-Instructions) and [FAQ](https://github.com/luc-github/ESP3D/issues?utf8=%E2%9C%93&q=label%3AFAQ+) or [submit ticket](https://github.com/luc-github/ESP3D/issues) - - :+1:Thanks * to @disneysw for bringing this module idea * to @lkarlslund for suggestion about independent reset using GPIO2 -* to all contributors (treepleks, j0hnlittle, openhardwarecoza, TRoager, all feedbacks owners and donations) +* to all contributors, feedbacks owners and donations. 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. @@ -31,7 +34,7 @@ Especially if need to buy new modules for testing. ##Features * Serial/Wifi bridge using configurable port 8888, here to enable/disable [TCP_IP_DATA_FEATURE](https://github.com/luc-github/ESP3D/blob/master/esp3d/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) +* Complete configuration by web browser (Station or Access point) or by Serial commands * Authentication for sensitive pages, here to enable/disable [AUTHENTICATION_FEATURE](https://github.com/luc-github/ESP3D/blob/master/esp3d/config.h) * Update firmware by web browser, here to enable/disable [WEB_UPDATE_FEATURE](https://github.com/luc-github/ESP3D/blob/master/esp3d/config.h) * Control ESP module using commands on serial or data port, here to enable/disable [SERIAL_COMMAND_FEATURE](https://github.com/luc-github/ESP3D/blob/master/esp3d/config.h) @@ -41,6 +44,8 @@ Especially if need to buy new modules for testing. * 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/ESP3D/blob/master/esp3d/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/ESP3D/blob/master/esp3d/config.h) * Fail safe mode (Access point)is enabled if cannot connect to defined station at boot. +* The web ui add even more feature : https://github.com/luc-github/ESP3D-WEBUI/blob/master/README.md#features + ##Web configuration *Wifi Mode : Access point / Client station @@ -63,7 +68,7 @@ IP Mode: Static IP IP: 192.168.0.1 Mask: 255.255.255.0 GW:192.168.0.1 -Baud rate: 9600 +Baud rate: 115200 Web port:80 Data port: 8888 Web Page refresh: 3 secondes @@ -72,168 +77,163 @@ Password: admin User:user Password: user -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 [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 embedded if they are not present. ##Direct commands: ``` -* Change STA SSID -[ESP100] -if authentication is on, need admin password -[ESP100]pwd= +* Change STA SSID +[ESP100] +if authentication is on, need admin password +[ESP100]pwd= -* Change STA Password -[ESP101] -if authentication is on, need admin password -[ESP101]pwd= +* Change STA Password +[ESP101] +if authentication is on, need admin password +[ESP101]pwd= -* Change Hostname -[ESP102] -if authentication is on, need admin password -[ESP102]pwd= +* Change Hostname +[ESP102] +if authentication is on, need admin password +[ESP102]pwd= -* Change Wifi mode (STA/AP) -[ESP103] -if authentication is on, need admin password -[ESP103]pwd= +* Change Wifi mode (STA/AP) +[ESP103] +if authentication is on, need admin password +[ESP103]pwd= -* Change STA IP mode (DHCP/STATIC) -[ESP104] -if authentication is on, need admin password -[ESP104]pwd= +* Change STA IP mode (DHCP/STATIC) +[ESP104] +if authentication is on, need admin password +[ESP104]pwd= -* Change AP SSID -[ESP105] -if authentication is on, need admin password -[ESP105]pwd= +* Change AP SSID +[ESP105] +if authentication is on, need admin password +[ESP105]pwd= -* Change AP Password -[ESP106] -if authentication is on, need admin password -[ESP106]pwd= +* Change AP Password +[ESP106] +if authentication is on, need admin password +[ESP106]pwd= -* Change AP IP mode (DHCP/STATIC) -[ESP107] -if authentication is on, need admin password -[ESP107]pwd= +* Change AP IP mode (DHCP/STATIC) +[ESP107] +if authentication is on, need admin password +[ESP107]pwd= -* Get current IP -[ESP111]
+* Set wifi on/off +[ESP110] +state can be ON, OFF, RESTART +if authentication is on, need admin password +[ESP110]pwd= -* Get hostname -[ESP112]
+* Get current IP +[ESP111]
-* Get/Set ESP mode -cmd can be RESET, SAFEMODE, CONFIG, RESTART -[ESP444] -if authentication is on, need admin password for RESET, RESTART and SAFEMODE -[ESP444]pwd= +* Get hostname +[ESP112]
-* Change / Reset user password -[ESP555]pwd= -if no password set it use default one -* Read SPIFFS file and send each line to serial -[ESP700] +*Get/Set pin value +[ESP201]P V [PULLUP=YES RAW=YES] +if no V get P value +if V 0/1 set INPUT_PULLUP value, but for GPIO16 INPUT_PULLDOWN_16 +GPIO1 and GPIO3 cannot be used as they are used for serial +if PULLUP=YES set input pull up, if not set input +if RAW=YES do not set pinmode just read value -* Get fw version -[ESP800]
-* Clear status/error/info list -cmd can be ALL, ERROR, INFO, STATUS -[ESP999] - +*Save data string +[ESP300] pwd= +*Get data string +[ESP301] pwd= + +*Get full EEPROM settings content +but do not give any passwords +can filter if only need wifi or printer +[ESP400] + +*Set EEPROM setting +position in EEPROM, type: B(byte), I(integer/long), S(string), A(IP address / mask) +[ESP401]P= T= V= pwd= + +*Get available AP list (limited to 30) +output is JSON or plain text according parameter +[ESP410] + +*Get current settings of ESP3D +output is JSON or plain text according parameter +[ESP420] + +* Get/Set ESP mode +cmd can be RESET, SAFEMODE, CONFIG, RESTART +[ESP444] +if authentication is on, need admin password for RESET, RESTART and SAFEMODE +[ESP444]pwd= + +* Change / Reset user password +[ESP555]pwd= +if no password set it use default one + +* Read SPIFFS file and send each line to serial +[ESP700] + +* Format SPIFFS +[ESP710]FORMAT pwd= + +* SPIFFS total size and used size +[ESP720]
+ +* Get fw version and basic information +[ESP800]
+ +* Get fw target +[ESP801]
+ +* Clear status/error/info list +cmd can be ALL, ERROR, INFO, STATUS +[ESP999] + ``` ##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 by adding in your preferences http://arduino.esp8266.com/version/2.0.0/package_esp8266com_index.json -with https://github.com/luc-github/ESP3D/releases/tag/v0.5.1 -or -use [Arduino IDE 1.6.8](http://arduino.cc/en/Main/Software) with the esp8266 module from board manager use 2.2.0 stable version by adding in your preferences http://arduino.esp8266.com/stable/package_esp8266com_index.json -with https://github.com/luc-github/ESP3D/releases/tag/v0.6.2 +1. Please follow installation of the ESP core you want to use : [ESP8266 core version](https://github.com/esp8266/Arduino) or [ESP32 core version](https://github.com/espressif/arduino-esp32) +2. Add missing libraries if you target ESP32 present in libraries directory +* DNSServer (from https://github.com/bbx10/DNSServer_tng) +* WebServer (from https://github.com/bbx10/WebServer_tng) +* NetBIOS and SSDP are currently disabled for ESP32 as not yet supported +3. Compile project (ESP3D.ino) according target: ESP8266 board or ESP32 board, please review config.h to enable disable a feature, by default athenticatio is disabled and all others are enabled. +* for ESP8266 set CPU freq to 160MHz for better (https://github.com/luc-github/ESP3D/wiki/Install-Instructions) +4. Upload the data content on ESP3D file system +* Using SPIFFS uploader, this plugin and install instructions is available on each ESP core - please refere to it +* Using embedded uploader (you may need to format SPIFFS using : [ESP710]FORMAT on ESP8266 first) +if embedded uploader does not show up you can force it ti display using : http://your_IP_address?forcefallback=yes +
-* 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.2.0/doc/installing.html#using-git-version) +##Update +* Generate a binary using the export binary menu from Arduino IDE and upload it using ESP-WEBUI or embedded interface -* To flash the module : -You must define the targeted FW, can be REPETIER (Original Repetier)/ REPETIER4DV (Repetier for Davinci) / MARLIN (Marlin)/ SMOOTHIEWARE (Smoothieware) in config.h and enable/disable any others features -``` -//MDNS_FEATURE: this feature allow type the name defined -//in web browser by default: http:\\esp8266.local and connect -//#define MDNS_FEATURE - -//SSDD_FEATURE: this feature is a discovery protocol, supported on Windows out of the box -#define SSDP_FEATURE - -//CAPTIVE_PORTAL_FEATURE: In SoftAP redirect all unknow call to main page -#define CAPTIVE_PORTAL_FEATURE - -//AUTHENTICATION_FEATURE: protect pages by login password -#define AUTHENTICATION_FEATURE - -//WEB_UPDATE_FEATURE: allow to flash fw using web UI -#define WEB_UPDATE_FEATURE - -//SERIAL_COMMAND_FEATURE: allow to send command by serial -#define SERIAL_COMMAND_FEATURE - -//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 - -//FIRMWARE_TARGET: the targeted FW, can be REPETIER (Original Repetier)/ REPETIER4DV (Repetier for Davinci) / MARLIN (Marlin)/ SMOOTHIEWARE (Smoothieware) -#define FIRMWARE_TARGET REPETIER4DV - -//DEBUG Flag -//#define DEBUG_ESP3D -``` - -For better performance select CPU Frequency to be 160MHz instead of default 80MHz -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

+

:warning:Do not flash your 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 every time 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/) +* The embedded page is created using nodejs then gulp to generate a compressed html page (tool.html.gz), all necessary modules can be installed using the install.bat file content, then it is included using bin2c (https://sourceforge.net/projects/bin2c/) to generate the h file used to create the file nofile.h, update the array and size according new out.h. +* The current UI is located [here](https://github.com/luc-github/ESP3D-WEBUI) +* An optional UI is under development using old repetier UI - check [UI\repetier\testui.htm] (https://github.com/luc-github/ESP3D/blob/master/UI/repetier/testui.htm) file -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 +Feedback/suggestion/discussions are always welcome -##Need more information about board or wiring ? +##Need more information about supported boards or wiring ? [Check the wiki](https://github.com/luc-github/ESP3D/wiki) + +##:question:Any question ? +Check [Wiki](https://github.com/luc-github/ESP3D/wiki/Install-Instructions) or [![Join the chat at https://gitter.im/luc-github/ESP3D](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/luc-github/ESP3D?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + +##:exclamation:Any issue/feedback ? +Check [Wiki](https://github.com/luc-github/ESP3D/wiki/Install-Instructions) and [FAQ](https://github.com/luc-github/ESP3D/issues?utf8=%E2%9C%93&q=label%3AFAQ+) or [submit ticket](https://github.com/luc-github/ESP3D/issues) + ##TODO -- Close open topics -- Do testing (a lot) -- UI Improvement +-- ESP3D V2 diff --git a/UI/mousediv.html b/UI/mousediv.html deleted file mode 100644 index b73843b4..00000000 --- a/UI/mousediv.html +++ /dev/null @@ -1,150 +0,0 @@ - - - - - - - - - - - -
-
-
-
-
- - - - diff --git a/UI/testui.htm b/UI/repetier/testui.htm similarity index 99% rename from UI/testui.htm rename to UI/repetier/testui.htm index 66f85add..c8a7bf59 100644 --- a/UI/testui.htm +++ b/UI/repetier/testui.htm @@ -522,7 +522,7 @@ function initrange( element) -Z + diff --git a/docs/Commands.txt b/docs/Commands.txt index 962b93fb..92c03b73 100644 --- a/docs/Commands.txt +++ b/docs/Commands.txt @@ -38,12 +38,20 @@ if authentication is on, need admin password if authentication is on, need admin password [ESP107]pwd= +* Set wifi on/off +[ESP110] +state can be ON, OFF, RESTART +if authentication is on, need admin password +[ESP110]pwd= + * Get current IP [ESP111]
* Get hostname [ESP112]
+* Restart time client +[ESP114] *Get/Set pin value [ESP201]P V [PULLUP=YES RAW=YES] @@ -53,6 +61,29 @@ GPIO1 and GPIO3 cannot be used as they are used for serial if PULLUP=YES set input pull up, if not set input if RAW=YES do not set pinmode just read value + +*Save data string +[ESP300] pwd= +*Get data string +[ESP301] pwd= + +*Get full EEPROM settings content +but do not give any passwords +can filter if only need wifi or printer +[ESP400] + +*Set EEPROM setting +position in EEPROM, type: B(byte), I(integer/long), S(string), A(IP address / mask) +[ESP401]P= T= V= pwd= + +*Get available AP list (limited to 30) +output is JSON or plain text according parameter +[ESP410] + +*Get current settings of ESP3D +output is JSON or plain text according parameter +[ESP420] + * Get/Set ESP mode cmd can be RESET, SAFEMODE, CONFIG, RESTART [ESP444] @@ -66,7 +97,13 @@ if no password set it use default one * Read SPIFFS file and send each line to serial [ESP700] -* Get fw version +* Format SPIFFS +[ESP710]FORMAT pwd= + +* SPIFFS total size and used size +[ESP720]
+ +* Get fw version and basic information [ESP800]
* Get fw target diff --git a/docs/EEPROM_OUTPUT_SAMPLE.txt b/docs/EEPROM_OUTPUT_SAMPLE.txt deleted file mode 100644 index 8d48ee3a..00000000 --- a/docs/EEPROM_OUTPUT_SAMPLE.txt +++ /dev/null @@ -1,122 +0,0 @@ -EPR:0 1028 7 Language -EPR:2 75 230400 Baudrate -EPR:0 1125 1 Display Mode: -EPR:0 1119 1 Light On: -EPR:0 1127 1 Keep Light On: -EPR:0 1126 0 Filament Sensor On: -EPR:0 1176 0 Top Sensor On: -EPR:0 1120 1 Sound On: -EPR:0 1177 1 Wifi On: -EPR:3 129 0.000 Filament printed [m] -EPR:2 125 0 Printer active [s] -EPR:2 79 0 Max. inactive time [ms,0=off] -EPR:2 83 360000 Stop stepper after inactivity [ms,0=off] -EPR:2 1121 0 Powersave after [ms,0=off]: -EPR:3 1160 180.000 Temp Ext PLA: -EPR:3 1164 230.000 Temp Ext ABS: -EPR:3 1168 60.000 Temp Bed PLA: -EPR:3 1172 90.000 Temp Bed ABS: -EPR:3 1179 2.000 Load Feed Rate: -EPR:3 1183 4.000 Unload Feed Rate: -EPR:3 1187 60.000 Unload/Load Distance: -EPR:3 3 80.0000 X-axis steps per mm -EPR:3 7 80.0000 Y-axis steps per mm -EPR:3 11 2560.0000 Z-axis steps per mm -EPR:3 15 200.000 X-axis max. feedrate [mm/s] -EPR:3 19 200.000 Y-axis max. feedrate [mm/s] -EPR:3 23 5.000 Z-axis max. feedrate [mm/s] -EPR:3 27 40.000 X-axis homing feedrate [mm/s] -EPR:3 31 40.000 Y-axis homing feedrate [mm/s] -EPR:3 35 4.000 Z-axis homing feedrate [mm/s] -EPR:3 39 20.000 Max. jerk [mm/s] -EPR:3 47 0.342 Max. Z-jerk [mm/s] -EPR:3 133 0.000 X min pos [mm] -EPR:3 137 0.000 Y min pos [mm] -EPR:3 141 0.000 Z min pos [mm] -EPR:3 145 199.000 X max length [mm] -EPR:3 149 204.000 Y max length [mm] -EPR:3 153 200.000 Z max length [mm] -EPR:3 51 1000.000 X-axis acceleration [mm/s^2] -EPR:3 55 1000.000 Y-axis acceleration [mm/s^2] -EPR:3 59 100.000 Z-axis acceleration [mm/s^2] -EPR:3 63 1000.000 X-axis travel acceleration [mm/s^2] -EPR:3 67 1000.000 Y-axis travel acceleration [mm/s^2] -EPR:3 71 150.000 Z-axis travel acceleration [mm/s^2] -EPR:3 1024 0.000 Coating thickness [mm] -EPR:3 1128 100.000 Manual-probe X1 [mm] -EPR:3 1132 180.000 Manual-probe Y1 [mm] -EPR:3 1136 100.000 Manual-probe X2 [mm] -EPR:3 1140 10.000 Manual-probe Y2 [mm] -EPR:3 1144 50.000 Manual-probe X3 [mm] -EPR:3 1148 95.000 Manual-probe Y3 [mm] -EPR:3 1152 150.000 Manual-probe X4 [mm] -EPR:3 1156 95.000 Manual-probe Y4 [mm] -EPR:3 808 0.280 Z-probe height [mm] -EPR:3 929 5.000 Max. z-probe - bed dist. [mm] -EPR:3 812 1.000 Z-probe speed [mm/s] -EPR:3 840 30.000 Z-probe x-y-speed [mm/s] -EPR:3 800 0.000 Z-probe offset x [mm] -EPR:3 804 0.000 Z-probe offset y [mm] -EPR:3 816 36.000 Z-probe X1 [mm] -EPR:3 820 -7.000 Z-probe Y1 [mm] -EPR:3 824 36.000 Z-probe X2 [mm] -EPR:3 828 203.000 Z-probe Y2 [mm] -EPR:3 832 171.000 Z-probe X3 [mm] -EPR:3 836 203.000 Z-probe Y3 [mm] -EPR:3 1036 0.000 Z-probe bending correction A [mm] -EPR:3 1040 0.000 Z-probe bending correction B [mm] -EPR:3 1044 0.000 Z-probe bending correction C [mm] -EPR:0 880 0 Autolevel active (1/0) -EPR:0 106 2 Bed Heat Manager [0-3] -EPR:0 107 255 Bed PID drive max -EPR:0 124 80 Bed PID drive min -EPR:3 108 196.000 Bed PID P-gain -EPR:3 112 33.000 Bed PID I-gain -EPR:3 116 290.000 Bed PID D-gain -EPR:0 120 255 Bed PID max value [0-255] -EPR:0 1020 0 Enable retraction conversion [0/1] -EPR:3 992 3.000 Retraction length [mm] -EPR:3 996 13.000 Retraction length extruder switch [mm] -EPR:3 1000 40.000 Retraction speed [mm/s] -EPR:3 1004 0.000 Retraction z-lift [mm] -EPR:3 1008 0.000 Extra extrusion on undo retract [mm] -EPR:3 1012 0.000 Extra extrusion on undo switch retract [mm] -EPR:3 1016 20.000 Retraction undo speed -EPR:3 200 99.000 Extr.1 steps per mm -EPR:3 204 50.000 Extr.1 max. feedrate [mm/s] -EPR:3 208 20.000 Extr.1 start feedrate [mm/s] -EPR:3 212 5000.000 Extr.1 acceleration [mm/s^2] -EPR:0 216 3 Extr.1 heat manager [0-3] -EPR:0 217 230 Extr.1 PID drive max -EPR:0 245 40 Extr.1 PID drive min -EPR:3 218 3.0000 Extr.1 PID P-gain/dead-time -EPR:3 222 2.0000 Extr.1 PID I-gain -EPR:3 226 40.0000 Extr.1 PID D-gain -EPR:0 230 255 Extr.1 PID max value [0-255] -EPR:2 231 0 Extr.1 X-offset [steps] -EPR:2 235 0 Extr.1 Y-offset [steps] -EPR:2 290 0 Extr.1 Z-offset [steps] -EPR:1 239 1 Extr.1 temp. stabilize time [s] -EPR:1 250 150 Extr.1 temp. for retraction when heating [C] -EPR:1 252 0 Extr.1 distance to retract when heating [mm] -EPR:0 254 255 Extr.1 extruder cooler speed [0-255] -EPR:3 246 0.000 Extr.1 advance L [0=off] -EPR:3 300 99.000 Extr.2 steps per mm -EPR:3 304 50.000 Extr.2 max. feedrate [mm/s] -EPR:3 308 20.000 Extr.2 start feedrate [mm/s] -EPR:3 312 5000.000 Extr.2 acceleration [mm/s^2] -EPR:0 316 3 Extr.2 heat manager [0-3] -EPR:0 317 230 Extr.2 PID drive max -EPR:0 345 40 Extr.2 PID drive min -EPR:3 318 3.0000 Extr.2 PID P-gain/dead-time -EPR:3 322 2.0000 Extr.2 PID I-gain -EPR:3 326 40.0000 Extr.2 PID D-gain -EPR:0 330 255 Extr.2 PID max value [0-255] -EPR:2 331 -2852 Extr.2 X-offset [steps] -EPR:2 335 12 Extr.2 Y-offset [steps] -EPR:2 390 0 Extr.2 Z-offset [steps] -EPR:1 339 1 Extr.2 temp. stabilize time [s] -EPR:1 350 150 Extr.2 temp. for retraction when heating [C] -EPR:1 352 0 Extr.2 distance to retract when heating [mm] -EPR:0 354 255 Extr.2 extruder cooler speed [0-255] -EPR:3 346 0.000 Extr.2 advance L [0=off] diff --git a/docs/keywords.txt b/docs/keywords.txt deleted file mode 100644 index 1d1487a4..00000000 --- a/docs/keywords.txt +++ /dev/null @@ -1,150 +0,0 @@ -[COMMON] -$INCLUDE[] : only one per line and alone, others will be ignored -$IP$ : current active ip -$WEB_ADDRESS$: current active ip , if port is not 80 it will add port like xxx.xxx.xxxx.xxx:XX -$MENU_HOME$/$MENU_SYSTEM$/$MENU_AP$/$MENU_STA$/$MENU_PRINTER$/$MENU_SETTINGS$: to highlight menu of active page (css use class active for active menu) -$SERVICE_PAGE$ : to add extra code like redirection or anything not managed by page -$PAGE_TILE$ : page title -$FILENAME$ : file name of tpl -$SHORT_FILENAME$ : file name of tpl without extension -$MODE$ : the mode when displaying page AP/STA/AP_STA -$FW_VER$ : Firmware version - -[HOME] -$HOSTNAME$: Hostname -$HOSTNAME_VISIBLE$ : if AP mode then hostname is not applicable so set to hidden, if in STA mode set to visible -$CHIP_ID$ : Chip ID -$CPU_FREQ$ : CPU Frequency -$FREE_MEM$ : Free memory on heap -$SDK_VER$ : SDK version -$MDNS_VISIBLE$: set to hidden if no MDNS and visible if present -$MDNS_NAME$ : mDNS name if enabled or "Not enabled" if not enabled -$SSDP_VISIBLE$ : set to hidden if no MDNS and visible if present -$SSDP_STATUS$ : set to Enabled / Not enabled according compilation settings -$CAPTIVE_PORTAL_VISIBLE$: set to hidden if no Captive portal and visible if present -$CAPTIVE_PORTAL_STATUS$: set to Enabled / Not enabled according compilation settings -$NET_PHY$ : Network type (b/g/n) -$SLEEP_MODE$ : Sleep Mode -$BOOT_VER$ : Boot version -$BAUD_RATE$ : Baud rates for serial communication -$WEB_PORT$ : Port for web access -$DATA_PORT$ : Port for tcp ip connection -$DATA_PORT_VISIBILITY$ : set to hidden if no enabled and visible if enabled - -$AP_STATUS_ENABLED$ : is Access Point enabled or disabled -$AP_VISIBILITY$ : if Access Point is enabled set visible, else set to hidden -$AP_MAC$ : Mac address of AP -$AP_SSID$ : SSID of AP -$AP_IS_VISIBLE$ : Is AP visible -$AP_CHANNEL$ : Channel -$AP_AUTH$ : Autehntification mode -$AP_MAX_CON$ : Maximum connections allowed -$AP_DHCP_STATUS$ : AP DHCP server status (started/stopped) -$AP_IP$ : AP IP address -$AP_GW$ : AP gateway address -$AP_SUBNET$ : AP mask of subnet - -$CONNECTED_STATIONS[ Repetive template using $ROW_NUMBER$ $MAC_CONNECTED$ $IP_CONNECTED$ ]$ -$CONNECTED_STATIONS_NB_ITEMS$ : number of item for connected stations list - or can get variables in direct access: - $ROW_NUMBER[0]$ - $MAC_CONNECTED[0]$ - $IP_CONNECTED[0]$ - until - $ROW_NUMBER[$CONNECTED_STATIONS_NB_ITEMS$ -1]$ - $MAC_CONNECTED[$CONNECTED_STATIONS_NB_ITEMS$ -1]$ - $IP_CONNECTED[$CONNECTED_STATIONS_NB_ITEMS$ -1]$ - -$STA_STATUS_ENABLED$ : is Station enabled or disabled -$STA_VISIBILITY$ : if Station is enabled set visible, else set to hidden -$STA_MAC$ : Mac address of Station -$STA_SSID$ : SSID used by STA -$STA_CHANNEL$ : Channel -$STA_STATUS$ : Connection Status -$STA_SIGNAL$ : Signal strength -$STA_DHCP_STATUS$ : DHCP Client status -$STA_IP$ : STA IP -$STA_GW$ : STA Gateway -$STA_SUBNET$ : STA Mask - -[SYSTEM CONFIGURATION] -$BAUD_RATE_OPTIONS_LIST$ : Baud rate list -$SLEEP_MODE_OPTIONS_LIST$ : Sleep mode list -$POLLING_OPTIONS_LIST$ : Refresh delay list -$WEB_PORT$ : Port for web access -$DATA_PORT$ : Port for tcp ip connection -$DATA_PORT_VISIBILITY$ : set to hidden if no enabled and visible if enabled -$ERROR_MSG$ : Error message if any -$SUCCESS_MSG$ : Success message announcing restart -$ERROR_MSG_VISIBILITY$ : Show/Hide Error message -$SUCCESS_MSG_VISIBILITY$ : Show/Hide Success message -$SUBMIT_BUTTON_VISIBILITY$ : Show if no submission or any error, hide if submission is successful -$BAUD_RATE_STATUS$ : change to has-error if issue, or has-success if ok -$SLEEP_MODE_STATUS$ : change to has-error if issue, or has-success if ok -$WEB_PORT_STATUS$ : change to has-error if issue, or has-success if ok -$DATA_PORT_STATUS$ : change to has-error if issue, or has-success if ok - -[AP CONFIGURATION] -$AP_SSID$ : Access point SSID -$AP_PASSWORD$ Access point password -$IS_SSID_VISIBLE$ : set to checked if SSID is visible -$NETWORK_OPTION_LIST$ : Option list for network for AP -$CHANNEL_OPTION_LIST$ : Channel list -$AUTH_OPTION_LIST$ Authentification methods list -$IS_STATIC_IP$ : set to checked if use static address -$AP_IP$ : Access point IP if static address -$AP_GW$ : Access point Gaieway if static address -$AP_SUBNET$ : : Access point network mask if static address -$ERROR_MSG$ : Error message if any -$SUCCESS_MSG$ : Success message announcing restart -$ERROR_MSG_VISIBILITY$ : Show/Hide Error message -$SUCCESS_MSG_VISIBILITY$ : Show/Hide Success message -$SUBMIT_BUTTON_VISIBILITY$ : Show if no submission or any error, hide if submission is successful -$AP_SSID_STATUS$ : change to has-error if issue, or has-success if ok -$AP_PASSWORD_STATUS$ : change to has-error if issue, or has-success if ok -$IS_SSID_VISIBLE_STATUS$ : change to has-error if issue, or has-success if ok -$NETWORK_OPTION_LIST_STATUS$ : change to has-error if issue, or has-success if ok -$CHANNEL_OPTION_LIST_STATUS$ : change to has-error if issue, or has-success if ok -$AUTH_OPTION_LIST_STATUS$ : change to has-error if issue, or has-success if ok -$AP_STATIC_IP_STATUS$ : change to has-error if issue, or has-success if ok -$AP_IP_STATUS$ : change to has-error if issue, or has-success if ok -$AP_GW_STATUS$ : change to has-error if issue, or has-success if ok -$AP_SUBNET_STATUS$ : change to has-error if issue, or has-success if ok - -[STATION CONFIGURATION] -$STA_SSID$ : Access point SSID -$STA_PASSWORD$ Access point password -$NETWORK_OPTION_LIST$ : Option list for network for AP -$IS_STATIC_IP$ : set to checked if use static address -$STA_IP$ : Access point IP if static address -$STA_GW$ : Access point Gaieway if static address -$STA_SUBNET$ : : Access point network mask if static address -$ERROR_MSG$ : Error message if any -$SUCCESS_MSG$ : Success message announcing restart -$ERROR_MSG_VISIBILITY$ : Show/Hide Error message -$SUCCESS_MSG_VISIBILITY$ : Show/Hide Success message -$SUBMIT_BUTTON_VISIBILITY$ : Show if no submission or any error, hide if submission is successful -$STA_SSID_STATUS$ : change to has-error if issue, or has-success if ok -$STA_PASSWORD_STATUS$ : change to has-error if issue, or has-success if ok -$NETWORK_OPTION_LIST_STATUS$ : change to has-error if issue, or has-success if ok -$STA_STATIC_IP_STATUS$ : change to has-error if issue, or has-success if ok -$STA_IP_STATUS$ : change to has-error if issue, or has-success if ok -$STA_GW_STATUS$ : change to has-error if issue, or has-success if ok -$STA_SUBNET_STATUS$ : change to has-error if issue, or has-success if ok -$AP_SCAN_VISIBILITY$ : Hide scan table which is not executed when saving to EEPROM - -[PRINTER STATUS] -$REFRESH_PAGE$ : Delay for refreshing pages -$XY_FEEDRATE$ : XY axis feedrate -$Z_FEEDRATE$ : Z axis feedrate -$E_FEEDRATE$ : Extruder feedrate - -[PRINTER SETTINGS] -$REFRESH_PAGE$ : Delay for refreshing pages -$XY_FEEDRATE$ : XY axis feedrate -$Z_FEEDRATE$ : Z axis feedrate -$E_FEEDRATE$ : Extruder feedrate -$REFRESH_PAGE_STATUS$ : change to has-error if issue, or has-success if ok -$XY_FEEDRATE_STATUS$ : change to has-error if issue, or has-success if ok -$Z_FEEDRATE_STATUS$ : change to has-error if issue, or has-success if ok -$E_FEEDRATE_STATUS$ : change to has-error if issue, or has-success if ok diff --git a/embedded/build.bat b/embedded/build.bat new file mode 100644 index 00000000..f4a9a8df --- /dev/null +++ b/embedded/build.bat @@ -0,0 +1 @@ +bin2c /infile tool.html.gz /outfile out.h /targetfolder . diff --git a/embedded/gulpfile.js b/embedded/gulpfile.js new file mode 100644 index 00000000..8deb4a79 --- /dev/null +++ b/embedded/gulpfile.js @@ -0,0 +1,125 @@ +var gulp = require('gulp'), + jshint = require('gulp-jshint'), + gulpif = require('gulp-if'), + concat = require('gulp-concat'), + uglify = require('gulp-uglify'), + cleanCSS = require('gulp-clean-css'), + removeCode = require('gulp-remove-code'), + merge = require('merge-stream'), + del = require('del'), + zip = require('gulp-zip'), + gzip = require('gulp-gzip'), + htmlmin = require('gulp-htmlmin'), + replace = require('gulp-replace'), + fs = require('fs'), + smoosher = require('gulp-smoosher'); + +var demoMode = false; +var testMode = false; + +function clean() { + return del(['dist']); +} + +function clean2() { + return del(['dist/js', 'dist/css']); +} +function lint() { + return gulp.src('www/js/**/script.js') + .pipe(jshint()) + .pipe(jshint.reporter('default')); +} + +function Copytest() { + return merge( + gulp.src(['www/tool.html']) + .pipe(removeCode({production: false})) + .pipe(gulp.dest('dist')), + gulp.src(['www/images/**/*.*']) + .pipe(gulp.dest('dist/images')) + ) +} + +function Copy() { + return merge( + gulp.src(['www/tool.html']) + .pipe(removeCode({production: true})) + .pipe(gulp.dest('dist')), + gulp.src(['www/images/**/*.*']) + .pipe(gulp.dest('dist/images')) + ) +} + +function concatApptest() { + return merge( + gulp.src([ 'www/js/**/*.js']) + .pipe(concat('script.js')) + .pipe(removeCode({production: false})) + .pipe(gulp.dest('./dist/js')), + + gulp.src([ 'www/css/**/*.css']) + .pipe(concat('style.css')) + .pipe(gulp.dest('./dist/css/')) + ) +} + +function concatApp() { + return merge( + gulp.src([ 'www/js/**/*.js']) + .pipe(concat('script.js')) + .pipe(removeCode({production: true})) + .pipe(gulp.dest('./dist/js')), + + gulp.src([ 'www/css/**/*.css']) + .pipe(concat('style.css')) + .pipe(gulp.dest('./dist/css/')) + ) +} + +function minifyApp() { + return merge( + gulp.src(['dist/js/script.js']) + .pipe(uglify({mangle: true})) + .pipe(gulp.dest('./dist/js/')), + + gulp.src('dist/css/style.css') + .pipe(cleanCSS({debug: true}, function(details) { + console.log(details.name + ': ' + details.stats.originalSize); + console.log(details.name + ': ' + details.stats.minifiedSize); + })) + .pipe(gulp.dest('./dist/css/')), + + gulp.src('dist/tool.html') + .pipe(htmlmin({collapseWhitespace: true, minifyCSS: true})) + .pipe(gulp.dest('dist')) + ) +} + +function smoosh() { + return gulp.src('dist/tool.html') + .pipe(smoosher()) + .pipe(gulp.dest('dist')) +} + +function compress() { + return gulp.src('dist/tool.html') + .pipe(gzip()) + .pipe(gulp.dest('.')); +} + +gulp.task(clean); +gulp.task(lint); +gulp.task(Copy); +gulp.task(Copytest); +gulp.task(concatApp); +gulp.task(concatApptest); +gulp.task(minifyApp); +gulp.task(smoosh); +gulp.task(clean2); + +var defaultSeries = gulp.series(clean, lint, Copy, concatApp, smoosh); +var packageSeries = gulp.series(clean, lint, Copy, concatApp,minifyApp, smoosh, compress, clean2); + +gulp.task('default', defaultSeries); +gulp.task('package', packageSeries); + diff --git a/embedded/install.bat b/embedded/install.bat new file mode 100644 index 00000000..e3f2831a --- /dev/null +++ b/embedded/install.bat @@ -0,0 +1,15 @@ +npm install --global gulp-cli +npm install --save-dev gulp +npm install --save-dev gulp-jshint +npm install --save-dev jshint +npm install --save-dev gulp-if +npm install --save-dev gulp-concat +npm install --save-dev gulp-uglify +npm install --save-dev gulp-clean-css +npm install --save-dev gulp-remove-code +npm install --save-dev del +npm install --save-dev gulp-zip +npm install --save-dev gulp-gzip +npm install --save-dev gulp-htmlmin +npm install --save-dev gulp-replace +npm install --save-dev gulp-smoosher diff --git a/embedded/package.json b/embedded/package.json new file mode 100644 index 00000000..00299619 --- /dev/null +++ b/embedded/package.json @@ -0,0 +1,30 @@ +{ + "name": "embedded4ESP3D", + "description": "Embedded files for ESP3D", + "devDependencies": { + "del": "^2.2.2", + "deprecated": "0.0.1", + "fs": "0.0.1-security", + "gulp": "github:gulpjs/gulp#4.0", + "gulp-bytediff": "^1.0.0", + "gulp-cdnizer": "^1.1.7", + "gulp-clean-css": "^2.4.0", + "gulp-concat": "^2.6.1", + "gulp-gzip": "^1.4.0", + "gulp-htmlmin": "^3.0.0", + "gulp-if": "^2.0.2", + "gulp-jshint": "^2.0.4", + "gulp-ng-annotate": "^2.0.0", + "gulp-remove-code": "^1.0.2", + "gulp-replace": "^0.5.4", + "gulp-smoosher": "0.0.9", + "gulp-uglify": "^2.1.2", + "gulp-util": "^3.0.1", + "gulp-zip": "^3.2.0", + "jshint": "^2.9.5", + "merge-stream": "^1.0.1" + }, + "repository": "https://github.com/luc-github/ESP3D", + "author": "Luc LEBOSSE", + "license": "(ISC OR GPL-3.0)" +} diff --git a/embedded/tool.html.gz b/embedded/tool.html.gz new file mode 100644 index 00000000..de11ef01 Binary files /dev/null and b/embedded/tool.html.gz differ diff --git a/esp3d/data/css.inc b/embedded/www/css/style.css similarity index 59% rename from esp3d/data/css.inc rename to embedded/www/css/style.css index f3ace5a2..d8b50635 100644 --- a/esp3d/data/css.inc +++ b/embedded/www/css/style.css @@ -50,3 +50,90 @@ caption{padding-top:8px;padding-bottom:8px;color:#777777;text-align:left;} .btnroundimg:hover{background-color:#F0F0F0;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #ce8483;box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #ce8483;} .blacklink {color:#000000;} .blacklink:hover, .filelink:focus {color:#0094FF;} +input[type="file"]::-webkit-file-upload-button{display:inline-block;margin-bottom:0;font-weight:normal;text-align:center;vertical-align:middle;-ms-touch-action:manipulation; touch-action:manipulation;cursor:pointer; +background-image:none;border:1px solid transparent;white-space:nowrap;padding:6px 12px;font-size:14px;line-height:1.42857143;border-radius:4px; +* -webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none; color: #ffffff;background-color: #5bc0de;border-color: #46b8da;} +input[type="file"]::-webkit-file-upload-button:focus{display:inline-block;margin-bottom:0;font-weight:normal;text-align:center;vertical-align:middle;-ms-touch-action:manipulation; touch-action:manipulation;cursor:pointer; +background-image:none;border:1px solid transparent;white-space:nowrap;padding:6px 12px;font-size:14px;line-height:1.42857143;border-radius:4px; +* -webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none; color: #ffffff;background-color: #31b0d5;border-color: #1b6d85;} +input[type="file"]::-webkit-file-upload-button:hover{display:inline-block;margin-bottom:0;font-weight:normal;text-align:center;vertical-align:middle;-ms-touch-action:manipulation; touch-action:manipulation;cursor:pointer; +background-image:none;border:1px solid transparent;white-space:nowrap;padding:6px 12px;font-size:14px;line-height:1.42857143;border-radius:4px; +* -webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none; color: #ffffff;background-color: #31b0d5;border-color: #269abc;} +.filelink {color:#000000;} +.filelink:hover, .filelink:focus {color:#0094FF;} +.panel-footer{padding:10px 15px;color:#31708f;background-color:#f5f5f5;border-color:#dddddd;border-top:1px solid #dddddd;} +.loader { + border: 4px solid #f3f3f3; /* Light grey */ + border-top: 4px solid #3498db; /* Blue */ + border-radius: 50%; + width: 12px; + height: 12px; + animation: spin 2s linear infinite; +} + +@keyframes spin { + 0% { transform: rotate(0deg); } + 100% { transform: rotate(360deg); } +} +.panel-footer{padding:10px 15px;color:#31708f;background-color:#f5f5f5;border-color:#dddddd;border-top:1px solid #dddddd;} + +.modal { + display: none; /* Hidden by default */ + position: fixed; /* Stay in place */ + z-index: 10000; /* Sit on top */ + padding-top: 100px; /* Location of the box */ + left: 0; + top: 0; + width: 100%; /* Full width */ + height: 100%; /* Full height */ + overflow: auto; /* Enable scroll if needed */ + background-color: rgb(0,0,0); /* Fallback color */ + background-color: rgba(0,0,0,0.4); /* Black w/ opacity */ +} + +/* Modal Content */ +.modal-content { + border-top-left-radius: 10px; + border-top-right-radius: 10px; + border-bottom-left-radius: 10px; + border-bottom-right-radius: 10px; + border: 2px solid #337AB7; + box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); + position: relative; + margin: auto; + padding: 0; + background-color: #fefefe; +} + +.modal-header { + padding: 2px 16px; + color: #0f0f0f; + background-color: #f2f2f2; + border-top-left-radius: 10px; + border-top-right-radius: 10px; + border-bottom: 1px solid #cfcfcf; +} + +.modal-body {padding: 10px 16px;} + +.modal-footer { + padding: 16px 16px; + height: 4.5em; + color: #0f0f0f; + background-color: #f2f2f2; + border-top: 1px solid #cfcfcf; + border-bottom-left-radius: 10px; + border-bottom-right-radius: 10px; +} + +@media (min-width: 768px) { + .modal-content { + width: 580px; + } +} + +@media screen and (max-width: 767px) { + .modal-content { + width: 100%; + } +} diff --git a/esp3d/data/settings.tpl b/embedded/www/js/script.js similarity index 60% rename from esp3d/data/settings.tpl rename to embedded/www/js/script.js index 69f5c0fe..f6f7428e 100644 --- a/esp3d/data/settings.tpl +++ b/embedded/www/js/script.js @@ -1,52 +1,3 @@ -$INCLUDE[header.inc]$ -$INCLUDE[css2.inc]$ - -
-
Extra Settings
-
-
-

-
-

-
-

-
-

-
- - -
-
- -
-
-
-
Flash Filesystem
-
- -   -

-
- -
-
- + -
-
 
-
-
TypeNameSize
-
- -
-
-
- -$INCLUDE[footer.inc]$ - +function RequestLogin(){ + document.getElementById('loader').style.visibility="hidden"; + document.getElementById('loginpage').style.display='block'; +} +function SubmitRequest (){ + document.getElementById('loginpage').style.display='none'; + var user = document.getElementById('login_user_text').value.trim(); + var password = document.getElementById('login_password_text').value.trim(); + var url = "/login?USER="+encodeURIComponent(user) + "&PASSWORD=" + encodeURIComponent(password) + "&SUBMIT=yes" ; + var xmlhttp = new XMLHttpRequest(); + xmlhttp.onreadystatechange = function() { + if (xmlhttp.readyState == 4 && xmlhttp.status != 200) { + RequestLogin(); + } + }; +xmlhttp.open("GET", url, true); +xmlhttp.send(); +} diff --git a/embedded/www/tool.html b/embedded/www/tool.html new file mode 100644 index 00000000..33c5cecd --- /dev/null +++ b/embedded/www/tool.html @@ -0,0 +1,100 @@ + + + + + + + +
+ V1.1 +    +
+
+

It seems you do not have any index.html neither index.html.gz, please upload it or update your firmware if necessary.

+
+ +
+
Flash Filesystem
+
+ +    +

+
+
+ + + + + + + +
+ + +
+ + +
+
+
+
+
 
+
+ + + + + + + + + + + +
TypeNameSize
+
+ +
+
+
+
+
Firmware Update
+
+ + + + + + + +
+
+
+ + + + + + + + diff --git a/esp3d/bridge.cpp b/esp3d/bridge.cpp index 3925d9a8..58d6d34d 100644 --- a/esp3d/bridge.cpp +++ b/esp3d/bridge.cpp @@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "config.h" #include "bridge.h" #include "command.h" #include "webinterface.h" @@ -29,92 +30,91 @@ WiFiClient serverClients[MAX_SRV_CLIENTS]; bool BRIDGE::header_sent = false; String BRIDGE::buffer_web = ""; -void BRIDGE::print (const __FlashStringHelper *data, tpipe output){ +void BRIDGE::print (const __FlashStringHelper *data, tpipe output) +{ String tmp = data; BRIDGE::print(tmp.c_str(), output); } -void BRIDGE::print (String & data, tpipe output){ +void BRIDGE::print (String & data, tpipe output) +{ BRIDGE::print(data.c_str(), output); } -void BRIDGE::print (const char * data, tpipe output){ - switch(output){ - case SERIAL_PIPE: - header_sent = false; - Serial.print(data); - break; - case SERIAL1_PIPE: - header_sent = false; - Serial1.print(data); +void BRIDGE::print (const char * data, tpipe output) +{ + switch(output) { + case SERIAL_PIPE: + header_sent = false; + ESP_SERIAL_OUT.print(data); break; #ifdef TCP_IP_DATA_FEATURE - case TCP_PIPE: - header_sent = false; - BRIDGE::send2TCP(data); + case TCP_PIPE: + header_sent = false; + BRIDGE::send2TCP(data); break; #endif - case WEB_PIPE: - if (!header_sent){ - web_interface->WebServer.setContentLength(CONTENT_LENGTH_UNKNOWN); - web_interface->WebServer.sendHeader("Content-Type","text/html"); - web_interface->WebServer.sendHeader("Cache-Control","no-cache"); - web_interface->WebServer.send(200); - header_sent = true; - } - buffer_web+=data; - if (buffer_web.length() > 1200) - { - //send data - web_interface->WebServer.sendContent(buffer_web); - //reset buffer - buffer_web=""; - } + case WEB_PIPE: + if (!header_sent) { + web_interface->web_server.setContentLength(CONTENT_LENGTH_UNKNOWN); + web_interface->web_server.sendHeader("Content-Type","text/html"); + web_interface->web_server.sendHeader("Cache-Control","no-cache"); + web_interface->web_server.send(200); + header_sent = true; + } + buffer_web+=data; + if (buffer_web.length() > 1200) { + //send data + web_interface->web_server.sendContent(buffer_web); + //reset buffer + buffer_web=""; + } break; - default: + default: break; } } -void BRIDGE::println (const __FlashStringHelper *data, tpipe output){ +void BRIDGE::println (const __FlashStringHelper *data, tpipe output) +{ BRIDGE::print(data,output); #ifdef TCP_IP_DATA_FEATURE BRIDGE::print("\r",output); #endif BRIDGE::print("\n",output); } -void BRIDGE::println (String & data, tpipe output){ +void BRIDGE::println (String & data, tpipe output) +{ BRIDGE::print(data,output); #ifdef TCP_IP_DATA_FEATURE BRIDGE::print("\r",output); #endif BRIDGE::print("\n",output); } -void BRIDGE::println (const char * data, tpipe output){ +void BRIDGE::println (const char * data, tpipe output) +{ BRIDGE::print(data,output); #ifdef TCP_IP_DATA_FEATURE BRIDGE::print("\r",output); #endif BRIDGE::print("\n",output); } -void BRIDGE::flush (tpipe output){ - switch(output){ - case SERIAL_PIPE: - Serial.flush(); - break; - case SERIAL1_PIPE: - Serial1.flush(); +void BRIDGE::flush (tpipe output) +{ + switch(output) { + case SERIAL_PIPE: + ESP_SERIAL_OUT.flush(); break; #ifdef TCP_IP_DATA_FEATURE - case TCP_PIPE: + case TCP_PIPE: break; #endif - case WEB_PIPE: - if(header_sent){ - //send data - web_interface->WebServer.sendContent(buffer_web); - //close line - web_interface->WebServer.sendContent(""); - } + case WEB_PIPE: + if(header_sent) { + //send data + web_interface->web_server.sendContent(buffer_web); + //close line + web_interface->web_server.sendContent(""); + } break; - default: + default: break; } header_sent = false; @@ -123,36 +123,42 @@ void BRIDGE::flush (tpipe output){ #ifdef TCP_IP_DATA_FEATURE -void BRIDGE::send2TCP(const __FlashStringHelper *data){ +void BRIDGE::send2TCP(const __FlashStringHelper *data) +{ String tmp = data; BRIDGE::send2TCP(tmp.c_str()); } -void BRIDGE::send2TCP(String data){ +void BRIDGE::send2TCP(String data) +{ BRIDGE::send2TCP(data.c_str()); } -void BRIDGE::send2TCP(const char * data){ +void BRIDGE::send2TCP(const char * data) +{ for(uint8_t i = 0; i < MAX_SRV_CLIENTS; i++) { - if (serverClients[i] && serverClients[i].connected()) { - serverClients[i].write(data, strlen(data)); - delay(0); - } + if (serverClients[i] && serverClients[i].connected()) { + serverClients[i].write(data, strlen(data)); + delay(0); } + } } #endif + bool BRIDGE::processFromSerial2TCP() { uint8_t i; //check UART for data - if(Serial.available()) { - size_t len = Serial.available(); + if(ESP_SERIAL_OUT.available()) { + size_t len = ESP_SERIAL_OUT.available(); uint8_t sbuf[len]; - Serial.readBytes(sbuf, len); + ESP_SERIAL_OUT.readBytes(sbuf, len); #ifdef TCP_IP_DATA_FEATURE - //push UART data to all connected tcp clients - for(i = 0; i < MAX_SRV_CLIENTS; i++) { - if (serverClients[i] && serverClients[i].connected()) { - serverClients[i].write(sbuf, len); - delay(0); + if (WiFi.getMode()!=WIFI_OFF ) { + //push UART data to all connected tcp clients + for(i = 0; i < MAX_SRV_CLIENTS; i++) { + if (serverClients[i] && serverClients[i].connected()) { + serverClients[i].write(sbuf, len); + delay(0); + } } } #endif @@ -192,7 +198,7 @@ void BRIDGE::processFromTCP2Serial() //get data from the tcp client and push it to the UART while(serverClients[i].available()) { data = serverClients[i].read(); - Serial.write(data); + ESP_SERIAL_OUT.write(data); COMMAND::read_buffer_tcp(data); } } diff --git a/esp3d/command.cpp b/esp3d/command.cpp index 066d5879..a40647a7 100644 --- a/esp3d/command.cpp +++ b/esp3d/command.cpp @@ -17,24 +17,26 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -#include "command.h" #include "config.h" -#include "wifi.h" +#include "command.h" +#include "wificonf.h" #include "webinterface.h" -#ifdef SDCARD_FEATURE #ifndef FS_NO_GLOBALS #define FS_NO_GLOBALS #endif -#endif #include - +#if defined(ARDUINO_ARCH_ESP32) +#include "SPIFFS.h" +#define MAX_GPIO 16 +#else +#define MAX_GPIO 37 +#endif String COMMAND::buffer_serial; String COMMAND::buffer_tcp; -#define ERROR_CMD_MSG F("M117 Cmd Error") -#define INCORRECT_CMD_MSG F("M117 Incorrect Cmd") -#define OK_CMD_MSG F("M117 Cmd Ok") +#define ERROR_CMD_MSG (output == WEB_PIPE)?F("Error: Wrong Command"):F("M117 Cmd Error") +#define INCORRECT_CMD_MSG (output == WEB_PIPE)?F("Error: Incorrect Command"):F("M117 Incorrect Cmd") +#define OK_CMD_MSG (output == WEB_PIPE)?F("ok"):F("M117 Cmd Ok") String COMMAND::get_param(String & cmd_params, const char * id, bool withspace) { @@ -60,10 +62,12 @@ String COMMAND::get_param(String & cmd_params, const char * id, bool withspace) if (!withspace) { end = cmd_params.indexOf(" ",start); } +#ifdef AUTHENTICATION_FEATURE //if space expected only one parameter but additional password may be present - else if (sid!="pwd=") { - end = cmd_params.indexOf("pwd=",start); + else if (sid != " pwd=") { + end = cmd_params.indexOf(" pwd=",start); } +#endif //if no end found - take all if (end == -1) { end = cmd_params.length(); @@ -75,11 +79,12 @@ String COMMAND::get_param(String & cmd_params, const char * id, bool withspace) return parameter; } #ifdef AUTHENTICATION_FEATURE +//check admin password bool COMMAND::isadmin(String & cmd_params) { String adminpassword; String sadminPassword; - if (!CONFIG::read_string(EP_ADMIN_PWD, sadminPassword , MAX_LOCAL_PASSWORD_LENGTH)) { + if (!CONFIG::read_string(EP_ADMIN_PWD, sadminPassword, MAX_LOCAL_PASSWORD_LENGTH)) { LOG("ERROR getting admin\r\n") sadminPassword=FPSTR(DEFAULT_ADMIN_PWD); } @@ -91,9 +96,38 @@ bool COMMAND::isadmin(String & cmd_params) return true; } } -#endif -void COMMAND::execute_command(int cmd,String cmd_params, tpipe output) +//check user password - admin password is also valid +bool COMMAND::isuser(String & cmd_params) { + String userpassword; + String suserPassword; + if (!CONFIG::read_string(EP_USER_PWD, suserPassword, MAX_LOCAL_PASSWORD_LENGTH)) { + LOG("ERROR getting user\r\n") + suserPassword=FPSTR(DEFAULT_USER_PWD); + } + userpassword = get_param(cmd_params,"pwd=", true); + //it is not user password + if (!suserPassword.equals(userpassword)) { + //check admin password + return COMMAND::isadmin(cmd_params); + } else { + return true; + } +} +#endif +bool COMMAND::execute_command(int cmd,String cmd_params, tpipe output, level_authenticate_type auth_level) +{ + bool response = true; +#ifdef AUTHENTICATION_FEATURE + level_authenticate_type auth_type = auth_level; + if (isadmin(cmd_params)) { + auth_type = LEVEL_ADMIN; + } + if (isuser(cmd_params) && (auth_type != LEVEL_ADMIN)) { + auth_type = LEVEL_USER; + } + +#endif //manage parameters byte mode = 254; String parameter; @@ -107,12 +141,13 @@ void COMMAND::execute_command(int cmd,String cmd_params, tpipe output) BRIDGE::println(INCORRECT_CMD_MSG, output); } #ifdef AUTHENTICATION_FEATURE - if (!isadmin(cmd_params)) { + if (auth_type != LEVEL_ADMIN) { BRIDGE::println(INCORRECT_CMD_MSG, output); } else #endif if(!CONFIG::write_string(EP_STA_SSID,parameter.c_str())) { BRIDGE::println(ERROR_CMD_MSG, output); + response = false; } else { BRIDGE::println(OK_CMD_MSG, output); } @@ -123,14 +158,17 @@ void COMMAND::execute_command(int cmd,String cmd_params, tpipe output) parameter = get_param(cmd_params,"", true); if (!CONFIG::isPasswordValid(parameter.c_str())) { BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; } #ifdef AUTHENTICATION_FEATURE - if (!isadmin(cmd_params)) { + if (auth_type != LEVEL_ADMIN) { BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; } else #endif if(!CONFIG::write_string(EP_STA_PASSWORD,parameter.c_str())) { BRIDGE::println(ERROR_CMD_MSG, output); + response = false; } else { BRIDGE::println(OK_CMD_MSG, output); } @@ -141,14 +179,17 @@ void COMMAND::execute_command(int cmd,String cmd_params, tpipe output) parameter = get_param(cmd_params,"", true); if (!CONFIG::isHostnameValid(parameter.c_str())) { BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; } #ifdef AUTHENTICATION_FEATURE - if (!isadmin(cmd_params)) { + if (auth_type != LEVEL_ADMIN) { BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; } else #endif if(!CONFIG::write_string(EP_HOSTNAME,parameter.c_str())) { BRIDGE::println(ERROR_CMD_MSG, output); + response = false; } else { BRIDGE::println(OK_CMD_MSG, output); } @@ -163,15 +204,18 @@ void COMMAND::execute_command(int cmd,String cmd_params, tpipe output) mode = AP_MODE; } else { BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; } if ((mode == CLIENT_MODE) || (mode == AP_MODE)) { #ifdef AUTHENTICATION_FEATURE - if (!isadmin(cmd_params)) { + if (auth_type != LEVEL_ADMIN) { BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; } else #endif if(!CONFIG::write_byte(EP_WIFI_MODE,mode)) { BRIDGE::println(ERROR_CMD_MSG, output); + response = false; } else { BRIDGE::println(OK_CMD_MSG, output); } @@ -187,15 +231,18 @@ void COMMAND::execute_command(int cmd,String cmd_params, tpipe output) mode = DHCP_MODE; } else { BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; } if ((mode == STATIC_IP_MODE) || (mode == DHCP_MODE)) { #ifdef AUTHENTICATION_FEATURE - if (!isadmin(cmd_params)) { + if (auth_type != LEVEL_ADMIN) { BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; } else #endif if(!CONFIG::write_byte(EP_STA_IP_MODE,mode)) { BRIDGE::println(ERROR_CMD_MSG, output); + response = false; } else { BRIDGE::println(OK_CMD_MSG, output); } @@ -207,14 +254,17 @@ void COMMAND::execute_command(int cmd,String cmd_params, tpipe output) parameter = get_param(cmd_params,"", true); if (!CONFIG::isSSIDValid(parameter.c_str())) { BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; } #ifdef AUTHENTICATION_FEATURE - if (!isadmin(cmd_params)) { + if (auth_type != LEVEL_ADMIN) { BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; } else #endif if(!CONFIG::write_string(EP_AP_SSID,parameter.c_str())) { BRIDGE::println(ERROR_CMD_MSG, output); + response = false; } else { BRIDGE::println(OK_CMD_MSG, output); } @@ -225,14 +275,17 @@ void COMMAND::execute_command(int cmd,String cmd_params, tpipe output) parameter = get_param(cmd_params,"", true); if (!CONFIG::isPasswordValid(parameter.c_str())) { BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; } #ifdef AUTHENTICATION_FEATURE - if (!isadmin(cmd_params)) { + if (auth_type != LEVEL_ADMIN) { BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; } else #endif if(!CONFIG::write_string(EP_AP_PASSWORD,parameter.c_str())) { BRIDGE::println(ERROR_CMD_MSG, output); + response = false; } else { BRIDGE::println(OK_CMD_MSG, output); } @@ -247,20 +300,64 @@ void COMMAND::execute_command(int cmd,String cmd_params, tpipe output) mode = DHCP_MODE; } else { BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; } if ((mode == STATIC_IP_MODE) || (mode == DHCP_MODE)) { #ifdef AUTHENTICATION_FEATURE - if (!isadmin(cmd_params)) { + if (auth_type != LEVEL_ADMIN) { BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; } else #endif if(!CONFIG::write_byte(EP_AP_IP_MODE,mode)) { BRIDGE::println(ERROR_CMD_MSG, output); + response = false; } else { BRIDGE::println(OK_CMD_MSG, output); } } break; + // Set wifi on/off + //[ESP110][pwd=] + case 110: + parameter = get_param(cmd_params,"", true); + if (parameter == "on") { + mode = 1; + } else if (parameter == "off") { + mode = 0; + } else if (parameter == "restart") { + mode = 2; + } else { + BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; + } + if (response) { + #ifdef AUTHENTICATION_FEATURE + if (auth_type != LEVEL_ADMIN) { + BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; + } else + #endif + if (mode == 0) { + if (WiFi.getMode() !=WIFI_OFF) { + //disable wifi + ESP_SERIAL_OUT.println("M117 Disabling Wifi"); + WiFi.mode(WIFI_OFF); + wifi_config.Disable_servers(); + return response; + } else BRIDGE::println("M117 Wifi already off", output); + } + else if (mode == 1) { //restart device is the best way to start everything clean + if (WiFi.getMode() == WIFI_OFF) { + ESP_SERIAL_OUT.println("M117 Enabling Wifi"); + CONFIG::esp_restart(); + } else BRIDGE::println("M117 Wifi already on", output); + } else { //restart wifi and restart is the best way to start everything clean + ESP_SERIAL_OUT.println("M117 Enabling Wifi"); + CONFIG::esp_restart(); + } + } + break; //Get current IP //[ESP111]
case 111: { @@ -281,7 +378,7 @@ void COMMAND::execute_command(int cmd,String cmd_params, tpipe output) //[ESP112]
case 112: { String shost ; - if (!CONFIG::read_string(EP_HOSTNAME, shost , MAX_HOSTNAME_LENGTH)) { + if (!CONFIG::read_string(EP_HOSTNAME, shost, MAX_HOSTNAME_LENGTH)) { shost=wifi_config.get_default_hostname(); } BRIDGE::print(cmd_params, output); @@ -291,108 +388,800 @@ void COMMAND::execute_command(int cmd,String cmd_params, tpipe output) LOG("\r\n") } break; - #ifdef DIRECT_PIN_FEATURE //Get/Set pin value //[ESP201]P V - case 201: { - //check if have pin - parameter = get_param(cmd_params,"P", false); - LOG("Pin:") - LOG(parameter) - LOG("\r\n") - if (parameter == "") { + case 201: + parameter = get_param(cmd_params,"", true); +#ifdef AUTHENTICATION_FEATURE + if (auth_type == LEVEL_GUEST) { BRIDGE::println(INCORRECT_CMD_MSG, output); - } else { - int pin = parameter.toInt(); - //check pin is valid and not serial used pins - if ((pin >= 0) && (pin <= 16) && !((pin == 1) || (pin == 3))) { - //check if is set or get - parameter = get_param(cmd_params,"V", false); - //it is a get - if (parameter == "") { - //this is to not set pin mode - parameter = get_param(cmd_params,"RAW=", false); - if (parameter !="YES") - { - parameter = get_param(cmd_params,"PULLUP=", false); - if (parameter == "YES"){ - //GPIO16 is different than others - if (pin <16) { - LOG("Set as input pull up\r\n") - pinMode(pin, INPUT_PULLUP); - } else { - LOG("Set as input pull down 16\r\n") - pinMode(pin, INPUT_PULLDOWN_16); - } - }else { - LOG("Set as input\r\n") - pinMode(pin, INPUT); - } - delay(100); - } - int value = digitalRead(pin); - LOG("Read:"); - BRIDGE::println(String(value).c_str(), output); - } else { - //it is a set - int value = parameter.toInt(); - //verify it is a 0 or a 1 - if ((value == 0) || (value == 1)) { - pinMode(pin, OUTPUT); - delay(10); - LOG("Set:") - LOG(String((value == 0)?LOW:HIGH)) - LOG("\r\n") - digitalWrite(pin, (value == 0)?LOW:HIGH); - } else { - BRIDGE::println(INCORRECT_CMD_MSG, output); - } - } - } else { + response = false; + } else +#endif + { + //check if have pin + parameter = get_param(cmd_params,"P", false); + LOG("Pin:") + LOG(parameter) + LOG("\r\n") + if (parameter == "") { BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; + } else { + int pin = parameter.toInt(); + //check pin is valid and not serial used pins + if ((pin >= 0) && (pin <= 16) && !((pin == 1) || (pin == 3))) { + //check if is set or get + parameter = get_param(cmd_params,"V", false); + //it is a get + if (parameter == "") { + //this is to not set pin mode + parameter = get_param(cmd_params,"RAW=", false); + if (parameter !="YES") { + parameter = get_param(cmd_params,"PULLUP=", false); + if (parameter == "YES") { + //GPIO16 is different than others + if (pin < MAX_GPIO) { + LOG("Set as input pull up\r\n") + pinMode(pin, INPUT_PULLUP); + } +#ifdef ARDUINO_ARCH_ESP8266 + else { + LOG("Set as input pull down 16\r\n") + pinMode(pin, INPUT_PULLDOWN_16); + } +#endif + } else { + LOG("Set as input\r\n") + pinMode(pin, INPUT); + } + delay(100); + } + int value = digitalRead(pin); + LOG("Read:"); + LOG(String(value).c_str()) + LOG("\n"); + BRIDGE::println(String(value).c_str(), output); + } else { + //it is a set + int value = parameter.toInt(); + //verify it is a 0 or a 1 + if ((value == 0) || (value == 1)) { + pinMode(pin, OUTPUT); + delay(10); + LOG("Set:") + LOG(String((value == 0)?LOW:HIGH)) + LOG("\r\n") + digitalWrite(pin, (value == 0)?LOW:HIGH); + BRIDGE::println(OK_CMD_MSG, output); + } else { + BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; + } + } + } else { + BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; + } } } - } - break; + break; #endif - //Get/Set ESP mode - //cmd is RESET, SAFEMODE, CONFIG, RESTART + //Save data string + //[ESP300]pwd= + case 300: + parameter = get_param(cmd_params,"", true); +#ifdef AUTHENTICATION_FEATURE + if (auth_type == LEVEL_GUEST) { + BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; + } else +#endif + { + if(!CONFIG::write_string(EP_DATA_STRING,parameter.c_str())) { + BRIDGE::println(ERROR_CMD_MSG, output); + response = false; + } else { + BRIDGE::println(OK_CMD_MSG, output); + } + } + break; + //get data string + //[ESP301] pwd= + case 301: + parameter = get_param(cmd_params,"", true); +#ifdef AUTHENTICATION_FEATURE + if (auth_type == LEVEL_GUEST) { + BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; + } else +#endif + { + char sbuf[MAX_DATA_LENGTH+1]; + if (CONFIG::read_string(EP_DATA_STRING, sbuf, MAX_DATA_LENGTH)) { + BRIDGE::println(sbuf, output); + } else { + BRIDGE::println(F("Error reading data"), output); + } + } + break; + //Get full EEPROM settings content + //[ESP400] + case 400: { + char sbuf[MAX_DATA_LENGTH+1]; + uint8_t ipbuf[4]; + byte bbuf=0; + int ibuf=0; + parameter = get_param(cmd_params,"", true); + delay(0); + //Start JSON + BRIDGE::println(F("{\"EEPROM\":["), output); + if (cmd_params == "network" || cmd_params == "") { + + //1- Baud Rate + BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_BAUD_RATE), output); + BRIDGE::print(F("\",\"T\":\"I\",\"V\":\""), output); + if (!CONFIG::read_buffer(EP_BAUD_RATE, (byte *)&ibuf, INTEGER_LENGTH)) { + BRIDGE::print("???", output); + } else { + BRIDGE::print((const char *)CONFIG::intTostr(ibuf), output); + } + BRIDGE::print(F("\",\"H\":\"Baud Rate\",\"O\":[{\"9600\":\"9600\"},{\"19200\":\"19200\"},{\"38400\":\"38400\"},{\"57600\":\"57600\"},{\"115200\":\"115200\"},{\"230400\":\"230400\"},{\"250000\":\"250000\"}]}"), output); + BRIDGE::println(F(","), output); + + //2-Sleep Mode + BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_SLEEP_MODE), output); + BRIDGE::print(F("\",\"T\":\"B\",\"V\":\""), output); + if (!CONFIG::read_byte(EP_SLEEP_MODE, &bbuf )) { + BRIDGE::print("???", output); + } else { + BRIDGE::print((const char *)CONFIG::intTostr(bbuf), output); + } + BRIDGE::print(F("\",\"H\":\"Sleep Mode\",\"O\":[{\"None\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(WIFI_NONE_SLEEP), output); +#ifdef ARDUINO_ARCH_ESP8266 + BRIDGE::print(F("\"},{\"Light\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(WIFI_LIGHT_SLEEP), output); +#endif + BRIDGE::print(F("\"},{\"Modem\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(WIFI_MODEM_SLEEP), output); + BRIDGE::print(F("\"}]}"), output); + BRIDGE::println(F(","), output); + + //3-Web Port + BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_WEB_PORT), output); + BRIDGE::print(F("\",\"T\":\"I\",\"V\":\""), output); + if (!CONFIG::read_buffer(EP_WEB_PORT, (byte *)&ibuf, INTEGER_LENGTH)) { + BRIDGE::print("???", output); + } else { + BRIDGE::print((const char *)CONFIG::intTostr(ibuf), output); + } + BRIDGE::print(F("\",\"H\":\"Web Port\",\"S\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MAX_WEB_PORT), output); + BRIDGE::print(F("\",\"M\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MIN_WEB_PORT), output); + BRIDGE::print(F("\"}"), output); + BRIDGE::println(F(","), output); + + //4-Data Port + BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_DATA_PORT), output); + BRIDGE::print(F("\",\"T\":\"I\",\"V\":\""), output); + if (!CONFIG::read_buffer(EP_DATA_PORT, (byte *)&ibuf, INTEGER_LENGTH)) { + BRIDGE::print("???", output); + } else { + BRIDGE::print((const char *)CONFIG::intTostr(ibuf), output); + } + BRIDGE::print(F("\",\"H\":\"Data Port\",\"S\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MAX_DATA_PORT), output); + BRIDGE::print(F("\",\"M\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MIN_DATA_PORT), output); + BRIDGE::print(F("\"}"), output); + BRIDGE::println(F(","), output); +#ifdef AUTHENTICATION_FEATURE + //5-Admin password + BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_ADMIN_PWD), output); + BRIDGE::print(F("\",\"T\":\"S\",\"V\":\""), output); + if (!CONFIG::read_string(EP_ADMIN_PWD, sbuf, MAX_LOCAL_PASSWORD_LENGTH)) { + BRIDGE::print("???", output); + } else { + BRIDGE::print("********", output); + } + BRIDGE::print(F("\",\"S\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(MAX_LOCAL_PASSWORD_LENGTH), output); + BRIDGE::print(F("\",\"H\":\"Admin Password\",\"M\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(MIN_LOCAL_PASSWORD_LENGTH), output); + BRIDGE::print(F("\"}"), output); + BRIDGE::println(F(","), output); + + //6-User password + BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_USER_PWD), output); + BRIDGE::print(F("\",\"T\":\"S\",\"V\":\""), output); + if (!CONFIG::read_string(EP_USER_PWD, sbuf, MAX_LOCAL_PASSWORD_LENGTH)) { + BRIDGE::print("???", output); + } else { + BRIDGE::print("********", output); + } + BRIDGE::print(F("\",\"S\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(MAX_LOCAL_PASSWORD_LENGTH), output); + BRIDGE::print(F("\",\"H\":\"User Password\",\"M\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(MIN_LOCAL_PASSWORD_LENGTH), output); + BRIDGE::print(F("\"}"), output); + BRIDGE::println(F(","), output); +#endif + //7-Hostname + BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_HOSTNAME), output); + BRIDGE::print(F("\",\"T\":\"S\",\"V\":\""), output); + if (!CONFIG::read_string(EP_HOSTNAME, sbuf, MAX_HOSTNAME_LENGTH)) { + BRIDGE::print("???", output); + } else { + BRIDGE::print(sbuf, output); + } + BRIDGE::print(F("\",\"H\":\"Hostname\" ,\"S\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(MAX_HOSTNAME_LENGTH), output); + BRIDGE::print(F("\", \"M\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(MIN_HOSTNAME_LENGTH), output); + BRIDGE::print(F("\"}"), output); + BRIDGE::println(F(","), output); + + //8-wifi mode + BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_WIFI_MODE), output); + BRIDGE::print(F("\",\"T\":\"B\",\"V\":\""), output); + if (!CONFIG::read_byte(EP_WIFI_MODE, &bbuf )) { + BRIDGE::print("???", output); + } else { + BRIDGE::print((const char *)CONFIG::intTostr(bbuf), output); + } + BRIDGE::print(F("\",\"H\":\"Wifi mode\",\"O\":[{\"AP\":\"1\"},{\"STA\":\"2\"}]}"), output); + BRIDGE::println(F(","), output); + + //9-STA SSID + BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_STA_SSID), output); + BRIDGE::print(F("\",\"T\":\"S\",\"V\":\""), output); + if (!CONFIG::read_string(EP_STA_SSID, sbuf, MAX_SSID_LENGTH)) { + BRIDGE::print("???", output); + } else { + BRIDGE::print(sbuf, output); + } + BRIDGE::print(F("\",\"S\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(MAX_SSID_LENGTH), output); + BRIDGE::print(F("\",\"H\":\"Station SSID\",\"M\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(MIN_SSID_LENGTH), output); + BRIDGE::print(F("\"}"), output); + BRIDGE::println(F(","), output); + + //10-STA password + BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_STA_PASSWORD), output); + BRIDGE::print(F("\",\"T\":\"S\",\"V\":\""), output); + if (!CONFIG::read_string(EP_STA_PASSWORD, sbuf, MAX_PASSWORD_LENGTH)) { + BRIDGE::print("???", output); + } else { + BRIDGE::print("********", output); + } + BRIDGE::print(F("\",\"S\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(MAX_PASSWORD_LENGTH), output); + BRIDGE::print(F("\",\"H\":\"Station Password\",\"M\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(MIN_PASSWORD_LENGTH), output); + BRIDGE::print(F("\"}"), output); + BRIDGE::println(F(","), output); + + //11-Station Network Mode + BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_STA_PHY_MODE), output); + BRIDGE::print(F("\",\"T\":\"B\",\"V\":\""), output); + if (!CONFIG::read_byte(EP_STA_PHY_MODE, &bbuf )) { + BRIDGE::print("???", output); + } else { + BRIDGE::print((const char *)CONFIG::intTostr(bbuf), output); + } + BRIDGE::print(F("\",\"H\":\"Station Network Mode\",\"O\":[{\"11b\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(WIFI_PHY_MODE_11B), output); + BRIDGE::print(F("\"},{\"11g\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(WIFI_PHY_MODE_11G), output); + BRIDGE::print(F("\"},{\"11n\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(WIFI_PHY_MODE_11N), output); + BRIDGE::print(F("\"}]}"), output); + BRIDGE::println(F(","), output); + + //12-STA IP mode + BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_STA_IP_MODE), output); + BRIDGE::print(F("\",\"T\":\"B\",\"V\":\""), output); + if (!CONFIG::read_byte(EP_STA_IP_MODE, &bbuf )) { + BRIDGE::print("???", output); + } else { + BRIDGE::print((const char *)CONFIG::intTostr(bbuf), output); + } + BRIDGE::print(F("\",\"H\":\"Station IP Mode\",\"O\":[{\"DHCP\":\"1\"},{\"Static\":\"2\"}]}"), output); + BRIDGE::println(F(","), output); + + //13-STA static IP + BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_STA_IP_VALUE), output); + BRIDGE::print(F("\",\"T\":\"A\",\"V\":\""), output); + if (!CONFIG::read_buffer(EP_STA_IP_VALUE,(byte *)ipbuf, IP_LENGTH)) { + BRIDGE::print("???", output); + } else { + BRIDGE::print(IPAddress(ipbuf).toString().c_str(), output); + } + BRIDGE::print(F("\",\"H\":\"Station Static IP\"}"), output); + BRIDGE::println(F(","), output); + + //14-STA static Mask + BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_STA_MASK_VALUE), output); + BRIDGE::print(F("\",\"T\":\"A\",\"V\":\""), output); + if (!CONFIG::read_buffer(EP_STA_MASK_VALUE,(byte *)ipbuf, IP_LENGTH)) { + BRIDGE::print("???", output); + } else { + BRIDGE::print(IPAddress(ipbuf).toString().c_str(), output); + } + BRIDGE::print(F("\",\"H\":\"Station Static Mask\"}"), output); + BRIDGE::println(F(","), output); + + //15-STA static Gateway + BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_STA_GATEWAY_VALUE), output); + BRIDGE::print(F("\",\"T\":\"A\",\"V\":\""), output); + if (!CONFIG::read_buffer(EP_STA_GATEWAY_VALUE,(byte *)ipbuf, IP_LENGTH)) { + BRIDGE::print("???", output); + } else { + BRIDGE::print(IPAddress(ipbuf).toString().c_str(), output); + } + BRIDGE::print(F("\",\"H\":\"Station Static Gateway\"}"), output); + BRIDGE::println(F(","), output); + + //16-AP SSID + BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_AP_SSID), output); + BRIDGE::print(F("\",\"T\":\"S\",\"V\":\""), output); + if (!CONFIG::read_string(EP_AP_SSID, sbuf, MAX_SSID_LENGTH)) { + BRIDGE::print("???", output); + } else { + BRIDGE::print(sbuf, output); + } + BRIDGE::print(F("\",\"S\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(MAX_SSID_LENGTH), output); + BRIDGE::print(F("\",\"H\":\"AP SSID\",\"M\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(MIN_SSID_LENGTH), output); + BRIDGE::print(F("\"}"), output); + BRIDGE::println(F(","), output); + + //17-AP password + BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_AP_PASSWORD), output); + BRIDGE::print(F("\",\"T\":\"S\",\"V\":\""), output); + if (!CONFIG::read_string(EP_AP_PASSWORD, sbuf, MAX_PASSWORD_LENGTH)) { + BRIDGE::print("???", output); + } else { + BRIDGE::print("********", output); + } + BRIDGE::print(F("\",\"S\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(MAX_PASSWORD_LENGTH), output); + BRIDGE::print(F("\",\"H\":\"AP Password\",\"M\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(MIN_PASSWORD_LENGTH), output); + BRIDGE::print(F("\"}"), output); + BRIDGE::println(F(","), output); + + //18 - AP Network Mode + BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_AP_PHY_MODE), output); + BRIDGE::print(F("\",\"T\":\"B\",\"V\":\""), output); + if (!CONFIG::read_byte(EP_AP_PHY_MODE, &bbuf )) { + BRIDGE::print("???", output); + } else { + BRIDGE::print((const char *)CONFIG::intTostr(bbuf), output); + } + BRIDGE::print(F("\",\"H\":\"AP Network Mode\",\"O\":[{\"11b\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(WIFI_PHY_MODE_11B), output); + BRIDGE::print(F("\"},{\"11g\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(WIFI_PHY_MODE_11G), output); + BRIDGE::print(F("\"}]}"), output); + BRIDGE::println(F(","), output); + + //19-AP SSID visibility + BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_SSID_VISIBLE), output); + BRIDGE::print(F("\",\"T\":\"B\",\"V\":\""), output); + if (!CONFIG::read_byte(EP_SSID_VISIBLE, &bbuf )) { + BRIDGE::print("???", output); + } else { + BRIDGE::print((const char *)CONFIG::intTostr(bbuf), output); + } + BRIDGE::print(F("\",\"H\":\"SSID Visible\",\"O\":[{\"No\":\"0\"},{\"Yes\":\"1\"}]}"), output); + BRIDGE::println(F(","), output); + + //20-AP Channel + BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_CHANNEL), output); + BRIDGE::print(F("\",\"T\":\"B\",\"V\":\""), output); + if (!CONFIG::read_byte(EP_CHANNEL, &bbuf )) { + BRIDGE::print("???", output); + } else { + BRIDGE::print((const char *)CONFIG::intTostr(bbuf), output); + } + BRIDGE::print(F("\",\"H\":\"AP Channel\",\"O\":["), output); + for (int i=1; i < 12 ; i++) { + BRIDGE::print(F("{\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(i), output); + BRIDGE::print(F("\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(i), output); + BRIDGE::print(F("\"}"), output); + if (i<11) { + BRIDGE::print(F(","), output); + } + } + BRIDGE::print(F("]}"), output); + BRIDGE::println(F(","), output); + + //21-AP Authentication + BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_AUTH_TYPE), output); + BRIDGE::print(F("\",\"T\":\"B\",\"V\":\""), output); + if (!CONFIG::read_byte(EP_AUTH_TYPE, &bbuf )) { + BRIDGE::print("???", output); + } else { + BRIDGE::print((const char *)CONFIG::intTostr(bbuf), output); + } + BRIDGE::print(F("\",\"H\":\"Authentication\",\"O\":[{\"Open\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(AUTH_OPEN), output); + BRIDGE::print(F("\"},{\"WPA\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(AUTH_WPA_PSK), output); + BRIDGE::print(F("\"},{\"WPA2\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(AUTH_WPA2_PSK), output); + BRIDGE::print(F("\"},{\"WPA/WPA2\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(AUTH_WPA_WPA2_PSK), output); + BRIDGE::print(F("\"}]}"), output); + BRIDGE::println(F(","), output); + + //22-AP IP mode + BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_AP_IP_MODE), output); + BRIDGE::print(F("\",\"T\":\"B\",\"V\":\""), output); + if (!CONFIG::read_byte(EP_AP_IP_MODE, &bbuf )) { + BRIDGE::print("???", output); + } else { + BRIDGE::print((const char *)CONFIG::intTostr(bbuf), output); + } + BRIDGE::print(F("\",\"H\":\"AP IP Mode\",\"O\":[{\"DHCP\":\"1\"},{\"Static\":\"2\"}]}"), output); + BRIDGE::println(F(","), output); + + //23-AP static IP + BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_AP_IP_VALUE), output); + BRIDGE::print(F("\",\"T\":\"A\",\"V\":\""), output); + if (!CONFIG::read_buffer(EP_AP_IP_VALUE,(byte *)ipbuf, IP_LENGTH)) { + BRIDGE::print("???", output); + } else { + BRIDGE::print(IPAddress(ipbuf).toString().c_str(), output); + } + BRIDGE::print(F("\",\"H\":\"AP Static IP\"}"), output); + BRIDGE::println(F(","), output); + + //24-AP static Mask + BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_AP_MASK_VALUE), output); + BRIDGE::print(F("\",\"T\":\"A\",\"V\":\""), output); + if (!CONFIG::read_buffer(EP_AP_MASK_VALUE,(byte *)ipbuf, IP_LENGTH)) { + BRIDGE::print("???", output); + } else { + BRIDGE::print(IPAddress(ipbuf).toString().c_str(), output); + } + BRIDGE::print(F("\",\"H\":\"AP Static Mask\"}"), output); + BRIDGE::println(F(","), output); + + //25-AP static Gateway + BRIDGE::print(F("{\"F\":\"network\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_AP_GATEWAY_VALUE), output); + BRIDGE::print(F("\",\"T\":\"A\",\"V\":\""), output); + if (!CONFIG::read_buffer(EP_AP_GATEWAY_VALUE,(byte *)ipbuf, IP_LENGTH)) { + BRIDGE::print("???", output); + } else { + BRIDGE::print(IPAddress(ipbuf).toString().c_str(), output); + } + BRIDGE::print(F("\",\"H\":\"AP Static Gateway\"}"), output); + delay(0); + } + + if (cmd_params == "printer" || cmd_params == "") { + if (cmd_params == "") { + BRIDGE::println(F(","), output); + } + //Target FW + BRIDGE::print(F("{\"F\":\"printer\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_TARGET_FW), output); + BRIDGE::print(F("\",\"T\":\"B\",\"V\":\""), output); + if (!CONFIG::read_byte(EP_TARGET_FW, &bbuf )) { + BRIDGE::print("Unknown", output); + } else { + BRIDGE::print((const char *)CONFIG::intTostr(bbuf), output); + } + BRIDGE::print(F("\",\"H\":\"Target FW\",\"O\":[{\"Repetier\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(REPETIER), output); + BRIDGE::print(F("\"},{\"Repetier for Davinci\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(REPETIER4DV), output); + BRIDGE::print(F("\"},{\"Marlin\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(MARLIN), output); + BRIDGE::print(F("\"},{\"Marlin Kimbra\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(MARLINKIMBRA), output); + BRIDGE::print(F("\"},{\"Smoothieware\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(SMOOTHIEWARE), output); + BRIDGE::print(F("\"},{\"Unknown\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(UNKNOWN_FW), output); + BRIDGE::print(F("\"}]}"), output); + BRIDGE::println(F(","), output); + + //Refresh time 1 + BRIDGE::print(F("{\"F\":\"printer\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_REFRESH_PAGE_TIME), output); + BRIDGE::print(F("\",\"T\":\"B\",\"V\":\""), output); + if (!CONFIG::read_byte(EP_REFRESH_PAGE_TIME, &bbuf )) { + BRIDGE::print("???", output); + } else { + BRIDGE::print((const char *)CONFIG::intTostr(bbuf), output); + } + BRIDGE::print(F("\",\"H\":\"Temperature Refresh Time\",\"S\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MAX_REFRESH), output); + BRIDGE::print(F("\",\"M\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MIN_REFRESH), output); + BRIDGE::print(F("\"}"), output); + BRIDGE::println(F(","), output); + + //Refresh time 2 + BRIDGE::print(F("{\"F\":\"printer\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_REFRESH_PAGE_TIME2), output); + BRIDGE::print(F("\",\"T\":\"B\",\"V\":\""), output); + if (!CONFIG::read_byte(EP_REFRESH_PAGE_TIME2, &bbuf )) { + BRIDGE::print("???", output); + } else { + BRIDGE::print((const char *)CONFIG::intTostr(bbuf), output); + } + BRIDGE::print(F("\",\"H\":\"Position Refresh Time\",\"S\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MAX_REFRESH), output); + BRIDGE::print(F("\",\"M\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MIN_REFRESH), output); + BRIDGE::print(F("\"}"), output); + BRIDGE::println(F(","), output); + + //XY feedrate + BRIDGE::print(F("{\"F\":\"printer\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_XY_FEEDRATE), output); + BRIDGE::print(F("\",\"T\":\"I\",\"V\":\""), output); + if (!CONFIG::read_buffer(EP_XY_FEEDRATE, (byte *)&ibuf, INTEGER_LENGTH)) { + BRIDGE::print("???", output); + } else { + BRIDGE::print((const char *)CONFIG::intTostr(ibuf), output); + } + BRIDGE::print(F("\",\"H\":\"XY feedrate\",\"S\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MAX_XY_FEEDRATE), output); + BRIDGE::print(F("\",\"M\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MIN_XY_FEEDRATE), output); + BRIDGE::print(F("\"}"), output); + BRIDGE::println(F(","), output); + + //Z feedrate + BRIDGE::print(F("{\"F\":\"printer\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_Z_FEEDRATE), output); + BRIDGE::print(F("\",\"T\":\"I\",\"V\":\""), output); + if (!CONFIG::read_buffer(EP_Z_FEEDRATE, (byte *)&ibuf, INTEGER_LENGTH)) { + BRIDGE::print("???", output); + } else { + BRIDGE::print((const char *)CONFIG::intTostr(ibuf), output); + } + BRIDGE::print(F("\",\"H\":\"Z feedrate\",\"S\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MAX_Z_FEEDRATE), output); + BRIDGE::print(F("\",\"M\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MIN_Z_FEEDRATE), output); + BRIDGE::print(F("\"}"), output); + BRIDGE::println(F(","), output); + + //E feedrate + BRIDGE::print(F("{\"F\":\"printer\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_E_FEEDRATE), output); + BRIDGE::print(F("\",\"T\":\"I\",\"V\":\""), output); + if (!CONFIG::read_buffer(EP_E_FEEDRATE, (byte *)&ibuf, INTEGER_LENGTH)) { + BRIDGE::print("???", output); + } else { + BRIDGE::print((const char *)CONFIG::intTostr(ibuf), output); + } + BRIDGE::print(F("\",\"H\":\"E feedrate\",\"S\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MAX_E_FEEDRATE), output); + BRIDGE::print(F("\",\"M\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(DEFAULT_MIN_E_FEEDRATE), output); + BRIDGE::print(F("\"}"), output); + BRIDGE::println(F(","), output); + + //Camera address, data string + BRIDGE::print(F("{\"F\":\"printer\",\"P\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(EP_DATA_STRING), output); + BRIDGE::print(F("\",\"T\":\"S\",\"V\":\""), output); + if (!CONFIG::read_string(EP_DATA_STRING, sbuf, MAX_DATA_LENGTH)) { + BRIDGE::print("???", output); + } else { + BRIDGE::print(sbuf, output); + } + BRIDGE::print(F("\",\"S\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(MAX_DATA_LENGTH), output); + BRIDGE::print(F("\",\"H\":\"Camera address\",\"M\":\""), output); + BRIDGE::print((const char *)CONFIG::intTostr(MIN_DATA_LENGTH), output); + BRIDGE::print(F("\"}"), output); + } + + //end JSON + BRIDGE::println(F("\n]}"), output); + delay(0); + } + break; + + //Set EEPROM setting + //[ESP401]P= T= V= pwd= + case 401: { + //check validity of parameters + String spos = get_param(cmd_params,"P=", false); + String styp = get_param(cmd_params,"T=", false); + String sval = get_param(cmd_params,"V=", true); + sval.trim(); + int pos = spos.toInt(); + if ((pos == 0 && spos != "0") || (pos > LAST_EEPROM_ADDRESS || pos < 0)) { + response = false; + } + if (!(styp == "B" || styp == "S" || styp == "A" || styp == "I")) { + response = false; + } + if (sval.length() == 0) { + response = false; + } + + +#ifdef AUTHENTICATION_FEATURE + if (response) { + //check authentication + level_authenticate_type auth_need = LEVEL_ADMIN; + for (int i = 0; i < AUTH_ENTRY_NB; i++) { + if (Setting[i][0] == pos ) { + auth_need = (level_authenticate_type)(Setting[i][1]); + i = AUTH_ENTRY_NB; + } + } + if ((auth_need == LEVEL_ADMIN && auth_type == LEVEL_USER) || (auth_type == LEVEL_GUEST)) { + response = false; + } + } +#endif + if (response) { + if (styp == "B") { + byte bbuf = sval.toInt(); + if(!CONFIG::write_byte(pos,bbuf)) { + response = false; + } else { + //dynamique refresh is better than restart the board + if (pos == EP_TARGET_FW)CONFIG::InitFirmwareTarget(); + if (pos == EP_IS_DIRECT_SD){ + CONFIG::InitDirectSD(); + if (CONFIG::is_direct_sd) CONFIG::InitPins(); + } + } + } + if (styp == "I") { + int ibuf = sval.toInt(); + if(!CONFIG::write_buffer(pos,(const byte *)&ibuf,INTEGER_LENGTH)) { + response = false; + } + } + if (styp == "S") { + if(!CONFIG::write_string(pos,sval.c_str())) { + response = false; + } + } + if (styp == "A") { + byte ipbuf[4]; + if (CONFIG::split_ip(sval.c_str(),ipbuf) < 4) { + response = false; + } else if(!CONFIG::write_buffer(pos,ipbuf,IP_LENGTH)) { + response = false; + } + } + } + if(!response) { + BRIDGE::println(INCORRECT_CMD_MSG, output); + } else { + BRIDGE::println(OK_CMD_MSG, output); + } + + } + break; + + //Get available AP list (limited to 30) + //output is JSON or plain text according parameter + //[ESP410] + case 410: { + parameter = get_param(cmd_params,"", true); + int n = WiFi.scanNetworks(); + bool plain = parameter == "plain"; + if (!plain)BRIDGE::print(F("{\"AP_LIST\":["), output); + for (int i = 0; i < n; ++i) { + if (i>0) { + if (!plain) BRIDGE::print(F(","), output); + else BRIDGE::print(F("\n"), output); + } + if (!plain)BRIDGE::print(F("{\"SSID\":\""), output); + BRIDGE::print(WiFi.SSID(i).c_str(), output); + if (!plain)BRIDGE::print(F("\",\"SIGNAL\":\""), output); + else BRIDGE::print(F("\t"), output); + BRIDGE::print(CONFIG::intTostr(wifi_config.getSignal(WiFi.RSSI(i))), output);; + //BRIDGE::print(F("%"), output); + if (!plain)BRIDGE::print(F("\",\"IS_PROTECTED\":\""), output); + if (WiFi.encryptionType(i) == ENC_TYPE_NONE) { + if (!plain)BRIDGE::print(F("0"), output); + else BRIDGE::print(F("\tOpen"), output); + } else { + if (!plain)BRIDGE::print(F("1"), output); + else BRIDGE::print(F("\tSecure"), output); + } + if (!plain)BRIDGE::print(F("\"}"), output); + } + if (!plain)BRIDGE::print(F("]}"), output); + WiFi.scanDelete(); + } + break; + //Get ESP current status in plain or JSON + //[ESP420] + case 420: { + parameter = get_param(cmd_params,"", true); + CONFIG::print_config(output, (parameter == "plain")); + } + break; + //Set ESP mode + //cmd is RESET, SAFEMODE, RESTART //[ESP444]pwd= case 444: parameter = get_param(cmd_params,"", true); #ifdef AUTHENTICATION_FEATURE - if (!isadmin(cmd_params)) { + if (auth_type != LEVEL_ADMIN) { BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; } else #endif { if (parameter=="RESET") { CONFIG::reset_config(); - } - if (parameter=="SAFEMODE") { + BRIDGE::println(F("Reset done - restart needed"), output); + } else if (parameter=="SAFEMODE") { wifi_config.Safe_Setup(); - } - if (parameter=="RESTART") { + BRIDGE::println(F("Set Safe Mode - restart needed"), output); + } else if (parameter=="RESTART") { + BRIDGE::println(F("Restart started"), output); + BRIDGE::flush( output); CONFIG::esp_restart(); + } else { + BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; } } - if (parameter=="CONFIG") { - CONFIG::print_config(output); - } break; #ifdef AUTHENTICATION_FEATURE //Change / Reset user password //[ESP555]pwd= case 555: { - if (isadmin(cmd_params)) { + if (auth_type == LEVEL_ADMIN) { parameter = get_param(cmd_params,"", true); if (parameter.length() == 0) { if(CONFIG::write_string(EP_USER_PWD,FPSTR(DEFAULT_USER_PWD))) { BRIDGE::println(OK_CMD_MSG, output); } else { BRIDGE::println(ERROR_CMD_MSG, output); + response = false; } } else { if (CONFIG::isLocalPasswordValid(parameter.c_str())) { @@ -400,13 +1189,16 @@ void COMMAND::execute_command(int cmd,String cmd_params, tpipe output) BRIDGE::println(OK_CMD_MSG, output); } else { BRIDGE::println(ERROR_CMD_MSG, output); + response = false; } } else { BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; } } } else { BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; } break; } @@ -421,71 +1213,159 @@ void COMMAND::execute_command(int cmd,String cmd_params, tpipe output) if ((cmd_params.length() > 0) && (cmd_params[0] != '/')) { cmd_params = "/" + cmd_params; } - FSFILE currentfile = SPIFFS.open(cmd_params, "r"); + FS_FILE currentfile = SPIFFS.open(cmd_params, SPIFFS_FILE_READ); if (currentfile) {//if file open success //flush to be sure send buffer is empty - Serial.flush(); + ESP_SERIAL_OUT.flush(); //read content String currentline = currentfile.readString(); //until no line in file while (currentline.length() >0) { - //send line to serial - Serial.println(currentline); - //flush to be sure send buffer is empty - delay(0); - Serial.flush(); + int ESPpos = currentline.indexOf("[ESP"); + if (ESPpos>-1) { + //is there the second part? + int ESPpos2 = currentline.indexOf("]",ESPpos); + if (ESPpos2>-1) { + //Split in command and parameters + String cmd_part1=currentline.substring(ESPpos+4,ESPpos2); + String cmd_part2=""; + //is there space for parameters? + if (ESPpos2 + case 710: + parameter = get_param(cmd_params,"", true); +#ifdef AUTHENTICATION_FEATURE + if (auth_type != LEVEL_ADMIN) { + BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; + } else +#endif + { + if (parameter=="FORMAT") { + BRIDGE::print(F("Formating"), output); + //SPIFFS.end(); + delay(0); + SPIFFS.format(); + //SPIFFS.begin(); + BRIDGE::println(F("...Done"), output); + } else { + BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; + } + } + break; + //SPIFFS total size and used size + //[ESP720]
+ case 720: + BRIDGE::print(cmd_params, output); +#ifdef ARDUINO_ARCH_ESP8266 + fs::FSInfo info; + SPIFFS.info(info); + BRIDGE::print("SPIFFS Total:", output); + BRIDGE::print(CONFIG::formatBytes(info.totalBytes).c_str(), output); + BRIDGE::print(" Used:", output); + BRIDGE::println(CONFIG::formatBytes(info.usedBytes).c_str(), output); +#else + BRIDGE::print("SPIFFS Total:", output); + BRIDGE::print(CONFIG::formatBytes(SPIFFS.totalBytes()).c_str(), output); + BRIDGE::print(" Used:", output); + BRIDGE::println(CONFIG::formatBytes(SPIFFS.usedBytes()).c_str(), output); +#endif + break; + //get fw version firmare target and fw version //[ESP800]
case 800: + { + byte sd_dir = 0; BRIDGE::print(cmd_params, output); - BRIDGE::print("FW version:", output); - BRIDGE::println(FW_VERSION, output); + BRIDGE::print(F("FW version:"), output); + BRIDGE::print(FW_VERSION, output); + BRIDGE::print(F(" # FW target:"), output); + BRIDGE::print(CONFIG::GetFirmwareTargetShortName(), output); + BRIDGE::print(F(" # FW HW:"), output); + if (CONFIG::is_direct_sd) BRIDGE::print(F("Direct SD"), output); + else BRIDGE::print(F("Serial SD"), output); + BRIDGE::print(F(" # primary sd:"), output); + if (!CONFIG::read_byte(EP_PRIMARY_SD, &sd_dir )) sd_dir = DEFAULT_PRIMARY_SD; + if (sd_dir == SD_DIRECTORY) BRIDGE::print(F("/sd/"), output); + else if (sd_dir == EXT_DIRECTORY) BRIDGE::print(F("/ext/"), output); + else BRIDGE::print(F("none"), output); + BRIDGE::print(F(" # secondary sd:"), output); + if (!CONFIG::read_byte(EP_SECONDARY_SD, &sd_dir )) sd_dir = DEFAULT_SECONDARY_SD; + if (sd_dir == SD_DIRECTORY) BRIDGE::print(F("/sd/"), output); + else if (sd_dir == EXT_DIRECTORY) BRIDGE::print(F("/ext/"), output); + else BRIDGE::print(F("none"), output); + BRIDGE::print(F(" # authentication:"), output); +#ifdef AUTHENTICATION_FEATURE + BRIDGE::print(F("yes"), output); +#else + BRIDGE::print(F("no"), output); +#endif + BRIDGE::println("", output); + } break; //get fw target //[ESP801]
case 801: BRIDGE::print(cmd_params, output); -#if FIRMWARE_TARGET == REPETIER - BRIDGE::println("Repetier", output); -#endif -#if FIRMWARE_TARGET == REPETIER4DV - BRIDGE::println("Repetier_Davinci", output); -#endif -#if FIRMWARE_TARGET == MARLIN - BRIDGE::println("Marlin", output); -#endif -#if FIRMWARE_TARGET == MARLINKIMBRA - BRIDGE::println("Marlin_Kimbra", output); -#endif -#if FIRMWARE_TARGET == SMOOTHIEWARE - BRIDGE::println("Smoothieware", output); -#endif + BRIDGE::println(CONFIG::GetFirmwareTargetShortName(), output); break; //clear status/error/info list + case 802: + if (CONFIG::check_update_presence( )) BRIDGE::println("yes", output); + else BRIDGE::println("no", output); + break; //[ESP999] case 999: cmd_params.trim(); #ifdef ERROR_MSG_FEATURE if (cmd_params=="ERROR") { web_interface->error_msg.clear(); + BRIDGE::println(OK_CMD_MSG, output); + break; } #endif #ifdef INFO_MSG_FEATURE if (cmd_params=="INFO") { web_interface->info_msg.clear(); + BRIDGE::println(OK_CMD_MSG, output); + break; } #endif #ifdef STATUS_MSG_FEATURE if (cmd_params=="STATUS") { web_interface->status_msg.clear(); + BRIDGE::println(OK_CMD_MSG, output); + break; } #endif if (cmd_params=="ALL") { @@ -498,10 +1378,14 @@ void COMMAND::execute_command(int cmd,String cmd_params, tpipe output) #ifdef INFO_MSG_FEATURE web_interface->info_msg.clear(); #endif + BRIDGE::println(OK_CMD_MSG, output); + break; } - break; - //default: + default: + BRIDGE::println(INCORRECT_CMD_MSG, output); + response = false; } + return response; } bool COMMAND::check_command(String buffer, tpipe output, bool handlelockserial) @@ -511,82 +1395,55 @@ bool COMMAND::check_command(String buffer, tpipe output, bool handlelockserial) LOG(buffer) LOG("\r\n") bool is_temp = false; + if ((buffer.indexOf("T:") > -1 ) || (buffer.indexOf("B:") > -1 )) is_temp = true; //feed the WD for safety delay(0); -#if ((FIRMWARE_TARGET == REPETIER) || (FIRMWARE_TARGET == REPETIER4DV)) - //save time no need to continue - if ((buffer.indexOf("busy:") > -1) || (buffer.startsWith("wait")))return false; - if (buffer.startsWith("ok"))return false; -#endif -//if direct access to SDCard no need to handle the M20 command answer -#ifndef DIRECT_SDCARD_FEATURE - static bool bfileslist=false; - static uint32_t start_list=0; - //if SD list is not on going - if (!bfileslist) { - //check if command is a start of SD File list - LOG("No File list ongoing\r\n") - int filesstart = buffer.indexOf("egin file list"); - //yes it is file list starting to be displayed - if (filesstart>-1) { - LOG("Found start File list\r\n") - //init time out - start_list = millis(); - //set file list started - bfileslist=true; - //clear current list - web_interface->fileslist.clear(); - //block any new output to serial from ESP to avoid pollution - if (handlelockserial)(web_interface->blockserial) = true; - return is_temp; + if (( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER)) { + //save time no need to continue + if ((buffer.indexOf("busy:") > -1) || (buffer.startsWith("wait"))) { + return false; } -#endif - int Tpos = buffer.indexOf("T:"); - if (Tpos > -1 ) is_temp = true; -#ifdef POS_MONITORING_FEATURE - int Xpos = buffer.indexOf("X:"); - int Ypos = buffer.indexOf("Y:"); - int Zpos = buffer.indexOf("Z:"); -#endif -#if FIRMWARE_TARGET == SMOOTHIEWARE - int Bpos = buffer.indexOf("B:"); - if (Bpos > -1 ) is_temp = true; -#ifdef SPEED_MONITORING_FEATURE - int Speedpos = buffer.indexOf("Speed factor at "); -#endif -#ifdef FLOW_MONITORING_FEATURE - int Flowpos = buffer.indexOf("Flow rate at "); -#endif + if (buffer.startsWith("ok")) { + return false; + } + } #ifdef ERROR_MSG_FEATURE - int Errorpos= buffer.indexOf("error:"); + int Errorpos = -1; #endif #ifdef INFO_MSG_FEATURE - int Infopos= buffer.indexOf("info:"); + int Infopos = -1; #endif #ifdef STATUS_MSG_FEATURE - int Statuspos= buffer.indexOf("warning:"); -#endif -#else -#ifdef SPEED_MONITORING_FEATURE - int Speedpos = buffer.indexOf("SpeedMultiply:"); -#endif -#ifdef FLOW_MONITORING_FEATURE - int Flowpos = buffer.indexOf("FlowMultiply:"); + int Statuspos = -1; #endif +if (CONFIG::GetFirmwareTarget() == SMOOTHIEWARE) { #ifdef ERROR_MSG_FEATURE - int Errorpos= buffer.indexOf("Error:"); + Errorpos= buffer.indexOf("error:"); #endif #ifdef INFO_MSG_FEATURE - int Infopos= buffer.indexOf("Info:"); + Infopos= buffer.indexOf("info:"); #endif #ifdef STATUS_MSG_FEATURE -#if FIRMWARE_TARGET == MARLIN - int Statuspos= buffer.indexOf("echo:"); -#else - int Statuspos= buffer.indexOf("Status:"); + Statuspos= buffer.indexOf("warning:"); #endif +} else { +#ifdef ERROR_MSG_FEATURE + Errorpos= buffer.indexOf("Error:"); #endif +#ifdef INFO_MSG_FEATURE + Infopos= buffer.indexOf("Info:"); #endif +#ifdef STATUS_MSG_FEATURE + Statuspos= -1; + if (CONFIG::GetFirmwareTarget() == MARLIN){ + Statuspos= buffer.indexOf("echo:"); + } + else { + Statuspos= buffer.indexOf("Status:"); + } + +#endif +} #ifdef SERIAL_COMMAND_FEATURE String ESP_Command; @@ -610,67 +1467,6 @@ bool COMMAND::check_command(String buffer, tpipe output, bool handlelockserial) } } #endif -#ifdef TEMP_MONITORING_FEATURE - //check for temperature - if (Tpos>-1) { - //look for valid temperature answer - int slashpos = buffer.indexOf(" /",Tpos); - int spacepos = buffer.indexOf(" ",slashpos+1); - //if match mask T:xxx.xx /xxx.xx - if(spacepos-Tpos < 17) { - web_interface->answer4M105=buffer; //do not interprete just need when requested so store it - web_interface->last_temp=millis(); - } else { - LOG("Not a T temp") - } - } -#if FIRMWARE_TARGET == SMOOTHIEWARE - else if (Bpos > -1 ){ - //look for valid temperature answer - int slashpos = buffer.indexOf(" /",Bpos); - int spacepos = buffer.indexOf(" ",slashpos+1); - //if match mask B:xxx.xx /xxx.xx - if(spacepos-Bpos < 17) { - web_interface->answer4M105=buffer; //do not interprete just need when requested so store it - web_interface->last_temp=millis(); - } else { - LOG("Not a B temp") - } - } -#endif -#endif -#ifdef POS_MONITORING_FEATURE - //Position of axis - if (Xpos>-1 && Ypos>-1 && Zpos>-1) { - web_interface->answer4M114=buffer; - } -#endif -#ifdef SPEED_MONITORING_FEATURE - //Speed - if (Speedpos>-1) { - //get just the value -#if FIRMWARE_TARGET == SMOOTHIEWARE - buffer2 =buffer.substring(Speedpos+16); - int p2 = buffer2.indexOf("."); - web_interface->answer4M220=buffer2.substring(0,p2); -#else - web_interface->answer4M220=buffer.substring(Speedpos+14); -#endif - } -#endif -#ifdef FLOW_MONITORING_FEATURE - //Flow - if (Flowpos>-1) { - //get just the value -#if FIRMWARE_TARGET == SMOOTHIEWARE - buffer2 =buffer.substring(Flowpos+13); - int p2 = buffer2.indexOf("."); - web_interface->answer4M221=buffer2.substring(0,p2); -#else - web_interface->answer4M221=buffer.substring(Flowpos+13); -#endif - } -#endif #ifdef ERROR_MSG_FEATURE //Error if (Errorpos>-1 && !(buffer.indexOf("Format error")!=-1 || buffer.indexOf("wait")==Errorpos+6) ) { @@ -692,47 +1488,16 @@ bool COMMAND::check_command(String buffer, tpipe output, bool handlelockserial) #ifdef STATUS_MSG_FEATURE //Status if (Statuspos>-1) { -#if FIRMWARE_TARGET == SMOOTHIEWARE - String ss = buffer.substring(Errorpos+8); -#else -#if FIRMWARE_TARGET == MARLIN - String ss = buffer.substring(Errorpos+5); -#else - String ss = buffer.substring(Errorpos+7); -#endif -#endif + String ss ; + if (CONFIG::GetFirmwareTarget() == SMOOTHIEWARE)ss = buffer.substring(Errorpos+8); + else if (CONFIG::GetFirmwareTarget() == MARLIN) ss = buffer.substring(Errorpos+5); + else ss = buffer.substring(Errorpos+7); ss.replace("\"",""); ss.replace("'",""); (web_interface->info_msg).add(ss.c_str()); } #endif -#ifndef DIRECT_SDCARD_FEATURE - } else { //listing file is on going - LOG("File list is ongoing\r\n") - //check if we are too long - if ((millis()-start_list)>30000) { //timeout in case of problem - bfileslist=false; - if(handlelockserial)(web_interface->blockserial) = false; //release serial - LOG("Time out\r\n"); - } else { - //check if this is the end - if (buffer.indexOf("nd file list")>-1) { - LOG("End File list detected\r\n") - bfileslist=false; - if(handlelockserial)(web_interface->blockserial) = false; - LOG("End list\r\n"); - } else { - //Serial.print(buffer); - //add list to buffer - web_interface->fileslist.add(buffer); - LOG(String(web_interface->fileslist.size())); - LOG(":"); - LOG(buffer); - LOG("\r\n"); - } - } - } -#endif + return is_temp; } @@ -781,7 +1546,6 @@ void COMMAND::read_buffer_tcp(uint8_t b) } } #endif - //read buffer as char void COMMAND::read_buffer_serial(uint8_t b) { diff --git a/esp3d/command.h b/esp3d/command.h index f6793548..2c055648 100644 --- a/esp3d/command.h +++ b/esp3d/command.h @@ -34,10 +34,10 @@ public: static void read_buffer_tcp(uint8_t b); #endif static bool check_command(String buffer, tpipe output, bool handlelockserial = true); - static void execute_command(int cmd,String cmd_params, tpipe output); + static bool execute_command(int cmd,String cmd_params, tpipe output, level_authenticate_type auth_level = LEVEL_GUEST); static String get_param(String & cmd_params, const char * id, bool withspace = false); static bool isadmin(String & cmd_params); - + static bool isuser(String & cmd_params); }; #endif diff --git a/esp3d/config.cpp b/esp3d/config.cpp index 2a58fd5b..a7733620 100644 --- a/esp3d/config.cpp +++ b/esp3d/config.cpp @@ -19,18 +19,697 @@ */ #include "config.h" #include -#include "wifi.h" +#ifndef FS_NO_GLOBALS +#define FS_NO_GLOBALS +#endif +#include +#include +#include "wificonf.h" +#ifdef ARDUINO_ARCH_ESP8266 extern "C" { #include "user_interface.h" } +#else +#include "Update.h" +#include "esp_wifi.h" +#endif #include "bridge.h" +#ifdef ARDUINO_ARCH_ESP32 +//This is output for ESP32 to avoid garbage +HardwareSerial Serial2(2); +#endif + +uint8_t CONFIG::FirmwareTarget = UNKNOWN_FW; + +bool CONFIG::SetFirmwareTarget(uint8_t fw){ + if ( fw >= 0 && fw <= MAX_FW_ID) { + FirmwareTarget = fw; + return true; + } else return false; +} +uint8_t CONFIG::GetFirmwareTarget() { + return FirmwareTarget; +} +const char* CONFIG::GetFirmwareTargetName() { + static String response; + if ( CONFIG::FirmwareTarget == REPETIER4DV)response = F("Repetier for Davinci"); + else if ( CONFIG::FirmwareTarget == REPETIER)response = F("Repetier"); + else if ( CONFIG::FirmwareTarget == MARLIN) response = F("Marlin"); + else if ( CONFIG::FirmwareTarget == MARLINKIMBRA) response = F("MarlinKimbra"); + else if ( CONFIG::FirmwareTarget == SMOOTHIEWARE) response = F("Smoothieware"); + else response = F("???"); + return response.c_str(); +} + +const char* CONFIG::GetFirmwareTargetShortName() { + static String response; + if ( CONFIG::FirmwareTarget == REPETIER4DV)response = F("repetier4davinci"); + else if ( CONFIG::FirmwareTarget == REPETIER)response = F("repetier"); + else if ( CONFIG::FirmwareTarget == MARLIN) response = F("marlin"); + else if ( CONFIG::FirmwareTarget == MARLINKIMBRA) response = F("marlinkimbra"); + else if ( CONFIG::FirmwareTarget == SMOOTHIEWARE) response = F("smoothieware"); + else response = F("???"); + return response.c_str(); +} + +void CONFIG::InitFirmwareTarget(){ + uint8_t b = UNKNOWN_FW; + if (!CONFIG::read_byte(EP_TARGET_FW, &b )) { + b = UNKNOWN_FW; + } + if (!SetFirmwareTarget(b))SetFirmwareTarget(UNKNOWN_FW) ; +} + +void CONFIG::InitDirectSD(){ + CONFIG::is_direct_sd = false; + +} + +bool CONFIG::InitBaudrate(){ + long baud_rate=0; + if ( !CONFIG::read_buffer(EP_BAUD_RATE, (byte *)&baud_rate, INTEGER_LENGTH)) return false; + if ( ! (baud_rate==9600 || baud_rate==19200 ||baud_rate==38400 ||baud_rate==57600 ||baud_rate==115200 ||baud_rate==230400 ||baud_rate==250000) ) return false; + //setup serial + if (ESP_SERIAL_OUT.baudRate() != baud_rate)ESP_SERIAL_OUT.begin(baud_rate); +#ifdef ARDUINO_ARCH_ESP8266 + ESP_SERIAL_OUT.setRxBufferSize(SERIAL_RX_BUFFER_SIZE); +#endif + wifi_config.baud_rate=baud_rate; + delay(1000); + return true; +} + +bool CONFIG::InitExternalPorts(){ + if (!CONFIG::read_buffer(EP_WEB_PORT, (byte *)&(wifi_config.iweb_port), INTEGER_LENGTH) || !CONFIG::read_buffer(EP_DATA_PORT, (byte *)&(wifi_config.idata_port), INTEGER_LENGTH)) return false; + if (wifi_config.iweb_port < DEFAULT_MIN_WEB_PORT ||wifi_config.iweb_port > DEFAULT_MAX_WEB_PORT || wifi_config.idata_port < DEFAULT_MIN_DATA_PORT || wifi_config.idata_port > DEFAULT_MAX_DATA_PORT) return false; + return true; +} + +#ifdef SDCARD_CONFIG_FEATURE +bool CONFIG::update_settings(){ + String filename = SDCARD_CONFIG_FILENAME; + filename.toLowerCase(); + //there is a config file + LOG("Check ") + LOG(filename) + LOG("\r\n") + bool answer = true; + if(SD.exists((const char *)filename.c_str())) { + bool success = true; + bool localerror = false; + const size_t bufferLen = 250; + char buffer[bufferLen]; + byte ip_sav[4]; + String stmp; + int itmp; + long baud_rate=0; + byte bflag; + LOG("Found config file\r\n") + String newfilename = filename; + IniFile espconfig((char *)filename.c_str()); + //validate file is correct + if (espconfig.open()) { + if (!espconfig.validate(buffer, bufferLen)) { + success = false; + LOG("Invalid config file\r\n") + } else { //file format is correct - let parse the settings + //Section [wifi] + //Hostname + //hostname = myesp + if (espconfig.getValue("network", "hostname", buffer, bufferLen)) { + if (!CONFIG::isHostnameValid(buffer)) { + success = false; + } else if(!CONFIG::write_string(EP_HOSTNAME,buffer)) { + success = false; + } + } + //baudrate = 115200 + if (espconfig.getValue("network", "baudrate", buffer, bufferLen, baud_rate)) { + if(!CONFIG::write_buffer(EP_BAUD_RATE,(const byte *)&baud_rate,INTEGER_LENGTH)) { + success = false; + } + } + //webport = 80 + if (espconfig.getValue("network", "webport", buffer, bufferLen, itmp)) { + if(!CONFIG::write_buffer(EP_WEB_PORT,(const byte *)&itmp,INTEGER_LENGTH)) { + success = false; + } + } + //dataport = 8888 + if (espconfig.getValue("network", "dataport", buffer, bufferLen, itmp)) { + if(!CONFIG::write_buffer(EP_DATA_PORT,(const byte *)&itmp,INTEGER_LENGTH)) { + success = false; + } + } + //adminpwd = admin + if (espconfig.getValue("network", "adminpwd", buffer, bufferLen)) { + if (!CONFIG::isLocalPasswordValid(buffer)) { + success = false; + } else if(!CONFIG::write_string(EP_ADMIN_PWD,buffer)) { + success = false; + } + } + //userpwd = user + if (espconfig.getValue("network", "userpwd", buffer, bufferLen)) { + if (!CONFIG::isLocalPasswordValid(buffer)) { + success = false; + } else if(!CONFIG::write_string(EP_USER_PWD,buffer)) { + success = false; + } + } + //sleep = none + if (espconfig.getValue("network", "sleep", buffer, bufferLen)) { + stmp = buffer; + localerror = false; + stmp.toLowerCase(); + bflag = 0; + if (stmp =="none") { + bflag = WIFI_NONE_SLEEP; +#ifdef ARDUINO_ARCH_ESP8266 + } else if (stmp =="light") { + bflag = WIFI_LIGHT_SLEEP; +#endif + } else if (stmp =="modem") { + bflag = WIFI_MODEM_SLEEP; + } else { + localerror = true; + success = false; + } + if (!localerror) { + if(!CONFIG::write_byte(EP_SLEEP_MODE,bflag)) { + success = false; + } + } + } + //wifimode = STA + if (espconfig.getValue("network", "wifimode", buffer, bufferLen)) { + stmp = buffer; + localerror = false; + stmp.toLowerCase(); + bflag = 0; + if (stmp =="sta") { + bflag = CLIENT_MODE; + } else if (stmp =="ap") { + bflag = AP_MODE; + } else { + localerror = true; + success = false; + } + if (!localerror) { + if(!CONFIG::write_byte(EP_WIFI_MODE,bflag)) { + success = false; + } + } + } + //STAssid = NETGEAR_2GEXT_OFFICE2 + if (espconfig.getValue("network", "STAssid", buffer, bufferLen)) { + if (!CONFIG::isSSIDValid(buffer)) { + success = false; + } else if(!CONFIG::write_string(EP_STA_SSID,buffer)) { + success = false; + } + } + //STApassword = mypassword + if (espconfig.getValue("network", "STApassword", buffer, bufferLen)) { + if (!CONFIG::isPasswordValid(buffer)) { + success = false; + } else if(!CONFIG::write_string(EP_STA_PASSWORD,buffer)) { + success = false; + } + } + //STAipmode = DHCP + if (espconfig.getValue("network", "STAipmode", buffer, bufferLen)) { + stmp = buffer; + localerror = false; + stmp.toLowerCase(); + bflag = 0; + if (stmp =="dhcp") { + bflag = DHCP_MODE; + } else if (stmp =="static") { + bflag = STATIC_IP_MODE; + } else { + localerror = true; + success = false; + } + if (!localerror) { + if(!CONFIG::write_byte(EP_STA_IP_MODE,bflag)) { + success = false; + } + } + } + //STAstatic_ip = 192.168.0.1 + if (espconfig.getValue("network", "STAstatic_ip", buffer, bufferLen)) { + if (!CONFIG::isIPValid(buffer)) { + success = false; + } else { + CONFIG::split_ip(buffer,ip_sav); + if(!CONFIG::write_buffer(EP_STA_IP_VALUE,ip_sav,IP_LENGTH)) { + success = false; + } + } + } + //STAstatic_mask = 255.255.255.0 + if (espconfig.getValue("network", "STAstatic_mask", buffer, bufferLen)) { + if (!CONFIG::isIPValid(buffer)) { + success = false; + } else { + CONFIG::split_ip(buffer,ip_sav); + if(!CONFIG::write_buffer(EP_STA_MASK_VALUE,ip_sav,IP_LENGTH)) { + success = false; + } + } + } + //STAstatic_gateway = 192.168.0.1 + if (espconfig.getValue("network", "STAstatic_gateway", buffer, bufferLen)) { + if (!CONFIG::isIPValid(buffer)) { + success = false; + } else { + CONFIG::split_ip(buffer,ip_sav); + if(!CONFIG::write_buffer(EP_STA_GATEWAY_VALUE,ip_sav,IP_LENGTH)) { + success = false; + } + } + } + //STANetwork_mode = 11g + if (espconfig.getValue("network", "STANetwork_mode", buffer, bufferLen)) { + stmp = buffer; + localerror = false; + stmp.toLowerCase(); + bflag = 0; + if (stmp =="11b") { + bflag = WIFI_PHY_MODE_11B; + } else if (stmp =="11g") { + bflag = WIFI_PHY_MODE_11G; + } else if (stmp =="11n") { + bflag = WIFI_PHY_MODE_11N; + } else { + localerror = true; + success = false; + } + if (!localerror) { + if(!CONFIG::write_byte(EP_STA_PHY_MODE,bflag)) { + success = false; + } + } + } + //APssid = NETGEAR_2GEXT_OFFICE2 + if (espconfig.getValue("network", "APssid", buffer, bufferLen)) { + if (!CONFIG::isSSIDValid(buffer)) { + success = false; + } else if(!CONFIG::write_string(EP_AP_SSID,buffer)) { + success = false; + } + } + //APpassword = 12345678 + if (espconfig.getValue("network", "APpassword", buffer, bufferLen)) { + if (!CONFIG::isPasswordValid(buffer)) { + success = false; + } else if(!CONFIG::write_string(EP_AP_PASSWORD,buffer)) { + success = false; + } + } + //APipmode = STATIC + if (espconfig.getValue("network", "APipmode", buffer, bufferLen)) { + stmp = buffer; + localerror = false; + stmp.toLowerCase(); + bflag = 0; + if (stmp =="dhcp") { + bflag = DHCP_MODE; + } else if (stmp =="static") { + bflag = STATIC_IP_MODE; + } else { + localerror = true; + success = false; + } + if (!localerror) { + if(!CONFIG::write_byte(EP_AP_IP_MODE,bflag)) { + success = false; + } + } + } + //APstatic_ip = 192.168.0.1 + if (espconfig.getValue("network", "APstatic_ip", buffer, bufferLen)) { + if (!CONFIG::isIPValid(buffer)) { + success = false; + } else { + CONFIG::split_ip(buffer,ip_sav); + if(!CONFIG::write_buffer(EP_AP_IP_VALUE,ip_sav,IP_LENGTH)) { + success = false; + } + } + } + //APstatic_mask = 255.255.255.0 + if (espconfig.getValue("network", "APstatic_mask", buffer, bufferLen)) { + if (!CONFIG::isIPValid(buffer)) { + success = false; + } else { + CONFIG::split_ip(buffer,ip_sav); + if(!CONFIG::write_buffer(EP_AP_MASK_VALUE,ip_sav,IP_LENGTH)) { + success = false; + } + } + } + //APstatic_gateway = 192.168.0.1 + if (espconfig.getValue("network", "APstatic_gateway", buffer, bufferLen)) { + if (!CONFIG::isIPValid(buffer)) { + success = false; + } else { + CONFIG::split_ip(buffer,ip_sav); + if(!CONFIG::write_buffer(EP_AP_GATEWAY_VALUE,ip_sav,IP_LENGTH)) { + success = false; + } + } + } + //AP_channel = 1 + if (espconfig.getValue("network", "AP_channel", buffer, bufferLen, itmp)) { + bflag = itmp; + if(!CONFIG::write_byte(EP_CHANNEL,bflag)) { + success = false; + } + } + //AP_visible = yes + if (espconfig.getValue("network", "AP_visible", buffer, bufferLen)) { + stmp = buffer; + localerror = false; + stmp.toLowerCase(); + bflag = 0; + if (stmp =="yes") { + bflag = 1; + } else if (stmp =="no") { + bflag = 0; + } else { + localerror = true; + success = false; + } + if (!localerror) { + if(!CONFIG::write_byte(EP_SSID_VISIBLE,bflag)) { + success = false; + } + } + } + //AP_auth = WPA + if (espconfig.getValue("network", "AP_auth", buffer, bufferLen)) { + stmp = buffer; + localerror = false; + stmp.toLowerCase(); + bflag = 0; + if (stmp =="open") { + bflag = AUTH_OPEN; + } else if (stmp =="wpa") { + bflag = AUTH_WPA_PSK; + } else if (stmp =="wpa2") { + bflag = AUTH_WPA2_PSK; + } else if (stmp =="wpa_wpa2") { + bflag = AUTH_WPA_WPA2_PSK; + } else { + localerror = true; + success = false; + } + if (!localerror) { + if(!CONFIG::write_byte(EP_AUTH_TYPE,bflag)) { + success = false; + } + } + } + //APNetwork_mode = 11g + if (espconfig.getValue("network", "APNetwork_mode", buffer, bufferLen)) { + stmp = buffer; + localerror = false; + stmp.toLowerCase(); + bflag = 0; + if (stmp =="11b") { + bflag = WIFI_PHY_MODE_11B; + } else if (stmp =="11g") { + bflag = WIFI_PHY_MODE_11G; + } else { + localerror = true; + success = false; + } + if (!localerror) { + if(!CONFIG::write_byte(EP_AP_PHY_MODE,bflag)) { + success = false; + } + } + } + + //Timezone + if (espconfig.getValue("network", "time_zone", buffer, bufferLen, itmp)) { + bflag = itmp; + if(!CONFIG::write_byte(EP_TIMEZONE,bflag)) { + success = false; + } + } + + //day saving time + if (espconfig.getValue("network", "day_st", buffer, bufferLen)) { + stmp = buffer; + localerror = false; + stmp.toLowerCase(); + bflag = 0; + if (stmp =="yes") { + bflag = 1; + } else if (stmp =="no") { + bflag = 0; + } else { + localerror = true; + success = false; + } + if (!localerror) { + if(!CONFIG::write_byte(EP_TIME_ISDST,bflag)) { + success = false; + } + } + } + //time server 1 + if (espconfig.getValue("network", "time_server_1", buffer, bufferLen)) { + if (strlen(buffer) > 128) { + success = false; + } else if(!CONFIG::write_string(EP_TIME_SERVER1,buffer)) { + success = false; + } + } + + //time server 2 + if (espconfig.getValue("network", "time_server_2", buffer, bufferLen)) { + if (strlen(buffer) > 128) { + success = false; + } else if(!CONFIG::write_string(EP_TIME_SERVER2,buffer)) { + success = false; + } + } + + //time server 3 + if (espconfig.getValue("network", "time_server_3", buffer, bufferLen)) { + if (strlen(buffer) > 128) { + success = false; + } else if(!CONFIG::write_string(EP_TIME_SERVER3,buffer)) { + success = false; + } + } + + //Section [printer] + //data = 192.168.1.1/video.cgi?user=luc&pwd=mypassword + if (espconfig.getValue("printer", "data", buffer, bufferLen)) { + if (strlen(buffer) > 128) { + success = false; + } else if(!CONFIG::write_string(EP_DATA_STRING,buffer)) { + success = false; + } + } + //refreshrate = 3 + if (espconfig.getValue("printer", "refreshrate", buffer, bufferLen, itmp)) { + bflag = itmp; + if(!CONFIG::write_byte(EP_REFRESH_PAGE_TIME,bflag)) { + success = false; + } + } + //refreshrate2 = 3 + if (espconfig.getValue("printer", "refreshrate2", buffer, bufferLen, itmp)) { + bflag = itmp; + if(!CONFIG::write_byte(EP_REFRESH_PAGE_TIME2,bflag)) { + success = false; + } + } + //XY_feedrate = 1000 + if (espconfig.getValue("printer", "XY_feedrate", buffer, bufferLen, itmp)) { + if(!CONFIG::write_buffer(EP_XY_FEEDRATE,(const byte *)&itmp,INTEGER_LENGTH)) { + success = false; + } + } + //Z_feedrate = 100 + if (espconfig.getValue("printer", "Z_feedrate", buffer, bufferLen, itmp)) { + if(!CONFIG::write_buffer(EP_Z_FEEDRATE,(const byte *)&itmp,INTEGER_LENGTH)) { + success = false; + } + } + //E_feedrate = 400 + if (espconfig.getValue("printer", "E_feedrate", buffer, bufferLen, itmp)) { + if(!CONFIG::write_buffer(EP_E_FEEDRATE,(const byte *)&itmp,INTEGER_LENGTH)) { + success = false; + } + } + + //target_printer= smoothieware + if (espconfig.getValue("printer", "target_printer", buffer, bufferLen)) { + stmp = buffer; + bflag = UNKNOWN_FW; + if ( stmp.equalsIgnoreCase(String(F("repetier"))))bflag = REPETIER; + else if ( stmp.equalsIgnoreCase(String(F("repetier4davinci"))))bflag = REPETIER4DV; + else if ( stmp.equalsIgnoreCase(String(F("marlin"))))bflag = MARLIN; + else if ( stmp.equalsIgnoreCase(String(F("marlinkimbra"))))bflag = MARLINKIMBRA; + else if ( stmp.equalsIgnoreCase(String(F("smoothieware"))))bflag = SMOOTHIEWARE; + else success = false; + if(!(success && CONFIG::write_byte(EP_TARGET_FW,bflag))) { + success = false; + } + } + + //direct sd connection + if (espconfig.getValue("printer", "direct_sd", buffer, bufferLen)) { + stmp = buffer; + localerror = false; + stmp.toLowerCase(); + bflag = 0; + if (stmp =="yes") { + bflag = 1; + } else if (stmp =="no") { + bflag = 0; + } else { + localerror = true; + success = false; + } + if (!localerror) { + if(!CONFIG::write_byte(EP_IS_DIRECT_SD,bflag)) { + success = false; + } + } + } + //sd check update at boot + if (espconfig.getValue("printer", "sd_check_update", buffer, bufferLen)) { + stmp = buffer; + localerror = false; + stmp.toLowerCase(); + bflag = 0; + if (stmp =="yes") { + bflag = 1; + } else if (stmp =="no") { + bflag = 0; + } else { + localerror = true; + success = false; + } + if (!localerror) { + if(!CONFIG::write_byte(EP_SD_CHECK_UPDATE_AT_BOOT,bflag)) { + success = false; + } + } + } + //direct sd boot check + if (espconfig.getValue("printer", "direct_sd_boot_check", buffer, bufferLen)) { + stmp = buffer; + localerror = false; + stmp.toLowerCase(); + bflag = 0; + if (stmp =="yes") { + bflag = 1; + } else if (stmp =="no") { + bflag = 0; + } else { + localerror = true; + success = false; + } + if (!localerror) { + if(!CONFIG::write_byte(EP_DIRECT_SD_CHECK,bflag)) { + success = false; + } + } + } + + //primary sd directory + if (espconfig.getValue("printer", "primary_sd ", buffer, bufferLen)) { + stmp = buffer; + localerror = false; + stmp.toLowerCase(); + bflag = 0; + if (stmp =="none") { + bflag = 0; + } else if (stmp =="sd") { + bflag = 1; + } else if (stmp =="ext") { + bflag = 2; + } else { + localerror = true; + success = false; + } + if (!localerror) { + if(!CONFIG::write_byte(EP_PRIMARY_SD,bflag)) { + success = false; + } + } + } + + //secondary sd directory + if (espconfig.getValue("printer", "secondary_sd ", buffer, bufferLen)) { + stmp = buffer; + localerror = false; + stmp.toLowerCase(); + bflag = 0; + if (stmp =="none") { + bflag = 0; + } else if (stmp =="sd") { + bflag = 1; + } else if (stmp =="ext") { + bflag = 2; + } else { + localerror = true; + success = false; + } + if (!localerror) { + if(!CONFIG::write_byte(EP_SECONDARY_SD,bflag)) { + success = false; + } + } + } + + } + espconfig.close(); + if(success) { + newfilename.replace(String(".txt"), String(".ok")); + } else { + newfilename.replace(String(".txt"), String(".bad")); + answer = false; + } + //rename if name is already used + if (!CONFIG::renameFile (newfilename)) { + LOG("Failed to rename previous file\r\n") + } + if (SD.rename((const char *)filename.c_str(),(const char *)newfilename.c_str())) { + LOG("File renamed, restarted file\r\n") + } else { + return false; + LOG("Failed to rename file\r\n") + } + } else { + return false; + LOG("Failed to open config file\r\n") + } + } else { + return false; + LOG("No config file\r\n") + } + return answer; +} +#endif void CONFIG::esp_restart() { LOG("Restarting\r\n") - Serial.flush(); + ESP_SERIAL_OUT.flush(); delay(500); - Serial.swap(); +#ifdef ARDUINO_ARCH_ESP8266 + ESP_SERIAL_OUT.swap(); +#endif delay(100); ESP.restart(); while (1) { @@ -38,12 +717,19 @@ void CONFIG::esp_restart() }; } +void CONFIG::InitPins(){ +#ifdef RECOVERY_FEATURE + pinMode(RESET_CONFIG_PIN, INPUT); +#endif +} + +bool CONFIG::is_direct_sd = false; bool CONFIG::isHostnameValid(const char * hostname) { //limited size char c; - if (strlen(hostname)>MAX_HOSTNAME_LENGTH || strlen(hostname) < 1) { + if (strlen(hostname)>MAX_HOSTNAME_LENGTH || strlen(hostname) < MIN_HOSTNAME_LENGTH) { return false; } //only letter and digit @@ -68,11 +754,11 @@ bool CONFIG::isSSIDValid(const char * ssid) } //only letter and digit for (int i=0; i < strlen(ssid); i++) { - c = ssid[i]; + if (!isPrintable(ssid[i]))return false; //if (!(isdigit(c) || isalpha(c))) return false; //if (c==' ') { - // return false; - //} + // return false; + //} } return true; } @@ -88,7 +774,6 @@ bool CONFIG::isPasswordValid(const char * password) if (password[i] == ' ') { return false; } - return true; } @@ -165,7 +850,7 @@ char * CONFIG::intTostr(int value) return result; } -String CONFIG::formatBytes(size_t bytes) +String CONFIG::formatBytes(uint32_t bytes) { if (bytes < 1024) { return String(bytes)+" B"; @@ -320,6 +1005,100 @@ bool CONFIG::write_string(int pos, const __FlashStringHelper *str) return write_string(pos,stmp.c_str()); } +bool CONFIG::check_update_presence( ){ + bool result = false; + if (CONFIG::is_direct_sd) { + long baud_rate=0; + if (!CONFIG::read_buffer(EP_BAUD_RATE, (byte *)&baud_rate, INTEGER_LENGTH)) return false; + if (ESP_SERIAL_OUT.baudRate() != baud_rate)ESP_SERIAL_OUT.begin(baud_rate); + CONFIG::InitFirmwareTarget(); + delay(500); + String cmd = "M20"; + //By default M20 should be applied + //if (CONFIG::FirmwareTarget == UNKNOWN_FW) return false; + if (CONFIG::FirmwareTarget == SMOOTHIEWARE) { + byte sd_dir = 0; + if (!CONFIG::read_byte(EP_PRIMARY_SD, &sd_dir )) sd_dir = DEFAULT_PRIMARY_SD; + if (sd_dir == SD_DIRECTORY) cmd = "ls /sd"; + else if (sd_dir == EXT_DIRECTORY) cmd = "ls /ext"; + else return false; + } + String tmp; + int count ; + //send command to serial as no need to transfer ESP command + //to avoid any pollution if Uploading file to SDCard + //block every query + //empty the serial buffer and incoming data + if(ESP_SERIAL_OUT.available()) { + BRIDGE::processFromSerial2TCP(); + delay(1); + } + //Send command + ESP_SERIAL_OUT.println(cmd); + count = 0; + String current_buffer; + String current_line; + int pos; + int temp_counter = 0; + + //pickup the list + while (count < MAX_TRY) { + //give some time between each buffer + if (ESP_SERIAL_OUT.available()) { + count = 0; + size_t len = ESP_SERIAL_OUT.available(); + uint8_t sbuf[len+1]; + //read buffer + ESP_SERIAL_OUT.readBytes(sbuf, len); + //change buffer as string + sbuf[len]='\0'; + //add buffer to current one if any + current_buffer += (char * ) sbuf; + while (current_buffer.indexOf("\n") !=-1) { + //remove the possible "\r" + current_buffer.replace("\r",""); + pos = current_buffer.indexOf("\n"); + //get line + current_line = current_buffer.substring(0,current_buffer.indexOf("\n")); + //if line is command ack - just exit so save the time out period + if ((current_line == "ok") || (current_line == "wait")) { + count = MAX_TRY; + break; + } + //check line + //save time no need to continue + if (current_line.indexOf("busy:") > -1 || current_line.indexOf("T:") > -1 || current_line.indexOf("B:") > -1) { + temp_counter++; + } else { + + } + if (temp_counter > 5) { + break; + } + //current remove line from buffer + tmp = current_buffer.substring(current_buffer.indexOf("\n")+1,current_buffer.length()); + current_buffer = tmp; + delay(0); + } + delay (0); + } else { + delay(1); + } + //it is sending too many temp status should be heating so let's exit the loop + if (temp_counter > 5) { + count = MAX_TRY; + } + count++; + } + if(ESP_SERIAL_OUT.available()) { + BRIDGE::processFromSerial2TCP(); + delay(1); + } + } + return result; +} + + //write a string (array of byte with a 0x00 at the end) bool CONFIG::write_string(int pos, const char * byte_buffer) { @@ -343,11 +1122,17 @@ bool CONFIG::write_string(int pos, const char * byte_buffer) case EP_HOSTNAME: maxsize = MAX_HOSTNAME_LENGTH; break; + case EP_TIME_SERVER1: + case EP_TIME_SERVER2: + case EP_TIME_SERVER3: + case EP_DATA_STRING: + maxsize = MAX_DATA_LENGTH; + break; default: maxsize = EEPROM_SIZE; break; } - if (size_buffer==0 || pos+size_buffer+1 > EEPROM_SIZE || size_buffer > maxsize || byte_buffer== NULL) { + if ((size_buffer==0 && !(pos == EP_DATA_STRING)) || pos+size_buffer+1 > EEPROM_SIZE || size_buffer > maxsize || byte_buffer== NULL) { LOG("Error write string\r\n") return false; } @@ -399,6 +1184,9 @@ bool CONFIG::write_byte(int pos, const byte value) bool CONFIG::reset_config() { + if(!CONFIG::write_string(EP_DATA_STRING,"")) { + return false; + } if(!CONFIG::write_byte(EP_WIFI_MODE,DEFAULT_WIFI_MODE)) { return false; } @@ -468,6 +1256,9 @@ bool CONFIG::reset_config() if(!CONFIG::write_byte(EP_REFRESH_PAGE_TIME,DEFAULT_REFRESH_PAGE_TIME)) { return false; } + if(!CONFIG::write_byte(EP_REFRESH_PAGE_TIME2,DEFAULT_REFRESH_PAGE_TIME)) { + return false; + } if(!CONFIG::write_string(EP_HOSTNAME,wifi_config.get_default_hostname())) { return false; } @@ -486,328 +1277,590 @@ bool CONFIG::reset_config() if(!CONFIG::write_string(EP_USER_PWD,FPSTR(DEFAULT_USER_PWD))) { return false; } + + if(!CONFIG::write_byte(EP_TARGET_FW, UNKNOWN_FW)) { + return false; + } + + if(!CONFIG::write_byte(EP_TIMEZONE, DEFAULT_TIME_ZONE)) { + return false; + } + + if(!CONFIG::write_byte(EP_TIME_ISDST, DEFAULT_TIME_DST)) { + return false; + } + + if(!CONFIG::write_byte(EP_PRIMARY_SD, DEFAULT_PRIMARY_SD)) { + return false; + } + + if(!CONFIG::write_byte(EP_SECONDARY_SD, DEFAULT_SECONDARY_SD)) { + return false; + } + + if(!CONFIG::write_byte(EP_IS_DIRECT_SD, DEFAULT_IS_DIRECT_SD)) { + return false; + } + + if(!CONFIG::write_byte(EP_DIRECT_SD_CHECK, DEFAULT_DIRECT_SD_CHECK)) { + return false; + } + + if(!CONFIG::write_byte(EP_SD_CHECK_UPDATE_AT_BOOT, DEFAULT_SD_CHECK_UPDATE_AT_BOOT)) { + return false; + } + + if(!CONFIG::write_string(EP_TIME_SERVER1,FPSTR(DEFAULT_TIME_SERVER1))) { + return false; + } + + if(!CONFIG::write_string(EP_TIME_SERVER2,FPSTR(DEFAULT_TIME_SERVER2))) { + return false; + } + + if(!CONFIG::write_string(EP_TIME_SERVER3,FPSTR(DEFAULT_TIME_SERVER3))) { + return false; + } return true; } -void CONFIG::print_config(tpipe output) -{ - //use biggest size for buffer - char sbuf[MAX_PASSWORD_LENGTH+1]; - uint8_t ipbuf[4]; - byte bbuf=0; - int ibuf=0; - if (CONFIG::read_buffer(EP_BAUD_RATE, (byte *)&ibuf , INTEGER_LENGTH)) { - BRIDGE::print(F("Baud rate: "), output); - BRIDGE::println(String(ibuf).c_str(), output); - } else { - BRIDGE::println(F("Error reading baud rate"), output); - } - if (CONFIG::read_byte(EP_SLEEP_MODE, &bbuf )) { - BRIDGE::print(F("Sleep mode: "), output); - if (byte(bbuf)==WIFI_NONE_SLEEP) { - BRIDGE::println(F("None"), output); - } else if (byte(bbuf)==WIFI_LIGHT_SLEEP) { - BRIDGE::println(F("Light"), output); - } else if (byte(bbuf)==WIFI_MODEM_SLEEP) { - BRIDGE::println(F("Modem"), output); - } else { - BRIDGE::println(F("???"), output); +void CONFIG::print_config(tpipe output, bool plaintext) +{ + if (!plaintext)BRIDGE::print(F("{\"chip_id\":\""), output); + else BRIDGE::print(F("Chip ID: "), output); +#ifdef ARDUINO_ARCH_ESP8266 + BRIDGE::print(String(ESP.getChipId()).c_str(), output); +#else + BRIDGE::print(String((uint16_t)(ESP.getEfuseMac()>>32)).c_str(), output); +#endif + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + if (!plaintext)BRIDGE::print(F("\"cpu\":\""), output); + else BRIDGE::print(F("CPU Frequency: "), output); + BRIDGE::print(String(ESP.getCpuFreqMHz()).c_str(), output); + if (plaintext)BRIDGE::print(F("Mhz"), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); +#ifdef ARDUINO_ARCH_ESP32 + if (!plaintext)BRIDGE::print(F("\"cpu_temp\":\""), output); + else BRIDGE::print(F("CPU Temperature: "), output); + BRIDGE::print(String(temperatureRead(),1).c_str(), output); + if (plaintext)BRIDGE::print(F("C"), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); +#endif + if (!plaintext)BRIDGE::print(F("\"freemem\":\""), output); + else BRIDGE::print(F("Free memory: "), output); + BRIDGE::print(formatBytes(ESP.getFreeHeap()).c_str(), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + if (!plaintext)BRIDGE::print(F("\""), output); + BRIDGE::print(F("SDK"), output); + if (!plaintext)BRIDGE::print(F("\":\""), output); + else BRIDGE::print(F(": "), output); + BRIDGE::print(ESP.getSdkVersion(), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + if (!plaintext)BRIDGE::print(F("\"flash_size\":\""), output); + else BRIDGE::print(F("Flash Size: "), output); + BRIDGE::print(formatBytes(ESP.getFlashChipSize()).c_str(), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); +#ifdef ARDUINO_ARCH_ESP8266 + if (!plaintext)BRIDGE::print(F("\"update_size\":\""), output); + else BRIDGE::print(F("Available Size for update: "), output); + uint32_t flashsize = ESP.getFlashChipSize(); + if (flashsize > 1024 * 1024) flashsize = 1024 * 1024; + BRIDGE::print(formatBytes(flashsize - ESP.getSketchSize()).c_str(), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else { + if ((flashsize - ESP.getSketchSize()) > (flashsize / 2)) BRIDGE::println(F("(Ok)"), output); + else BRIDGE::print(F("(Not enough)"), output); } - } else { - BRIDGE::println(F("Error reading sleep mode"), output); - } - if (CONFIG::read_string(EP_HOSTNAME, sbuf , MAX_HOSTNAME_LENGTH)) { - BRIDGE::print(F("Hostname: "), output); - BRIDGE::println(sbuf, output); - } else { - BRIDGE::println(F("Error reading hostname"), output); - } - if (CONFIG::read_byte(EP_WIFI_MODE, &bbuf )) { - BRIDGE::print(F("Mode: "), output); - if (byte(bbuf) == CLIENT_MODE) { - BRIDGE::println(F("Station"), output); - BRIDGE::print(F("Signal: "), output); - BRIDGE::print(String(wifi_config.getSignal(WiFi.RSSI())).c_str(), output); - BRIDGE::println(F("%"), output); - } else if (byte(bbuf)==AP_MODE) { - BRIDGE::println(F("Access Point"), output); - } else { - BRIDGE::println("???", output); + + if (!plaintext)BRIDGE::print(F("\"spiffs_size\":\""), output); + else BRIDGE::print(F("Available Size for SPIFFS: "), output); + fs::FSInfo info; + SPIFFS.info(info); + BRIDGE::print(formatBytes(info.totalBytes).c_str(), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); +#else + if (!plaintext)BRIDGE::print(F("\"update_size\":\""), output); + else BRIDGE::print(F("Available Size for update: "), output); + uint32_t flashsize = ESP.getFlashChipSize(); +//Not OTA on 2Mb board per spec + if (flashsize > 0x20000) flashsize = 0x140000; + else flashsize = 0x0; + BRIDGE::print(formatBytes(flashsize).c_str(), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else { + if (flashsize > 0x0) BRIDGE::println(F("(Ok)"), output); + else BRIDGE::print(F("(Not enough)"), output); } + if (!plaintext)BRIDGE::print(F("\"spiffs_size\":\""), output); + else BRIDGE::print(F("Available Size for SPIFFS: "), output); + BRIDGE::print(formatBytes(SPIFFS.totalBytes()).c_str(), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); +#endif + if (!plaintext)BRIDGE::print(F("\"baud_rate\":\""), output); + else BRIDGE::print(F("Baud rate: "), output); + uint32_t br = ESP_SERIAL_OUT.baudRate(); +#ifdef ARDUINO_ARCH_ESP32 + //workaround for ESP32 + if(br == 115201)br = 115200; + if(br == 230423)br = 230400; +#endif + BRIDGE::print(String(br).c_str(), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + if (!plaintext)BRIDGE::print(F("\"sleep_mode\":\""), output); + else BRIDGE::print(F("Sleep mode: "), output); +#ifdef ARDUINO_ARCH_ESP32 + wifi_ps_type_t ps_type; + esp_wifi_get_ps(&ps_type); +#else + WiFiSleepType_t ps_type; + ps_type = WiFi.getSleepMode(); +#endif + if (ps_type == WIFI_NONE_SLEEP) { + BRIDGE::print(F("None"), output); +#ifdef ARDUINO_ARCH_ESP8266 + } else if (ps_type == WIFI_LIGHT_SLEEP) { + BRIDGE::print(F("Light"), output); +#endif + } else if (ps_type == WIFI_MODEM_SLEEP) { + BRIDGE::print(F("Modem"), output); } else { - BRIDGE::println(F("Error reading mode"), output); + BRIDGE::print(F("???"), output); } - - if (CONFIG::read_string(EP_STA_SSID, sbuf , MAX_SSID_LENGTH)) { - BRIDGE::print(F("Client SSID: "), output); - BRIDGE::println(sbuf, output); - } else { - BRIDGE::println(F("Error reading SSID"), output); - } - - if (CONFIG::read_byte(EP_STA_IP_MODE, &bbuf )) { - BRIDGE::print(F("STA IP Mode: "), output); - if (byte(bbuf)==STATIC_IP_MODE) { - BRIDGE::println(F("Static"), output); - if (CONFIG::read_buffer(EP_STA_IP_VALUE,(byte *)ipbuf , IP_LENGTH)) { - BRIDGE::print(F("IP: "), output); - BRIDGE::println(IPAddress(ipbuf).toString().c_str(), output); - } else { - BRIDGE::println(F("Error reading IP"), output); - } - - if (CONFIG::read_buffer(EP_STA_MASK_VALUE, (byte *)ipbuf , IP_LENGTH)) { - BRIDGE::print(F("Subnet: "), output); - BRIDGE::println(IPAddress(ipbuf).toString().c_str(), output); - } else { - BRIDGE::println(F("Error reading subnet"), output); - } - - if (CONFIG::read_buffer(EP_STA_GATEWAY_VALUE, (byte *)ipbuf , IP_LENGTH)) { - BRIDGE::print(F("Gateway: "), output); - BRIDGE::println(IPAddress(ipbuf).toString().c_str(), output); - } else { - BRIDGE::println(F("Error reading gateway"), output); - } - } else if (byte(bbuf)==DHCP_MODE) { - BRIDGE::println(F("DHCP"), output); - } else { - BRIDGE::println(F("???"), output); - } - } else { - BRIDGE::println(F("Error reading IP mode"), output); - } - - if (CONFIG::read_byte(EP_STA_PHY_MODE, &bbuf )) { - BRIDGE::print(F("STA Phy mode: "), output); - if (byte(bbuf)==WIFI_PHY_MODE_11B) { - BRIDGE::println(F("11b"), output); - } else if (byte(bbuf)==WIFI_PHY_MODE_11G) { - BRIDGE::println(F("11g"), output); - } else if (byte(bbuf)==WIFI_PHY_MODE_11N) { - BRIDGE::println(F("11n"), output); - } else { - BRIDGE::println(F("???"), output); - } - } else { - BRIDGE::println(F("Error reading phy mode"), output); - } - - if (CONFIG::read_string(EP_AP_SSID, sbuf , MAX_SSID_LENGTH)) { - BRIDGE::print(F("AP SSID: "), output); - BRIDGE::println(sbuf, output); - } else { - BRIDGE::println(F("Error reading SSID"), output); - } - - if (CONFIG::read_byte(EP_AP_IP_MODE, &bbuf )) { - BRIDGE::print(F("AP IP Mode: "), output); - if (byte(bbuf)==STATIC_IP_MODE) { - BRIDGE::println(F("Static"), output); - if (CONFIG::read_buffer(EP_AP_IP_VALUE,(byte *)ipbuf , IP_LENGTH)) { - BRIDGE::print(F("IP: "), output); - BRIDGE::println(IPAddress(ipbuf).toString().c_str(), output); - } else { - BRIDGE::println(F("Error reading IP"), output); - } - - if (CONFIG::read_buffer(EP_AP_MASK_VALUE, (byte *)ipbuf , IP_LENGTH)) { - BRIDGE::print(F("Subnet: "), output); - BRIDGE::println(IPAddress(ipbuf).toString().c_str(), output); - } else { - BRIDGE::println(F("Error reading subnet"), output); - } - - if (CONFIG::read_buffer(EP_AP_GATEWAY_VALUE, (byte *)ipbuf , IP_LENGTH)) { - BRIDGE::print(F("Gateway: "), output); - BRIDGE::println(IPAddress(ipbuf).toString().c_str(), output); - } else { - BRIDGE::println(F("Error reading gateway"), output); - } - } else if (byte(bbuf)==DHCP_MODE) { - BRIDGE::println(F("DHCP"), output); - } else { - BRIDGE::println(intTostr(bbuf), output); - BRIDGE::println(F("???"), output); - } - } else { - BRIDGE::println(F("Error reading IP mode"), output); - } - - if (CONFIG::read_byte(EP_AP_PHY_MODE, &bbuf )) { - BRIDGE::print(F("AP Phy mode: "), output); - if (byte(bbuf)==WIFI_PHY_MODE_11B) { - BRIDGE::println(F("11b"), output); - } else if (byte(bbuf)==WIFI_PHY_MODE_11G) { - BRIDGE::println(F("11g"), output); - } else if (byte(bbuf)==WIFI_PHY_MODE_11N) { - BRIDGE::println(F("11n"), output); - } else { - BRIDGE::println(F("???"), output); - } - } else { - BRIDGE::println(F("Error reading phy mode"), output); - } - - if (CONFIG::read_byte(EP_CHANNEL, &bbuf )) { - BRIDGE::print(F("Channel: "), output); - BRIDGE::println(String(byte(bbuf)).c_str(), output); - } else { - BRIDGE::println(F("Error reading channel"), output); - } - - if (CONFIG::read_byte(EP_AUTH_TYPE, &bbuf )) { - BRIDGE::print(F("Authentification: "), output); - if (byte(bbuf)==AUTH_OPEN) { - BRIDGE::println(F("None"), output); - } else if (byte(bbuf)==AUTH_WEP) { - BRIDGE::println(F("WEP"), output); - } else if (byte(bbuf)==AUTH_WPA_PSK) { - BRIDGE::println(F("WPA"), output); - } else if (byte(bbuf)==AUTH_WPA2_PSK) { - BRIDGE::println(F("WPA2"), output); - } else if (byte(bbuf)==AUTH_WPA_WPA2_PSK) { - BRIDGE::println(F("WPA/WPA2"), output); - } else { - BRIDGE::println(F("???"), output); - } - } else { - BRIDGE::println(F("Error reading authentification"), output); - } - - if (CONFIG::read_byte(EP_SSID_VISIBLE, &bbuf )) { - BRIDGE::print(F("SSID visibility: "), output); - if (bbuf==0) { - BRIDGE::println(F("Hidden"), output); - } else if (bbuf==1) { - BRIDGE::println(F("Visible"), output); - } else { - BRIDGE::println(String(bbuf).c_str(), output); - } - } else { - BRIDGE::println(F("Error reading SSID visibility"), output); - } - - if (CONFIG::read_buffer(EP_WEB_PORT, (byte *)&ibuf , INTEGER_LENGTH)) { - BRIDGE::print(F("Web port: "), output); - BRIDGE::println(String(ibuf).c_str(), output); - } else { - BRIDGE::println(F("Error reading web port"), output); - } - BRIDGE::print(F("Data port: "), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + if (!plaintext)BRIDGE::print(F("\"channel\":\""), output); + else BRIDGE::print(F("Channel: "), output); + BRIDGE::print(String(WiFi.channel()).c_str(), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); +#ifdef ARDUINO_ARCH_ESP32 + uint8_t PhyMode; + if (WiFi.getMode() == WIFI_STA)esp_wifi_get_protocol(ESP_IF_WIFI_STA, &PhyMode); + else esp_wifi_get_protocol(ESP_IF_WIFI_AP, &PhyMode); +#else + WiFiPhyMode_t PhyMode = WiFi.getPhyMode(); +#endif + if (!plaintext)BRIDGE::print(F("\"phy_mode\":\""), output); + else BRIDGE::print(F("Phy Mode: "), output); + if (PhyMode == WIFI_PHY_MODE_11G )BRIDGE::print(F("11g"), output); + else if (PhyMode == WIFI_PHY_MODE_11B )BRIDGE::print(F("11b"), output); + else if (PhyMode == WIFI_PHY_MODE_11N )BRIDGE::print(F("11n"), output); + else BRIDGE::print(F("???"), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + if (!plaintext)BRIDGE::print(F("\"web_port\":\""), output); + else BRIDGE::print(F("Web port: "), output); + BRIDGE::print(String(wifi_config.iweb_port).c_str(), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + if (!plaintext)BRIDGE::print(F("\"data_port\":\""), output); + else BRIDGE::print(F("Data port: "), output); #ifdef TCP_IP_DATA_FEATURE - if (CONFIG::read_buffer(EP_DATA_PORT, (byte *)&ibuf , INTEGER_LENGTH)) { - BRIDGE::println(String(ibuf).c_str(), output); - } else { - BRIDGE::println(F("Error reading data port"), output); - } + BRIDGE::print(String(wifi_config.idata_port).c_str(), output); #else - BRIDGE::println(F("Disabled"), output); + BRIDGE::print(F("Disabled"), output); #endif - if (CONFIG::read_byte(EP_REFRESH_PAGE_TIME, &bbuf )) { - BRIDGE::print(F("Web page refresh time: "), output); - BRIDGE::println(String(byte(bbuf)).c_str(), output); - } else { - BRIDGE::println(F("Error reading refresh page"), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + if (WiFi.getMode() == WIFI_STA || WiFi.getMode() == WIFI_AP_STA) { + if (!plaintext)BRIDGE::print(F("\"hostname\":\""), output); + else BRIDGE::print(F("Hostname: "), output); +#ifdef ARDUINO_ARCH_ESP32 + BRIDGE::print(WiFi.getHostname(), output); +#else + BRIDGE::print(WiFi.hostname().c_str(), output); +#endif + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); } - if (CONFIG::read_buffer(EP_XY_FEEDRATE, (byte *)&ibuf , INTEGER_LENGTH)) { - BRIDGE::print(F("XY feed rate: "), output); - BRIDGE::println(String(ibuf).c_str(), output); + if (!plaintext)BRIDGE::print(F("\"active_mode\":\""), output); + else BRIDGE::print(F("Active Mode: "), output); + if (WiFi.getMode() == WIFI_STA) { + BRIDGE::print(F("Station ("), output); + BRIDGE::print(WiFi.macAddress().c_str(), output); + BRIDGE::print(F(")"), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + if (WiFi.isConnected()) { + if (!plaintext)BRIDGE::print(F("\"connected_ssid\":\""), output); + else BRIDGE::print(F("Connected to: "), output); + BRIDGE::print(WiFi.SSID().c_str(), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + if (!plaintext)BRIDGE::print(F("\"connected_signal\":\""), output); + else BRIDGE::print(F("Signal: "), output); + BRIDGE::print(String(wifi_config.getSignal(WiFi.RSSI())).c_str(), output); + BRIDGE::print(F("%"), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + } + else { + if (!plaintext)BRIDGE::print(F("\"connection_status\":\""), output); + else BRIDGE::print(F("Connection Status: "), output); + BRIDGE::print(F("Connection Status: "), output); + if (WiFi.status() == WL_DISCONNECTED) { + BRIDGE::print(F("Disconnected"), output); + } else if (WiFi.status() == WL_CONNECTION_LOST) { + BRIDGE::print(F("Connection lost"), output); + } else if (WiFi.status() == WL_CONNECT_FAILED) { + BRIDGE::print(F("Connection failed"), output); + } else if (WiFi.status() == WL_NO_SSID_AVAIL) { + BRIDGE::print(F("No connection"), output); + } else if (WiFi.status() == WL_IDLE_STATUS ) { + BRIDGE::print(F("Idle"), output); + } else BRIDGE::print(F("Unknown"), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + } + if (!plaintext)BRIDGE::print(F("\"ip_mode\":\""), output); + else BRIDGE::print(F("IP Mode: "), output); +#ifdef ARDUINO_ARCH_ESP32 + tcpip_adapter_dhcp_status_t dhcp_status; + tcpip_adapter_dhcpc_get_status(TCPIP_ADAPTER_IF_STA, &dhcp_status); + if (dhcp_status == TCPIP_ADAPTER_DHCP_STARTED) +#else + if (wifi_station_dhcpc_status()==DHCP_STARTED) +#endif + { + BRIDGE::print(F("DHCP"), output); + } + else BRIDGE::print(F("Static"), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + if (!plaintext)BRIDGE::print(F("\"ip\":\""), output); + else BRIDGE::print(F("IP: "), output); + BRIDGE::print(WiFi.localIP().toString().c_str(), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + if (!plaintext)BRIDGE::print(F("\"gw\":\""), output); + else BRIDGE::print(F("Gateway: "), output); + BRIDGE::print(WiFi.gatewayIP().toString().c_str(), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + if (!plaintext)BRIDGE::print(F("\"msk\":\""), output); + else BRIDGE::print(F("Mask: "), output); + BRIDGE::print(WiFi.subnetMask().toString().c_str(), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + if (!plaintext)BRIDGE::print(F("\"dns\":\""), output); + else BRIDGE::print(F("DNS: "), output); + BRIDGE::print(WiFi.dnsIP().toString().c_str(), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + if (!plaintext)BRIDGE::print(F("\"disabled_mode\":\""), output); + else BRIDGE::print(F("Disabled Mode: "), output); + BRIDGE::print(F("Access Point ("), output); + BRIDGE::print(WiFi.softAPmacAddress().c_str(), output); + BRIDGE::print(F(")"), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + } else if (WiFi.getMode() == WIFI_AP) { + BRIDGE::print(F("Access Point ("), output); + BRIDGE::print(WiFi.softAPmacAddress().c_str(), output); + BRIDGE::print(F(")"), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + //get current config +#ifdef ARDUINO_ARCH_ESP32 + wifi_ap_config_t apconfig; + wifi_config_t conf; + esp_wifi_get_config(ESP_IF_WIFI_AP, &conf); + apconfig.ssid_hidden = conf.ap.ssid_hidden; + apconfig.authmode = conf.ap.authmode; + apconfig.max_connection = conf.ap.max_connection; +#else + struct softap_config apconfig; + wifi_softap_get_config(&apconfig); +#endif + if (!plaintext)BRIDGE::print(F("\"ap_ssid\":\""), output); + else BRIDGE::print(F("SSID: "), output); +#ifdef ARDUINO_ARCH_ESP32 + BRIDGE::print((const char*)conf.ap.ssid, output); +#else + BRIDGE::print((const char*)apconfig.ssid, output); +#endif + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + if (!plaintext)BRIDGE::print(F("\"ssid_visible\":\""), output); + else BRIDGE::print(F("Visible: "), output); + BRIDGE::print((apconfig.ssid_hidden == 0)?F("Yes"):F("No"), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + if (!plaintext)BRIDGE::print(F("\"ssid_authentication\":\""), output); + else BRIDGE::print(F("Authentication: "), output); + if (apconfig.authmode==AUTH_OPEN) { + BRIDGE::print(F("None"), output); + } else if (apconfig.authmode==AUTH_WEP) { + BRIDGE::print(F("WEP"), output); + } else if (apconfig.authmode==AUTH_WPA_PSK) { + BRIDGE::print(F("WPA"), output); + } else if (apconfig.authmode==AUTH_WPA2_PSK) { + BRIDGE::print(F("WPA2"), output); + } else { + BRIDGE::print(F("WPA/WPA2"), output); + } + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + if (!plaintext)BRIDGE::print(F("\"ssid_max_connections\":\""), output); + else BRIDGE::print(F("Max Connections: "), output); + BRIDGE::print(String(apconfig.max_connection).c_str(), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + if (!plaintext)BRIDGE::print(F("\"ssid_dhcp\":\""), output); + else BRIDGE::print(F("DHCP Server: "), output); +#ifdef ARDUINO_ARCH_ESP32 + tcpip_adapter_dhcp_status_t dhcp_status; + tcpip_adapter_dhcps_get_status(TCPIP_ADAPTER_IF_AP, &dhcp_status); + if (dhcp_status == TCPIP_ADAPTER_DHCP_STARTED) +#else + if(wifi_softap_dhcps_status() == DHCP_STARTED) +#endif + { + BRIDGE::print(F("Started"), output); + } + else BRIDGE::print(F("Stopped"), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + if (!plaintext)BRIDGE::print(F("\"ip\":\""), output); + else BRIDGE::print(F("IP: "), output); + BRIDGE::print(WiFi.softAPIP().toString().c_str(), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); +#ifdef ARDUINO_ARCH_ESP32 + tcpip_adapter_ip_info_t ip; + tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_AP, &ip); +#else + struct ip_info ip; + wifi_get_ip_info(SOFTAP_IF, &ip); +#endif + if (!plaintext)BRIDGE::print(F("\"gw\":\""), output); + else BRIDGE::print(F("Gateway: "), output); + BRIDGE::print(IPAddress(ip.gw.addr).toString().c_str(), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + if (!plaintext)BRIDGE::print(F("\"msk\":\""), output); + else BRIDGE::print(F("Mask: "), output); + BRIDGE::print(IPAddress(ip.netmask.addr).toString().c_str(), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + + if (!plaintext)BRIDGE::print(F("\"connected_clients\":["), output); + else BRIDGE::print(F("Connected clients: "), output); + int client_counter=0; +#ifdef ARDUINO_ARCH_ESP32 + wifi_sta_list_t station; + tcpip_adapter_sta_list_t tcpip_sta_list; + esp_wifi_ap_get_sta_list(&station); + tcpip_adapter_get_sta_list(&station, &tcpip_sta_list); +#else + struct station_info * station; + station = wifi_softap_get_station_info(); +#endif + String stmp =""; +#ifdef ARDUINO_ARCH_ESP32 + for (int i=0; i < station.num; i++){ +#else + while(station) { +#endif + if(stmp.length() > 0) { + if (!plaintext)stmp+=F(","); + else stmp+=F("\n"); + + } + if (!plaintext)stmp+=F("{\"bssid\":\""); + //BSSID +#ifdef ARDUINO_ARCH_ESP32 + stmp += CONFIG::mac2str(tcpip_sta_list.sta[i].mac); +#else + stmp += CONFIG::mac2str(station->bssid); +#endif + if (!plaintext)stmp+=F("\",\"ip\":\""); + else stmp += F(" "); + //IP +#ifdef ARDUINO_ARCH_ESP32 + stmp += IPAddress(tcpip_sta_list.sta[i].ip.addr).toString().c_str(); +#else + stmp += IPAddress((const uint8_t *)&station->ip).toString().c_str(); +#endif + if (!plaintext)stmp+=F("\"}"); + //increment counter + client_counter++; +#ifdef ARDUINO_ARCH_ESP32 + } +#else + //go next record + station =STAILQ_NEXT(station, next); + } + wifi_softap_free_station_info(); +#endif + if (!plaintext) { + BRIDGE::print(stmp.c_str(), output); + BRIDGE::print(F("],"), output); + } + else { + //display number of client + BRIDGE::println(String(client_counter).c_str(), output); + //display list if any + if(stmp.length() > 0)BRIDGE::println(stmp.c_str(), output); + } + + if (!plaintext)BRIDGE::print(F("\"disabled_mode\":\""), output); + else BRIDGE::print(F("Disabled Mode: "), output); + BRIDGE::print(F("Station ("), output); + BRIDGE::print(WiFi.macAddress().c_str(), output); + BRIDGE::print(F(") is disabled"), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + } else if (WiFi.getMode() == WIFI_AP_STA) { + BRIDGE::print(F("Mixed"), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + if (!plaintext)BRIDGE::print(F("\"active_mode\":\""), output); + else BRIDGE::print(F("Active Mode: "), output); + BRIDGE::print(F("Access Point ("), output); + BRIDGE::print(WiFi.softAPmacAddress().c_str(), output); + BRIDGE::println(F(")"), output); + BRIDGE::print(F("Station ("), output); + BRIDGE::print(WiFi.macAddress().c_str(), output); + BRIDGE::print(F(")"), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); } else { - BRIDGE::println(F("Error reading XY feed rate"), output); + BRIDGE::print("Wifi Off", output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); } - if (CONFIG::read_buffer(EP_Z_FEEDRATE, (byte *)&ibuf , INTEGER_LENGTH)) { - BRIDGE::print(F("Z feed rate: "), output); - BRIDGE::println(String(ibuf).c_str(), output); - } else { - BRIDGE::println(F("Error reading Z feed rate"), output); - } - - if (CONFIG::read_buffer(EP_E_FEEDRATE, (byte *)&ibuf , INTEGER_LENGTH)) { - BRIDGE::print(F("E feed rate: "), output); - BRIDGE::println(String(ibuf).c_str(), output); - } else { - BRIDGE::println(F("Error reading E feed rate"), output); - } - - BRIDGE::print(F("Free memory: "), output); - BRIDGE::println(formatBytes(ESP.getFreeHeap()).c_str(), output); - - BRIDGE::print(F("Captive portal: "), output); + if (!plaintext)BRIDGE::print(F("\"captive_portal\":\""), output); + else BRIDGE::print(F("Captive portal: "), output); #ifdef CAPTIVE_PORTAL_FEATURE - BRIDGE::println(F("Enabled"), output); + BRIDGE::print(F("Enabled"), output); #else - BRIDGE::println(F("Disabled"), output); + BRIDGE::print(F("Disabled"), output); #endif - BRIDGE::print(F("SSDP: "), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + if (!plaintext)BRIDGE::print(F("\"ssdp\":\""), output); + else BRIDGE::print(F("SSDP: "), output); #ifdef SSDP_FEATURE - BRIDGE::println(F("Enabled"), output); + BRIDGE::print(F("Enabled"), output); #else - BRIDGE::println(F("Disabled"), output); + BRIDGE::print(F("Disabled"), output); #endif - BRIDGE::print(F("NetBios: "), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + if (!plaintext)BRIDGE::print(F("\"netbios\":\""), output); + else BRIDGE::print(F("NetBios: "), output); #ifdef NETBIOS_FEATURE - BRIDGE::println(F("Enabled"), output); + BRIDGE::print(F("Enabled"), output); #else - BRIDGE::println(F("Disabled"), output); + BRIDGE::print(F("Disabled"), output); #endif - BRIDGE::print(F("mDNS: "), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + if (!plaintext)BRIDGE::print(F("\"mdns\":\""), output); + else BRIDGE::print(F("mDNS: "), output); #ifdef MDNS_FEATURE - BRIDGE::println(F("Enabled"), output); + BRIDGE::print(F("Enabled"), output); #else - BRIDGE::println(F("Disabled"), output); + BRIDGE::print(F("Disabled"), output); #endif - BRIDGE::print(F("Web update: "), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + if (!plaintext)BRIDGE::print(F("\"web_update\":\""), output); + else BRIDGE::print(F("Web Update: "), output); #ifdef WEB_UPDATE_FEATURE - BRIDGE::println(F("Enabled"), output); + BRIDGE::print(F("Enabled"), output); #else - BRIDGE::println(F("Disabled"), output); + BRIDGE::print(F("Disabled"), output); #endif - BRIDGE::print(F("Pin 2 Recovery: "), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + if (!plaintext)BRIDGE::print(F("\"pin recovery\":\""), output); + else BRIDGE::print(F("Pin Recovery: "), output); #ifdef RECOVERY_FEATURE - BRIDGE::println(F("Enabled"), output); + BRIDGE::print(F("Enabled"), output); #else - BRIDGE::println(F("Disabled"), output); + BRIDGE::print(F("Disabled"), output); #endif - BRIDGE::print(F("Authentication: "), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + if (!plaintext)BRIDGE::print(F("\"autentication\":\""), output); + else BRIDGE::print(F("Authentication: "), output); #ifdef AUTHENTICATION_FEATURE - BRIDGE::println(F("Enabled"), output); + BRIDGE::print(F("Enabled"), output); #else - BRIDGE::println(F("Disabled"), output); -#endif - BRIDGE::print(F("Target Firmware: "), output); -#if FIRMWARE_TARGET == REPETIER - BRIDGE::println(F("Repetier"), output); -#elif FIRMWARE_TARGET == REPETIER4DV - BRIDGE::println(F("Repetier for DaVinci"), output); -#elif FIRMWARE_TARGET == MARLIN - BRIDGE::println(F("Marlin"), output); -#elif FIRMWARE_TARGET == SMOOTHIEWARE - BRIDGE::println(F("Smoothieware"), output); -#else - BRIDGE::println(F("???"), output); -#endif - BRIDGE::print(F("SD Card support: "), output); -#ifdef SDCARD_FEATURE - BRIDGE::println(F("Enabled"), output); -#else - BRIDGE::println(F("Disabled"), output); + BRIDGE::print(F("Disabled"), output); #endif + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); + + if (!plaintext)BRIDGE::print(F("\"target_fw\":\""), output); + else BRIDGE::print(F("Target Firmware: "), output); + BRIDGE::print(CONFIG::GetFirmwareTargetName(), output); + if (!plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); #ifdef DEBUG_ESP3D + if (!plaintext)BRIDGE::print(F("\"debug\":\""), output); + else BRIDGE::print(F("Debug: "), output); BRIDGE::print(F("Debug Enabled :"), output); #ifdef DEBUG_OUTPUT_SPIFFS - BRIDGE::println(F("SPIFFS"), output); + BRIDGE::print(F("SPIFFS"), output); #endif #ifdef DEBUG_OUTPUT_SD - BRIDGE::println(F("SD"), output); + BRIDGE::print(F("SD"), output); #endif #ifdef DEBUG_OUTPUT_SERIAL - BRIDGE::println(F("serial"), output); + BRIDGE::print(F("serial"), output); #endif #ifdef DEBUG_OUTPUT_TCP - BRIDGE::println(F("TCP"), output); + BRIDGE::print(F("TCP"), output); #endif + if (plaintext)BRIDGE::print(F("\","), output); + else BRIDGE::print(F("\n"), output); #endif + if (!plaintext)BRIDGE::print(F("\"fw\":\""), output); + else BRIDGE::print(F("FW version: "), output); + BRIDGE::print(FW_VERSION, output); + if (!plaintext)BRIDGE::print(F("\"}"), output); + else BRIDGE::print(F("\n"), output); } diff --git a/esp3d/config.h b/esp3d/config.h index 81a8d7b9..6b70a55f 100644 --- a/esp3d/config.h +++ b/esp3d/config.h @@ -19,15 +19,47 @@ */ //definition -#define REPETIER 0 -#define REPETIER4DV 1 +#define UNKNOWN_FW 0 +#define REPETIER4DV 1 #define MARLIN 2 #define MARLINKIMBRA 3 -#define SMOOTHIEWARE 4 +#define SMOOTHIEWARE 4 +#define REPETIER 5 -//FIRMWARE_TARGET: the targeted FW, can be REPETIER (Original Repetier)/ REPETIER4DV (Repetier for Davinci) / MARLIN (Marlin)/ SMOOTHIEWARE (Smoothieware) -#define FIRMWARE_TARGET MARLIN +#ifdef ARDUINO_ARCH_ESP32 +#include "FS.h" +#include "SPIFFS.h" +#define WIFI_NONE_SLEEP WIFI_PS_NONE +#define WIFI_MODEM_SLEEP WIFI_PS_MODEM +#define WIFI_PHY_MODE_11B WIFI_PROTOCOL_11B +#define WIFI_PHY_MODE_11G WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G +#define WIFI_PHY_MODE_11N WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N +#define AUTH_OPEN WIFI_AUTH_OPEN +#define AUTH_WEP WIFI_AUTH_WEP +#define AUTH_WPA_PSK WIFI_AUTH_WPA_PSK +#define AUTH_WPA2_PSK WIFI_AUTH_WPA2_PSK +#define AUTH_WPA_WPA2_PSK WIFI_AUTH_WPA_WPA2_PSK +#define ENC_TYPE_NONE AUTH_OPEN +#define FS_FILE File +#define FS_DIR File +#define ESP_SERIAL_OUT Serial +#define SD_FILE_READ FILE_READ +#define SPIFFS_FILE_READ FILE_READ +#define SD_FILE_WRITE FILE_WRITE +#define SPIFFS_FILE_WRITE FILE_WRITE +extern HardwareSerial Serial2; +#else +#define FS_DIR fs::Dir +#define FS_FILE fs::File +#define ESP_SERIAL_OUT Serial +#define SD_FILE_READ FILE_READ +#define SPIFFS_FILE_READ "r" +#define SD_FILE_WRITE FILE_WRITE +#define SPIFFS_FILE_WRITE "w" +#endif + +#define MAX_FW_ID REPETIER //number of clients allowed to use data port at once #define MAX_SRV_CLIENTS 1 @@ -41,7 +73,16 @@ #define SSDP_FEATURE //NETBIOS_FEATURE: this feature is a discovery protocol, supported on Windows out of the box -//#define NETBIOS_FEATURE +#define NETBIOS_FEATURE + +#ifdef ARDUINO_ARCH_ESP32 +#ifdef SSDP_FEATURE +#undef SSDP_FEATURE +#endif +#ifdef NETBIOS_FEATURE +#undef NETBIOS_FEATURE +#endif +#endif //CAPTIVE_PORTAL_FEATURE: In SoftAP redirect all unknow call to main page #define CAPTIVE_PORTAL_FEATURE @@ -78,86 +119,97 @@ //STATUS_MSG_FEATURE: catch the status msg and filter it to specific table #define STATUS_MSG_FEATURE -//TEMP_MONITORING_FEATURE : catch the specific answer and store it to variable -#define TEMP_MONITORING_FEATURE -//SPEED_MONITORING_FEATURE : catch the specific answer and store it to variable -#define SPEED_MONITORING_FEATURE -//POS_MONITORING_FEATURE : catch the specific answer and store it to variable -#define POS_MONITORING_FEATURE -//FLOW_MONITORING_FEATURE : catch the specific answer and store it to variable -#define FLOW_MONITORING_FEATURE - - //Serial rx buffer size is 256 but can be extended #define SERIAL_RX_BUFFER_SIZE 512 -//DEBUG Flag do not do this when connected to printer unless you know what you are doing!!! +#ifdef ARDUINO_ARCH_ESP32 +#ifdef SSDP_FEATURE +#undef SSDP_FEATURE +#endif +#ifdef NETBIOS_FEATURE +#undef NETBIOS_FEATURE +#endif +#endif + + +//DEBUG Flag do not do this when connected to printer !!! +//be noted all upload may failed if enabled //#define DEBUG_ESP3D //#define DEBUG_OUTPUT_SPIFFS -//#define DEBUG_OUTPUT_SD //#define DEBUG_OUTPUT_SERIAL //#define DEBUG_OUTPUT_TCP //store performance result in storestring variable : info_msg / status_msg //#define DEBUG_PERFORMANCE #define DEBUG_PERF_VARIABLE (web_interface->info_msg) +/* +#ifndef FS_NO_GLOBALS +#define FS_NO_GLOBALS +#endif +#include +#define DEBUG_ESP3D(string) { FS_FILE logfile = SPIFFS.open("/log.txt", "a+");logfile.print(string);logfile.close();} +*/ #ifdef DEBUG_ESP3D #ifdef DEBUG_OUTPUT_SPIFFS - /*#ifdef SDCARD_FEATURE - #ifndef FS_NO_GLOBALS - #define FS_NO_GLOBALS - #endif - #endif*/ - #include - #define DEBUG_PIPE NO_PIPE - #define LOG(string) {FSFILE logfile = SPIFFS.open("/log.txt", "a+");logfile.print(string);logfile.close();} +#ifndef FS_NO_GLOBALS +#define FS_NO_GLOBALS +#endif +#include +#define DEBUG_PIPE NO_PIPE +#define LOG(string) { FS_FILE logfile = SPIFFS.open("/log.txt", "a+");logfile.print(string);logfile.close();} #endif #ifdef DEBUG_OUTPUT_SERIAL - #define LOG(string) {Serial.print(string);} - #define DEBUG_PIPE SERIAL_PIPE +#define LOG(string) {ESP_SERIAL_OUT.print(string);} +#define DEBUG_PIPE SERIAL_PIPE #endif #ifdef DEBUG_OUTPUT_TCP - #include "bridge.h" - #define LOG(string) {BRIDGE::send2TCP(string);} - #define DEBUG_PIPE TCP_PIPE +#include "bridge.h" +#define LOG(string) {BRIDGE::send2TCP(string);} +#define DEBUG_PIPE TCP_PIPE #endif #else #define LOG(string) {} #define DEBUG_PIPE NO_PIPE #endif -#ifdef SDCARD_FEATURE -#define FSFILE fs::File -#define FSDIR fs::Dir -#define FSINFO fs::FSInfo -#else -#define FSFILE File -#define FSDIR fs::Dir -#define FSINFO FSInfo -#endif - #ifndef CONFIG_h #define CONFIG_h #include +#ifdef ARDUINO_ARCH_ESP8266 extern "C" { #include "user_interface.h" } -#include "wifi.h" +#else +//Nothing here +#endif +#include "wificonf.h" //version and sources location -#define FW_VERSION "0.9.78" +#define FW_VERSION "0.9.99" #define REPOSITORY "https://github.com/luc-github/ESP3D" typedef enum { - NO_PIPE = 0, - SERIAL_PIPE = 2, + NO_PIPE = 0, + SERIAL_PIPE = 2, SERIAL1_PIPE = 3, #ifdef TCP_IP_DATA_FEATURE - TCP_PIPE = 4, + TCP_PIPE = 4, #endif WEB_PIPE = 5 - } tpipe; +} tpipe; + +typedef enum { + LEVEL_GUEST = 0, + LEVEL_USER = 1, + LEVEL_ADMIN = 2 +} level_authenticate_type; + + +#define NO_SD 0 +#define SD_DIRECTORY 1 +#define EXT_DIRECTORY 2 + //flags #define AP_MODE 1 @@ -196,14 +248,29 @@ typedef enum { #define EP_AP_GATEWAY_VALUE 324 //4 bytes xxx.xxx.xxx.xxx #define EP_AP_IP_MODE 329 //1 byte = flag #define EP_AP_PHY_MODE 330 //1 byte = flag -//next available is 330 -//space left 512 - 330 = 18 +#define EP_DATA_STRING 331 //129 bytes 128+1 = string ; warning does not support multibyte char like chinese +#define EP_REFRESH_PAGE_TIME2 460 //1 bytes = flag +#define EP_TARGET_FW 461 //1 bytes = flag +#define EP_TIMEZONE 462//1 bytes = flag +#define EP_TIME_ISDST 463//1 bytes = flag +#define EP_TIME_SERVER1 464//129 bytes 128+1 = string ; warning does not support multibyte char like chinese +#define EP_TIME_SERVER2 593 //129 bytes 128+1 = string ; warning does not support multibyte char like chinese +#define EP_TIME_SERVER3 722 //129 bytes 128+1 = string ; warning does not support multibyte char like chinese +#define EP_IS_DIRECT_SD 850//1 bytes = flag +#define EP_PRIMARY_SD 851//1 bytes = flag +#define EP_SECONDARY_SD 852//1 bytes = flag +#define EP_DIRECT_SD_CHECK 853//1 bytes = flag +#define EP_SD_CHECK_UPDATE_AT_BOOT 854//1 bytes = flag + +#define LAST_EEPROM_ADDRESS 855 +//next available is 855 +//space left 1024 - 855 = 169 //default values #define DEFAULT_WIFI_MODE AP_MODE -const char DEFAULT_AP_SSID [] PROGMEM = "ESP8266"; +const char DEFAULT_AP_SSID [] PROGMEM = "ESP3D"; const char DEFAULT_AP_PASSWORD [] PROGMEM = "12345678"; -const char DEFAULT_STA_SSID [] PROGMEM = "ESP8266"; +const char DEFAULT_STA_SSID [] PROGMEM = "ESP3D"; const char DEFAULT_STA_PASSWORD [] PROGMEM = "12345678"; const byte DEFAULT_STA_IP_MODE = DHCP_MODE; const byte DEFAULT_AP_IP_MODE = STATIC_IP_MODE; @@ -229,24 +296,105 @@ const char DEFAULT_ADMIN_PWD [] PROGMEM = "admin"; const char DEFAULT_USER_PWD [] PROGMEM = "user"; const char DEFAULT_ADMIN_LOGIN [] PROGMEM = "admin"; const char DEFAULT_USER_LOGIN [] PROGMEM = "user"; +const char DEFAULT_TIME_SERVER1 [] PROGMEM = "time.nist.gov"; +const char DEFAULT_TIME_SERVER2 [] PROGMEM = "0.pool.ntp.org"; +const char DEFAULT_TIME_SERVER3 [] PROGMEM = "1.pool.ntp.org"; +#define DEFAULT_TIME_ZONE 1 +#define DEFAULT_TIME_DST 0 +#define DEFAULT_PRIMARY_SD 1 +#define DEFAULT_SECONDARY_SD 2 +#define DEFAULT_DIRECT_SD_CHECK 0 +#define DEFAULT_SD_CHECK_UPDATE_AT_BOOT 1 +#define DEFAULT_IS_DIRECT_SD 0 + + + + +const uint16_t Setting[][2] = { + {EP_WIFI_MODE, LEVEL_ADMIN},//0 + {EP_STA_SSID, LEVEL_ADMIN},//1 + {EP_STA_PASSWORD, LEVEL_ADMIN},//2 + {EP_STA_IP_MODE, LEVEL_ADMIN},//3 + {EP_STA_IP_VALUE, LEVEL_ADMIN},//4 + {EP_STA_MASK_VALUE, LEVEL_ADMIN},//5 + {EP_STA_GATEWAY_VALUE, LEVEL_ADMIN},//6 + {EP_BAUD_RATE, LEVEL_ADMIN},//7 + {EP_STA_PHY_MODE, LEVEL_ADMIN},//8 + {EP_SLEEP_MODE, LEVEL_ADMIN},//9 + {EP_CHANNEL, LEVEL_ADMIN},//10 + {EP_AUTH_TYPE, LEVEL_ADMIN},//11 + {EP_SSID_VISIBLE, LEVEL_ADMIN},//12 + {EP_WEB_PORT, LEVEL_ADMIN},//13 + {EP_DATA_PORT, LEVEL_ADMIN},//14 + {EP_REFRESH_PAGE_TIME, LEVEL_USER},//15 + {EP_HOSTNAME, LEVEL_ADMIN},//16 + {EP_XY_FEEDRATE, LEVEL_USER},//17 + {EP_Z_FEEDRATE, LEVEL_USER},//18 + {EP_E_FEEDRATE, LEVEL_USER},//19 + {EP_ADMIN_PWD, LEVEL_ADMIN},//20 + {EP_USER_PWD, LEVEL_USER},//21 + {EP_AP_SSID, LEVEL_ADMIN},//22 + {EP_AP_PASSWORD, LEVEL_ADMIN},//23 + {EP_AP_IP_VALUE, LEVEL_ADMIN},//24 + {EP_AP_MASK_VALUE, LEVEL_ADMIN},//25 + {EP_AP_GATEWAY_VALUE, LEVEL_ADMIN},//26 + {EP_AP_IP_MODE, LEVEL_ADMIN},//27 + {EP_AP_PHY_MODE, LEVEL_ADMIN},//28 + {EP_DATA_STRING, LEVEL_USER},//29 + {EP_REFRESH_PAGE_TIME2, LEVEL_USER},//30 + {EP_TARGET_FW, LEVEL_USER},//31 + {EP_TIMEZONE, LEVEL_USER},//32 + {EP_TIME_ISDST, LEVEL_USER},//33 + {EP_TIME_SERVER1, LEVEL_USER},//34 + {EP_TIME_SERVER2, LEVEL_USER},//35 + {EP_TIME_SERVER3, LEVEL_USER},//36 + {EP_IS_DIRECT_SD, LEVEL_USER},//37 + {EP_PRIMARY_SD, LEVEL_USER},//38 + {EP_SECONDARY_SD, LEVEL_USER},//39 + {EP_DIRECT_SD_CHECK, LEVEL_USER}, //40 + {EP_SD_CHECK_UPDATE_AT_BOOT, LEVEL_USER} //41 +}; +#define AUTH_ENTRY_NB 42 +//values +#define DEFAULT_MAX_REFRESH 120 +#define DEFAULT_MIN_REFRESH 0 +#define DEFAULT_MAX_XY_FEEDRATE 9999 +#define DEFAULT_MIN_XY_FEEDRATE 1 +#define DEFAULT_MAX_Z_FEEDRATE 9999 +#define DEFAULT_MIN_Z_FEEDRATE 1 +#define DEFAULT_MAX_E_FEEDRATE 9999 +#define DEFAULT_MIN_E_FEEDRATE 1 +#define DEFAULT_MAX_WEB_PORT 65001 +#define DEFAULT_MIN_WEB_PORT 1 +#define DEFAULT_MAX_DATA_PORT 65001 +#define DEFAULT_MIN_DATA_PORT 1 + +#define MAX_TRY 2000 + //sizes -#define EEPROM_SIZE 512 //max is 512 +#define EEPROM_SIZE 1024 //max is 1024 #define MAX_SSID_LENGTH 32 #define MIN_SSID_LENGTH 1 #define MAX_PASSWORD_LENGTH 64 -#define MIN_PASSWORD_LENGTH 8 +//min size of password is 0 or upper than 8 char +//so let set min is 0 +#define MIN_PASSWORD_LENGTH 0 #define MAX_LOCAL_PASSWORD_LENGTH 16 #define MIN_LOCAL_PASSWORD_LENGTH 1 +#define MAX_DATA_LENGTH 128 +#define MIN_DATA_LENGTH 0 #define IP_LENGTH 4 #define INTEGER_LENGTH 4 #define MAX_HOSTNAME_LENGTH 32 +#define MIN_HOSTNAME_LENGTH 1 #define WL_MAC_ADDR_LENGTH 6 class CONFIG { public: + static bool is_direct_sd; static bool read_string(int pos, char byte_buffer[], int size_max); static bool read_string(int pos, String & sbuffer, int size_max); static bool read_buffer(int pos, byte byte_buffer[], int size_buffer); @@ -256,18 +404,30 @@ public: static bool write_buffer(int pos, const byte * byte_buffer, int size_buffer); static bool write_byte(int pos, const byte value); static bool reset_config(); - static void print_config(tpipe output); + static void print_config(tpipe output, bool plaintext); + static bool SetFirmwareTarget(uint8_t fw); + static void InitFirmwareTarget(); + static void InitDirectSD(); + static void InitPins(); + static bool InitBaudrate(); + static bool InitExternalPorts(); + static bool check_update_presence(); + static uint8_t GetFirmwareTarget(); + static const char* GetFirmwareTargetName(); + static const char* GetFirmwareTargetShortName(); static bool isHostnameValid(const char * hostname); static bool isSSIDValid(const char * ssid); static bool isPasswordValid(const char * password); static bool isLocalPasswordValid(const char * password); static bool isIPValid(const char * IP); static char * intTostr(int value); - static String formatBytes(size_t bytes); + static String formatBytes(uint32_t bytes); static char * mac2str(uint8_t mac [WL_MAC_ADDR_LENGTH]); static byte split_ip (const char * ptr,byte * part); static void esp_restart(); static void flashfromSD(const char * Filename, int flashtype); +private: + static uint8_t FirmwareTarget; }; #endif diff --git a/esp3d/data/404.htm b/esp3d/data/404.htm new file mode 100644 index 00000000..a1dec29a --- /dev/null +++ b/esp3d/data/404.htm @@ -0,0 +1,18 @@ + + +404 page + + +
+

+ + + + +404 Error, unknown page!

+

What are you doing here ?

+You are not supposed to find this location... +
+ + + diff --git a/esp3d/data/404.tpl b/esp3d/data/404.tpl deleted file mode 100644 index 3f3c993f..00000000 --- a/esp3d/data/404.tpl +++ /dev/null @@ -1,30 +0,0 @@ - - -Redirecting... - - -
Unknown page - you will be redirected... -

-if not redirected, click here -

- - - -
- - - diff --git a/esp3d/data/config_ap.tpl b/esp3d/data/config_ap.tpl deleted file mode 100644 index 2c59ec2d..00000000 --- a/esp3d/data/config_ap.tpl +++ /dev/null @@ -1,65 +0,0 @@ -$INCLUDE[header.inc]$ -
-
Access Point
-
-
-

-
-
-
-

-
-
-

-
-

-
-

-
- -
-
-

-
-

-
-

-
-
- -
-
- -
-
- -$INCLUDE[footer.inc]$ - diff --git a/esp3d/data/config_sta.tpl b/esp3d/data/config_sta.tpl deleted file mode 100644 index 19955f02..00000000 --- a/esp3d/data/config_sta.tpl +++ /dev/null @@ -1,66 +0,0 @@ -$INCLUDE[header.inc]$ -
-
Station
-
-
-
- - - -$AVAILABLE_AP[]$ -
$AVAILABLE_AP_NB_ITEMS$ AP(s) available
#SSIDSignalProtected
#$ROW_NUMBER$$AP_SSID$$AP_SIGNAL$$IS_PROTECTED$
-
-

-

-
-

-
-

-
-

-
- -
-
-
-

-
-

-
-

-
-
- -
-
- -
-
- -$INCLUDE[footer.inc]$ diff --git a/esp3d/data/css2.inc b/esp3d/data/css2.inc deleted file mode 100644 index ae0d19b3..00000000 --- a/esp3d/data/css2.inc +++ /dev/null @@ -1,27 +0,0 @@ - diff --git a/esp3d/data/footer.inc b/esp3d/data/footer.inc deleted file mode 100644 index 3bdf08d6..00000000 --- a/esp3d/data/footer.inc +++ /dev/null @@ -1,6 +0,0 @@ -$SERVICE_PAGE$ -

-
-
- - diff --git a/esp3d/data/header.inc b/esp3d/data/header.inc deleted file mode 100644 index 3f7c4361..00000000 --- a/esp3d/data/header.inc +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - -$PAGE_TITLE$ - -
ESP3D powered-GPL licensed
- - - - - - - - - - - - - - diff --git a/esp3d/data/home.tpl b/esp3d/data/home.tpl deleted file mode 100644 index 0ad8c982..00000000 --- a/esp3d/data/home.tpl +++ /dev/null @@ -1,55 +0,0 @@ -$INCLUDE[header.inc]$ -
-
System
-

-
-
-
-

-

-

-

-
-
-
-
-
-
-
-
Access Point ($AP_STATUS_ENABLED$)
-

-
-
-
-
-
-
-
-
-
-
- - - -$CONNECTED_STATIONS[]$ -
$CONNECTED_STATIONS_NB_ITEMS$ connected station(s)
#MacIP
#$ROW_NUMBER$$MAC_CONNECTED$$IP_CONNECTED$
-
-
-
-
-
Station ($STA_STATUS_ENABLED$)
-

-
-
-
-
-
-
-
-
-
-
-
-
-$INCLUDE[footer.inc]$ - diff --git a/esp3d/data/index.html.gz b/esp3d/data/index.html.gz new file mode 100644 index 00000000..c502eb64 Binary files /dev/null and b/esp3d/data/index.html.gz differ diff --git a/esp3d/data/login.tpl b/esp3d/data/login.tpl deleted file mode 100644 index 705e079b..00000000 --- a/esp3d/data/login.tpl +++ /dev/null @@ -1,21 +0,0 @@ -$INCLUDE[header.inc]$ -
-
Log in
-
-
-

- -
-

-
- -
-
- -
-
-$INCLUDE[footer.inc]$ diff --git a/esp3d/data/macrocfg.json b/esp3d/data/macrocfg.json new file mode 100644 index 00000000..07b5bd33 --- /dev/null +++ b/esp3d/data/macrocfg.json @@ -0,0 +1,74 @@ +[ + { + "name": "", + "glyph": "", + "filename": "", + "target": "", + "class": "", + "index": 0 + }, + { + "name": "", + "glyph": "", + "filename": "", + "target": "", + "class": "", + "index": 1 + }, + { + "name": "", + "glyph": "", + "filename": "", + "target": "", + "class": "", + "index": 2 + }, + { + "name": "", + "glyph": "", + "filename": "", + "target": "", + "class": "", + "index": 3 + }, + { + "name": "", + "glyph": "", + "filename": "", + "target": "", + "class": "", + "index": 4 + }, + { + "name": "", + "glyph": "", + "filename": "", + "target": "", + "class": "", + "index": 5 + }, + { + "name": "", + "glyph": "", + "filename": "", + "target": "", + "class": "", + "index": 6 + }, + { + "name": "", + "glyph": "", + "filename": "", + "target": "", + "class": "", + "index": 7 + }, + { + "name": "", + "glyph": "", + "filename": "", + "target": "", + "class": "", + "index": 8 + } +] \ No newline at end of file diff --git a/esp3d/data/password.tpl b/esp3d/data/password.tpl deleted file mode 100644 index 6ae1d619..00000000 --- a/esp3d/data/password.tpl +++ /dev/null @@ -1,111 +0,0 @@ -$INCLUDE[header.inc]$ -
-
Change Password
-
-
-

-
-

-
- -
-
- -
-
- -$INCLUDE[footer.inc]$ diff --git a/esp3d/data/printer.tpl b/esp3d/data/printer.tpl deleted file mode 100644 index b7ea3b90..00000000 --- a/esp3d/data/printer.tpl +++ /dev/null @@ -1,870 +0,0 @@ -$INCLUDE[header.inc]$ -$INCLUDE[css2.inc]$ -
-
  Control
-
- - - - - - -
- -
- -
- -
- - - - - - - - - -
0300% -    -
- - - - - - -
Status:
-
-
-
   - - -
-
- - - - - - - - - -
0300% -       
-
-
-
- -
-
  Command
-
- - -
- -
-
- -
-
  Information
-
-
-
-"; - - -
-
-
-
-
-
  Error
-
-
-
-"; - - -
-
-
-
-
-
  Status
-
-
-
-"; - - -
-
-
-
-
-
  Print
-
- - - - - - - - -
- - -   
-
-
-
-
  Jog
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - X - - - - - - - - - - -
- -10
- -1
- -0.1
-
- - Y - - - - - - - - - - - -
- -10 -
- -1 -
- -0.1 -
-
- - - - - - -
- 10 - 1 - 0.1 -
-
- - - - - -
- -0.1 - -1 - - -10 -
-
Z
- - - - - - - - - - - -
- 0.1
- 1
- 10
-
- Z - - - - - - - - - - -
- 0.1
- 1
- 10
-
-
-
-
-
  SD Files
-
- -   -

-
- -
- -
 
-
-
TypeNameSize
-
- -
-
-
- - -$INCLUDE[footer.inc]$ diff --git a/esp3d/data/restart.tpl b/esp3d/data/restart.tpl deleted file mode 100644 index 89e84af9..00000000 --- a/esp3d/data/restart.tpl +++ /dev/null @@ -1,27 +0,0 @@ - - -Restarting... - - -
Restarting, please wait.... -
- -
- - - diff --git a/esp3d/data/system.tpl b/esp3d/data/system.tpl deleted file mode 100644 index a6da1266..00000000 --- a/esp3d/data/system.tpl +++ /dev/null @@ -1,108 +0,0 @@ -$INCLUDE[header.inc]$ -$INCLUDE[css2.inc]$ -
-
System
-
-
-
-
-
-
-
-
-

-
-

-
- -
-
- -
-
-
-
Firmware Update
-
- - - - -
-
- -
- -$INCLUDE[footer.inc]$ diff --git a/esp3d/data/tags.json b/esp3d/data/tags.json deleted file mode 100644 index 5aebc12c..00000000 --- a/esp3d/data/tags.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "WEB_ADDRESS":"localhost", - "PAGE_TITLE":"Testing things..." -} diff --git a/esp3d/esp3d.ino b/esp3d/esp3d.ino index 1337d23f..24bec6aa 100644 --- a/esp3d/esp3d.ino +++ b/esp3d/esp3d.ino @@ -23,71 +23,87 @@ Main author: luc lebosse */ -//be sure correct IDE and settings are used for ESP8266 -#ifndef ARDUINO_ARCH_ESP8266 -#error Oops! Make sure you have 'ESP8266' compatible board selected from the 'Tools -> Boards' menu. +//be sure correct IDE and settings are used for ESP8266 or ESP32 +#if !(defined( ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)) +#error Oops! Make sure you have 'ESP8266 or ESP32' compatible board selected from the 'Tools -> Boards' menu. #endif #include #include "config.h" -#include "wifi.h" +#include "wificonf.h" #include "bridge.h" #include "webinterface.h" #include "command.h" -#include -#include -#include +#ifdef ARDUINO_ARCH_ESP8266 +#include "ESP8266WiFi.h" #ifdef MDNS_FEATURE #include #endif +#include +#else +#include +#ifdef MDNS_FEATURE +#include +#endif +#include "esp_wifi.h" +#include +#include "FS.h" +#include "SPIFFS.h" +#include "Update.h" +#endif +#include + + #ifdef CAPTIVE_PORTAL_FEATURE #include -const byte DNS_PORT = 53; -DNSServer dnsServer; +extern DNSServer dnsServer; #endif #ifdef SSDP_FEATURE +#ifdef ARDUINO_ARCH_ESP8266 #include +#else +//#include +#endif #endif #ifdef NETBIOS_FEATURE +#ifdef ARDUINO_ARCH_ESP8266 #include +#else +//#include #endif +#endif +#ifndef FS_NO_GLOBALS +#define FS_NO_GLOBALS +#endif +#include void setup() { bool breset_config=false; - long baud_rate=0; + bool directsd_check = false; web_interface = NULL; #ifdef TCP_IP_DATA_FEATURE data_server = NULL; #endif // init: #ifdef DEBUG_ESP3D - Serial.begin(DEFAULT_BAUD_RATE); + if (ESP_SERIAL_OUT.baudRate() != DEFAULT_BAUD_RATE)ESP_SERIAL_OUT.begin(DEFAULT_BAUD_RATE); delay(2000); LOG("\r\nDebug Serial set\r\n") #endif //WiFi.disconnect(); WiFi.mode(WIFI_OFF); + delay(8000); + CONFIG::InitDirectSD(); + CONFIG::InitPins(); #ifdef RECOVERY_FEATURE delay(8000); //check if reset config is requested - pinMode(RESET_CONFIG_PIN, INPUT); if (digitalRead(RESET_CONFIG_PIN)==0) { breset_config=true; //if requested =>reset settings } #endif //check if EEPROM has value - if ( CONFIG::read_buffer(EP_BAUD_RATE, (byte *)&baud_rate , INTEGER_LENGTH)&&CONFIG::read_buffer(EP_WEB_PORT, (byte *)&(wifi_config.iweb_port) , INTEGER_LENGTH)&&CONFIG::read_buffer(EP_DATA_PORT, (byte *)&(wifi_config.idata_port) , INTEGER_LENGTH)) { - //check if baud value is one of allowed ones - if ( ! (baud_rate==9600 || baud_rate==19200 ||baud_rate==38400 ||baud_rate==57600 ||baud_rate==115200 ||baud_rate==230400 ||baud_rate==250000) ) { - LOG("Error for EEPROM baud rate\r\n") - breset_config=true; //baud rate is incorrect =>reset settings - } - if (wifi_config.iweb_port<1 ||wifi_config.iweb_port>65001 || wifi_config.idata_port <1 || wifi_config.idata_port >65001) { - breset_config=true; //out of range =>reset settings - LOG("Error for EEPROM port values\r\n") - } - - } else { + if ( !CONFIG::InitBaudrate() || !CONFIG::InitExternalPorts()) { breset_config=true; //cannot access to config settings=> reset settings LOG("Error no EEPROM access\r\n") } @@ -95,114 +111,78 @@ void setup() //reset is requested if(breset_config) { //update EEPROM with default settings - Serial.begin(DEFAULT_BAUD_RATE); - Serial.setRxBufferSize(SERIAL_RX_BUFFER_SIZE); + if (ESP_SERIAL_OUT.baudRate() != DEFAULT_BAUD_RATE)ESP_SERIAL_OUT.begin(DEFAULT_BAUD_RATE); +#ifdef ARDUINO_ARCH_ESP8266 + ESP_SERIAL_OUT.setRxBufferSize(SERIAL_RX_BUFFER_SIZE); +#endif delay(2000); - Serial.println(F("M117 ESP EEPROM reset")); + ESP_SERIAL_OUT.println(F("M117 ESP EEPROM reset")); #ifdef DEBUG_ESP3D - CONFIG::print_config(DEBUG_PIPE); + CONFIG::print_config(DEBUG_PIPE, true); delay(1000); #endif CONFIG::reset_config(); delay(1000); //put some default value to a void some exception at first start WiFi.mode(WIFI_AP); +#ifdef ARDUINO_ARCH_ESP8266 WiFi.setPhyMode(WIFI_PHY_MODE_11G); +#else + esp_wifi_set_protocol(ESP_IF_WIFI_AP, WIFI_PHY_MODE_11G); +#endif CONFIG::esp_restart(); } #if defined(DEBUG_ESP3D) && defined(DEBUG_OUTPUT_SERIAL) LOG("\r\n"); delay(500); - Serial.flush(); + ESP_SERIAL_OUT.flush(); #endif - //setup serial - Serial.begin(baud_rate); - Serial.setRxBufferSize(SERIAL_RX_BUFFER_SIZE); - delay(1000); - LOG("Serial Set\r\n"); - wifi_config.baud_rate=baud_rate; + //get target FW + CONFIG::InitFirmwareTarget(); //Update is done if any so should be Ok - SPIFFS.begin(); - +#ifdef ARDUINO_ARCH_ESP32 + SPIFFS.begin(true); +#else + SPIFFS.begin(); +#endif + //setup wifi according settings if (!wifi_config.Setup()) { - Serial.println(F("M117 Safe mode 1")); + ESP_SERIAL_OUT.println(F("M117 Safe mode 1")); //try again in AP mode - if (!wifi_config.Setup(true)) { - Serial.println(F("M117 Safe mode 2")); + if (!wifi_config.Setup(true)) { + ESP_SERIAL_OUT.println(F("M117 Safe mode 2")); wifi_config.Safe_Setup(); } } delay(1000); - //start web interface - web_interface = new WEBINTERFACE_CLASS(wifi_config.iweb_port); - //here the list of headers to be recorded - const char * headerkeys[] = {"Cookie"} ; - size_t headerkeyssize = sizeof(headerkeys)/sizeof(char*); - //ask server to track these headers - web_interface->WebServer.collectHeaders(headerkeys, headerkeyssize ); -#ifdef CAPTIVE_PORTAL_FEATURE - if (WiFi.getMode()!=WIFI_STA ) { - // if DNSServer is started with "*" for domain name, it will reply with - // provided IP to all DNS request - dnsServer.start(DNS_PORT, "*", WiFi.softAPIP()); + //setup servers + if (!wifi_config.Enable_servers()) { + ESP_SERIAL_OUT.println(F("M117 Error enabling servers")); } -#endif - web_interface->WebServer.begin(); -#ifdef TCP_IP_DATA_FEATURE - //start TCP/IP interface - data_server = new WiFiServer (wifi_config.idata_port); - data_server->begin(); - data_server->setNoDelay(true); -#endif - -#ifdef MDNS_FEATURE - // Check for any mDNS queries and send responses - wifi_config.mdns.addService("http", "tcp", wifi_config.iweb_port); -#endif -#if defined(SSDP_FEATURE) || defined(NETBIOS_FEATURE) - String shost; - if (!CONFIG::read_string(EP_HOSTNAME, shost , MAX_HOSTNAME_LENGTH)) { - shost=wifi_config.get_default_hostname(); - } -#endif -#ifdef SSDP_FEATURE - String stmp; - SSDP.setSchemaURL("description.xml"); - SSDP.setHTTPPort( wifi_config.iweb_port); - SSDP.setName(shost.c_str()); - stmp=String(ESP.getChipId()); - SSDP.setSerialNumber(stmp.c_str()); - SSDP.setURL("/"); - SSDP.setModelName("ESP8266 01"); - SSDP.setModelNumber("01"); - SSDP.setModelURL("http://espressif.com/en/products/esp8266/"); - SSDP.setManufacturer("Espressif Systems"); - SSDP.setManufacturerURL("http://espressif.com"); - SSDP.setDeviceType("upnp:rootdevice"); - SSDP.begin(); -#endif -#ifdef NETBIOS_FEATURE - NBNS.begin(shost.c_str()); -#endif LOG("Setup Done\r\n"); } + //main loop void loop() { + //be sure wifi is on to proceed wifi function + if (WiFi.getMode()!=WIFI_OFF ) { #ifdef CAPTIVE_PORTAL_FEATURE - if (WiFi.getMode()!=WIFI_STA ) { - dnsServer.processNextRequest(); - } + if (WiFi.getMode()!=WIFI_STA ) { + dnsServer.processNextRequest(); + } #endif //web requests - web_interface->WebServer.handleClient(); + web_interface->web_server.handleClient(); #ifdef TCP_IP_DATA_FEATURE - BRIDGE::processFromTCP2Serial(); + BRIDGE::processFromTCP2Serial(); #endif - BRIDGE::processFromSerial2TCP(); + } + BRIDGE::processFromSerial2TCP(); + //in case of restart requested if (web_interface->restartmodule) { CONFIG::esp_restart(); } diff --git a/esp3d/esp3d.ino.nodemcu.bin b/esp3d/esp3d.ino.nodemcu.bin deleted file mode 100644 index 19532b13..00000000 Binary files a/esp3d/esp3d.ino.nodemcu.bin and /dev/null differ diff --git a/esp3d/nofile.h b/esp3d/nofile.h new file mode 100644 index 00000000..e2fff90d --- /dev/null +++ b/esp3d/nofile.h @@ -0,0 +1,326 @@ +/* + nofile.h - ESP3D data file + + Copyright (c) 2014 Luc Lebosse. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +//data generated by https://github.com/AraHaan/bin2c +//bin2c Conversion Tool v0.14.0 - Windows - [FINAL]. +#define PAGE_NOFILES_SIZE 4776 +const char PAGE_NOFILES [] PROGMEM = +{ + + 0x1F, 0x8B, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B, 0xED, 0x5C, 0x7D, 0x93, 0xDA, 0x46, + 0x93, 0xFF, 0x2A, 0xB2, 0x52, 0x36, 0x70, 0x2B, 0x58, 0x49, 0xBC, 0xA3, 0x05, 0x3F, 0x49, 0x1C, + 0x5F, 0x7C, 0xE5, 0xC4, 0x2E, 0xEF, 0xFA, 0xEE, 0xAA, 0xE2, 0x94, 0x4B, 0x48, 0x03, 0xE8, 0xB1, + 0x90, 0x74, 0xD2, 0xB0, 0xBB, 0x98, 0xF0, 0xDD, 0xAF, 0x7B, 0x5E, 0xA4, 0x91, 0x10, 0x2C, 0xBB, + 0x49, 0x9E, 0x3C, 0x7F, 0x24, 0x78, 0x11, 0xCC, 0x4C, 0xF7, 0xF4, 0xF4, 0x74, 0xFF, 0xBA, 0xA7, + 0x87, 0xCA, 0xD5, 0x8A, 0xAE, 0xC3, 0xD9, 0xD5, 0x8A, 0xB8, 0xFE, 0xEC, 0x2A, 0xA3, 0xDB, 0x90, + 0xCC, 0xB0, 0x65, 0xB7, 0x88, 0x23, 0xDA, 0x5E, 0xB8, 0xEB, 0x20, 0xDC, 0x4E, 0x32, 0x37, 0xCA, + 0xDA, 0x19, 0x49, 0x83, 0x85, 0xD3, 0x5E, 0x67, 0x6D, 0x4A, 0xEE, 0x69, 0x3B, 0x0B, 0xBE, 0x92, + 0xB6, 0xEB, 0xFF, 0x73, 0x93, 0xD1, 0x89, 0x65, 0x9A, 0xCF, 0x9D, 0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0x12, 0xB7, 0x42, 0x8D, 0xB7, 0x9C, 0x6C, 0xD8, + 0xCB, 0x8F, 0xD7, 0x3F, 0x7C, 0x50, 0x4F, 0x58, 0x98, 0x71, 0x80, 0x78, 0x11, 0x85, 0x4C, 0xE4, + 0x42, 0x7F, 0xF1, 0xFE, 0xDB, 0xEB, 0xEB, 0xFF, 0x79, 0xF7, 0xE1, 0x55, 0xFD, 0x10, 0x8A, 0x43, + 0xAE, 0x3F, 0x7E, 0xF7, 0xD3, 0x9B, 0x9B, 0xE9, 0x16, 0x33, 0xC6, 0xA0, 0x0E, 0xF1, 0x83, 0x07, + 0x4E, 0x5A, 0x70, 0xCC, 0x0A, 0x94, 0x63, 0xD6, 0x8B, 0x17, 0x00, 0xE1, 0xCF, 0xA0, 0x49, 0xBA, + 0x66, 0xD9, 0x02, 0xF6, 0x46, 0xA0, 0x9E, 0x75, 0x22, 0x16, 0x36, 0x02, 0x79, 0xD6, 0x41, 0xA5, + 0xAA, 0x05, 0x67, 0x08, 0x49, 0xCE, 0x5D, 0x10, 0xF9, 0xF1, 0x5D, 0x4D, 0xB4, 0x38, 0x7E, 0xDB, + 0xE1, 0x5C, 0x5D, 0x8A, 0xEB, 0xE4, 0xAB, 0x4B, 0xF1, 0x03, 0x17, 0xF6, 0x3F, 0x96, 0xF9, 0x7F, + 0x4B, 0x13, 0x97, 0xBB, 0x5F, 0x46, 0x00, 0x00 +}; diff --git a/esp3d/storestrings.cpp b/esp3d/storestrings.cpp index c5bcafb9..9f306118 100644 --- a/esp3d/storestrings.cpp +++ b/esp3d/storestrings.cpp @@ -19,7 +19,7 @@ */ #include "storestrings.h" //Constructor -STORESTRINGS_CLASS::STORESTRINGS_CLASS (int maxsize , int maxstringlength) +STORESTRINGS_CLASS::STORESTRINGS_CLASS (int maxsize, int maxstringlength) { //for rolling buffer //if max size is reached then remove oldest one and add the new one diff --git a/esp3d/storestrings.h b/esp3d/storestrings.h index a9012c07..ca89df0a 100644 --- a/esp3d/storestrings.h +++ b/esp3d/storestrings.h @@ -20,7 +20,7 @@ #ifndef STORESTRINGS_h #define STORESTRINGS_h -#include +#include #include "GenLinkedList.h" class STORESTRINGS_CLASS { diff --git a/esp3d/webinterface.cpp b/esp3d/webinterface.cpp index 6c60206c..4359e062 100644 --- a/esp3d/webinterface.cpp +++ b/esp3d/webinterface.cpp @@ -21,12 +21,24 @@ #include #include "config.h" #include "webinterface.h" -#include "wifi.h" +#include "wificonf.h" #include #include #include -#include +#ifndef FS_NO_GLOBALS +#define FS_NO_GLOBALS +#endif +#include +#ifdef ARDUINO_ARCH_ESP8266 +#include "ESP8266WiFi.h" #include +#else +#include +#include +#include "SPIFFS.h" +#include "Update.h" +#endif + #include "GenLinkedList.h" #include "storestrings.h" #include "command.h" @@ -36,9 +48,13 @@ #include #endif +//embedded response file if no files on SPIFFS +#include "nofile.h" + #define MAX_AUTH_IP 10 #define HIDDEN_PASSWORD "********" + typedef enum { UPLOAD_STATUS_NONE = 0, UPLOAD_STATUS_FAILED = 1, @@ -47,2545 +63,41 @@ typedef enum { UPLOAD_STATUS_ONGOING =4 } upload_status_type; -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"; -const char VALUE_11G[] PROGMEM = "11g"; -const char VALUE_NONE[] PROGMEM = "None"; -const char VALUE_LIGHT[] PROGMEM = "Light"; -const char VALUE_MODEM[] PROGMEM = "Modem"; -const char VALUE_ENABLED[] PROGMEM = "Enabled"; -const char VALUE_DISABLED[] PROGMEM = "Disabled"; -const char VALUE_WEP[] PROGMEM = "WEP"; -const char VALUE_WPA[] PROGMEM = "WPA"; -const char VALUE_WPA2[] PROGMEM = "WPA2"; -const char VALUE_WPAWPA2[] PROGMEM = "WPA/WPA2"; -const char VALUE_STARTED[] PROGMEM = "Started"; -const char VALUE_STOPPED[] PROGMEM = "Stopped"; -const char VALUE_NO[] PROGMEM = "No"; -const char VALUE_YES[] PROGMEM = "Yes"; -const char VALUE_CONNECTED[] PROGMEM = "Connected"; -const char VALUE_NO_SSID[] PROGMEM = "SSID not Available!"; -const char VALUE_CONNECTION_FAILED[] PROGMEM = "Connection failed!"; -const char VALUE_CONNECTION_FAILED2[] PROGMEM = "Connection failed! (Wrong Password)"; -const char VALUE_IDLE[] PROGMEM = "Idle"; -const char VALUE_DISCONNECTED[] PROGMEM = "Disconnected"; -const char VALUE_ITEM_VISIBLE[] PROGMEM = "visibility:visible;"; -const char VALUE_ITEM_HIDDEN[] PROGMEM ="visibility:hidden;height:0px;width:0px;padding:0px"; -const char KEY_IP[] PROGMEM ="$IP$"; -const char KEY_WEB_ADDRESS[] PROGMEM ="$WEB_ADDRESS$"; -const char KEY_HOSTNAME[] PROGMEM ="$HOSTNAME$"; -const char KEY_HOSTNAME_VISIBLE[] PROGMEM ="$HOSTNAME_VISIBLE$"; -const char KEY_NOT_APPLICABLE_4_AP[] PROGMEM ="Not applicable for Access Point"; -const char KEY_PAGE_TITLE[] PROGMEM ="$PAGE_TITLE$"; -const char VALUE_HOME[] PROGMEM = "Home"; -const char VALUE_FW_VERSION[] PROGMEM = FW_VERSION; -const char VALUE_NOT_AVAILABLE [] PROGMEM ="Not available"; -const char VALUE_NO_IP [] PROGMEM = "0.0.0.0"; -const char KEY_FILE_NAME [] PROGMEM ="$FILE_NAME$"; -const char KEY_SHORT_FILE_NAME [] PROGMEM ="$SHORT_FILE_NAME$"; -const char KEY_MENU_HOME [] PROGMEM ="$MENU_HOME$"; -const char KEY_MENU_SYSTEM [] PROGMEM ="$MENU_SYSTEM$"; -const char KEY_MENU_AP [] PROGMEM ="$MENU_AP$"; -const char KEY_MENU_STA [] PROGMEM ="$MENU_STA$"; -const char KEY_MENU_PRINTER [] PROGMEM ="$MENU_PRINTER$"; -const char KEY_MENU_SETTINGS [] PROGMEM ="$MENU_SETTINGS$"; -const char KEY_MENU_ADMIN [] PROGMEM ="$MENU_ADMIN$"; -const char KEY_FW_VER [] PROGMEM ="$FW_VER$"; -const char KEY_CHIP_ID [] PROGMEM ="$CHIP_ID$"; -const char KEY_CPU_FREQ [] PROGMEM ="$CPU_FREQ$"; -const char KEY_SDK_VER [] PROGMEM ="$SDK_VER$"; -const char KEY_MDNS_NAME [] PROGMEM = "$MDNS_NAME$"; -const char KEY_MDNS_VISIBLE [] PROGMEM ="$MDNS_VISIBLE$"; -const char KEY_CONNECTED_STATIONS_NB_ITEMS [] PROGMEM = "$CONNECTED_STATIONS_NB_ITEMS$"; -const char KEY_CAPTIVE_PORTAL_STATUS [] PROGMEM = "$CAPTIVE_PORTAL_STATUS$"; -const char KEY_CAPTIVE_PORTAL_VISIBLE [] PROGMEM = "$CAPTIVE_PORTAL_VISIBLE$"; -const char KEY_SSDP_STATUS [] PROGMEM ="$SSDP_STATUS$"; -const char KEY_SSDP_VISIBLE [] PROGMEM ="$SSDP_VISIBLE$"; -const char KEY_NET_PHY [] PROGMEM ="$NET_PHY$"; -const char KEY_SLEEP_MODE [] PROGMEM = "$SLEEP_MODE$"; -const char KEY_BOOT_VER [] PROGMEM = "$BOOT_VER$"; -const char KEY_WEB_PORT [] PROGMEM = "$WEB_PORT$"; -const char KEY_DATA_PORT[] PROGMEM = "$DATA_PORT$"; -const char KEY_BAUD_RATE [] PROGMEM = "$BAUD_RATE$"; -const char KEY_REFRESH_PAGE [] PROGMEM = "$REFRESH_PAGE$"; -const char KEY_AP_STATUS_ENABLED [] PROGMEM = "$AP_STATUS_ENABLED$"; -const char KEY_AP_VISIBILITY [] PROGMEM = "$AP_VISIBILITY$"; -const char KEY_AP_MAC [] PROGMEM = "$AP_MAC$"; -const char KEY_AP_SSID [] PROGMEM = "$AP_SSID$"; -const char KEY_AP_IS_VISIBLE [] PROGMEM = "$AP_IS_VISIBLE$"; -const char KEY_AP_CHANNEL [] PROGMEM = "$AP_CHANNEL$"; -const char KEY_AP_AUTH [] PROGMEM = "$AP_AUTH$"; -const char KEY_AP_MAX_CON [] PROGMEM = "$AP_MAX_CON$"; -const char KEY_AP_DHCP_STATUS [] PROGMEM = "$AP_DHCP_STATUS$"; -const char KEY_AP_IP [] PROGMEM = "$AP_IP$"; -const char KEY_AP_GW [] PROGMEM = "$AP_GW$";; -const char KEY_AP_SUBNET [] PROGMEM = "$AP_SUBNET$";; -const char KEY_STA_STATUS_ENABLED [] PROGMEM = "$STA_STATUS_ENABLED$"; -const char KEY_STA_VISIBILITY [] PROGMEM = "$STA_VISIBILITY$"; -const char VALUE_ACTIVE [] PROGMEM = "active"; -const char KEY_STA_DHCP_STATUS [] PROGMEM = "$STA_DHCP_STATUS$"; -const char KEY_STA_IP [] PROGMEM = "$STA_IP$"; -const char KEY_STA_GW [] PROGMEM = "$STA_GW$"; -const char KEY_STA_SUBNET [] PROGMEM = "$STA_SUBNET$"; -const char KEY_STA_MAC [] PROGMEM = "$STA_MAC$"; -const char KEY_STA_SSID [] PROGMEM = "$STA_SSID$"; -const char KEY_STA_CHANNEL [] PROGMEM = "$STA_CHANNEL$"; -const char KEY_STA_STATUS [] PROGMEM = "$STA_STATUS$"; -const char KEY_FREE_MEM [] PROGMEM = "$FREE_MEM$"; -const char KEY_SERVICE_PAGE [] PROGMEM = "$SERVICE_PAGE$"; -const char ARG_SUBMIT [] PROGMEM = "SUBMIT"; -const char KEY_MODE [] PROGMEM = "$MODE$"; -const char VALUE_AP [] PROGMEM = "AP"; -const char VALUE_STA [] PROGMEM = "STA"; -const char VALUE_AP_STA [] PROGMEM = "AP_STA"; -const char KEY_BAUD_RATE_OPTIONS_LIST [] PROGMEM ="$BAUD_RATE_OPTIONS_LIST$"; -const char KEY_SLEEP_MODE_OPTIONS_LIST [] PROGMEM ="$SLEEP_MODE_OPTIONS_LIST$"; -const char KEY_ERROR_MSG [] PROGMEM ="$ERROR_MSG$"; -const char KEY_SUCCESS_MSG [] PROGMEM ="$SUCCESS_MSG$"; -const char KEY_ERROR_MSG_VISIBILITY [] PROGMEM ="$ERROR_MSG_VISIBILITY$"; -const char KEY_SUCCESS_MSG_VISIBILITY[] PROGMEM ="$SUCCESS_MSG_VISIBILITY$"; -const char KEY_SUBMIT_BUTTON_VISIBILITY [] PROGMEM ="$SUBMIT_BUTTON_VISIBILITY$"; -const char VALUE_CONFIG_AP [] PROGMEM = "Configuration Access Point"; -const char VALUE_CONFIG_STA [] PROGMEM = "Configuration Station Client"; -const char VALUE_PRINTER [] PROGMEM = "Printer Interface"; -const char VALUE_HAS_ERROR [] PROGMEM = "has-error"; -const char VALUE_HAS_SUCCESS [] PROGMEM = "has-success"; -const char KEY_BAUD_RATE_STATUS [] PROGMEM = "$BAUD_RATE_STATUS$"; -const char KEY_SLEEP_MODE_STATUS [] PROGMEM ="$SLEEP_MODE_STATUS$"; -const char KEY_WEB_PORT_STATUS [] PROGMEM = "$WEB_PORT_STATUS$"; -const char KEY_DATA_PORT_STATUS [] PROGMEM ="$DATA_PORT_STATUS$"; -const char KEY_AP_SSID_STATUS [] PROGMEM = "$AP_SSID_STATUS$"; -const char KEY_AP_PASSWORD_STATUS [] PROGMEM = "$AP_PASSWORD_STATUS$"; -const char KEY_NETWORK_OPTION_LIST_STATUS [] PROGMEM = "$NETWORK_OPTION_LIST_STATUS$"; -const char KEY_NETWORK_OPTION_LIST [] PROGMEM = "$NETWORK_OPTION_LIST$"; -const char KEY_CHANNEL_OPTION_LIST_STATUS [] PROGMEM = "$CHANNEL_OPTION_LIST_STATUS$"; -const char KEY_CHANNEL_OPTION_LIST [] PROGMEM = "$CHANNEL_OPTION_LIST$"; -const char KEY_AUTH_OPTION_LIST_STATUS [] PROGMEM = "$AUTH_OPTION_LIST_STATUS$"; -const char KEY_AUTH_OPTION_LIST [] PROGMEM = "$AUTH_OPTION_LIST$"; -const char KEY_AP_IP_STATUS [] PROGMEM = "$AP_IP_STATUS$"; -const char KEY_AP_GW_STATUS [] PROGMEM = "$AP_GW_STATUS$"; -const char KEY_AP_SUBNET_STATUS [] PROGMEM = "$AP_SUBNET_STATUS$"; -const char KEY_AP_PASSWORD [] PROGMEM = "$AP_PASSWORD$"; -const char KEY_IS_SSID_VISIBLE_STATUS [] PROGMEM = "$IS_SSID_VISIBLE_STATUS$"; -const char KEY_IS_SSID_VISIBLE [] PROGMEM = "$IS_SSID_VISIBLE$"; -const char VALUE_CHECKED [] PROGMEM = "checked"; -const char VALUE_SELECTED [] PROGMEM ="selected"; -const char KEY_IS_STATIC_IP [] PROGMEM = "$IS_STATIC_IP$"; -const char KEY_AP_STATIC_IP_STATUS [] PROGMEM = "$AP_STATIC_IP_STATUS$"; -const char KEY_STA_STATIC_IP_STATUS [] PROGMEM = "$STA_STATIC_IP_STATUS$"; -const char KEY_STA_SSID_STATUS [] PROGMEM = "$STA_SSID_STATUS$"; -const char KEY_STA_PASSWORD_STATUS [] PROGMEM = "$STA_PASSWORD_STATUS$"; -const char KEY_STA_IP_STATUS [] PROGMEM = "$STA_IP_STATUS$"; -const char KEY_STA_GW_STATUS [] PROGMEM = "$STA_GW_STATUS$"; -const char KEY_STA_SUBNET_STATUS [] PROGMEM = "$STA_SUBNET_STATUS$"; -const char KEY_STA_PASSWORD [] PROGMEM = "$STA_PASSWORD$"; -const char KEY_AVAILABLE_AP_NB_ITEMS [] PROGMEM = "$AVAILABLE_AP_NB_ITEMS$"; -const char KEY_AP_SCAN_VISIBILITY [] PROGMEM = "$AP_SCAN_VISIBILITY$"; -const char KEY_HOSTNAME_STATUS [] PROGMEM = "$HOSTNAME_STATUS$"; -const char KEY_XY_FEEDRATE [] PROGMEM = "$XY_FEEDRATE$"; -const char KEY_Z_FEEDRATE [] PROGMEM = "$Z_FEEDRATE$"; -const char KEY_E_FEEDRATE [] PROGMEM = "$E_FEEDRATE$"; -const char KEY_XY_FEEDRATE_STATUS [] PROGMEM = "$XY_FEEDRATE_STATUS$"; -const char KEY_Z_FEEDRATE_STATUS [] PROGMEM = "$Z_FEEDRATE_STATUS$"; -const char KEY_E_FEEDRATE_STATUS [] PROGMEM = "$E_FEEDRATE_STATUS$"; -const char VALUE_SETTINGS [] PROGMEM = "Extra Settings"; -const char KEY_REFRESH_PAGE_STATUS [] PROGMEM = "$REFRESH_PAGE_STATUS$"; -const char KEY_DISCONNECT_VISIBILITY [] PROGMEM = "$DISCONNECT_VISIBILITY$"; -const char VALUE_LOGIN [] PROGMEM = "Login page"; -const char KEY_USER_STATUS [] PROGMEM = "$USER_STATUS$"; -const char KEY_USER_PASSWORD_STATUS [] PROGMEM = "$USER_PASSWORD_STATUS$"; -const char KEY_USER_PASSWORD_STATUS2 [] PROGMEM = "$USER_PASSWORD_STATUS2$"; -const char KEY_USER [] PROGMEM = "$USER$"; -const char KEY_USER_PASSWORD [] PROGMEM = "$USER_PASSWORD$"; -const char KEY_USER_PASSWORD2 [] PROGMEM = "$USER_PASSWORD2$"; -const char KEY_RETURN [] PROGMEM = "$RETURN$"; -const char VALUE_CHANGE_PASSWORD [] PROGMEM = "Change Password"; -const char MISSING_DATA [] PROGMEM = "Error: Missing data"; -const char EEPROM_NOWRITE [] PROGMEM = "Error: Cannot write to EEPROM"; -const char KEY_WEB_UPDATE [] PROGMEM = "$WEB_UPDATE_VISIBILITY$"; -const char KEY_STA_SIGNAL [] PROGMEM = "$STA_SIGNAL$"; -const char KEY_DATA_PORT_VISIBILITY [] PROGMEM = "$DATA_PORT_VISIBILITY$"; -const char KEY_LOGIN_ID [] PROGMEM = "$LOGIN_ID$"; -const char KEY_IS_DEFAULT_MODE [] PROGMEM = "$IS_DEFAULT_MODE$"; +const char PAGE_404 [] PROGMEM ="\n\nRedirecting... \n\n\n
Unknown page : $QUERY$- you will be redirected...\n

\nif not redirected, click here\n

\n\n\n\n
\n\n\n\n"; +const char PAGE_CAPTIVE [] PROGMEM ="\n\nCaptive Portal \n\n\n
Captive Portal page : $QUERY$- you will be redirected...\n

\nif not redirected, click here\n

\n\n\n\n
\n\n\n\n"; +const char CONTENT_TYPE_HTML [] PROGMEM ="text/html"; - -bool WEBINTERFACE_CLASS::generateJSON(STORESTRINGS_CLASS & KeysList , STORESTRINGS_CLASS & ValuesList ) -{ - LOG("process JSON\r\n") - if(KeysList.size() != ValuesList.size()) { //Sanity check - Serial.print("M117 Error"); - LOG("Error\r\n") - return false; - } - bool header_sent=false; - String buffer2send="{"; - for (int pos = 0; pos < KeysList.size(); pos++){ - //add current entry to buffer - if (pos > 0)buffer2send+=","; - String keystring = KeysList.get(pos); - keystring.replace(String("$"),String("")); - //this allow to add extra info in array - buffer2send+="\""; - buffer2send+=keystring; - buffer2send+="\":"; - if (ValuesList.get(pos)[0]!='\"')buffer2send+="\""; - buffer2send+=ValuesList.get(pos); - if (ValuesList.get(pos)[0]!='\"')buffer2send+="\""; - - //if buffer limit is reached - if (buffer2send.length()>1200) { - //if header is not send yet - if (!header_sent) { - //send header with calculated size - header_sent=true; - web_interface->WebServer.setContentLength(CONTENT_LENGTH_UNKNOWN); - web_interface->WebServer.sendHeader("Content-Type","application/json",true); - web_interface->WebServer.sendHeader("Cache-Control","no-cache"); - web_interface->WebServer.send(200); - } - //send data - web_interface->WebServer.sendContent(buffer2send); - //reset buffer - buffer2send=""; - } - //add a delay for safety for WDT - delay(0); - } - buffer2send+="}"; - //check if something is still in buffer and need to be send - if (buffer2send!="") { - //if header is not send yet - if (!header_sent) { - //send header - web_interface->WebServer.setContentLength(CONTENT_LENGTH_UNKNOWN); - web_interface->WebServer.sendHeader("Content-Type","application/json",true); - web_interface->WebServer.sendHeader("Cache-Control","no-cache"); - web_interface->WebServer.send(200); - } - //send data - web_interface->WebServer.sendContent(buffer2send); - } - //close line - web_interface->WebServer.sendContent(""); - LOG("Process template done\r\n") - return true; -} - - -bool WEBINTERFACE_CLASS::processTemplate(const char * filename, STORESTRINGS_CLASS & KeysList , STORESTRINGS_CLASS & ValuesList ) -{ - LOG("process template\r\n") - if(KeysList.size() != ValuesList.size()) { //Sanity check - Serial.print("M117 Error"); - LOG("Error\r\n") - return false; - } - - GenLinkedList myFileList = GenLinkedList(); - String buffer2send; - bool header_sent=false; - - buffer2send=""; - //open template file - FSFILE currentfile = SPIFFS.open(filename, "r"); - //if error display error on web page - if (!currentfile) { - buffer2send = String(F("Error opening: ")) + filename; - web_interface->WebServer.send(200,"text/plain",buffer2send); - return false; - } else { //template is open - int b ; - String sLine; - bool bprocessing=true; - - while (bprocessing) { //read all bytes - b = currentfile.read(); //from current open file - if (b!=-1) { //if not EOF - sLine+=char(b); //add to current line - if (b=='\n') { //end of line is reached - //change all variables by their values - for (int k=0; k-1) { - //get value - nb=atoi(ValuesList.get(ipos)); - ipos=ipos-(nb*3); - } - //do a sanity check data are there - String Last_IP_Key = "$IP_CONNECTED["+String(nb-1)+"]$"; - if (nb>0 && (KeysList.get_index("$ROW_NUMBER[0]$")==ipos) &&(Last_IP_Key==KeysList.get(ipos-1+(nb*3)))) { - for (int j=0; j-1) { - tmppart.replace("$ROW_NUMBER$",ValuesList.get(ipos+0+(j*3))); - tmppart.replace("$MAC_CONNECTED$",ValuesList.get(ipos+1+(j*3))); - tmppart.replace("$IP_CONNECTED$",ValuesList.get(ipos+2+(j*3))); - } - tablepart +=tmppart; - } - } - //now build back - sLine = beforelinetoprocess + tablepart + afterlinetoprocess; - } - - pos_tag=sLine.indexOf("$AVAILABLE_AP["); - if (pos_tag!=-1) { //if yes - //extract line - int pos_tag_end = sLine.indexOf("]$",pos_tag); - int nb = -1; - int ipos = -1; - //part before repetitive section - String beforelinetoprocess=sLine.substring( 0,pos_tag); - //part after repetitive section - String afterlinetoprocess=sLine.substring( pos_tag_end+2); - //repetitive section itself - String linetoprocess =sLine.substring( pos_tag+strlen("$AVAILABLE_AP["),pos_tag_end); - String tablepart; - //get how many items - ipos=KeysList.get_index("$AVAILABLE_AP_NB_ITEMS$"); - if (ipos >-1) { - //get value - nb=atoi(ValuesList.get(ipos)); - ipos=ipos-(nb*4); - } - //do a sanity check data are there - String Last_IP_Key = "$IS_PROTECTED["+String(nb-1)+"]$"; - if (nb>0 && (KeysList.get_index("$ROW_NUMBER[0]$")==ipos) &&(Last_IP_Key==KeysList.get(ipos-1+(nb*4)))) { - for (int j=0; j-1) { - tmppart.replace("$ROW_NUMBER$",ValuesList.get(ipos+0+(j*4))); - tmppart.replace("$AP_SSID$",ValuesList.get(ipos+1+(j*4))); - tmppart.replace("$AP_SIGNAL$",ValuesList.get(ipos+2+(j*4))); - tmppart.replace("$IS_PROTECTED$",ValuesList.get(ipos+3+(j*4))); - } - tablepart +=tmppart; - } - } - //now build back - sLine = beforelinetoprocess + tablepart + afterlinetoprocess; - } - - //add current line to buffer - buffer2send+=sLine; - //if buffer limit is reached - if (buffer2send.length()>1200) { - //if header is not send yet - if (!header_sent) { - //send header with calculated size - header_sent=true; - web_interface->WebServer.setContentLength(CONTENT_LENGTH_UNKNOWN); - web_interface->WebServer.sendHeader("Content-Type","text/html",true); - web_interface->WebServer.sendHeader("Cache-Control","no-cache"); - web_interface->WebServer.send(200); - } - //send data - web_interface->WebServer.sendContent(buffer2send); - //reset buffer - buffer2send=""; - } - } - //reset line - sLine=""; - //add a delay for safety for WDT - delay(0); - } - } else { //EOF is reached - //close current file - currentfile.close(); - //if current file is not template file but included one - if (myFileList.size()>0) { - //get level +1 file description and continue - currentfile = myFileList.pop(); - } else { - //we have done template parsing, let's stop reading - bprocessing=false; - } - } - } - } - //check if something is still in buffer and need to be send - if (buffer2send!="") { - //if header is not send yet - if (!header_sent) { - //send header - web_interface->WebServer.setContentLength(CONTENT_LENGTH_UNKNOWN); - web_interface->WebServer.sendHeader("Content-Type","text/html",true); - web_interface->WebServer.sendHeader("Cache-Control","no-cache"); - web_interface->WebServer.send(200); - } - //send data - web_interface->WebServer.sendContent(buffer2send); - } - //close line - web_interface->WebServer.sendContent(""); - LOG("Process template done\r\n") - return true; -} - -// ----------------------------------------------------------------------------- -// Helper for FreeMem and Firmware -// ----------------------------------------------------------------------------- -void WEBINTERFACE_CLASS::GetFreeMem(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList) -{ - //FreeMem - KeysList.add(FPSTR(KEY_FREE_MEM)); - ValuesList.add(CONFIG::intTostr(ESP.getFreeHeap())); - //FW Version - KeysList.add(FPSTR(KEY_FW_VER)); - ValuesList.add(FPSTR(VALUE_FW_VERSION)); -} - -// ----------------------------------------------------------------------------- -// Helper for Login ID -// ----------------------------------------------------------------------------- -void WEBINTERFACE_CLASS::GetLogin(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList,level_authenticate_type auth_level,bool ishtmloutput) -{ - if (ishtmloutput)KeysList.add(FPSTR(KEY_DISCONNECT_VISIBILITY)); -#ifdef AUTHENTICATION_FEATURE - - if (auth_level != LEVEL_GUEST) { - if (ishtmloutput)ValuesList.add(FPSTR(VALUE_ITEM_VISIBLE)); - KeysList.add(FPSTR(KEY_LOGIN_ID)); - if (auth_level == LEVEL_ADMIN) { - ValuesList.add(FPSTR(DEFAULT_ADMIN_LOGIN)); - } else { - ValuesList.add(FPSTR(DEFAULT_USER_LOGIN)); - } - } else -#endif - { - if (ishtmloutput)ValuesList.add(FPSTR(VALUE_ITEM_HIDDEN)); - KeysList.add(FPSTR(KEY_LOGIN_ID)); - ValuesList.add(""); - } -} - -// ----------------------------------------------------------------------------- -// Helper for IP+Web address -// ----------------------------------------------------------------------------- -void WEBINTERFACE_CLASS::GetIpWeb(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList) -{ - String stmp; - - KeysList.add(FPSTR(KEY_IP)); - if (WiFi.getMode() == WIFI_STA ) { - stmp = WiFi.localIP().toString(); - } else { - stmp = WiFi.softAPIP().toString(); - } - ValuesList.add(stmp); - - //Web address = ip + port - KeysList.add(FPSTR(KEY_WEB_ADDRESS)); - if (wifi_config.iweb_port != 80) { - stmp.concat(":"); - stmp.concat(wifi_config.iweb_port); - } - ValuesList.add(stmp); -} -// ----------------------------------------------------------------------------- -// Helper for Wifi Mode -// ----------------------------------------------------------------------------- -void WEBINTERFACE_CLASS::GetMode(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList) -{ - if (WiFi.getMode() == WIFI_STA ) { - KeysList.add(FPSTR(KEY_MODE)); - ValuesList.add(FPSTR(VALUE_STA)); - } else { - if (WiFi.getMode() == WIFI_AP ) { - KeysList.add(FPSTR(KEY_MODE)); - ValuesList.add(FPSTR(VALUE_AP)); - } else { - KeysList.add(FPSTR(KEY_MODE)); - ValuesList.add(FPSTR(VALUE_AP_STA)); - } - } -} -// ----------------------------------------------------------------------------- -// Helper for Web ports -// ----------------------------------------------------------------------------- -void WEBINTERFACE_CLASS::GetPorts(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList, bool ishtmloutput) -{ - //Web port - KeysList.add(FPSTR(KEY_WEB_PORT)); - ValuesList.add(CONFIG::intTostr(wifi_config.iweb_port)); - //Data port - KeysList.add(FPSTR(KEY_DATA_PORT)); - if(ishtmloutput)KeysList.add(FPSTR(KEY_DATA_PORT_VISIBILITY)); -#ifdef TCP_IP_DATA_FEATURE - ValuesList.add(CONFIG::intTostr(wifi_config.idata_port)); - if(ishtmloutput)ValuesList.add(FPSTR(VALUE_ITEM_VISIBLE)); -#else - ValuesList.add(FPSTR(VALUE_NONE)); - if(ishtmloutput)ValuesList.add(FPSTR(VALUE_ITEM_HIDDEN)); -#endif -} -// ----------------------------------------------------------------------------- -// Helper for Page properties -// ----------------------------------------------------------------------------- -void WEBINTERFACE_CLASS::SetPageProp(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList, - const __FlashStringHelper *title, const __FlashStringHelper *filename) -{ - String fullFilename(filename); - fullFilename.concat(".tpl"); - - //page title - KeysList.add(FPSTR(KEY_PAGE_TITLE)); - ValuesList.add(title); - //tpl file name with extension - KeysList.add(FPSTR(KEY_FILE_NAME)); - ValuesList.add(fullFilename); - //tpl file name without extension - KeysList.add(FPSTR(KEY_SHORT_FILE_NAME)); - ValuesList.add(filename); -} - -// ----------------------------------------------------------------------------- -// Helper for DHCP (APP/STA)tus -// ----------------------------------------------------------------------------- -void WEBINTERFACE_CLASS::GetDHCPStatus(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList) -{ - KeysList.add(FPSTR(KEY_AP_DHCP_STATUS)); - if (wifi_softap_dhcps_status() == DHCP_STARTED) { - ValuesList.add(FPSTR(VALUE_STARTED)); - } else { - ValuesList.add(FPSTR(VALUE_STOPPED)); - } - - KeysList.add(FPSTR(KEY_STA_DHCP_STATUS)); - if (wifi_station_dhcpc_status()==DHCP_STARTED) { - ValuesList.add(FPSTR(VALUE_STARTED)); - } else { - ValuesList.add(FPSTR(VALUE_STOPPED)); - } -} - -// ----------------------------------------------------------------------------- -// Helper for Error Msg processing -// ----------------------------------------------------------------------------- -void WEBINTERFACE_CLASS::ProcessAlertError(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList, String & smsg, bool ishtmloutput) -{ - KeysList.add(FPSTR(KEY_ERROR_MSG)); - ValuesList.add(smsg); - if (ishtmloutput){ - KeysList.add(FPSTR(KEY_SUCCESS_MSG)); - ValuesList.add(""); - KeysList.add(FPSTR(KEY_ERROR_MSG_VISIBILITY )); - ValuesList.add(FPSTR(VALUE_ITEM_VISIBLE)); - KeysList.add(FPSTR(KEY_SUCCESS_MSG_VISIBILITY)); - ValuesList.add(FPSTR(VALUE_ITEM_HIDDEN)); - KeysList.add(FPSTR(KEY_SUBMIT_BUTTON_VISIBILITY)); - ValuesList.add(FPSTR(VALUE_ITEM_VISIBLE)); - KeysList.add(FPSTR(KEY_SERVICE_PAGE)); - ValuesList.add(""); - } -} - -// ----------------------------------------------------------------------------- -// Helper for Success Msg processing -// ----------------------------------------------------------------------------- -void WEBINTERFACE_CLASS::ProcessAlertSuccess(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList, String & smsg, bool ishtmloutput) -{ - KeysList.add(FPSTR(KEY_ERROR_MSG)); - ValuesList.add(""); - if (ishtmloutput){ - KeysList.add(FPSTR(KEY_SUCCESS_MSG)); - ValuesList.add(smsg); - KeysList.add(FPSTR(KEY_ERROR_MSG_VISIBILITY )); - ValuesList.add(FPSTR(VALUE_ITEM_HIDDEN)); - KeysList.add(FPSTR(KEY_SUCCESS_MSG_VISIBILITY)); - ValuesList.add(FPSTR(VALUE_ITEM_VISIBLE)); - KeysList.add(FPSTR(KEY_SUBMIT_BUTTON_VISIBILITY)); - ValuesList.add(FPSTR(VALUE_ITEM_HIDDEN)); - } -} - -// ----------------------------------------------------------------------------- -// Helper for No Msg processing -// ----------------------------------------------------------------------------- -void WEBINTERFACE_CLASS::ProcessNoAlert(STORESTRINGS_CLASS & KeysList, STORESTRINGS_CLASS & ValuesList, bool ishtmloutput) -{ - KeysList.add(FPSTR(KEY_ERROR_MSG)); - ValuesList.add(""); - if (ishtmloutput){ - KeysList.add(FPSTR(KEY_SUCCESS_MSG)); - ValuesList.add(""); - KeysList.add(FPSTR(KEY_ERROR_MSG_VISIBILITY )); - ValuesList.add(FPSTR(VALUE_ITEM_HIDDEN)); - KeysList.add(FPSTR(KEY_SUCCESS_MSG_VISIBILITY)); - ValuesList.add(FPSTR(VALUE_ITEM_HIDDEN)); - KeysList.add(FPSTR(KEY_SUBMIT_BUTTON_VISIBILITY)); - ValuesList.add(FPSTR(VALUE_ITEM_VISIBLE)); - KeysList.add(FPSTR(KEY_SERVICE_PAGE)); - ValuesList.add(""); - } -} - -//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"; String path = "/index.html"; String contentType = web_interface->getContentType(path); String pathWithGz = path + ".gz"; //if have a index.html or gzip version this is default root page - if(SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)) { - if(SPIFFS.exists(pathWithGz)) { - path = pathWithGz; - } - FSFILE file = SPIFFS.open(path, "r"); - web_interface->WebServer.streamFile(file, contentType); - file.close(); - return; + if((SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)) && !web_interface->web_server.hasArg("fallback") && web_interface->web_server.arg("forcefallback")!="yes") { + if(SPIFFS.exists(pathWithGz)) { + path = pathWithGz; } - //if no lets launch the /HOME - web_interface->WebServer.sendContent_P(HOME_PAGE); -} - -//root insterface -void handle_web_interface_home() -{ - String stmp; - //long lstatus; - int istatus; - //byte bbuf; - STORESTRINGS_CLASS KeysList ; - STORESTRINGS_CLASS ValuesList ; - struct softap_config apconfig; - struct ip_info info; - uint8_t mac [WL_MAC_ADDR_LENGTH]; - bool outputjson = false; - if (web_interface->WebServer.hasArg("output")){ - if (web_interface->WebServer.arg("output") == "JSON") - { - outputjson = true; - } - } - LOG("request /HOME\r\n") - //login - web_interface->GetLogin(KeysList, ValuesList,web_interface->is_authenticated(), !outputjson); - - //IP+Web - web_interface->GetIpWeb(KeysList, ValuesList); - - //Hostname - if (WiFi.getMode()==WIFI_STA ) { - KeysList.add(FPSTR(KEY_MODE)); - ValuesList.add(FPSTR(VALUE_STA)); - KeysList.add(FPSTR(KEY_HOSTNAME)); - ValuesList.add(wifi_config.get_hostname()); - if (!outputjson){ - KeysList.add(FPSTR(KEY_HOSTNAME_VISIBLE)); - ValuesList.add(FPSTR(VALUE_ITEM_VISIBLE)); - } - } else { - KeysList.add(FPSTR(KEY_HOSTNAME)); - ValuesList.add(FPSTR(KEY_NOT_APPLICABLE_4_AP)); - if (!outputjson){ - KeysList.add(FPSTR(KEY_HOSTNAME_VISIBLE)); - ValuesList.add(FPSTR(VALUE_ITEM_HIDDEN)); - } - if (WiFi.getMode()==WIFI_AP ) { - KeysList.add(FPSTR(KEY_MODE)); - ValuesList.add(FPSTR(VALUE_AP)); - } else { - KeysList.add(FPSTR(KEY_MODE)); - ValuesList.add(FPSTR(VALUE_AP_STA)); - } - } - if (!outputjson){ - //page title and filenames - web_interface->SetPageProp(KeysList,ValuesList,FPSTR(VALUE_HOME),F("home")); - //menu item - KeysList.add(FPSTR(KEY_MENU_HOME)); - ValuesList.add(FPSTR(VALUE_ACTIVE)); - } - //Chip ID - KeysList.add(FPSTR(KEY_CHIP_ID)); - ValuesList.add(CONFIG::intTostr(system_get_chip_id())); - //CPU Freq - KeysList.add(FPSTR(KEY_CPU_FREQ)); - ValuesList.add(CONFIG::intTostr(system_get_cpu_freq())); - //SDK Version - KeysList.add(FPSTR(KEY_SDK_VER)); - ValuesList.add(system_get_sdk_version()); - - //MDNS Feature -#ifdef MDNS_FEATURE - KeysList.add(FPSTR(KEY_MDNS_NAME)); - stmp="http://"; - stmp+=wifi_config.get_hostname(); - stmp+=".local"; - ValuesList.add(stmp); - if (!outputjson){ - KeysList.add(FPSTR(KEY_MDNS_VISIBLE)); - ValuesList.add(FPSTR(VALUE_ITEM_VISIBLE)); - } -#else - if (!outputjson){ - KeysList.add(FPSTR(KEY_MDNS_NAME)); - ValuesList.add(FPSTR(VALUE_DISABLED)); - KeysList.add(FPSTR(KEY_MDNS_VISIBLE)); - ValuesList.add(FPSTR(VALUE_ITEM_HIDDEN)); - } -#endif - - //SSDP Feature -#ifdef SSDP_FEATURE - KeysList.add(FPSTR(KEY_SSDP_STATUS)); - ValuesList.add(FPSTR(VALUE_ENABLED)); - if (!outputjson){ - KeysList.add(FPSTR(KEY_SSDP_VISIBLE)); - ValuesList.add(FPSTR(VALUE_ITEM_VISIBLE)); - } -#else - KeysList.add(FPSTR(KEY_SSDP_STATUS)); - ValuesList.add(FPSTR(VALUE_DISABLED)); - if (!outputjson){ - KeysList.add(FPSTR(KEY_SSDP_VISIBLE)); - ValuesList.add(FPSTR(VALUE_ITEM_HIDDEN)); - } -#endif - - //Captive portal Feature -#ifdef CAPTIVE_PORTAL_FEATURE - if (WiFi.getMode()==WIFI_AP) { - KeysList.add(FPSTR(KEY_CAPTIVE_PORTAL_STATUS)); - ValuesList.add(FPSTR(VALUE_ENABLED)); - if (!outputjson){ - KeysList.add(FPSTR(KEY_CAPTIVE_PORTAL_VISIBLE)); - ValuesList.add(FPSTR(VALUE_ITEM_VISIBLE)); - } - } else { - KeysList.add(FPSTR(KEY_CAPTIVE_PORTAL_STATUS)); - ValuesList.add(FPSTR(VALUE_DISABLED)); - if (!outputjson){ - KeysList.add(FPSTR(KEY_CAPTIVE_PORTAL_VISIBLE)); - ValuesList.add(FPSTR(VALUE_ITEM_HIDDEN)); - } - } -#else - KeysList.add(FPSTR(KEY_CAPTIVE_PORTAL_STATUS)); - ValuesList.add(FPSTR(VALUE_DISABLED)); - if (!outputjson){ - KeysList.add(FPSTR(KEY_CAPTIVE_PORTAL_VISIBLE)); - ValuesList.add(FPSTR(VALUE_ITEM_HIDDEN)); - } -#endif - - //network - KeysList.add(FPSTR(KEY_NET_PHY)); - if (WiFi.getPhyMode()==WIFI_PHY_MODE_11B) { - ValuesList.add(FPSTR(VALUE_11B)); - } else if (WiFi.getPhyMode()==WIFI_PHY_MODE_11G) { - ValuesList.add(FPSTR(VALUE_11G)); - } else { - ValuesList.add(FPSTR(VALUE_11N)); - } - //sleep mode - KeysList.add(FPSTR(KEY_SLEEP_MODE)); - if (WiFi.getSleepMode()==WIFI_NONE_SLEEP) { - ValuesList.add(FPSTR(VALUE_NONE)); - } else if (WiFi.getSleepMode()==WIFI_LIGHT_SLEEP) { - ValuesList.add(FPSTR(VALUE_LIGHT)); - } else { - ValuesList.add(FPSTR(VALUE_MODEM)); - } - //Boot version - KeysList.add(FPSTR(KEY_BOOT_VER)); - ValuesList.add(CONFIG::intTostr(system_get_boot_version())); - //Baud rate - KeysList.add(FPSTR(KEY_BAUD_RATE)); - ValuesList.add(CONFIG::intTostr(wifi_config.baud_rate)); - // Web and Data ports - web_interface->GetPorts(KeysList, ValuesList, !outputjson); - - //AP part - if (WiFi.getMode()==WIFI_AP || WiFi.getMode()==WIFI_AP_STA) { - int client_counter=0; - struct station_info * station; - //AP is enabled - KeysList.add(FPSTR(KEY_AP_STATUS_ENABLED)); - ValuesList.add(FPSTR(VALUE_ENABLED)); - //set visible - if (!outputjson){ - KeysList.add(FPSTR(KEY_AP_VISIBILITY)); - ValuesList.add(FPSTR(VALUE_ITEM_VISIBLE)); - } - //list of connected clients - station = wifi_softap_get_station_info(); - while(station) { - //Row number - stmp = "$ROW_NUMBER["+String(client_counter)+"]$"; - KeysList.add(stmp.c_str()); - stmp=String(client_counter+1); - ValuesList.add(stmp); - //BSSID - stmp = "$MAC_CONNECTED["+String(client_counter)+"]$"; - KeysList.add(stmp.c_str()); - ValuesList.add(CONFIG::mac2str(station->bssid)); - //IP - stmp = "$IP_CONNECTED["+String(client_counter)+"]$"; - KeysList.add(stmp.c_str()); - ValuesList.add(IPAddress((const uint8_t *)&station->ip).toString().c_str()); - //increment counter - client_counter++; - //go next record - //removed due to queue.h removed - //station = STAILQ_NEXT(station, next); - station = station->next; - } - wifi_softap_free_station_info(); - //Connected clients - KeysList.add(FPSTR(KEY_CONNECTED_STATIONS_NB_ITEMS)); - ValuesList.add(CONFIG::intTostr(client_counter)); - } else { - //AP is disabled - KeysList.add(FPSTR(KEY_AP_STATUS_ENABLED)); - ValuesList.add(FPSTR(VALUE_DISABLED)); - if (!outputjson){ - //set hide - KeysList.add(FPSTR(KEY_AP_VISIBILITY)); - ValuesList.add(FPSTR(VALUE_ITEM_HIDDEN)); - } - //Connected clients - KeysList.add(FPSTR(KEY_CONNECTED_STATIONS_NB_ITEMS)); - ValuesList.add("0"); - } - //AP mac address - KeysList.add(FPSTR(KEY_AP_MAC)); - ValuesList.add(CONFIG::mac2str(WiFi.softAPmacAddress(mac))); - //AP configuration - if (wifi_softap_get_config(&apconfig)) { - //SSID - KeysList.add(FPSTR(KEY_AP_SSID)); - ValuesList.add((char *)(apconfig.ssid)); - //AP visible or hidden - KeysList.add(FPSTR(KEY_AP_IS_VISIBLE)); - if(apconfig.ssid_hidden==1) { - ValuesList.add(FPSTR(VALUE_NO)); - } else { - ValuesList.add(FPSTR(VALUE_YES)); - } - //Channel - KeysList.add(FPSTR(KEY_AP_CHANNEL)); - ValuesList.add(CONFIG::intTostr(apconfig.channel)); - //Authentification mode - KeysList.add(FPSTR(KEY_AP_AUTH)); - if (apconfig.authmode==AUTH_OPEN) { - ValuesList.add(FPSTR(VALUE_NONE)); - } else if (apconfig.authmode==AUTH_WEP) { - ValuesList.add(FPSTR(VALUE_WEP)); - } else if (apconfig.authmode==AUTH_WPA_PSK) { - ValuesList.add(FPSTR(VALUE_WPA)); - } else if (apconfig.authmode==AUTH_WPA2_PSK) { - ValuesList.add(FPSTR(VALUE_WPA2)); - } else { - ValuesList.add(FPSTR(VALUE_WPAWPA2)); - } - - //Max connections - KeysList.add(FPSTR(KEY_AP_MAX_CON)); - ValuesList.add(CONFIG::intTostr(apconfig.max_connection)); - } else { - //SSID - KeysList.add(FPSTR(KEY_AP_SSID)); - ValuesList.add(FPSTR(VALUE_NOT_AVAILABLE)); - //AP visible or hidden - KeysList.add(FPSTR(KEY_AP_IS_VISIBLE)); - ValuesList.add(FPSTR(VALUE_NOT_AVAILABLE)); - //Channel - KeysList.add(FPSTR(KEY_AP_CHANNEL)); - ValuesList.add(FPSTR(VALUE_NOT_AVAILABLE)); - //Authentification mode - KeysList.add(FPSTR(KEY_AP_AUTH)); - ValuesList.add(FPSTR(VALUE_NOT_AVAILABLE)); - //Max connections - KeysList.add(FPSTR(KEY_AP_MAX_CON)); - ValuesList.add(FPSTR(VALUE_NOT_AVAILABLE)); - } - //DHCP Status - web_interface->GetDHCPStatus(KeysList, ValuesList); - //IP/GW/MASK - if (wifi_get_ip_info(SOFTAP_IF,&info)) { - //IP address - KeysList.add(FPSTR(KEY_AP_IP)); - ValuesList.add(IPAddress((const uint8_t *)&(info.ip.addr)).toString().c_str()); - //GW address - KeysList.add(FPSTR(KEY_AP_GW)); - ValuesList.add(IPAddress((const uint8_t *)&(info.gw.addr)).toString().c_str()); - //Sub Net Mask - KeysList.add(FPSTR(KEY_AP_SUBNET)); - ValuesList.add(IPAddress((const uint8_t *)&(info.netmask.addr)).toString().c_str()); - } else { - //IP address - KeysList.add(FPSTR(KEY_AP_IP)); - ValuesList.add(FPSTR(VALUE_NO_IP)); - //GW address - KeysList.add(FPSTR(KEY_AP_GW)); - ValuesList.add(FPSTR(VALUE_NO_IP)); - //Sub Net Mask - KeysList.add(FPSTR(KEY_AP_SUBNET)); - ValuesList.add(FPSTR(VALUE_NO_IP)); - } - //STA part - if (WiFi.getMode()==WIFI_STA || WiFi.getMode()==WIFI_AP_STA) { - //STA is enabled - KeysList.add(FPSTR(KEY_STA_STATUS_ENABLED)); - ValuesList.add(FPSTR(VALUE_ENABLED)); - if (!outputjson){ - //set visible - KeysList.add(FPSTR(KEY_STA_VISIBILITY)); - ValuesList.add(FPSTR(VALUE_ITEM_VISIBLE)); - } - } else { - //STA is disabled - KeysList.add(FPSTR(KEY_STA_STATUS_ENABLED)); - ValuesList.add(FPSTR(VALUE_DISABLED)); - if (!outputjson){ - //set hide - KeysList.add(FPSTR(KEY_STA_VISIBILITY)); - ValuesList.add(FPSTR(VALUE_ITEM_HIDDEN)); - } - } - //STA mac address - KeysList.add(FPSTR(KEY_STA_MAC)); - ValuesList.add(CONFIG::mac2str(WiFi.macAddress(mac))); - //SSID used by STA - KeysList.add(FPSTR(KEY_STA_SSID)); - if (WiFi.SSID().length()==0) { - ValuesList.add(FPSTR(VALUE_NOT_AVAILABLE)); - } else { - ValuesList.add(WiFi.SSID().c_str()); - } - //Channel - KeysList.add(FPSTR(KEY_STA_CHANNEL)); - ValuesList.add(CONFIG::intTostr (wifi_get_channel())); - //Connection status - istatus = wifi_station_get_connect_status(); - KeysList.add(FPSTR(KEY_STA_STATUS)); - if (istatus==STATION_GOT_IP) { - ValuesList.add(FPSTR(VALUE_CONNECTED)); - } else if (istatus==STATION_NO_AP_FOUND) { - ValuesList.add(FPSTR(VALUE_NO_SSID)); - } else if (istatus==STATION_CONNECT_FAIL) { - ValuesList.add(FPSTR(VALUE_CONNECTION_FAILED)); - } else if (istatus==STATION_WRONG_PASSWORD) { - ValuesList.add(FPSTR(VALUE_CONNECTION_FAILED2)); - } else if (istatus==STATION_IDLE) { - ValuesList.add(FPSTR(VALUE_IDLE)); //should not happen - } else { - ValuesList.add(FPSTR(VALUE_DISCONNECTED)); - } - //Signal strength - KeysList.add(FPSTR(KEY_STA_SIGNAL)); - ValuesList.add(CONFIG::intTostr(wifi_config.getSignal(WiFi.RSSI()))); - //DHCP Client status - web_interface->GetDHCPStatus(KeysList, ValuesList); - //IP address - KeysList.add(FPSTR(KEY_STA_IP)); - ValuesList.add(WiFi.localIP().toString().c_str()); - //GW address - KeysList.add(FPSTR(KEY_STA_GW)); - ValuesList.add(WiFi.gatewayIP().toString().c_str()); - //Sub Net Mask - KeysList.add(FPSTR(KEY_STA_SUBNET)); - ValuesList.add(WiFi.subnetMask().toString().c_str()); - if (!outputjson){ - //Service page / no need refresh on this page - KeysList.add(FPSTR(KEY_SERVICE_PAGE)); - ValuesList.add(""); - } - //Firmware & Free Mem, at the end to reflect situation - web_interface->GetFreeMem(KeysList, ValuesList); - //check if need template or do a JSON - if (outputjson){ - web_interface->generateJSON(KeysList , ValuesList); - }//process the template file and provide list of variables - else web_interface->processTemplate("/home.tpl", KeysList , ValuesList); - //need to clean to speed up memory recovery - KeysList.clear(); - ValuesList.clear(); - LOG("request /HOME done\r\n") -} - -void handle_web_interface_configSys() -{ - static const char NOT_AUTH_CS [] PROGMEM = "HTTP/1.1 301 OK\r\nLocation: /LOGIN?return=CONFIGSYS\r\nCache-Control: no-cache\r\n\r\n"; - - String stmp,smsg; - //long lstatus; - int istatus; - //byte bbuf; - long ibaud=DEFAULT_BAUD_RATE; - int iweb_port =DEFAULT_WEB_PORT; - int idata_port =DEFAULT_DATA_PORT; - byte bsleepmode=DEFAULT_SLEEP_MODE; - bool msg_alert_error=false; - bool msg_alert_success=false; - long lbaudlist[] = {9600 ,19200,38400,57600,115200,230400,250000,-1}; - int bmodemvaluelist[] = {WIFI_NONE_SLEEP,WIFI_LIGHT_SLEEP,WIFI_MODEM_SLEEP, -1}; - const __FlashStringHelper *smodemdisplaylist[]= {FPSTR(VALUE_NONE),FPSTR(VALUE_LIGHT),FPSTR(VALUE_MODEM),FPSTR(VALUE_MODEM)}; - STORESTRINGS_CLASS KeysList ; - STORESTRINGS_CLASS ValuesList ; - bool outputjson = false; - if (web_interface->WebServer.hasArg("output")){ - if (web_interface->WebServer.arg("output") == "JSON") - { - outputjson = true; - } - } - level_authenticate_type auth_level= web_interface->is_authenticated(); - if (auth_level != LEVEL_ADMIN) { - web_interface->WebServer.sendContent_P(NOT_AUTH_CS); + FS_FILE file = SPIFFS.open(path, SPIFFS_FILE_READ); + web_interface->web_server.streamFile(file, contentType); + file.close(); return; } - //login - web_interface->GetLogin(KeysList, ValuesList,auth_level, !outputjson); - //IP+Web - web_interface->GetIpWeb(KeysList, ValuesList); - //mode - web_interface->GetMode(KeysList, ValuesList); - if (!outputjson){ - //page title and filenames - web_interface->SetPageProp(KeysList,ValuesList,FPSTR(VALUE_HOME),F("system")); - //menu item - KeysList.add(FPSTR(KEY_MENU_SYSTEM)); - ValuesList.add(FPSTR(VALUE_ACTIVE)); - } - //check is it is a submission or a display - if (web_interface->WebServer.hasArg("SUBMIT")) { - //is there a correct list of values? - if (web_interface->WebServer.hasArg("BAUD_RATE") - && web_interface->WebServer.hasArg("SLEEP_MODE") -#ifdef TCP_IP_DATA_FEATURE - && web_interface->WebServer.hasArg("DATAPORT") -#endif - && web_interface->WebServer.hasArg("WEBPORT")) { - //is each value correct ? - ibaud = web_interface->WebServer.arg("BAUD_RATE").toInt(); - iweb_port = web_interface->WebServer.arg("WEBPORT").toInt(); -#ifdef TCP_IP_DATA_FEATURE - idata_port = web_interface->WebServer.arg("DATAPORT").toInt(); -#endif - bsleepmode = web_interface->WebServer.arg("SLEEP_MODE").toInt(); - - if (!(iweb_port>0 && iweb_port<65001)) { - msg_alert_error=true; - smsg.concat(F("Error: invalid port value for web port
")); - KeysList.add(FPSTR(KEY_WEB_PORT_STATUS)); - ValuesList.add(FPSTR(VALUE_HAS_ERROR)); - } -#ifdef TCP_IP_DATA_FEATURE - if (!(idata_port>0 && idata_port<65001)) { - msg_alert_error=true; - smsg.concat("Error: invalid port value for data port
"); - KeysList.add(FPSTR(KEY_DATA_PORT_STATUS)); - ValuesList.add(FPSTR(VALUE_HAS_ERROR)); - } -#endif - if (iweb_port== idata_port) { - msg_alert_error=true; - smsg.concat("Error: web port and data port cannot be identical
"); - KeysList.add(FPSTR(KEY_WEB_PORT_STATUS)); - ValuesList.add(FPSTR(VALUE_HAS_ERROR)); - KeysList.add(FPSTR(KEY_DATA_PORT_STATUS)); - ValuesList.add(FPSTR(VALUE_HAS_ERROR)); - } - if (!(ibaud==9600 || ibaud==19200|| ibaud==38400|| ibaud==57600|| ibaud==115200|| ibaud==230400 || ibaud==250000)) { - msg_alert_error=true; - smsg.concat(F("Error: value for baud rate is not correct
")); - KeysList.add(FPSTR(KEY_BAUD_RATE_STATUS)); - ValuesList.add(FPSTR(VALUE_HAS_ERROR)); - } - if (!(bsleepmode==WIFI_NONE_SLEEP ||bsleepmode==WIFI_LIGHT_SLEEP ||bsleepmode==WIFI_MODEM_SLEEP )) { - msg_alert_error=true; - smsg.concat(F("Error: value for sleeping mode is not correct
")); - KeysList.add(FPSTR(KEY_SLEEP_MODE_STATUS)); - ValuesList.add(FPSTR(VALUE_HAS_ERROR)); - } - } else { - msg_alert_error=true; - smsg = FPSTR(MISSING_DATA); - } - //if no error apply the changes - if (msg_alert_error!=true) { - if(!CONFIG::write_buffer(EP_BAUD_RATE,(const byte *)&ibaud,INTEGER_LENGTH) - ||!CONFIG::write_buffer(EP_WEB_PORT,(const byte *)&iweb_port,INTEGER_LENGTH) -#ifdef TCP_IP_DATA_FEATURE - ||!CONFIG::write_buffer(EP_DATA_PORT,(const byte *)&idata_port,INTEGER_LENGTH) -#endif - ||!CONFIG::write_byte(EP_SLEEP_MODE,bsleepmode)) { - msg_alert_error=true; - smsg = FPSTR(EEPROM_NOWRITE); - } else { - msg_alert_success=true; -#ifdef TCP_IP_DATA_FEATURE - wifi_config.iweb_port=iweb_port; -#endif - wifi_config.idata_port=idata_port; - smsg = F("Changes saved to EEPROM, restarting...."); - } - } - } else { //no submit need to get data from EEPROM - if (!CONFIG::read_buffer(EP_BAUD_RATE, (byte *)&ibaud , INTEGER_LENGTH)) { - ibaud=DEFAULT_BAUD_RATE; - } - if (!CONFIG::read_byte(EP_SLEEP_MODE, &bsleepmode )) { - bsleepmode=DEFAULT_SLEEP_MODE; - } - if (!CONFIG::read_buffer(EP_WEB_PORT, (byte *)&iweb_port , INTEGER_LENGTH)) { - iweb_port=DEFAULT_WEB_PORT; - } - wifi_config.iweb_port=iweb_port; - if (!CONFIG::read_buffer(EP_DATA_PORT, (byte *)&idata_port , INTEGER_LENGTH)) { - idata_port=DEFAULT_DATA_PORT; - } - wifi_config.idata_port=idata_port; - }; - //Baud rate list - istatus = 0; - stmp=""; - if (!outputjson){ - while (lbaudlist[istatus]>-1) { - - stmp+="