diff --git a/.travis.yml b/.travis.yml index f5fdc0af..8b137891 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,53 +1 @@ -sudo: false -language: bash - -os: - - linux - -before_install: - - "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16" - -before_script: - - "export DISPLAY=:99.0" - - sleep 3 # give xvfb some time to start - - 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 - - git clone https://github.com/esp8266/Arduino.git esp8266 - - cd esp8266/tools - - python get.py - - cd .. - - 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 - - -script: - - cd $TRAVIS_BUILD_DIR - - source command.sh - - export PATH="$HOME/arduino_ide:$PATH" - - 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: - on_success: change - on_failure: change diff --git a/README.md b/README.md index 7d808d8f..be97a8fc 100644 --- a/README.md +++ b/README.md @@ -1,137 +1,3 @@ -# ESP3D[![Code Climate](https://codeclimate.com/github/luc-github/ESP3D/badges/gpa.svg)](https://codeclimate.com/github/luc-github/ESP3D) +# ESP3D 3.0 -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/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 -Arduino ide 1.8.5 with stable [2.4.0](http://arduino.esp8266.com/versions/2.4.0/package_esp8266com_index.json) from ESP8266, please use https://github.com/luc-github/ESP3D/releases/tag/1.0 [![Build Status](https://travis-ci.org/luc-github/ESP3D.svg?branch=master)](https://travis-ci.org/luc-github/ESP3D) - -[Development version for 2.0 (2.0 branch)](https://github.com/luc-github/ESP3D/tree/2.0) & [ESP-WEBUI (2.0 branch)](https://github.com/luc-github/ESP3D-WEBUI/tree/2.0): -Arduino ide 1.8.5 with git version from ESP8266 or ESP32 for 100% support of ESP32 : [![Build Status](https://travis-ci.org/luc-github/ESP3D.svg?branch=2.0)](https://travis-ci.org/luc-github/ESP3D) - -[All releases](https://github.com/luc-github/ESP3D/wiki) - -:+1:Thanks -* to @disneysw for bringing this module idea -* to @lkarlslund for suggestion about independent reset using GPIO2 -* to Roy Cortes from http://www.panucatt.com for supporting and pushing me implementing great features -* to all contributors, feedbacks owners and donations. - -## Donate -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. - -## 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) -* 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) -* UI fully constomizable without reflashing FW using html templates, [keywords](https://raw.githubusercontent.com/luc-github/ESP3D/master/docs/keywords.txt) and html files/images -* Captive portal in Access point mode which redirect all unknow call to main page, here to enable/disable [CAPTIVE_PORTAL_FEATURE](https://github.com/luc-github/ESP3D/blob/master/esp3d/config.h) -* mDNS which allows to key the name defined in web browser and connect only with bonjour installed on computer, here to enable/disable [MDNS_FEATURE](https://github.com/luc-github/ESP3D/blob/master/esp3d/config.h) -* SSDP, this feature is a discovery protocol, supported on Windows out of the box, here to enable/disable [SSDP_FEATURE](https://github.com/luc-github/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 -*IP Generation: DHCP/Static IP -*IP/MASK/GATEWAY for static data -*Baud Rate for serial (supported : 9600, 19200, 38400, 57600, 115200, 230400, 250000) -*web port and data port - - -## Default Configuration -Default Settings: -AP:ESP8266 -PW:12345678 -Authentification: WPA -Mode: g (n is not supported by AP, just by STA) -channel: 11 -AP: visible -Sleep Mode: Modem -IP Mode: Static IP -IP: 192.168.0.1 -Mask: 255.255.255.0 -GW:192.168.0.1 -Baud rate: 115200 -Web port:80 -Data port: 8888 -Web Page refresh: 3 secondes -User: admin -Password: admin -User:user -Password: user - - - -## Direct commands: -Check wiki : https://github.com/luc-github/ESP3D/wiki/Direct-ESP3D-commands - -## Installation -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 -
- -## Update -* Generate a binary using the export binary menu from Arduino IDE and upload it using ESP-WEBUI or embedded interface - -

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

- -## Contribution/customization -* 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 - -Feedback/suggestion/discussions are always welcome - -## 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) - -## ESP3D is used by : -* Custom version is used on azteeg mini wifi : http://www.panucatt.com/azteeg_X5_mini_reprap_3d_printer_controller_p/ax5mini.htm -* GRBL_Esp32 a GRBL port on ESP32 done by @bdring - https://github.com/bdring/Grbl_Esp32 -[![](https://img.youtube.com/vi/7vtWNn9jyDs/mqdefault.jpg)](https://www.youtube.com/watch?v=7vtWNn9jyDs) -* Marlin_ESP32 a Marlin port on ESP32 done by @simon-jouet is under sync : https://github.com/luc-github/Marlin/tree/eps32_webui -* More to come... - -If you use ESP3D on your product, drop me a message so I can link your product page here. - - - -## TODO/On going : --- Version 2.X --- Close open topics --- Do testing (a lot) --- UI Improvement --- ESP3D V2 +

Coming Soon!

diff --git a/UI/repetier/testui.htm b/UI/repetier/testui.htm deleted file mode 100644 index c8a7bf59..00000000 --- a/UI/repetier/testui.htm +++ /dev/null @@ -1,840 +0,0 @@ - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - -X - -0.00 - - - - -Y - -100.00 - - - - -Z - -0.00 - - - - - - - -
-
- -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - X - - - - - - - - - Y - - - - - - - - - Z - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -X/Y - - - - - - - - - - - - - - - -Z - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -P - - - - - - -1 - - - - - - -2 - - - - - - -3 - - - - - - -4 - - - - - - -5 - - - - - - -? - - - - -
-
-
- - - - - - - - - -
- - - - - - - - - - - - -
- - - - - - - - Feedrate - -
-
- -
-
- - - - - - - - -
- - - - - - - - Flowrate - -
-
- -
- - - - - - - - -
- - - - - - - - Fan - -
-
- -
-
- - - - - - - - - - - - -
- - - - - - - - - - - - - - - - -Bed Temperature -60.43°C - - -
-
- -
-
- - - - -1 - - - - -
- - - - - - - - - - - - - - - - -Extruder 1 -180.03°C - - -
-
-
-
- - - - -2 - - - - -
- - - - - - - - - - - - - - - - -Extruder 2 -180.03°C - - -
-
-
-
-
- - - diff --git a/docs/Commands.txt b/docs/Commands.txt deleted file mode 100644 index 501fc2c7..00000000 --- a/docs/Commands.txt +++ /dev/null @@ -1,115 +0,0 @@ -* 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 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 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 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= - -* 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]pwd= -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 - - -*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] - diff --git a/embedded/build.bat b/embedded/build.bat deleted file mode 100644 index f4a9a8df..00000000 --- a/embedded/build.bat +++ /dev/null @@ -1 +0,0 @@ -bin2c /infile tool.html.gz /outfile out.h /targetfolder . diff --git a/embedded/gulpfile.js b/embedded/gulpfile.js deleted file mode 100644 index 8deb4a79..00000000 --- a/embedded/gulpfile.js +++ /dev/null @@ -1,125 +0,0 @@ -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 deleted file mode 100644 index e3f2831a..00000000 --- a/embedded/install.bat +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index 00299619..00000000 --- a/embedded/package.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "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 deleted file mode 100644 index de11ef01..00000000 Binary files a/embedded/tool.html.gz and /dev/null differ diff --git a/embedded/www/css/style.css b/embedded/www/css/style.css deleted file mode 100644 index d8b50635..00000000 --- a/embedded/www/css/style.css +++ /dev/null @@ -1,139 +0,0 @@ -html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%; font-size:10px;} -body{font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px;line-height:1.42857143;color:#333333;background-color:#ffffff;} -.container{margin-right:auto;margin-left:auto;padding-left:15px;padding-right:15px;} -table{border:0px;border-spacing:0;max-width:100%;} -.table-bordered{ width:100%; border:1px solid #dddddd;margin-bottom:20px;} -td{white-space:nowrap; padding:2mm;} -th{text-align:left;} -.table>thead>tr>th,.table>tbody>tr>th,.table>thead>tr>td,.table>tbody>tr>td{padding:8px;line-height:1.42857143;vertical-align:top;border-top:1px solid #dddddd;} -.table-bordered>thead>tr>th,.table-bordered>tbody>tr>th,.table-bordered>thead>tr>td,.table-bordered>tbody>tr>td{border:1px solid #dddddd;} -.table-bordered>thead>tr>th,.table-bordered>thead>tr>td{border-bottom-width:2px;} -.table-striped>tbody>tr:nth-of-type(odd){background-color:#f9f9f9;} -@media (min-width:768px){.container{width:750px;}} -@media (min-width:992px){.container{width:970px;}} -@media (min-width:1200px){.container{width:1170px;}} -.nav{ width:100%; color:#cccccc;padding-left:10;padding-right:10;list-style:none;background-color:#333333;border-radius:6px ;margin-bottom:20px;} -a{position:relative;display:block;padding:10px 15px;text-decoration:none;color:#cccccc;} -.active{color:#ffffff;background-color:#000000;} -.active a,a:hover,a:focus{color:#FFFFFF;} -.panel{margin-bottom:20px;background-color:#ffffff;border:1px solid #dddddd;border-radius:4px;-webkit-box-shadow:0 1px 1px rgba(0,0,0,0.05);box-shadow:0 1px 1px rgba(0,0,0,0.05);} -.panel-body{padding:15px;} -.panel-heading{padding:10px 15px;color:#333333;background-color:#f5f5f5;border-color:#dddddd;border-top-right-radius:3px;border-top-left-radius:3px;border-bottom:1px solid #dddddd;} -label{display:inline-block;max-width:100%;margin-bottom:5px;font-weight:bold;} -.text-info{color:#31708f;} -.form-control{display:block;width:auto;height:34px;padding:6px 12px;font-size:14px;line-height:1.42857143;color:#555555;background-color:#ffffff -;background-image:none;border:1px solid #cccccc;border-radius:4px;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075); -* -webkit-transition:border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;-o-transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s; -* transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;}.form-control:focus{border-color:#66afe9;outline:0;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,0.6); -* box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,0.6);} -.form-group{margin-bottom:15px;} -.btn{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;} -.btn-primary{color:#ffffff;background-color:#337ab7;border-color:#2e6da4;} -.btn-primary:focus,.btn-primary:active,.btn-primary:hover,.btn-primary.focus,.btn-primary.active,.btn-primary.hover{color:#ffffff;background-color:#286090;border-color:#122b40;} -caption{padding-top:8px;padding-bottom:8px;color:#777777;text-align:left;} -.alert{padding:15px;margin-bottom:20px;border:1px solid transparent;border-radius:4px;} -.alert-success{background-color:#dff0d8;border-color:#d6e9c6;color:#3c763d;} -.alert-danger{background-color:#f2dede;border-color:#ebccd1;color:#a94442;} -.has-error .form-control{border-color:#a94442;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);} -.has-error .form-control:focus{border-color:#843534;-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;} -.has-error .control-label{color:#a94442;} -.has-success .form-control {border-color: #3c763d;-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);} -.has-success .form-control:focus {border-color: #2b542c;-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #67b168;box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #67b168;} -.has-success .control-label{color: #3c763d;} -.btn-danger{color:#ffffff;background-color:#d9534f;border-color:#d43f3a;} -.btn-danger:focus,.btn-danger:active,.btn-danger:hover,.btn-danger.focus,.btn-danger.active,.btn-danger.hover{color: #ffffff;background-color:#c9302c;border-color:#761c19;} -.btnimg {cursor:hand; border-radius:6px ;;border:1px solid #FFFFFF;} -.btnimg:hover{background-color:#F0F0F0;border-color:#00FFFF;-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;} -.btnroundimg {cursor:hand; border-radius:30px;} -.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/embedded/www/js/script.js b/embedded/www/js/script.js deleted file mode 100644 index f6f7428e..00000000 --- a/embedded/www/js/script.js +++ /dev/null @@ -1,249 +0,0 @@ -var currentpath = "/"; -function navbar(){ - var content=""; - var tlist = currentpath.split("/"); - var path="/"; - var nb = 1; - content+=""; - while (nb < (tlist.length-1)) - { - path+=tlist[nb] + "/"; - content+=""; - nb++; - } - content+="
/"+tlist[nb] +"/
"; - return content; -} -function trash_icon(){ - var content =""; - content +=""; - content +=""; - content +=""; - content +=""; - content +=""; - content +=""; - content +=""; - content +=""; - return content; -} -function back_icon(){ - var content =""; - return content; -} -function select_dir(directoryname){ - currentpath+=directoryname + "/"; - SendCommand('list','all'); -} -function compareStrings(a, b) { - // case-insensitive comparison - a = a.toLowerCase(); - b = b.toLowerCase(); - return (a < b) ? -1 : (a > b) ? 1 : 0; -} -function dispatchfilestatus(jsonresponse) -{ -var content =""; -content ="  Status: "+jsonresponse.status; -content +="  |  Total space: "+jsonresponse.total; -content +="  |  Used space: "+jsonresponse.used; -content +="  |  Occupation: "; -content +=" "+jsonresponse.occupation +"%"; -document.getElementById('status').innerHTML=content; -content =""; -if (currentpath!="/") - { - var pos = currentpath.lastIndexOf("/",currentpath.length-2); - var previouspath = currentpath.slice(0,pos+1); - content +=""+back_icon()+" Up.."; - } -jsonresponse.files.sort(function(a, b) { - return compareStrings(a.name, b.name); -}); -for (var i1=0;i1
"; - content +=jsonresponse.files[i1].name; - content +="
"; - content +=jsonresponse.files[i1].size; - content +="
"; - content +=trash_icon(); - content +="
"; - } -} -//then display directories -for (var i2=0;i2 "; - content +=jsonresponse.files[i2].name; - content +=""; - content +="
"; - content +=trash_icon(); - content +="
"; - } -} - - document.getElementById('file_list').innerHTML=content; - document.getElementById('path').innerHTML=navbar();} -function Delete(filename){ -if (confirm("Confirm deletion of file: " + filename))SendCommand("delete",filename); -} -function Deletedir(filename){ -if (confirm("Confirm deletion of directory: " + filename))SendCommand("deletedir",filename); -} -function Createdir(){ -var filename = prompt("Please enter directory name", ""); -if (filename != null) { - SendCommand("createdir",filename.trim()); - } -} -function SendCommand(action,filename){ -var xmlhttp = new XMLHttpRequest(); -var url = "/files?action="+action; -url += "&filename="+encodeURI(filename); -url += "&path="+encodeURI(currentpath); -document.getElementById('loader').style.visibility="visible"; -xmlhttp.onreadystatechange = function() { - if (xmlhttp.readyState == 4 ) { - if(xmlhttp.status == 200) { - var jsonresponse = JSON.parse(xmlhttp.responseText); - document.getElementById('loader').style.visibility="hidden"; - dispatchfilestatus(jsonresponse);} - else SubmitRequest () - } -}; -xmlhttp.open("GET", url, true); -xmlhttp.send(); -} -function Sendfile(){ -var files = document.getElementById('file-select').files; -if (files.length==0)return; -document.getElementById('upload-button').value = "Uploading..."; -document.getElementById('prg').style.visibility = "visible"; -var formData = new FormData(); -formData.append('path', currentpath); -for (var i3 = 0; i3 < files.length; i3++) { -var file = files[i3]; - formData.append('myfiles[]', file, currentpath+file.name);} -var xmlhttp = new XMLHttpRequest(); -xmlhttp.open('POST', '/files', true); -//progress upload event -xmlhttp.upload.addEventListener("progress", updateProgress, false); -//progress function -function updateProgress (oEvent) { - if (oEvent.lengthComputable) { - var percentComplete = (oEvent.loaded / oEvent.total)*100; - document.getElementById('prg').value=percentComplete; - document.getElementById('upload-button').value = "Uploading ..." + percentComplete.toFixed(0)+"%" ; - } else { - // Impossible because size is unknown - } -} - -xmlhttp.onload = function () { - if (xmlhttp.status === 200) { -document.getElementById('upload-button').value = 'Upload'; -document.getElementById('prg').style.visibility = "hidden"; -document.getElementById('file-select').value=""; -var jsonresponse = JSON.parse(xmlhttp.responseText); -dispatchfilestatus(jsonresponse); - } else alert('An error occurred!'); -}; -xmlhttp.send(formData); -} - -window.onload = function() { -SendCommand('list','all'); -}; -function Uploadfile(){ -if (!confirm("Confirm Firmware Update ?"))return; -var files = document.getElementById('fw-select').files; -if (files.length==0)return; -document.getElementById('uploadfw-button').style.visibility = 'hidden'; -document.getElementById('fw-select').style.visibility = 'hidden'; -document.getElementById('msg').style.visibility = "visible"; -document.getElementById('msg').innerHTML=""; -document.getElementById('SPIFFS').style.display = "none"; -document.getElementById('prgfw').style.visibility = "visible"; -var formData = new FormData(); -for (var i4 = 0; i4 < files.length; i4++) { -var file = files[i4]; - formData.append('myfile[]', file, "/"+file.name);} -var xmlhttp = new XMLHttpRequest(); -xmlhttp.open('POST', '/updatefw', true); -//progress upload event -xmlhttp.upload.addEventListener("progress", updateProgress, false); -//progress function -function updateProgress (oEvent) { - if (oEvent.lengthComputable) { - var percentComplete = (oEvent.loaded / oEvent.total)*100; - document.getElementById('prgfw').value=percentComplete; - document.getElementById('msg').innerHTML = "Uploading ..." + percentComplete.toFixed(0)+"%" ; - } else { - // Impossible because size is unknown - } -} -xmlhttp.onload = function () { - if (xmlhttp.status === 200) { -document.getElementById('uploadfw-button').value = 'Upload'; -document.getElementById('msg').innerHTML="Restarting, please wait...."; -document.getElementById('counter').style.visibility = "visible"; -document.getElementById('uploadfw-button').style.visibility = 'hidden'; -document.getElementById('uploadfw-button').style.width = '0px'; -document.getElementById('fw-select').value=""; -document.getElementById('fw-select').style.visibility = 'hidden'; -document.getElementById('fw-select').style.width = '0px'; - -var jsonresponse = JSON.parse(xmlhttp.responseText); -if (jsonresponse.status=='1' || jsonresponse.status=='4' || jsonresponse.status=='1')alert("Update failed"); -if (jsonresponse.status=='2')alert('Update canceled!'); -else if (jsonresponse.status=='3') -{ - var i5 = 0; - var interval; - var x = document.getElementById("prgfw"); - x.max=40; - interval = setInterval(function(){ - i5=i5+1; - var x = document.getElementById("prgfw"); - x.value=i5; - document.getElementById('counter').innerHTML=41-i5; - if (i5>40) - { - clearInterval(interval); - location.reload(); - } - },1000); -} -else alert('Update failed!'); - } else alert('An error occurred!'); -}; -xmlhttp.send(formData); -} - -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 deleted file mode 100644 index 33c5cecd..00000000 --- a/embedded/www/tool.html +++ /dev/null @@ -1,100 +0,0 @@ - - - - - - - -
- 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/GenLinkedList.h b/esp3d/GenLinkedList.h deleted file mode 100644 index f2051cec..00000000 --- a/esp3d/GenLinkedList.h +++ /dev/null @@ -1,340 +0,0 @@ -/* - GenLinkedList.h - V1.1 - Generic LinkedList implementation - Works better with FIFO, because LIFO will need to - search the entire List to find the last one; - - For instructions, go to https://github.com/ivanseidel/LinkedList - - Created by Ivan Seidel Gomes, March, 2013. - Released into the public domain. - Changelog: 2015/10/05: [Luc] Change false to NULL for pointers -*/ - - -#ifndef GenLinkedList_h -#define GenLinkedList_h - -template -struct ListNode { - T data; - ListNode *next; -}; - -template -class GenLinkedList -{ - -protected: - int _size; - ListNode *root; - ListNode *last; - - // Helps "get" method, by saving last position - ListNode *lastNodeGot; - int lastIndexGot; - // isCached should be set to FALSE - // every time the list suffer changes - bool isCached; - - ListNode* getNode(int index); - -public: - GenLinkedList(); - ~GenLinkedList(); - - /* - Returns current size of GenLinkedList - */ - virtual int size(); - /* - Adds a T object in the specified index; - Unlink and link the GenLinkedList correcly; - Increment _size - */ - virtual bool add(int index, T); - /* - Adds a T object in the end of the GenLinkedList; - Increment _size; - */ - virtual bool add(T); - /* - Adds a T object in the start of the GenLinkedList; - Increment _size; - */ - virtual bool unshift(T); - /* - Set the object at index, with T; - Increment _size; - */ - virtual bool set(int index, T); - /* - Remove object at index; - If index is not reachable, returns false; - else, decrement _size - */ - virtual T remove(int index); - /* - Remove last object; - */ - virtual T pop(); - /* - Remove first object; - */ - virtual T shift(); - /* - Get the index'th element on the list; - Return Element if accessible, - else, return false; - */ - virtual T get(int index); - - /* - Clear the entire array - */ - virtual void clear(); - -}; - -// Initialize GenLinkedList with false values -template -GenLinkedList::GenLinkedList() -{ - root=NULL; - last=NULL; - _size=0; - - lastNodeGot = root; - lastIndexGot = 0; - isCached = false; -} - -// Clear Nodes and free Memory -template -GenLinkedList::~GenLinkedList() -{ - ListNode* tmp; - while(root!=NULL) { - tmp=root; - root=root->next; - delete tmp; - } - last = NULL; - _size=0; - isCached = false; -} - -/* - Actually "logic" coding -*/ - -template -ListNode* GenLinkedList::getNode(int index) -{ - - int _pos = 0; - ListNode* current = root; - - // Check if the node trying to get is - // immediately AFTER the previous got one - if(isCached && lastIndexGot <= index) { - _pos = lastIndexGot; - current = lastNodeGot; - } - - while(_pos < index && current) { - current = current->next; - - _pos++; - } - - // Check if the object index got is the same as the required - if(_pos == index) { - isCached = true; - lastIndexGot = index; - lastNodeGot = current; - - return current; - } - - return NULL; -} - -template -int GenLinkedList::size() -{ - return _size; -} - -template -bool GenLinkedList::add(int index, T _t) -{ - - if(index >= _size) { - return add(_t); - } - - if(index == 0) { - return unshift(_t); - } - - ListNode *tmp = new ListNode(), - *_prev = getNode(index-1); - tmp->data = _t; - tmp->next = _prev->next; - _prev->next = tmp; - - _size++; - isCached = false; - - return true; -} - -template -bool GenLinkedList::add(T _t) -{ - - ListNode *tmp = new ListNode(); - tmp->data = _t; - tmp->next = NULL; - - if(root) { - // Already have elements inserted - last->next = tmp; - last = tmp; - } else { - // First element being inserted - root = tmp; - last = tmp; - } - - _size++; - isCached = false; - - return true; -} - -template -bool GenLinkedList::unshift(T _t) -{ - - if(_size == 0) { - return add(_t); - } - - ListNode *tmp = new ListNode(); - tmp->next = root; - tmp->data = _t; - root = tmp; - - _size++; - isCached = false; - - return true; -} - -template -bool GenLinkedList::set(int index, T _t) -{ - // Check if index position is in bounds - if(index < 0 || index >= _size) { - return false; - } - - getNode(index)->data = _t; - return true; -} - -template -T GenLinkedList::pop() -{ - if(_size <= 0) { - return T(); - } - - isCached = false; - - if(_size >= 2) { - ListNode *tmp = getNode(_size - 2); - T ret = tmp->next->data; - delete(tmp->next); - tmp->next = NULL; - last = tmp; - _size--; - return ret; - } else { - // Only one element left on the list - T ret = root->data; - delete(root); - root = NULL; - last = NULL; - _size = 0; - return ret; - } -} - -template -T GenLinkedList::shift() -{ - if(_size <= 0) { - return T(); - } - - if(_size > 1) { - ListNode *_next = root->next; - T ret = root->data; - delete(root); - root = _next; - _size --; - isCached = false; - - return ret; - } else { - // Only one left, then pop() - return pop(); - } - -} - -template -T GenLinkedList::remove(int index) -{ - if (index < 0 || index >= _size) { - return T(); - } - - if(index == 0) { - return shift(); - } - - if (index == _size-1) { - return pop(); - } - - ListNode *tmp = getNode(index - 1); - ListNode *toDelete = tmp->next; - T ret = toDelete->data; - tmp->next = tmp->next->next; - delete(toDelete); - _size--; - isCached = false; - return ret; -} - - -template -T GenLinkedList::get(int index) -{ - ListNode *tmp = getNode(index); - - return (tmp ? tmp->data : T()); -} - -template -void GenLinkedList::clear() -{ - while(size() > 0) { - shift(); - } -} - -#endif diff --git a/esp3d/bridge.cpp b/esp3d/bridge.cpp deleted file mode 100644 index 58d6d34d..00000000 --- a/esp3d/bridge.cpp +++ /dev/null @@ -1,209 +0,0 @@ -/* - bridge.cpp - esp3d bridge serial/tcp class - - 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 -*/ - -#include "config.h" -#include "bridge.h" -#include "command.h" -#include "webinterface.h" - -#ifdef TCP_IP_DATA_FEATURE -WiFiServer * data_server; -WiFiClient serverClients[MAX_SRV_CLIENTS]; -#endif - -bool BRIDGE::header_sent = false; -String BRIDGE::buffer_web = ""; -void BRIDGE::print (const __FlashStringHelper *data, tpipe output) -{ - String tmp = data; - BRIDGE::print(tmp.c_str(), 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; - ESP_SERIAL_OUT.print(data); - break; -#ifdef TCP_IP_DATA_FEATURE - case TCP_PIPE: - header_sent = false; - BRIDGE::send2TCP(data); - break; -#endif - 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: - break; - } -} -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) -{ - 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) -{ - 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: - ESP_SERIAL_OUT.flush(); - break; -#ifdef TCP_IP_DATA_FEATURE - case TCP_PIPE: - break; -#endif - case WEB_PIPE: - if(header_sent) { - //send data - web_interface->web_server.sendContent(buffer_web); - //close line - web_interface->web_server.sendContent(""); - } - break; - default: - break; - } - header_sent = false; - buffer_web = String(); -} - - -#ifdef TCP_IP_DATA_FEATURE -void BRIDGE::send2TCP(const __FlashStringHelper *data) -{ - String tmp = data; - BRIDGE::send2TCP(tmp.c_str()); -} -void BRIDGE::send2TCP(String data) -{ - BRIDGE::send2TCP(data.c_str()); -} -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); - } - } -} -#endif - -bool BRIDGE::processFromSerial2TCP() -{ - uint8_t i; - //check UART for data - if(ESP_SERIAL_OUT.available()) { - size_t len = ESP_SERIAL_OUT.available(); - uint8_t sbuf[len]; - ESP_SERIAL_OUT.readBytes(sbuf, len); -#ifdef TCP_IP_DATA_FEATURE - 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 - //process data if any - COMMAND::read_buffer_serial(sbuf, len); - return true; - } else { - return false; - } -} -#ifdef TCP_IP_DATA_FEATURE -void BRIDGE::processFromTCP2Serial() -{ - uint8_t i,data; - //check if there are any new clients - if (data_server->hasClient()) { - for(i = 0; i < MAX_SRV_CLIENTS; i++) { - //find free/disconnected spot - if (!serverClients[i] || !serverClients[i].connected()) { - if(serverClients[i]) { - serverClients[i].stop(); - } - serverClients[i] = data_server->available(); - continue; - } - } - //no free/disconnected spot so reject - WiFiClient serverClient = data_server->available(); - serverClient.stop(); - } - //check clients for data - //to avoid any pollution if Uploading file to SDCard - if ((web_interface->blockserial) == false) { - for(i = 0; i < MAX_SRV_CLIENTS; i++) { - if (serverClients[i] && serverClients[i].connected()) { - if(serverClients[i].available()) { - //get data from the tcp client and push it to the UART - while(serverClients[i].available()) { - data = serverClients[i].read(); - ESP_SERIAL_OUT.write(data); - COMMAND::read_buffer_tcp(data); - } - } - } - } - } -} -#endif diff --git a/esp3d/bridge.h b/esp3d/bridge.h deleted file mode 100644 index 6bff0f8f..00000000 --- a/esp3d/bridge.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - bridge.h - esp3d bridge serial/tcp class - - 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 -*/ - -#ifndef BRIDGE_H -#define BRIDGE_H -#include -#include "config.h" -#ifdef TCP_IP_DATA_FEATURE -extern WiFiServer * data_server; -#endif - -class BRIDGE -{ -public: - static bool header_sent; - static String buffer_web; - static bool processFromSerial2TCP(); - static void print (const __FlashStringHelper *data, tpipe output); - static void print (String & data, tpipe output); - static void print (const char * data, tpipe output); - static void println (const __FlashStringHelper *data, tpipe output); - static void println (String & data, tpipe output); - static void println (const char * data, tpipe output); - static void flush (tpipe output); -#ifdef TCP_IP_DATA_FEATURE - static void processFromTCP2Serial(); - static void send2TCP(const __FlashStringHelper *data); - static void send2TCP(String data); - static void send2TCP(const char * data); -#endif -}; -#endif diff --git a/esp3d/command.cpp b/esp3d/command.cpp deleted file mode 100644 index 9b86fe72..00000000 --- a/esp3d/command.cpp +++ /dev/null @@ -1,1600 +0,0 @@ -/* - command.cpp - ESP3D configuration class - - 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 -*/ -#include "config.h" -#include "command.h" -#include "wificonf.h" -#include "webinterface.h" -#ifndef FS_NO_GLOBALS -#define FS_NO_GLOBALS -#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 (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) -{ - static String parameter; - String sid=id; - int start; - int end = -1; - parameter = ""; - //if no id it means it is first part of cmd - if (strlen(id) == 0) { - start = 0; - } - //else find id position - else { - start = cmd_params.indexOf(id); - } - //if no id found and not first part leave - if (start == -1 ) { - return parameter; - } - //password and SSID can have space so handle it - //if no space expected use space as delimiter - 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); - } -#endif - //if no end found - take all - if (end == -1) { - end = cmd_params.length(); - } - //extract parameter - parameter = cmd_params.substring(start+strlen(id),end); - //be sure no extra space - parameter.trim(); - 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)) { - LOG("ERROR getting admin\r\n") - sadminPassword=FPSTR(DEFAULT_ADMIN_PWD); - } - adminpassword = get_param(cmd_params,"pwd=", true); - if (!sadminPassword.equals(adminpassword)) { - LOG("Not identified from command line\r\n") - return false; - } else { - return true; - } -} -//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; - level_authenticate_type auth_type = auth_level; -#ifdef AUTHENTICATION_FEATURE - if (isadmin(cmd_params)) { - auth_type = LEVEL_ADMIN; - LOG("admin identified\r\n"); - } - if (isuser(cmd_params) && (auth_type != LEVEL_ADMIN)) { - auth_type = LEVEL_USER; - LOG("user identified\r\n"); - } -#ifdef DEBUG_ESP3D - if ( auth_type == LEVEL_ADMIN) - { - LOG("admin identified\r\n"); - } - else { - if( auth_type == LEVEL_USER) - { - LOG("user identified\r\n"); - } - else - { - LOG("guest identified\r\n"); - } - } -#endif -#endif - //manage parameters - byte mode = 254; - String parameter; - LOG("Execute Command\r\n") - switch(cmd) { - //STA SSID - //[ESP100][pwd=] - case 100: - parameter = get_param(cmd_params,"", true); - if (!CONFIG::isSSIDValid(parameter.c_str())) { - BRIDGE::println(INCORRECT_CMD_MSG, output); - } -#ifdef AUTHENTICATION_FEATURE - 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); - } - break; - //STA Password - //[ESP101][pwd=] - case 101: - parameter = get_param(cmd_params,"", true); - if (!CONFIG::isPasswordValid(parameter.c_str())) { - BRIDGE::println(INCORRECT_CMD_MSG, output); - response = false; - } -#ifdef AUTHENTICATION_FEATURE - 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); - } - break; - //Hostname - //[ESP102][pwd=] - case 102: - parameter = get_param(cmd_params,"", true); - if (!CONFIG::isHostnameValid(parameter.c_str())) { - BRIDGE::println(INCORRECT_CMD_MSG, output); - response = false; - } -#ifdef AUTHENTICATION_FEATURE - 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); - } - break; - //Wifi mode (STA/AP) - //[ESP103][pwd=] - case 103: - parameter = get_param(cmd_params,"", true); - if (parameter == "STA") { - mode = CLIENT_MODE; - } else if (parameter == "AP") { - mode = AP_MODE; - } else { - BRIDGE::println(INCORRECT_CMD_MSG, output); - response = false; - } - if ((mode == CLIENT_MODE) || (mode == AP_MODE)) { -#ifdef AUTHENTICATION_FEATURE - 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); - } - } - break; - //STA IP mode (DHCP/STATIC) - //[ESP104][pwd=] - case 104: - parameter = get_param(cmd_params,"", true); - if (parameter == "STATIC") { - mode = STATIC_IP_MODE; - } else if (parameter == "DHCP") { - mode = DHCP_MODE; - } else { - BRIDGE::println(INCORRECT_CMD_MSG, output); - response = false; - } - if ((mode == STATIC_IP_MODE) || (mode == DHCP_MODE)) { -#ifdef AUTHENTICATION_FEATURE - 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); - } - } - break; - //AP SSID - //[ESP105][pwd=] - case 105: - parameter = get_param(cmd_params,"", true); - if (!CONFIG::isSSIDValid(parameter.c_str())) { - BRIDGE::println(INCORRECT_CMD_MSG, output); - response = false; - } -#ifdef AUTHENTICATION_FEATURE - 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); - } - break; - //AP Password - //[ESP106][pwd=] - case 106: - parameter = get_param(cmd_params,"", true); - if (!CONFIG::isPasswordValid(parameter.c_str())) { - BRIDGE::println(INCORRECT_CMD_MSG, output); - response = false; - } -#ifdef AUTHENTICATION_FEATURE - 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); - } - break; - //AP IP mode (DHCP/STATIC) - //[ESP107][pwd=] - case 107: - parameter = get_param(cmd_params,"", true); - if (parameter == "STATIC") { - mode = STATIC_IP_MODE; - } else if (parameter == "DHCP") { - mode = DHCP_MODE; - } else { - BRIDGE::println(INCORRECT_CMD_MSG, output); - response = false; - } - if ((mode == STATIC_IP_MODE) || (mode == DHCP_MODE)) { -#ifdef AUTHENTICATION_FEATURE - 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: { - String currentIP ; - if (WiFi.getMode()==WIFI_STA) { - currentIP=WiFi.localIP().toString(); - } else { - currentIP=WiFi.softAPIP().toString(); - } - BRIDGE::print(cmd_params, output); - BRIDGE::println(currentIP, output); - LOG(cmd_params) - LOG(currentIP) - LOG("\r\n") - } - break; - //Get hostname - //[ESP112]
- case 112: { - String shost ; - if (!CONFIG::read_string(EP_HOSTNAME, shost, MAX_HOSTNAME_LENGTH)) { - shost=wifi_config.get_default_hostname(); - } - BRIDGE::print(cmd_params, output); - BRIDGE::println(shost, output); - LOG(cmd_params) - LOG(shost) - LOG("\r\n") - } - break; -#ifdef DIRECT_PIN_FEATURE - //Get/Set pin value - //[ESP201]P V [PULLUP=YES RAW=YES]pwd= - case 201: - parameter = get_param(cmd_params,"", true); -#ifdef AUTHENTICATION_FEATURE - if (auth_type == LEVEL_GUEST) { - BRIDGE::println(INCORRECT_CMD_MSG, output); - 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; -#endif - - //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); - else BRIDGE::print(F("\n"), 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 (auth_type != LEVEL_ADMIN) { - BRIDGE::println(INCORRECT_CMD_MSG, output); - response = false; - } else -#endif - { - if (parameter=="RESET") { - CONFIG::reset_config(); - BRIDGE::println(F("Reset done - restart needed"), output); - } else if (parameter=="SAFEMODE") { - wifi_config.Safe_Setup(); - 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; - } - } - break; -#ifdef AUTHENTICATION_FEATURE - //Change / Reset user password - //[ESP555]pwd= - case 555: { - 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())) { - if(CONFIG::write_string(EP_USER_PWD,parameter.c_str())) { - 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; - } -#endif - //[ESP700] - case 700: { //read local file - //be sure serial is locked - if ((web_interface->blockserial)) { - break; - } - cmd_params.trim() ; - if ((cmd_params.length() > 0) && (cmd_params[0] != '/')) { - cmd_params = "/" + cmd_params; - } - FS_FILE currentfile = SPIFFS.open(cmd_params, SPIFFS_FILE_READ); - if (currentfile) {//if file open success - //flush to be sure send buffer is empty - ESP_SERIAL_OUT.flush(); - //until no line in file - while (currentfile.available()) { - String currentline = currentfile.readStringUntil('\n'); - currentline.replace("\n",""); - currentline.replace("\r",""); - if (currentline.length() > 0) { - 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(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); - 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") { -#ifdef ERROR_MSG_FEATURE - web_interface->error_msg.clear(); -#endif -#ifdef STATUS_MSG_FEATURE - web_interface->status_msg.clear(); -#endif -#ifdef INFO_MSG_FEATURE - web_interface->info_msg.clear(); -#endif - BRIDGE::println(OK_CMD_MSG, output); - break; - } - default: - BRIDGE::println(INCORRECT_CMD_MSG, output); - response = false; - } - return response; -} - -bool COMMAND::check_command(String buffer, tpipe output, bool handlelockserial) -{ - String buffer2; - LOG("Check Command:") - 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 (( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER)) { - //save time no need to continue - if ((buffer.indexOf("busy:") > -1) || (buffer.startsWith("wait"))) { - return false; - } - if (buffer.startsWith("ok")) { - return false; - } - } -#ifdef ERROR_MSG_FEATURE - int Errorpos = -1; -#endif -#ifdef INFO_MSG_FEATURE - int Infopos = -1; -#endif -#ifdef STATUS_MSG_FEATURE - int Statuspos = -1; -#endif -if (CONFIG::GetFirmwareTarget() == SMOOTHIEWARE) { -#ifdef ERROR_MSG_FEATURE - Errorpos= buffer.indexOf("error:"); -#endif -#ifdef INFO_MSG_FEATURE - Infopos= buffer.indexOf("info:"); -#endif -#ifdef STATUS_MSG_FEATURE - 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; - int ESPpos = buffer.indexOf("[ESP"); - if (ESPpos>-1) { - //is there the second part? - int ESPpos2 = buffer.indexOf("]",ESPpos); - if (ESPpos2>-1) { - //Split in command and parameters - String cmd_part1=buffer.substring(ESPpos+4,ESPpos2); - String cmd_part2=""; - //is there space for parameters? - if (ESPpos2-1 && !(buffer.indexOf("Format error")!=-1 || buffer.indexOf("wait")==Errorpos+6) ) { - String ss = buffer.substring(Errorpos+6); - ss.replace("\"",""); - ss.replace("'",""); - (web_interface->error_msg).add(ss.c_str()); - } -#endif -#ifdef INFO_MSG_FEATURE - //Info - if (Infopos>-1) { - String ss = buffer.substring(Errorpos+5); - ss.replace("\"",""); - ss.replace("'",""); - (web_interface->info_msg).add(ss.c_str()); - } -#endif -#ifdef STATUS_MSG_FEATURE - //Status - if (Statuspos>-1) { - 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 - - return is_temp; -} - -//read a buffer in an array -void COMMAND::read_buffer_serial(uint8_t *b, size_t len) -{ - for (long i = 0; i< len; i++) { - read_buffer_serial(b[i]); - //*b++; - } -} - -#ifdef TCP_IP_DATA_FEATURE -//read buffer as char -void COMMAND::read_buffer_tcp(uint8_t b) -{ - static bool previous_was_char=false; - static bool iscomment=false; -//to ensure it is continuous string, no char separated by binaries - if (!previous_was_char) { - buffer_tcp=""; - iscomment = false; - } -//is comment ? - if (char(b) == ';') { - iscomment = true; - } -//it is a char so add it to buffer - if (isPrintable(b)) { - previous_was_char=true; - //add char if not a comment - if (!iscomment) { - buffer_tcp+=char(b); - } - } else { - previous_was_char=false; //next call will reset the buffer - } -//this is not printable but end of command check if need to handle it - if (b==13 || b==10) { - //reset comment flag - iscomment = false; - //Minimum is something like M10 so 3 char - if (buffer_tcp.length()>3) { - check_command(buffer_tcp, TCP_PIPE); - } - } -} -#endif -//read buffer as char -void COMMAND::read_buffer_serial(uint8_t b) -{ - static bool previous_was_char=false; - static bool iscomment=false; -//to ensure it is continuous string, no char separated by binaries - if (!previous_was_char) { - buffer_serial=""; - iscomment = false; - } -//is comment ? - if (char(b) == ';') { - iscomment = true; - } -//it is a char so add it to buffer - if (isPrintable(b)) { - previous_was_char=true; - if (!iscomment) { - buffer_serial+=char(b); - } - } else { - previous_was_char=false; //next call will reset the buffer - } -//this is not printable but end of command check if need to handle it - if (b==13 || b==10) { - //reset comment flag - iscomment = false; - //Minimum is something like M10 so 3 char - if (buffer_serial.length()>3) { - check_command(buffer_serial, SERIAL_PIPE); - } - } -} diff --git a/esp3d/command.h b/esp3d/command.h deleted file mode 100644 index 2c055648..00000000 --- a/esp3d/command.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - command.h - ESP3D configuration class - - 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 -*/ - -#ifndef COMMAND_h -#define COMMAND_h -#include -#include "bridge.h" - -class COMMAND -{ -public: - static String buffer_serial; - static String buffer_tcp; - static void read_buffer_serial(uint8_t *b, size_t len); - static void read_buffer_serial(uint8_t b); -#ifdef TCP_IP_DATA_FEATURE - static void read_buffer_tcp(uint8_t b); -#endif - static bool check_command(String buffer, tpipe output, bool handlelockserial = true); - 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 deleted file mode 100644 index 9b55b265..00000000 --- a/esp3d/config.cpp +++ /dev/null @@ -1,1865 +0,0 @@ -/* - config.cpp- ESP3D configuration class - - 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 -*/ -#include "config.h" -#include -#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" - - -uint8_t CONFIG::FirmwareTarget = UNKNOWN_FW; - -bool CONFIG::SetFirmwareTarget(uint8_t fw){ - if ( 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") - ESP_SERIAL_OUT.flush(); - delay(500); -#ifdef ARDUINO_ARCH_ESP8266 - ESP_SERIAL_OUT.swap(); -#endif - delay(100); - ESP.restart(); - while (1) { - delay(1); - }; -} - -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) < MIN_HOSTNAME_LENGTH) { - return false; - } - //only letter and digit - for (int i=0; i < strlen(hostname); i++) { - c = hostname[i]; - if (!(isdigit(c) || isalpha(c) || c=='_')) { - return false; - } - if (c==' ') { - return false; - } - } - return true; -} - -bool CONFIG::isSSIDValid(const char * ssid) -{ - //limited size - //char c; - if (strlen(ssid)>MAX_SSID_LENGTH || strlen(ssid)MAX_PASSWORD_LENGTH) { - return false; - } - #if MIN_PASSWORD_LENGTH > 0 - if (strlen(password)MAX_LOCAL_PASSWORD_LENGTH)|| (strlen(password)15 || strlen(IP)==0) { - return false; - } - //cannot start with . - if (IP[0]=='.') { - return false; - } - //only letter and digit - for (int i=0; i < strlen(IP); i++) { - c = IP[i]; - if (isdigit(c)) { - //only 3 digit at once - internalcount++; - previouswasdot=false; - if (internalcount>3) { - return false; - } - } else if(c=='.') { - //cannot have 2 dots side by side - if (previouswasdot) { - return false; - } - previouswasdot=true; - internalcount=0; - dotcount++; - }//if not a dot neither a digit it is wrong - else { - return false; - } - } - //if not 3 dots then it is wrong - if (dotcount!=3) { - return false; - } - //cannot have the last dot as last char - if (IP[strlen(IP)-1]=='.') { - return false; - } - return true; -} - -char * CONFIG::intTostr(int value) -{ - static char result [12]; - sprintf(result,"%d",value); - return result; -} - -String CONFIG::formatBytes(uint32_t bytes) -{ - if (bytes < 1024) { - return String(bytes)+" B"; - } else if(bytes < (1024 * 1024)) { - return String(bytes/1024.0)+" KB"; - } else if(bytes < (1024 * 1024 * 1024)) { - return String(bytes/1024.0/1024.0)+" MB"; - } else { - return String(bytes/1024.0/1024.0/1024.0)+" GB"; - } -} - -//helper to convert string to IP -//do not use IPAddress.fromString() because lack of check point and error result -//return number of parts -byte CONFIG::split_ip (const char * ptr,byte * part) -{ - if (strlen(ptr)>15 || strlen(ptr)< 7) { - part[0]=0; - part[1]=0; - part[2]=0; - part[3]=0; - return 0; - } - - char pstart [16]; - char * ptr2; - strcpy(pstart,ptr); - ptr2 = pstart; - byte i = strlen(pstart); - byte pos = 0; - for (byte j=0; jsprintf(macstr,"%02X:%02X:%02X:%02X:%02X:%02X",mac[0],mac[1],mac[2],mac[3],mac[4],mac[5])) { - strcpy (macstr, "00:00:00:00:00:00"); - } - return macstr; -} - - -//read a string -//a string is multibyte + \0, this is won't work if 1 char is multibyte like chinese char -bool CONFIG::read_string(int pos, char byte_buffer[], int size_max) -{ - //check if parameters are acceptable - if (size_max==0 || pos+size_max+1 > EEPROM_SIZE || byte_buffer== NULL) { - LOG("Error read string\r\n") - return false; - } - EEPROM.begin(EEPROM_SIZE); - byte b = 13; // non zero for the while loop below - int i=0; - - //read until max size is reached or \0 is found - while (i < size_max && b != 0) { - b = EEPROM.read(pos+i); - byte_buffer[i]=b; - i++; - } - - // Be sure there is a 0 at the end. - if (b!=0) { - byte_buffer[i-1]=0x00; - } - EEPROM.end(); - - return true; -} - -bool CONFIG::read_string(int pos, String & sbuffer, int size_max) -{ - //check if parameters are acceptable - if (size_max==0 || pos+size_max+1 > EEPROM_SIZE ) { - LOG("Error read string\r\n") - return false; - } - byte b = 13; // non zero for the while loop below - int i=0; - sbuffer=""; - - EEPROM.begin(EEPROM_SIZE); - //read until max size is reached or \0 is found - while (i < size_max && b != 0) { - b = EEPROM.read(pos+i); - if (b!=0) { - sbuffer+=char(b); - } - i++; - } - EEPROM.end(); - - return true; -} - -//read a buffer of size_buffer -bool CONFIG::read_buffer(int pos, byte byte_buffer[], int size_buffer) -{ - //check if parameters are acceptable - if (size_buffer==0 || pos+size_buffer > EEPROM_SIZE || byte_buffer== NULL) { - LOG("Error read buffer\r\n") - return false; - } - int i=0; - EEPROM.begin(EEPROM_SIZE); - //read until max size is reached - while (i EEPROM_SIZE) { - LOG("Error read byte\r\n") - return false; - } - EEPROM.begin(EEPROM_SIZE); - value[0] = EEPROM.read(pos); - EEPROM.end(); - return true; -} - -bool CONFIG::write_string(int pos, const __FlashStringHelper *str) -{ - String stmp = 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) -{ - int size_buffer; - int maxsize = EEPROM_SIZE; - size_buffer= strlen(byte_buffer); - //check if parameters are acceptable - switch (pos) { - case EP_ADMIN_PWD: - case EP_USER_PWD: - maxsize = MAX_LOCAL_PASSWORD_LENGTH; - break; - case EP_AP_SSID: - case EP_STA_SSID: - maxsize = MAX_SSID_LENGTH; - break; - case EP_AP_PASSWORD: - case EP_STA_PASSWORD: - maxsize = MAX_PASSWORD_LENGTH; - break; - 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 == EP_DATA_STRING)) || pos+size_buffer+1 > EEPROM_SIZE || size_buffer > maxsize || byte_buffer== NULL) { - LOG("Error write string\r\n") - return false; - } - //copy the value(s) - EEPROM.begin(EEPROM_SIZE); - for (int i = 0; i < size_buffer; i++) { - EEPROM.write(pos + i, byte_buffer[i]); - } - - //0 terminal - EEPROM.write(pos + size_buffer, 0x00); - EEPROM.commit(); - EEPROM.end(); - return true; -} - -//write a buffer -bool CONFIG::write_buffer(int pos, const byte * byte_buffer, int size_buffer) -{ - //check if parameters are acceptable - if (size_buffer==0 || pos+size_buffer > EEPROM_SIZE || byte_buffer== NULL) { - LOG("Error write buffer\r\n") - return false; - } - EEPROM.begin(EEPROM_SIZE); - //copy the value(s) - for (int i = 0; i < size_buffer; i++) { - EEPROM.write(pos + i, byte_buffer[i]); - } - EEPROM.commit(); - EEPROM.end(); - return true; -} - -//read a flag / byte -bool CONFIG::write_byte(int pos, const byte value) -{ - //check if parameters are acceptable - if (pos+1 > EEPROM_SIZE) { - LOG("Error write byte\r\n") - return false; - } - EEPROM.begin(EEPROM_SIZE); - EEPROM.write(pos, value); - EEPROM.commit(); - EEPROM.end(); - return true; -} - -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; - } - if(!CONFIG::write_buffer(EP_BAUD_RATE,(const byte *)&DEFAULT_BAUD_RATE,INTEGER_LENGTH)) { - return false; - } - if(!CONFIG::write_string(EP_AP_SSID,FPSTR(DEFAULT_AP_SSID))) { - return false; - } - if(!CONFIG::write_string(EP_AP_PASSWORD,FPSTR(DEFAULT_AP_PASSWORD))) { - return false; - } - if(!CONFIG::write_string(EP_STA_SSID,FPSTR(DEFAULT_STA_SSID))) { - return false; - } - if(!CONFIG::write_string(EP_STA_PASSWORD,FPSTR(DEFAULT_STA_PASSWORD))) { - return false; - } - if(!CONFIG::write_byte(EP_AP_IP_MODE,DEFAULT_AP_IP_MODE)) { - return false; - } - if(!CONFIG::write_byte(EP_STA_IP_MODE,DEFAULT_STA_IP_MODE)) { - return false; - } - if(!CONFIG::write_buffer(EP_STA_IP_VALUE,DEFAULT_IP_VALUE,IP_LENGTH)) { - return false; - } - if(!CONFIG::write_buffer(EP_STA_MASK_VALUE,DEFAULT_MASK_VALUE,IP_LENGTH)) { - return false; - } - if(!CONFIG::write_buffer(EP_STA_GATEWAY_VALUE,DEFAULT_GATEWAY_VALUE,IP_LENGTH)) { - return false; - } - if(!CONFIG::write_byte(EP_STA_PHY_MODE,DEFAULT_PHY_MODE)) { - return false; - } - if(!CONFIG::write_buffer(EP_AP_IP_VALUE,DEFAULT_IP_VALUE,IP_LENGTH)) { - return false; - } - if(!CONFIG::write_buffer(EP_AP_MASK_VALUE,DEFAULT_MASK_VALUE,IP_LENGTH)) { - return false; - } - if(!CONFIG::write_buffer(EP_AP_GATEWAY_VALUE,DEFAULT_GATEWAY_VALUE,IP_LENGTH)) { - return false; - } - if(!CONFIG::write_byte(EP_AP_PHY_MODE,DEFAULT_PHY_MODE)) { - return false; - } - if(!CONFIG::write_byte(EP_SLEEP_MODE,DEFAULT_SLEEP_MODE)) { - return false; - } - if(!CONFIG::write_byte(EP_CHANNEL,DEFAULT_CHANNEL)) { - return false; - } - if(!CONFIG::write_byte(EP_AUTH_TYPE,DEFAULT_AUTH_TYPE)) { - return false; - } - if(!CONFIG::write_byte(EP_SSID_VISIBLE,DEFAULT_SSID_VISIBLE)) { - return false; - } - if(!CONFIG::write_buffer(EP_WEB_PORT,(const byte *)&DEFAULT_WEB_PORT,INTEGER_LENGTH)) { - return false; - } - if(!CONFIG::write_buffer(EP_DATA_PORT,(const byte *)&DEFAULT_DATA_PORT,INTEGER_LENGTH)) { - return false; - } - 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; - } - if(!CONFIG::write_buffer(EP_XY_FEEDRATE,(const byte *)&DEFAULT_XY_FEEDRATE,INTEGER_LENGTH)) { - return false; - } - if(!CONFIG::write_buffer(EP_Z_FEEDRATE,(const byte *)&DEFAULT_Z_FEEDRATE,INTEGER_LENGTH)) { - return false; - } - if(!CONFIG::write_buffer(EP_E_FEEDRATE,(const byte *)&DEFAULT_E_FEEDRATE,INTEGER_LENGTH)) { - return false; - } - if(!CONFIG::write_string(EP_ADMIN_PWD,FPSTR(DEFAULT_ADMIN_PWD))) { - return false; - } - 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, 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 - fs::FSInfo info; - SPIFFS.info(info); - 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()-info.totalBytes).c_str(), output); - if (!plaintext)BRIDGE::print(F("\","), output); - else { - if ((flashsize - ESP.getSketchSize()-info.totalBytes) > (ESP.getSketchSize())) BRIDGE::println(F("(Ok)"), output); - else BRIDGE::println(F("(Not enough)"), output); - } - - if (!plaintext)BRIDGE::print(F("\"spiffs_size\":\""), output); - else BRIDGE::print(F("Available Size for SPIFFS: "), output); - - 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::print(F("???"), 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 - BRIDGE::print(String(wifi_config.idata_port).c_str(), output); -#else - BRIDGE::print(F("Disabled"), output); -#endif - 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 (!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::print("Wifi Off", output); - if (!plaintext)BRIDGE::print(F("\","), output); - else BRIDGE::print(F("\n"), output); - } - - if (!plaintext)BRIDGE::print(F("\"captive_portal\":\""), output); - else BRIDGE::print(F("Captive portal: "), output); -#ifdef CAPTIVE_PORTAL_FEATURE - BRIDGE::print(F("Enabled"), output); -#else - BRIDGE::print(F("Disabled"), output); -#endif - 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::print(F("Enabled"), output); -#else - BRIDGE::print(F("Disabled"), output); -#endif - 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::print(F("Enabled"), output); -#else - BRIDGE::print(F("Disabled"), output); -#endif - 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::print(F("Enabled"), output); -#else - BRIDGE::print(F("Disabled"), output); -#endif - 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::print(F("Enabled"), output); -#else - BRIDGE::print(F("Disabled"), output); -#endif - 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::print(F("Enabled"), output); -#else - BRIDGE::print(F("Disabled"), output); -#endif - 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::print(F("Enabled"), output); -#else - 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::print(F("SPIFFS"), output); -#endif -#ifdef DEBUG_OUTPUT_SD - BRIDGE::print(F("SD"), output); -#endif -#ifdef DEBUG_OUTPUT_SERIAL - BRIDGE::print(F("serial"), output); -#endif -#ifdef DEBUG_OUTPUT_TCP - 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 deleted file mode 100644 index ec02dc4b..00000000 --- a/esp3d/config.h +++ /dev/null @@ -1,430 +0,0 @@ -/* - config.h - ESP3D configuration class - - 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 -*/ - -//definition -#define UNKNOWN_FW 0 -#define REPETIER4DV 1 -#define MARLIN 2 -#define MARLINKIMBRA 3 -#define SMOOTHIEWARE 4 -#define REPETIER 5 - -#ifdef ARDUINO_ARCH_ESP32 -#include "FS.h" -#include "SPIFFS.h" -#define WIFI_NONE_SLEEP WIFI_PS_NONE -#define WIFI_MODEM_SLEEP WIFI_PS_MAX_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 -#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 - -//comment to disable -//MDNS_FEATURE: this feature allow type the name defined -//in web browser by default: http:\\esp8266.local and connect -#define MDNS_FEATURE - -//SSDD_FEATURE: this feature is a discovery protocol, supported on Windows out of the box -#define SSDP_FEATURE - -//NETBIOS_FEATURE: this feature is a discovery protocol, supported on Windows out of the box -#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 - -//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 - -#ifdef RECOVERY_FEATURE -//pin used to reset setting -#define RESET_CONFIG_PIN 2 -#endif - -//DIRECT_PIN_FEATURE: allow to access pin using ESP201 command -#define DIRECT_PIN_FEATURE - -//INFO_MSG_FEATURE: catch the Info msg and filter it to specific table -#define INFO_MSG_FEATURE - -//ERROR_MSG_FEATURE: catch the error msg and filter it to specific table -#define ERROR_MSG_FEATURE - -//STATUS_MSG_FEATURE: catch the status msg and filter it to specific table -#define STATUS_MSG_FEATURE - -//Serial rx buffer size is 256 but can be extended -#define SERIAL_RX_BUFFER_SIZE 512 - -#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_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 -#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) {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 -#endif -#else -#define LOG(string) {} -#define DEBUG_PIPE NO_PIPE -#endif - -#ifndef CONFIG_h -#define CONFIG_h - -#include -#ifdef ARDUINO_ARCH_ESP8266 -extern "C" { -#include "user_interface.h" -} -#else -//Nothing here -#endif -#include "wificonf.h" -//version and sources location -#define FW_VERSION "1.0" -#define REPOSITORY "https://github.com/luc-github/ESP3D" - -typedef enum { - NO_PIPE = 0, - SERIAL_PIPE = 2, - SERIAL1_PIPE = 3, -#ifdef TCP_IP_DATA_FEATURE - TCP_PIPE = 4, -#endif - WEB_PIPE = 5 -} 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 -#define CLIENT_MODE 2 -#define DHCP_MODE 1 -#define STATIC_IP_MODE 2 - -//position in EEPROM -//AP mode = 1; Station client mode = 2 -#define EP_WIFI_MODE 0 //1 byte = flag -#define EP_STA_SSID 1 //33 bytes 32+1 = string ; warning does not support multibyte char like chinese -#define EP_STA_PASSWORD 34 //65 bytes 64 +1 = string ;warning does not support multibyte char like chinese -#define EP_STA_IP_MODE 99 //1 byte = flag -#define EP_STA_IP_VALUE 100 //4 bytes xxx.xxx.xxx.xxx -#define EP_STA_MASK_VALUE 104 //4 bytes xxx.xxx.xxx.xxx -#define EP_STA_GATEWAY_VALUE 108 //4 bytes xxx.xxx.xxx.xxx -#define EP_BAUD_RATE 112 //4 bytes = int -#define EP_STA_PHY_MODE 116 //1 byte = flag -#define EP_SLEEP_MODE 117 //1 byte = flag -#define EP_CHANNEL 118 //1 byte = flag -#define EP_AUTH_TYPE 119 //1 byte = flag -#define EP_SSID_VISIBLE 120 //1 byte = flag -#define EP_WEB_PORT 121 //4 bytes = int -#define EP_DATA_PORT 125 //4 bytes = int -#define EP_REFRESH_PAGE_TIME 129 //1 bytes = flag -#define EP_HOSTNAME 130//33 bytes 32+1 = string ; warning does not support multibyte char like chinese -#define EP_XY_FEEDRATE 164//4 bytes = int -#define EP_Z_FEEDRATE 168//4 bytes = int -#define EP_E_FEEDRATE 172//4 bytes = int -#define EP_ADMIN_PWD 176//21 bytes 20+1 = string ; warning does not support multibyte char like chinese -#define EP_USER_PWD 197//21 bytes 20+1 = string ; warning does not support multibyte char like chinese -#define EP_AP_SSID 218 //33 bytes 32+1 = string ; warning does not support multibyte char like chinese -#define EP_AP_PASSWORD 251 //65 bytes 64 +1 = string ;warning does not support multibyte char like chinese -#define EP_AP_IP_VALUE 316 //4 bytes xxx.xxx.xxx.xxx -#define EP_AP_MASK_VALUE 320 //4 bytes xxx.xxx.xxx.xxx -#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 -#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 = "ESP3D"; -const char DEFAULT_AP_PASSWORD [] PROGMEM = "12345678"; -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; -const byte DEFAULT_IP_VALUE[] = {192, 168, 0, 1}; -const byte DEFAULT_MASK_VALUE[] = {255, 255, 255, 0}; -#define DEFAULT_GATEWAY_VALUE DEFAULT_IP_VALUE -const long DEFAULT_BAUD_RATE = 115200; -const char M117_[] PROGMEM = "M117 "; -#define DEFAULT_PHY_MODE WIFI_PHY_MODE_11G -#define DEFAULT_SLEEP_MODE WIFI_MODEM_SLEEP -#define DEFAULT_CHANNEL 11 -#define DEFAULT_AUTH_TYPE AUTH_WPA_PSK -#define DEFAULT_SSID_VISIBLE 1 -#define DEFAULT_MAX_CONNECTIONS 4 -#define DEFAULT_BEACON_INTERVAL 100 -const int DEFAULT_WEB_PORT = 80; -const int DEFAULT_DATA_PORT = 8888; -#define DEFAULT_REFRESH_PAGE_TIME 3 -const int DEFAULT_XY_FEEDRATE=1000; -const int DEFAULT_Z_FEEDRATE =100; -const int DEFAULT_E_FEEDRATE=400; -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 0 -#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 1024 //max is 1024 -#define MAX_SSID_LENGTH 32 -#define MIN_SSID_LENGTH 1 -#define MAX_PASSWORD_LENGTH 64 -//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); - static bool read_byte(int pos, byte * value); - static bool write_string(int pos, const char * byte_buffer); - static bool write_string(int pos, const __FlashStringHelper *str); - 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, 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(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(); -private: - static uint8_t FirmwareTarget; -}; - -#endif diff --git a/esp3d/data/404.htm b/esp3d/data/404.htm deleted file mode 100644 index a1dec29a..00000000 --- a/esp3d/data/404.htm +++ /dev/null @@ -1,18 +0,0 @@ - - -404 page - - -
-

- - - - -404 Error, unknown page!

-

What are you doing here ?

-You are not supposed to find this location... -
- - - diff --git a/esp3d/data/favicon.ico b/esp3d/data/favicon.ico deleted file mode 100644 index b2b24df7..00000000 Binary files a/esp3d/data/favicon.ico and /dev/null differ diff --git a/esp3d/data/index.html.gz b/esp3d/data/index.html.gz deleted file mode 100644 index 8ed88ab7..00000000 Binary files a/esp3d/data/index.html.gz and /dev/null differ diff --git a/esp3d/data/macrocfg.json b/esp3d/data/macrocfg.json deleted file mode 100644 index 07b5bd33..00000000 --- a/esp3d/data/macrocfg.json +++ /dev/null @@ -1,74 +0,0 @@ -[ - { - "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/esp3d.ino b/esp3d/esp3d.ino deleted file mode 100644 index 24bec6aa..00000000 --- a/esp3d/esp3d.ino +++ /dev/null @@ -1,189 +0,0 @@ -/* - This file is part of ESP3D Firmware for 3D printer. - - ESP3D Firmware for 3D printer is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ESP3D Firmware for 3D printer 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this Firmware. If not, see . - - This firmware is using the standard arduino IDE with module to support ESP8266: - https://github.com/esp8266/Arduino from Bootmanager - - Latest version of the code and documentation can be found here : - https://github.com/luc-github/ESP3D - - Main author: luc lebosse - -*/ -//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 "wificonf.h" -#include "bridge.h" -#include "webinterface.h" -#include "command.h" -#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 -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; - bool directsd_check = false; - web_interface = NULL; -#ifdef TCP_IP_DATA_FEATURE - data_server = NULL; -#endif - // init: -#ifdef DEBUG_ESP3D - 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 - if (digitalRead(RESET_CONFIG_PIN)==0) { - breset_config=true; //if requested =>reset settings - } -#endif - //check if EEPROM has value - if ( !CONFIG::InitBaudrate() || !CONFIG::InitExternalPorts()) { - breset_config=true; //cannot access to config settings=> reset settings - LOG("Error no EEPROM access\r\n") - } - - //reset is requested - if(breset_config) { - //update EEPROM with default settings - 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); - ESP_SERIAL_OUT.println(F("M117 ESP EEPROM reset")); -#ifdef DEBUG_ESP3D - 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); - ESP_SERIAL_OUT.flush(); -#endif - //get target FW - CONFIG::InitFirmwareTarget(); - //Update is done if any so should be Ok -#ifdef ARDUINO_ARCH_ESP32 - SPIFFS.begin(true); -#else - SPIFFS.begin(); -#endif - - //setup wifi according settings - if (!wifi_config.Setup()) { - ESP_SERIAL_OUT.println(F("M117 Safe mode 1")); - //try again in AP mode - if (!wifi_config.Setup(true)) { - ESP_SERIAL_OUT.println(F("M117 Safe mode 2")); - wifi_config.Safe_Setup(); - } - } - delay(1000); - //setup servers - if (!wifi_config.Enable_servers()) { - ESP_SERIAL_OUT.println(F("M117 Error enabling servers")); - } - 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(); - } -#endif -//web requests - web_interface->web_server.handleClient(); -#ifdef TCP_IP_DATA_FEATURE - BRIDGE::processFromTCP2Serial(); -#endif - } - BRIDGE::processFromSerial2TCP(); - //in case of restart requested - if (web_interface->restartmodule) { - CONFIG::esp_restart(); - } -} diff --git a/esp3d/nofile.h b/esp3d/nofile.h deleted file mode 100644 index e2fff90d..00000000 --- a/esp3d/nofile.h +++ /dev/null @@ -1,326 +0,0 @@ -/* - 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, 0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x08, 0xCB, 0x7E, 0xA0, 0xAD, 0x94, 0xD0, 0x2B, 0x99, - 0xF7, 0x29, 0x79, 0x8E, 0xF2, 0x64, 0xA8, 0x2D, 0x6C, 0xF6, 0x34, 0xBD, 0x72, 0x47, 0x2C, 0x36, - 0x52, 0x1C, 0xC2, 0x8C, 0x13, 0x11, 0xB5, 0xEE, 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 deleted file mode 100644 index 9f306118..00000000 --- a/esp3d/storestrings.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/* - storestrings.cpp - rolling storage class - - 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 -*/ -#include "storestrings.h" -//Constructor -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 - _maxsize=maxsize; -//to limit the storage space - _maxstringlength=maxstringlength; -//need space for the "..." - if (_maxstringlength<4 && _maxstringlength!=-1) { - _maxstringlength=4; - } -} -//Destructor -STORESTRINGS_CLASS::~STORESTRINGS_CLASS () -{ - // clear list and content - clear(); -} - -bool STORESTRINGS_CLASS::setsize(int size) -{ - _maxsize=size; - return true; -} -bool STORESTRINGS_CLASS::setlength(int len) -{ - if (len < 4) { - return false; - } - _maxstringlength = len; - return true; -} - -//Clear list and content -void STORESTRINGS_CLASS::clear() -{ - //while list is not empty - while(_charlist.size()) { - //remove element - char * str = _charlist.pop(); - //destroy it - delete str; - } -} - -bool STORESTRINGS_CLASS::add (const __FlashStringHelper *str) -{ - String stmp; - stmp=str; - return add(stmp.c_str()); -} -//Add element in storage -bool STORESTRINGS_CLASS::add (const char * string) -{ - //if we reach max size - if (_maxsize==_charlist.size()) { - //remove oldest one - char * str = _charlist.shift(); - delete str; - } - //add new one - //get size including \0 at the end - size_t size = strlen(string)+1; - bool need_resize=false; - if ( (_maxstringlength!=-1) && (size >_maxstringlength+1 )) { - need_resize = true; - size=_maxstringlength+1; - } - //reserve memory - char * ptr = new char[size*sizeof(char)]; - //copy string to storage - if (need_resize) { - //copy maximum length minus 3 - strncpy(ptr,string,_maxstringlength-3); - strcpy(ptr+_maxstringlength-3,"..."); - } else { - //copy as it is - strcpy(ptr,string); - } - //add storage to list - _charlist.add(ptr); - return true; -} -//Remove element at pos position -bool STORESTRINGS_CLASS::remove(int pos) -{ - //be sure index is in range - if (pos<0 && pos>(_charlist.size()-1)) { - return false; - } - //remove item from list - char * str = _charlist.remove(pos); - //destroy item - delete str; - return true; -} -//Get element at pos position -const char * STORESTRINGS_CLASS::get(int pos) -{ - //be sure index is in range - if (pos<0 && pos>(_charlist.size()-1)) { - return NULL; - } - return (const char *) _charlist.get(pos); -} -//Get index for defined string -int STORESTRINGS_CLASS::get_index(const char * string) -{ - //parse the list until it is found - for (int p=0; p<_charlist.size(); p++) { - if (strcmp ( _charlist.get(p), string)==0) { - return p; - } - } - //if not found return -1 - return -1; -} - diff --git a/esp3d/storestrings.h b/esp3d/storestrings.h deleted file mode 100644 index ca89df0a..00000000 --- a/esp3d/storestrings.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - storestrings.h - rolling storage class - - 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 -*/ - -#ifndef STORESTRINGS_h -#define STORESTRINGS_h -#include -#include "GenLinkedList.h" -class STORESTRINGS_CLASS -{ -public: - STORESTRINGS_CLASS (int maxsize = -1, int maxstringlength=-1); - ~STORESTRINGS_CLASS (); - bool add (const char * string); - inline bool add (String & string) - { - return add(string.c_str()); - }; - bool add (const __FlashStringHelper *str); - bool remove(int pos); - const char * get(int pos); - int get_index(const char * string); - void clear(); - inline int size() - { - return _charlist.size(); - }; - bool setsize(int size); - bool setlength(int len); - inline int getsize() - { - return _maxsize; - }; - inline int getlength() - { - return _maxstringlength; - }; - -private: - int _maxsize; - int _maxstringlength; - GenLinkedList _charlist; -}; - -#endif diff --git a/esp3d/webinterface.cpp b/esp3d/webinterface.cpp deleted file mode 100644 index 3e8c0e15..00000000 --- a/esp3d/webinterface.cpp +++ /dev/null @@ -1,1740 +0,0 @@ -/* - webinterface.cpp - ESP3D configuration class - - 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 -*/ - -#include -#include "config.h" -#include "webinterface.h" -#include "wificonf.h" -#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" -#include "bridge.h" - -#ifdef SSDP_FEATURE -#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, - UPLOAD_STATUS_CANCELLED = 2, - UPLOAD_STATUS_SUCCESSFUL = 3, - UPLOAD_STATUS_ONGOING =4 -} upload_status_type; - -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"; - -void handle_web_interface_root() -{ - 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)) && !web_interface->web_server.hasArg("fallback") && web_interface->web_server.arg("forcefallback")!="yes") { - if(SPIFFS.exists(pathWithGz)) { - path = pathWithGz; - } - FS_FILE file = SPIFFS.open(path, SPIFFS_FILE_READ); - web_interface->web_server.streamFile(file, contentType); - file.close(); - return; - } - //if no lets launch the default content - web_interface->web_server.sendHeader("Content-Encoding", "gzip"); - web_interface->web_server.send_P(200,CONTENT_TYPE_HTML,PAGE_NOFILES,PAGE_NOFILES_SIZE); -} - -//concat several catched informations temperatures/position/status/flow/speed -void handle_web_interface_status() -{ - // static const char NO_TEMP_LINE[] PROGMEM = "\"temperature\":\"0\",\"target\":\"0\",\"active\":\"0\""; - //we do not care if need authentication - just reset counter - web_interface->is_authenticated(); - //int tagpos,tagpos2; - String buffer2send; - String value; - //start JSON answer - buffer2send="{"; -#ifdef INFO_MSG_FEATURE - //information - buffer2send.concat(F("\"InformationMsg\":[")); - - for (int i=0; iinfo_msg.size(); i++) { - if (i>0) { - buffer2send+=","; - } - buffer2send+="{\"line\":\""; - buffer2send+=web_interface->info_msg.get(i); - buffer2send+="\"}"; - } - buffer2send+="],"; -#endif -#ifdef ERROR_MSG_FEATURE - //Error - buffer2send.concat(F("\"ErrorMsg\":[")); - for (int i=0; ierror_msg.size(); i++) { - if (i>0) { - buffer2send+=","; - } - buffer2send+="{\"line\":\""; - buffer2send+=web_interface->error_msg.get(i); - buffer2send+="\"}"; - } - buffer2send+="],"; -#endif -#ifdef STATUS_MSG_FEATURE - //Status - buffer2send.concat(F("\"StatusMsg\":[")); - - for (int i=0; istatus_msg.size(); i++) { - if (i>0) { - buffer2send+=","; - } - buffer2send+="{\"line\":\""; - buffer2send+=web_interface->status_msg.get(i); - buffer2send+="\"}"; - } - buffer2send+="],"; -#endif - //status color - buffer2send+="\"status\":\""+value +"\""; - buffer2send+="}"; - web_interface->web_server.sendHeader("Cache-Control", "no-cache"); - web_interface->web_server.send(200, "application/json",buffer2send); -} - -//SPIFFS files uploader handle -void SPIFFSFileupload() -{ -#ifdef DEBUG_PERFORMANCE - static uint32_t startupload; - static uint32_t write_time; - static size_t filesize; -#endif - //get authentication status - level_authenticate_type auth_level= web_interface->is_authenticated(); - //Guest cannot upload - if (auth_level == LEVEL_GUEST) { - web_interface->_upload_status=UPLOAD_STATUS_CANCELLED; - ESP_SERIAL_OUT.println("M117 Error ESP upload"); -#ifdef ARDUINO_ARCH_ESP8266 - web_interface->web_server.client().stopAll(); -#else - web_interface->web_server.client().stop(); -#endif - return; - } - - static String filename; - //get current file ID - HTTPUpload& upload = (web_interface->web_server).upload(); - //Upload start - //************** - if(upload.status == UPLOAD_FILE_START) { -#ifdef DEBUG_PERFORMANCE - startupload = millis(); - write_time = 0; - filesize = 0; -#endif - //according User or Admin the root is different as user is isolate to /user when admin has full access - if(auth_level == LEVEL_ADMIN) { - filename = upload.filename; - } else { - filename = "/user" + upload.filename; - } - ESP_SERIAL_OUT.println("M117 Start ESP upload"); - //create file - web_interface->fsUploadFile = SPIFFS.open(filename, SPIFFS_FILE_WRITE); - //check If creation succeed - if (web_interface->fsUploadFile) { - //if yes upload is started - web_interface->_upload_status= UPLOAD_STATUS_ONGOING; - } else { - //if no set cancel flag - web_interface->_upload_status=UPLOAD_STATUS_CANCELLED; - ESP_SERIAL_OUT.println("M117 Error ESP create"); -#ifdef ARDUINO_ARCH_ESP8266 - web_interface->web_server.client().stopAll(); -#else - web_interface->web_server.client().stop(); -#endif - } - //Upload write - //************** - } else if(upload.status == UPLOAD_FILE_WRITE) { - //check if file is available and no error - if(web_interface->fsUploadFile && web_interface->_upload_status == UPLOAD_STATUS_ONGOING) { -#ifdef DEBUG_PERFORMANCE - filesize+=upload.currentSize; - uint32_t startwrite = millis(); -#endif - //no error so write post date - web_interface->fsUploadFile.write(upload.buf, upload.currentSize); -#ifdef DEBUG_PERFORMANCE - write_time += (millis()-startwrite); -#endif - } else { - //we have a problem set flag UPLOAD_STATUS_CANCELLED - web_interface->_upload_status=UPLOAD_STATUS_CANCELLED; -#ifdef ARDUINO_ARCH_ESP8266 - web_interface->web_server.client().stopAll(); -#else - web_interface->web_server.client().stop(); -#endif - ESP_SERIAL_OUT.println("M117 Error ESP write"); - } - //Upload end - //************** - } else if(upload.status == UPLOAD_FILE_END) { -#ifdef DEBUG_PERFORMANCE - uint32_t endupload = millis(); - DEBUG_PERF_VARIABLE.add(String(endupload-startupload).c_str()); - DEBUG_PERF_VARIABLE.add(String(write_time).c_str()); - DEBUG_PERF_VARIABLE.add(String(filesize).c_str()); -#endif - ESP_SERIAL_OUT.println("M117 End ESP upload"); - //check if file is still open - if(web_interface->fsUploadFile) { - //close it - web_interface->fsUploadFile.close(); - web_interface->_upload_status=UPLOAD_STATUS_SUCCESSFUL; - } else { - //we have a problem set flag UPLOAD_STATUS_CANCELLED - web_interface->_upload_status=UPLOAD_STATUS_CANCELLED; -#ifdef ARDUINO_ARCH_ESP8266 - web_interface->web_server.client().stopAll(); -#else - web_interface->web_server.client().stop(); -#endif - SPIFFS.remove(filename); - ESP_SERIAL_OUT.println("M117 Error ESP close"); - } - //Upload cancelled - //************** - } else { - ESP_SERIAL_OUT.println("M117 Error ESP close"); - return; - web_interface->_upload_status=UPLOAD_STATUS_CANCELLED; - SPIFFS.remove(filename); - ESP_SERIAL_OUT.println("M117 Error ESP upload"); - } - delay(0); -} - -#define NB_RETRY 5 -#define MAX_RESEND_BUFFER 128 -//SD file upload by serial -void SDFile_serial_upload() -{ - static char buffer_line[MAX_RESEND_BUFFER]; //if need to resend - static char previous = 0; - static int buffer_size; - static bool com_error = false; - static bool is_comment = false; - bool client_closed = false; - static String filename; - String response; - //Guest cannot upload - only admin and user - if(web_interface->is_authenticated() == LEVEL_GUEST) { - web_interface->_upload_status=UPLOAD_STATUS_CANCELLED; - ESP_SERIAL_OUT.println("M117 SD upload rejected"); - LOG("SD upload rejected\r\n"); - if (!client_closed){ - //web_interface->web_server.client().stopAll(); - LOG("Need to stop"); - client_closed = true; - } - return; - } -#ifdef DEBUG_PERFORMANCE - static uint32_t startupload; - static uint32_t write_time; - static size_t filesize; -#endif - //retrieve current file id - HTTPUpload& upload = (web_interface->web_server).upload(); - //Upload start - //************** - if(upload.status == UPLOAD_FILE_START) { - //need to lock serial out to avoid garbage in file - (web_interface->blockserial) = true; - //init flags - buffer_size=0; - com_error = false; - is_comment = false; - previous = 0; - web_interface->_upload_status= UPLOAD_STATUS_ONGOING; - ESP_SERIAL_OUT.println("M117 Uploading..."); - ESP_SERIAL_OUT.flush(); -#ifdef DEBUG_PERFORMANCE - startupload = millis(); - write_time = 0; - filesize = 0; -#endif - LOG("Clear Serial\r\n"); - if(ESP_SERIAL_OUT.available()) { - //get size of buffer - size_t len = ESP_SERIAL_OUT.available(); - uint8_t sbuf[len+1]; - //read buffer - ESP_SERIAL_OUT.readBytes(sbuf, len); - //convert buffer to zero end array - sbuf[len]='\0'; - //use string because easier to handle - response = (const char*)sbuf; - LOG(response); - LOG("\r\n"); - } - //command to pritnter to start print - String command = "M28 " + upload.filename; - LOG(command); - LOG("\r\n"); - ESP_SERIAL_OUT.println(command); - ESP_SERIAL_OUT.flush(); - filename = upload.filename; - //now need to purge all serial data - //let's sleep 1s - //delay(1000); - for (int retry=0; retry < 400; retry++) { //time out is 5x400ms = 2000ms - //if there is something in serial buffer - if(ESP_SERIAL_OUT.available()) { - //get size of buffer - size_t len = ESP_SERIAL_OUT.available(); - uint8_t sbuf[len+1]; - //read buffer - ESP_SERIAL_OUT.readBytes(sbuf, len); - //convert buffer to zero end array - sbuf[len]='\0'; - //use string because easier to handle - response =(const char*)sbuf; - LOG(response); - //if there is a wait it means purge is done - if (response.indexOf("wait")>-1) { - LOG("Exit start writing\r\n"); - break; - } - if (response.indexOf("Resend")>-1 || response.indexOf("failed")>-1) { - com_error = true; - web_interface->blockserial = false; - LOG("Error start writing\r\n"); - break; - } - } - delay(5); - } - //Upload write - //************** - //upload is on going with data coming by 2K blocks - } else if((upload.status == UPLOAD_FILE_WRITE) && (com_error == false)) { //if com error no need to send more data to serial - web_interface->_upload_status= UPLOAD_STATUS_ONGOING; -#ifdef DEBUG_PERFORMANCE - filesize+=upload.currentSize; - uint32_t startwrite = millis(); -#endif - for (int pos = 0; pos < upload.currentSize; pos++) { //parse full post data - if (buffer_size < MAX_RESEND_BUFFER-1) { //raise error/handle if overbuffer - copy is space available - //remove/ignore every comment to save transfert time and avoid over buffer issues - if (upload.buf[pos] == ';') { - is_comment = true; - previous = ';'; - } - if (!is_comment) { - buffer_line[buffer_size] = upload.buf[pos]; //copy current char to buffer to send/resend - buffer_size++; - //convert buffer to zero end array - buffer_line[buffer_size] = '\0'; - //check it is not an end line char and line is not empty - if (((buffer_line[0] == '\n') && (buffer_size==1)) ||((buffer_line[1] == '\n') && (buffer_line[0] == '\r') && (buffer_size==2)) || ((buffer_line[0] == ' ') && (buffer_size==1)) ) { - //ignore empty line - buffer_size=0; - buffer_line[buffer_size] = '\0'; - } - //line is not empty so check if last char is an end line - //if error no need to proceed - else if (((buffer_line[buffer_size-1] == '\n')) && (com_error == false)) { //end of line and no error - //if resend use buffer - bool success = false; - - //check NB_RETRY times if get no error when send line - for (int r = 0 ; r < NB_RETRY ; r++) { - response = ""; - //print out line - ESP_SERIAL_OUT.print(buffer_line); - LOG(buffer_line); - //ensure buffer is empty before continuing - ESP_SERIAL_OUT.flush(); - //wait for answer with time out - for (int retry=0; retry < 30; retry++) { //time out 30x5ms = 150ms - //if there is serial data - if(ESP_SERIAL_OUT.available()) { - //get size of available data - size_t len = ESP_SERIAL_OUT.available(); - uint8_t sbuf[len+1]; - //read serial buffer - ESP_SERIAL_OUT.readBytes(sbuf, len); - //convert buffer in zero end array - sbuf[len]='\0'; - //use string because easier - response = (const char*)sbuf; - LOG("Retry:"); - LOG(String(retry)); - LOG("\r\n"); - LOG(response); - //if buffer contain ok or wait - it means command is pass - if ((response.indexOf("wait")>-1)||(response.indexOf("ok")>-1)) { - success = true; - break; - } - //if buffer contain resend then need to resend - if (response.indexOf("Resend") > -1) { //if error - success = false; - break; - } - } - delay(5); - } - //if command is pass no need to retry - if (success == true) { - break; - } - //purge extra serial if any - if(ESP_SERIAL_OUT.available()) { - //get size of available data - size_t len = ESP_SERIAL_OUT.available(); - uint8_t sbuf[len+1]; - //read serial buffer - ESP_SERIAL_OUT.readBytes(sbuf, len); - //convert buffer in zero end array - sbuf[len]='\0'; - } - } - //if even after the number of retry still have error - then we are in error - if (!success) { - //raise error - LOG("Error detected\r\n"); - LOG(response); - com_error = true; - } - //reset buffer for next command - buffer_size = 0; - buffer_line[buffer_size] = '\0'; - } - } else { //it is a comment - if (upload.buf[pos] == '\r') { //store if CR - previous = '\r'; - } else if (upload.buf[pos] == '\n') { //this is the end of the comment - is_comment = false; - if (buffer_size > 0) { - if (previous == '\r') { - pos--; - } - pos--; //do a loop back and process as normal - } - previous = '\n'; - }//if not just ignore and continue - else { - previous = upload.buf[pos]; - } - - } - } else { //raise error - LOG("\r\nlong line detected\r\n"); - LOG(buffer_line); - com_error = true; - } - } -#ifdef DEBUG_PERFORMANCE - write_time += (millis()-startwrite); -#endif - //Upload end - //************** - } else if(upload.status == UPLOAD_FILE_END) { - if (buffer_size > 0) { //if last part does not have '\n' - //print the line - ESP_SERIAL_OUT.print(buffer_line); - if (is_comment && (previous == '\r')) { - ESP_SERIAL_OUT.print("\r\n"); - } else { - ESP_SERIAL_OUT.print("\n"); - } - ESP_SERIAL_OUT.flush(); - //if resend use buffer - bool success = false; - //check NB_RETRY times if get no error when send line - for (int r = 0 ; r < NB_RETRY ; r++) { - response = ""; - ESP_SERIAL_OUT.print(buffer_line); - ESP_SERIAL_OUT.flush(); - //wait for answer with time out - for (int retry=0; retry < 20; retry++) { //time out - if(ESP_SERIAL_OUT.available()) { - size_t len = ESP_SERIAL_OUT.available(); - uint8_t sbuf[len+1]; - ESP_SERIAL_OUT.readBytes(sbuf, len); - sbuf[len]='\0'; - response = (const char*)sbuf; - if ((response.indexOf("wait")>-1)||(response.indexOf("ok")>-1)) { - success = true; - break; - } - if (response.indexOf("Resend") > -1) { //if error - success = false; - break; - } - } - delay(5); - } - if (success == true) { - break; - } - } - if (!success) { - //raise error - LOG("Error detected 2\r\n"); - LOG(response); - com_error = true; - } - //reset buffer for next command - buffer_size = 0; - buffer_line[buffer_size] = '\0'; - - } - LOG("Upload finished "); - buffer_size=0; - buffer_line[buffer_size] = '\0'; - //send M29 command to close file on SD - ESP_SERIAL_OUT.print("\r\nM29\r\n"); - ESP_SERIAL_OUT.flush(); - web_interface->blockserial = false; - delay(1000);//give time to FW - //resend M29 command to close file on SD as first command may be lost - ESP_SERIAL_OUT.print("\r\nM29\r\n"); - ESP_SERIAL_OUT.flush(); -#ifdef DEBUG_PERFORMANCE - uint32_t endupload = millis(); - DEBUG_PERF_VARIABLE.add(String(endupload-startupload).c_str()); - DEBUG_PERF_VARIABLE.add(String(write_time).c_str()); - DEBUG_PERF_VARIABLE.add(String(filesize).c_str()); -#endif - if (com_error) { - web_interface->blockserial = false; - LOG("with error\r\n"); - web_interface->_upload_status=UPLOAD_STATUS_CANCELLED; - if (!client_closed){ - //web_interface->web_server.client().stopAll(); - LOG("Need to stop"); - client_closed = true; - } - filename = "M30 " + filename; - ESP_SERIAL_OUT.println(filename); - ESP_SERIAL_OUT.println("M117 SD upload failed"); - ESP_SERIAL_OUT.flush(); - - } else { - LOG("with success\r\n"); - web_interface->_upload_status=UPLOAD_STATUS_SUCCESSFUL; - ESP_SERIAL_OUT.println("M117 SD upload done"); - ESP_SERIAL_OUT.flush(); - } - //Upload cancelled - //************** - } else { //UPLOAD_FILE_ABORTED - LOG("Error, Something happened\r\n"); - com_error = true; - web_interface->_upload_status=UPLOAD_STATUS_CANCELLED; - buffer_size=0; - buffer_line[buffer_size] = '\0'; - //send M29 command to close file on SD - ESP_SERIAL_OUT.print("\r\nM29\r\n"); - ESP_SERIAL_OUT.flush(); - web_interface->blockserial = false; - delay(1000); - //resend M29 command to close file on SD as first command may be lost - ESP_SERIAL_OUT.print("\r\nM29\r\n"); - ESP_SERIAL_OUT.flush(); - filename = "M30 " + filename; - ESP_SERIAL_OUT.println(filename); - ESP_SERIAL_OUT.println("M117 SD upload failed"); - ESP_SERIAL_OUT.flush(); - } -} - - -//FW update using Web interface -#ifdef WEB_UPDATE_FEATURE -void WebUpdateUpload() -{ - static size_t last_upload_update; - static uint32_t maxSketchSpace ; - //only admin can update FW - if(web_interface->is_authenticated() != LEVEL_ADMIN) { - web_interface->_upload_status=UPLOAD_STATUS_CANCELLED; -#ifdef ARDUINO_ARCH_ESP8266 - web_interface->web_server.client().stopAll(); -#else - web_interface->web_server.client().stop(); -#endif - ESP_SERIAL_OUT.println("M117 Update failed"); - LOG("SD Update failed\r\n"); - return; - } - //get current file ID - HTTPUpload& upload = (web_interface->web_server).upload(); - //Upload start - //************** - if(upload.status == UPLOAD_FILE_START) { - ESP_SERIAL_OUT.println(F("M117 Update Firmware")); - web_interface->_upload_status= UPLOAD_STATUS_ONGOING; -#ifdef ARDUINO_ARCH_ESP8266 - WiFiUDP::stopAll(); -#endif -#ifdef ARDUINO_ARCH_ESP8266 - maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000; -#else -//Not sure can do OTA on 2Mb board - maxSketchSpace = (ESP.getFlashChipSize()>0x20000)?0x140000:0x140000/2; -#endif - last_upload_update = 0; - if(!Update.begin(maxSketchSpace)) { //start with max available size - web_interface->_upload_status=UPLOAD_STATUS_CANCELLED; - } else { - if (( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER)) ESP_SERIAL_OUT.println(F("M117 Update 0%%")); - else ESP_SERIAL_OUT.println(F("M117 Update 0%")); - } - //Upload write - //************** - } else if(upload.status == UPLOAD_FILE_WRITE) { - //check if no error - if (web_interface->_upload_status == UPLOAD_STATUS_ONGOING) { - //we do not know the total file size yet but we know the available space so let's use it - if ( ((100 * upload.totalSize) / maxSketchSpace) !=last_upload_update) { - last_upload_update = (100 * upload.totalSize) / maxSketchSpace; - ESP_SERIAL_OUT.print(F("M117 Update ")); - ESP_SERIAL_OUT.print(last_upload_update); - if (( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER)) ESP_SERIAL_OUT.println(F("%%")); - else ESP_SERIAL_OUT.println(F("%")); - } - if(Update.write(upload.buf, upload.currentSize) != upload.currentSize) { - web_interface->_upload_status=UPLOAD_STATUS_CANCELLED; - } - } - //Upload end - //************** - } else if(upload.status == UPLOAD_FILE_END) { - if(Update.end(true)) { //true to set the size to the current progress - //Now Reboot - if (( CONFIG::GetFirmwareTarget() == REPETIER4DV) || (CONFIG::GetFirmwareTarget() == REPETIER)) ESP_SERIAL_OUT.println(F("M117 Update 100%%")); - else ESP_SERIAL_OUT.println(F("M117 Update 100%")); - web_interface->_upload_status=UPLOAD_STATUS_SUCCESSFUL; - } - } else if(upload.status == UPLOAD_FILE_ABORTED) { - ESP_SERIAL_OUT.println(F("M117 Update Failed")); - Update.end(); - web_interface->_upload_status=UPLOAD_STATUS_CANCELLED; - } - delay(0); -} - -void handleUpdate() -{ - level_authenticate_type auth_level = web_interface->is_authenticated(); - if (auth_level != LEVEL_ADMIN) { - web_interface->_upload_status=UPLOAD_STATUS_NONE; - web_interface->web_server.send(403,"text/plain","Not allowed, log in first!\n"); - return; - } - String jsonfile = "{\"status\":\"" ; - jsonfile+=CONFIG::intTostr(web_interface->_upload_status); - jsonfile+="\"}"; - //send status - web_interface->web_server.sendHeader("Cache-Control", "no-cache"); - web_interface->web_server.send(200, "application/json", jsonfile); - //if success restart - if (web_interface->_upload_status==UPLOAD_STATUS_SUCCESSFUL) { - web_interface->restartmodule=true; - } else { - web_interface->_upload_status=UPLOAD_STATUS_NONE; - } -} -#endif - -//SPIFFS files list and file commands -void handleFileList() -{ - level_authenticate_type auth_level = web_interface->is_authenticated(); - if (auth_level == LEVEL_GUEST) { - web_interface->_upload_status=UPLOAD_STATUS_NONE; - web_interface->web_server.send(401,"text/plain","Authentication failed!\n"); - return; - } - String path ; - String status = "Ok"; - if ((web_interface->_upload_status == UPLOAD_STATUS_FAILED) || (web_interface->_upload_status == UPLOAD_STATUS_CANCELLED)) { - status = "Upload failed"; - } - //be sure root is correct according authentication - if (auth_level == LEVEL_ADMIN) { - path = "/"; - } else { - path = "/user"; - } - //get current path - if(web_interface->web_server.hasArg("path")) { - path += web_interface->web_server.arg("path") ; - } - //to have a clean path - path.trim(); - path.replace("//","/"); - if (path[path.length()-1] !='/') { - path +="/"; - } - //check if query need some action - if(web_interface->web_server.hasArg("action")) { - //delete a file - if(web_interface->web_server.arg("action") == "delete" && web_interface->web_server.hasArg("filename")) { - String filename; - String shortname = web_interface->web_server.arg("filename"); - shortname.replace("/",""); - filename = path + web_interface->web_server.arg("filename"); - filename.replace("//","/"); - if(!SPIFFS.exists(filename)) { - status = shortname + F(" does not exists!"); - } else { - if (SPIFFS.remove(filename)) { - status = shortname + F(" deleted"); - //what happen if no "/." and no other subfiles ? -#ifdef ARDUINO_ARCH_ESP8266 - FS_DIR dir = SPIFFS.openDir(path); - if (!dir.next()) { -#else - String ptmp = path; - if ((path != "/") && (path[path.length()-1]='/'))ptmp = path.substring(0,path.length()-1); - FS_FILE dir = SPIFFS.open(ptmp); - FS_FILE dircontent = dir.openNextFile(); - if (!dircontent) { -#endif - //keep directory alive even empty - FS_FILE r = SPIFFS.open(path+"/.", SPIFFS_FILE_WRITE); - if (r) { - r.close(); - } - } - } else { - status = F("Cannot deleted ") ; - status+=shortname ; - } - } - } - //delete a directory - if(web_interface->web_server.arg("action") == "deletedir" && web_interface->web_server.hasArg("filename")) { - String filename; - String shortname = web_interface->web_server.arg("filename"); - shortname.replace("/",""); - filename = path + web_interface->web_server.arg("filename"); - filename += "/"; - filename.replace("//","/"); - if (filename != "/") { - bool delete_error = false; -#ifdef ARDUINO_ARCH_ESP8266 - FS_DIR dir = SPIFFS.openDir(path + shortname); - { - while (dir.next()) { -#else - FS_FILE dir = SPIFFS.open(path + shortname); - { - FS_FILE file2deleted = dir.openNextFile(); - while (file2deleted) { -#endif -#ifdef ARDUINO_ARCH_ESP8266 - String fullpath = dir.fileName(); -#else - String fullpath = file2deleted.name(); -#endif - if (!SPIFFS.remove(fullpath)) { - delete_error = true; - status = F("Cannot deleted ") ; - status+=fullpath; - } -#ifdef ARDUINO_ARCH_ESP32 - file2deleted = dir.openNextFile(); -#endif - } - } - if (!delete_error) { - status = shortname ; - status+=" deleted"; - } - } - } - //create a directory - if(web_interface->web_server.arg("action")=="createdir" && web_interface->web_server.hasArg("filename")) { - String filename; - filename = path + web_interface->web_server.arg("filename") +"/."; - String shortname = web_interface->web_server.arg("filename"); - shortname.replace("/",""); - filename.replace("//","/"); - if(SPIFFS.exists(filename)) { - status = shortname + F(" already exists!"); - } else { - FS_FILE r = SPIFFS.open(filename,SPIFFS_FILE_WRITE); - if (!r) { - status = F("Cannot create "); - status += shortname ; - } else { - r.close(); - status = shortname + F(" created"); - } - } - } - } - String jsonfile = "{"; -#ifdef ARDUINO_ARCH_ESP8266 - FS_DIR dir = SPIFFS.openDir(path); -#else - String ptmp = path; - if ((path != "/") && (path[path.length()-1]='/'))ptmp = path.substring(0,path.length()-1); - FS_FILE dir = SPIFFS.open(ptmp); -#endif - jsonfile+="\"files\":["; - bool firstentry=true; - String subdirlist=""; -#ifdef ARDUINO_ARCH_ESP8266 - while (dir.next()) { - String filename = dir.fileName(); -#else - File fileparsed = dir.openNextFile(); - while (fileparsed) { - String filename = fileparsed.name(); -#endif - String size =""; - bool addtolist=true; - //remove path from name - filename = filename.substring(path.length(),filename.length()); - //check if file or subfile - if (filename.indexOf("/")>-1) { - //Do not rely on "/." to define directory as SPIFFS upload won't create it but directly files - //and no need to overload SPIFFS if not necessary to create "/." if no need - //it will reduce SPIFFS available space so limit it to creation - filename = filename.substring(0,filename.indexOf("/")); - String tag="*"; - tag += filename + "*"; - if (subdirlist.indexOf(tag)>-1 || filename.length()==0) { //already in list - addtolist = false; //no need to add - } else { - size = -1; //it is subfile so display only directory, size will be -1 to describe it is directory - if (subdirlist.length()==0) { - subdirlist+="*"; - } - subdirlist += filename + "*"; //add to list - } - } else { - //do not add "." file - if (!((filename==".") || (filename==""))) { -#ifdef ARDUINO_ARCH_ESP8266 - size = CONFIG::formatBytes(dir.fileSize()); -#else - size = CONFIG::formatBytes(fileparsed.size()); -#endif - - } else { - addtolist = false; - } - } - if(addtolist) { - if (!firstentry) { - jsonfile+=","; - } else { - firstentry=false; - } - jsonfile+="{"; - jsonfile+="\"name\":\""; - jsonfile+=filename; - jsonfile+="\",\"size\":\""; - jsonfile+=size; - jsonfile+="\""; - jsonfile+="}"; - } -#ifdef ARDUINO_ARCH_ESP32 - fileparsed = dir.openNextFile(); -#endif - } - jsonfile+="],"; - jsonfile+="\"path\":\"" + path + "\","; - jsonfile+="\"status\":\"" + status + "\","; - size_t totalBytes; - size_t usedBytes; -#ifdef ARDUINO_ARCH_ESP8266 - fs::FSInfo info; - SPIFFS.info(info); - totalBytes = info.totalBytes; - usedBytes = info.usedBytes; -#else - totalBytes = SPIFFS.totalBytes(); - usedBytes = SPIFFS.usedBytes(); -#endif - jsonfile+="\"total\":\"" + CONFIG::formatBytes(totalBytes) + "\","; - jsonfile+="\"used\":\"" + CONFIG::formatBytes(usedBytes) + "\","; - jsonfile.concat(F("\"occupation\":\"")); - jsonfile+= CONFIG::intTostr(100*usedBytes/totalBytes); - jsonfile+="\""; - jsonfile+="}"; - path = ""; - web_interface->web_server.sendHeader("Cache-Control", "no-cache"); - web_interface->web_server.send(200, "application/json", jsonfile); - web_interface->_upload_status=UPLOAD_STATUS_NONE; -} - -//serial SD files list -void handle_serial_SDFileList() -{ - //this is only for admin an user - if (web_interface->is_authenticated() == LEVEL_GUEST) { - web_interface->_upload_status=UPLOAD_STATUS_NONE; - web_interface->web_server.sendHeader("Cache-Control", "no-cache"); - web_interface->web_server.send(401, "application/json", "{\"status\":\"Authentication failed!\"}"); - return; - } - LOG("serial SD upload done\r\n") - String sstatus="Ok"; - if ((web_interface->_upload_status == UPLOAD_STATUS_FAILED) || (web_interface->_upload_status == UPLOAD_STATUS_CANCELLED)) { - sstatus = "Upload failed"; - web_interface->_upload_status = UPLOAD_STATUS_NONE; - } - String jsonfile = "{\"status\":\"" + sstatus + "\"}"; - web_interface->web_server.sendHeader("Cache-Control", "no-cache"); - web_interface->web_server.send(200, "application/json", jsonfile); - web_interface->blockserial = false; - web_interface->_upload_status=UPLOAD_STATUS_NONE; -} - - -//do a redirect to avoid to many query -//and handle not registred path -void handle_not_found() -{ - static const char NOT_AUTH_NF [] PROGMEM = "HTTP/1.1 301 OK\r\nLocation: /\r\nCache-Control: no-cache\r\n\r\n"; - - if (web_interface->is_authenticated() == LEVEL_GUEST) { - web_interface->web_server.sendContent_P(NOT_AUTH_NF); - //web_interface->web_server.client().stop(); - return; - } - bool page_not_found = false; - String path = web_interface->web_server.urlDecode(web_interface->web_server.uri()); - String contentType = web_interface->getContentType(path); - String pathWithGz = path + ".gz"; - LOG("request:") - LOG(path) - LOG("\r\n") -#ifdef DEBUG_ESP3D - int nb = web_interface->web_server.args(); - for (int i = 0 ; i < nb; i++) { - LOG(web_interface->web_server.argName(i)) - LOG(":") - LOG(web_interface->web_server.arg(i)) - LOG("\r\n") - - } -#endif - LOG("type:") - LOG(contentType) - LOG("\r\n") - if(SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)) { - if(SPIFFS.exists(pathWithGz)) { - path = pathWithGz; - } - FS_FILE file = SPIFFS.open(path, SPIFFS_FILE_READ); - web_interface->web_server.streamFile(file, contentType); - file.close(); - return; - } else { - page_not_found = true; - } - - if (page_not_found ) { -#ifdef CAPTIVE_PORTAL_FEATURE - if (WiFi.getMode()!=WIFI_STA ) { - String contentType=FPSTR(PAGE_CAPTIVE); - String stmp = WiFi.softAPIP().toString(); - //Web address = ip + port - String KEY_IP = F("$WEB_ADDRESS$"); - String KEY_QUERY = F("$QUERY$"); - if (wifi_config.iweb_port!=80) { - stmp+=":"; - stmp+=CONFIG::intTostr(wifi_config.iweb_port); - } - contentType.replace(KEY_IP,stmp); - contentType.replace(KEY_IP,stmp); - contentType.replace(KEY_QUERY,web_interface->web_server.uri()); - web_interface->web_server.send(200,"text/html",contentType); - //web_interface->web_server.sendContent_P(NOT_AUTH_NF); - //web_interface->web_server.client().stop(); - return; - } -#endif - LOG("Page not found\r\n") - path = F("/404.htm"); - contentType = web_interface->getContentType(path); - pathWithGz = path + F(".gz"); - if(SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)) { - if(SPIFFS.exists(pathWithGz)) { - path = pathWithGz; - } - FS_FILE file = SPIFFS.open(path, SPIFFS_FILE_READ); - web_interface->web_server.streamFile(file, contentType); - file.close(); - - } else { - //if not template use default page - contentType=FPSTR(PAGE_404); - String stmp; - if (WiFi.getMode()==WIFI_STA ) { - stmp=WiFi.localIP().toString(); - } else { - stmp=WiFi.softAPIP().toString(); - } - //Web address = ip + port - String KEY_IP = F("$WEB_ADDRESS$"); - String KEY_QUERY = F("$QUERY$"); - if (wifi_config.iweb_port!=80) { - stmp+=":"; - stmp+=CONFIG::intTostr(wifi_config.iweb_port); - } - contentType.replace(KEY_IP,stmp); - contentType.replace(KEY_QUERY,web_interface->web_server.uri()); - web_interface->web_server.send(200,"text/html",contentType); - } - } -} - -#ifdef AUTHENTICATION_FEATURE -void handle_login() -{ - String smsg; - String sUser,sPassword; - String auths; - int code = 200; - bool msg_alert_error=false; - //disconnect can be done anytime no need to check credential - if (web_interface->web_server.hasArg("DISCONNECT")) { - String cookie = web_interface->web_server.header("Cookie"); - int pos = cookie.indexOf("ESPSESSIONID="); - String sessionID; - if (pos!= -1) { - int pos2 = cookie.indexOf(";",pos); - sessionID = cookie.substring(pos+strlen("ESPSESSIONID="),pos2); - } - web_interface->ClearAuthIP(web_interface->web_server.client().remoteIP(), sessionID.c_str()); - web_interface->web_server.sendHeader("Set-Cookie","ESPSESSIONID=0"); - web_interface->web_server.sendHeader("Cache-Control","no-cache"); - String buffer2send = "{\"status\":\"Ok\",\"authentication_lvl\":\"guest\"}"; - web_interface->web_server.send(code, "application/json", buffer2send); - //web_interface->web_server.client().stop(); - return; - } - - level_authenticate_type auth_level= web_interface->is_authenticated(); - if (auth_level == LEVEL_GUEST) auths = F("guest"); - else if (auth_level == LEVEL_USER) auths = F("user"); - else if (auth_level == LEVEL_ADMIN) auths = F("admin"); - else auths = F("???"); - - //check is it is a submission or a query - if (web_interface->web_server.hasArg("SUBMIT")) { - //is there a correct list of query? - if ( web_interface->web_server.hasArg("PASSWORD")&& web_interface->web_server.hasArg("USER")) { - //USER - sUser = web_interface->web_server.arg("USER"); - if ( !((sUser==FPSTR(DEFAULT_ADMIN_LOGIN)) || (sUser==FPSTR(DEFAULT_USER_LOGIN)))) { - msg_alert_error=true; - smsg=F("Error : Incorrect User"); - code=401; - } - if (msg_alert_error == false) { - //Password - sPassword = web_interface->web_server.arg("PASSWORD"); - String sadminPassword; - - if (!CONFIG::read_string(EP_ADMIN_PWD, sadminPassword, MAX_LOCAL_PASSWORD_LENGTH)) { - sadminPassword=FPSTR(DEFAULT_ADMIN_PWD); - } - - String suserPassword; - - if (!CONFIG::read_string(EP_USER_PWD, suserPassword, MAX_LOCAL_PASSWORD_LENGTH)) { - suserPassword=FPSTR(DEFAULT_USER_PWD); - } - - if(!(((sUser==FPSTR(DEFAULT_ADMIN_LOGIN)) && (strcmp(sPassword.c_str(),sadminPassword.c_str())==0)) || - ((sUser==FPSTR(DEFAULT_USER_LOGIN)) && (strcmp(sPassword.c_str(),suserPassword.c_str()) == 0)))) { - msg_alert_error=true; - smsg=F("Error: Incorrect password"); - code = 401; - } - } - } else { - msg_alert_error=true; - smsg = F("Error: Missing data"); - code = 500; - } - //change password - if ( web_interface->web_server.hasArg("PASSWORD")&& web_interface->web_server.hasArg("USER") && web_interface->web_server.hasArg("NEWPASSWORD") && (msg_alert_error==false) ) { - String newpassword = web_interface->web_server.arg("NEWPASSWORD"); - if (CONFIG::isLocalPasswordValid(newpassword.c_str())) { - int pos=0; - if(sUser==FPSTR(DEFAULT_ADMIN_LOGIN)) pos = EP_ADMIN_PWD; - else pos = EP_USER_PWD; - if (!CONFIG::write_string(pos,newpassword.c_str())){ - msg_alert_error=true; - smsg = F("Error: Cannot apply changes"); - code = 500; - } - } else { - msg_alert_error=true; - smsg = F("Error: Incorrect password"); - code = 500; - } - } - if ((code == 200) || (code == 500)) { - level_authenticate_type current_auth_level; - if(sUser == FPSTR(DEFAULT_ADMIN_LOGIN)) { - current_auth_level = LEVEL_ADMIN; - } else if(sUser == FPSTR(DEFAULT_USER_LOGIN)){ - current_auth_level = LEVEL_USER; - } else { - current_auth_level = LEVEL_GUEST; - } - //create Session - if ((current_auth_level != auth_level) || (auth_level== LEVEL_GUEST)) { - auth_ip * current_auth = new auth_ip; - current_auth->level = current_auth_level; - current_auth->ip=web_interface->web_server.client().remoteIP(); - strcpy(current_auth->sessionID,web_interface->create_session_ID()); - strcpy(current_auth->userID,sUser.c_str()); - current_auth->last_time=millis(); - if (web_interface->AddAuthIP(current_auth)) { - String tmps ="ESPSESSIONID="; - tmps+=current_auth->sessionID; - web_interface->web_server.sendHeader("Set-Cookie",tmps); - web_interface->web_server.sendHeader("Cache-Control","no-cache"); - switch(current_auth->level) { - case LEVEL_ADMIN: - auths = "admin"; - break; - case LEVEL_USER: - auths = "user"; - break; - default: - auths = "guest"; - } - } else { - delete current_auth; - msg_alert_error=true; - code = 500; - smsg = F("Error: Too many connections"); - } - } - } - if (code == 200) smsg = F("Ok"); - - //build JSON - String buffer2send = "{\"status\":\"" + smsg + "\",\"authentication_lvl\":\""; - buffer2send += auths; - buffer2send += "\"}"; - web_interface->web_server.send(code, "application/json", buffer2send); - } else { - if (auth_level != LEVEL_GUEST) { - String cookie = web_interface->web_server.header("Cookie"); - int pos = cookie.indexOf("ESPSESSIONID="); - String sessionID; - if (pos!= -1) { - int pos2 = cookie.indexOf(";",pos); - sessionID = cookie.substring(pos+strlen("ESPSESSIONID="),pos2); - auth_ip * current_auth_info = web_interface->GetAuth(web_interface->web_server.client().remoteIP(), sessionID.c_str()); - if (current_auth_info != NULL){ - sUser = current_auth_info->userID; - } - } - } - String buffer2send = "{\"status\":\"200\",\"authentication_lvl\":\""; - buffer2send += auths; - buffer2send += "\",\"user\":\""; - buffer2send += sUser; - buffer2send +="\"}"; - web_interface->web_server.send(code, "application/json", buffer2send); - } -} -#endif - - -//Handle web command query and send answer -void handle_web_command() -{ - level_authenticate_type auth_level= web_interface->is_authenticated(); - /* if (auth_level == LEVEL_GUEST) { - web_interface->web_server.send(403,"text/plain","Not allowed, log in first!\n"); - return; - }*/ - String buffer2send = ""; - LOG(String (web_interface->web_server.args())) - LOG(" Web command\r\n") -#ifdef DEBUG_ESP3D - int nb = web_interface->web_server.args(); - for (int i = 0 ; i < nb; i++) { - LOG(web_interface->web_server.argName(i)) - LOG(":") - LOG(web_interface->web_server.arg(i)) - LOG("\r\n") - } -#endif - String cmd = ""; - int count ; - if (web_interface->web_server.hasArg("plain") || web_interface->web_server.hasArg("commandText")) { - if (web_interface->web_server.hasArg("plain")) { - cmd = web_interface->web_server.arg("plain"); - } else { - cmd = web_interface->web_server.arg("commandText"); - } - LOG("Web Command:") - LOG(cmd) - LOG("\r\n") - } else { - LOG("invalid argument\r\n") - web_interface->web_server.send(200,"text/plain","Invalid command"); - return; - } - //if it is for ESP module [ESPXXX] - cmd.trim(); - int ESPpos = cmd.indexOf("[ESP"); - if (ESPpos>-1) { - //is there the second part? - int ESPpos2 = cmd.indexOf("]",ESPpos); - if (ESPpos2>-1) { - //Split in command and parameters - String cmd_part1=cmd.substring(ESPpos+4,ESPpos2); - String cmd_part2=""; - //only [ESP800] is allowed login free if authentication is enabled - if ((auth_level == LEVEL_GUEST) && (cmd_part1.toInt()!=800)) { - web_interface->web_server.send(401,"text/plain","Authentication failed!\n"); - return; - } - //is there space for parameters? - if (ESPpos2web_server.send(401,"text/plain","Authentication failed!\n"); - return; - } - //send command to serial as no need to transfer ESP command - //to avoid any pollution if Uploading file to SDCard - if ((web_interface->blockserial) == false) { - //block every query - web_interface->blockserial = true; - LOG("Block Serial\r\n") - //empty the serial buffer and incoming data - LOG("Start PurgeSerial\r\n") - if(ESP_SERIAL_OUT.available()) { - BRIDGE::processFromSerial2TCP(); - delay(1); - } - LOG("End PurgeSerial\r\n") - web_interface->web_server.setContentLength(CONTENT_LENGTH_UNKNOWN); - web_interface->web_server.sendHeader("Content-Type","text/plain",true); - web_interface->web_server.sendHeader("Cache-Control","no-cache"); - web_interface->web_server.send(200); - //send command - LOG(String(cmd.length())) - LOG("Start PurgeSerial\r\n") - if(ESP_SERIAL_OUT.available()) { - BRIDGE::processFromSerial2TCP(); - delay(1); - } - LOG("End PurgeSerial\r\n") - LOG("Send Command\r\n") - ESP_SERIAL_OUT.println(cmd); - count = 0; - String current_buffer; - String current_line; - //int pos; - int temp_counter = 0; - String tmp; - bool datasent = false; - //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; - LOG("Found ok\r\n") - break; - } - //get the line and transmit it - LOG("Check command: ") - LOG(current_line) - LOG("\r\n") - //check command - if ((CONFIG::GetFirmwareTarget() == REPETIER) || (CONFIG::GetFirmwareTarget() == REPETIER4DV)){ - //save time no need to continue - if (current_line.indexOf("busy:") > -1) { - temp_counter++; - } else if (COMMAND::check_command(current_line, NO_PIPE, false)) { - temp_counter ++ ; - } - }else { - if (COMMAND::check_command(current_line, NO_PIPE, false)) { - temp_counter ++ ; - } - } - if (temp_counter > 5) { - break; - } - if ((CONFIG::GetFirmwareTarget() == REPETIER) || (CONFIG::GetFirmwareTarget() == REPETIER4DV)) { - if (!current_line.startsWith( "ok ")) - { - buffer2send +=current_line; - buffer2send +="\n"; - } - } else { - buffer2send +=current_line; - buffer2send +="\n"; - } - if (buffer2send.length() > 1200) { - web_interface->web_server.sendContent(buffer2send); - buffer2send = ""; - datasent = true; - } - //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++; - } - //to be sure connection close - if (buffer2send.length() > 0) { - web_interface->web_server.sendContent(buffer2send); - datasent = true; - } - if (!datasent) { - web_interface->web_server.sendContent(" \r\n"); - } - web_interface->web_server.sendContent(""); - LOG("Start PurgeSerial\r\n") - if(ESP_SERIAL_OUT.available()) { - BRIDGE::processFromSerial2TCP(); - delay(1); - } - LOG("End PurgeSerial\r\n") - web_interface->blockserial = false; - LOG("Release Serial\r\n") - } else { - web_interface->web_server.send(200,"text/plain","Serial is busy, retry later!"); - } - } -} - -//Handle web command query and sent ack or fail instead of answer -void handle_web_command_silent() -{ - level_authenticate_type auth_level= web_interface->is_authenticated(); - if (auth_level == LEVEL_GUEST) { - web_interface->web_server.send(401,"text/plain","Authentication failed!\n"); - return; - } - String buffer2send = ""; - LOG(String (web_interface->web_server.args())) - LOG(" Web silent command\r\n") -#ifdef DEBUG_ESP3D - int nb = web_interface->web_server.args(); - for (int i = 0 ; i < nb; i++) { - LOG(web_interface->web_server.argName(i)) - LOG(":") - LOG(web_interface->web_server.arg(i)) - LOG("\r\n") - } -#endif - String cmd = ""; - //int count ; - if (web_interface->web_server.hasArg("plain") || web_interface->web_server.hasArg("commandText")) { - if (web_interface->web_server.hasArg("plain")) { - cmd = web_interface->web_server.arg("plain"); - } else { - cmd = web_interface->web_server.arg("commandText"); - } - LOG("Web Command:") - LOG(cmd) - LOG("\r\n") - } else { - LOG("invalid argument\r\n") - web_interface->web_server.send(200,"text/plain","Invalid command"); - return; - } - //if it is for ESP module [ESPXXX] - cmd.trim(); - int ESPpos = cmd.indexOf("[ESP"); - if (ESPpos>-1) { - //is there the second part? - int ESPpos2 = cmd.indexOf("]",ESPpos); - if (ESPpos2>-1) { - //Split in command and parameters - String cmd_part1=cmd.substring(ESPpos+4,ESPpos2); - String cmd_part2=""; - //is there space for parameters? - if (ESPpos2web_server.send(200,"text/plain","ok"); - } else { - web_interface->web_server.send(500,"text/plain","error"); - } - - } - //if not is not a valid [ESPXXX] command - } - } else { - //send command to serial as no need to transfer ESP command - //to avoid any pollution if Uploading file to SDCard - if ((web_interface->blockserial) == false) { - LOG("Send Command\r\n") - //send command - ESP_SERIAL_OUT.println(cmd); - web_interface->web_server.send(200,"text/plain","ok"); - } else { - web_interface->web_server.send(200,"text/plain","Serial is busy, retry later!"); - } - } - -} - -#ifdef SSDP_FEATURE -void handle_SSDP() -{ - SSDP.schema(web_interface->web_server.client()); -} -#endif - -//constructor -WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port):web_server(port) -{ - //init what will handle "/" - web_server.on("/",HTTP_ANY, handle_web_interface_root); - web_server.on("/command",HTTP_ANY, handle_web_command); - web_server.on("/command_silent",HTTP_ANY, handle_web_command_silent); - web_server.on("/upload_serial", HTTP_ANY, handle_serial_SDFileList,SDFile_serial_upload); - web_server.on("/files", HTTP_ANY, handleFileList,SPIFFSFileupload); -#ifdef WEB_UPDATE_FEATURE - web_server.on("/updatefw",HTTP_ANY, handleUpdate,WebUpdateUpload); -#endif -#ifdef AUTHENTICATION_FEATURE - web_server.on("/login", HTTP_ANY, handle_login); -#endif - //TODO: to be reviewed - web_server.on("/STATUS",HTTP_ANY, handle_web_interface_status); -#ifdef SSDP_FEATURE - web_server.on("/description.xml", HTTP_GET, handle_SSDP); -#endif -#ifdef CAPTIVE_PORTAL_FEATURE - web_server.on("/generate_204",HTTP_ANY, handle_web_interface_root); - web_server.on("/gconnectivitycheck.gstatic.com",HTTP_ANY, handle_web_interface_root); - //do not forget the / at the end - web_server.on("/fwlink/",HTTP_ANY, handle_web_interface_root); -#endif - web_server.onNotFound( handle_not_found); - blockserial = false; - restartmodule=false; - //rolling list of 4entries with a maximum of 50 char for each entry -#ifdef ERROR_MSG_FEATURE - error_msg.setsize(4); - error_msg.setlength(50); -#endif -#ifdef INFO_MSG_FEATURE - info_msg.setsize(4); - info_msg.setlength(50); -#endif -#ifdef STATUS_MSG_FEATURE - status_msg.setsize(4); - status_msg.setlength(50); -#endif - fsUploadFile=(FS_FILE)0; - _head=NULL; - _nb_ip=0; - _upload_status=UPLOAD_STATUS_NONE; -} -//Destructor -WEBINTERFACE_CLASS::~WEBINTERFACE_CLASS() -{ -#ifdef INFO_MSG_FEATURE - info_msg.clear(); -#endif -#ifdef ERROR_MSG_FEATURE - error_msg.clear(); -#endif -#ifdef STATUS_MSG_FEATURE - status_msg.clear(); -#endif - while (_head) { - auth_ip * current = _head; - _head=_head->_next; - delete current; - } - _nb_ip=0; -} -//check authentification -level_authenticate_type WEBINTERFACE_CLASS::is_authenticated() -{ -#ifdef AUTHENTICATION_FEATURE - if (web_server.hasHeader("Cookie")) { - String cookie = web_server.header("Cookie"); - int pos = cookie.indexOf("ESPSESSIONID="); - if (pos!= -1) { - int pos2 = cookie.indexOf(";",pos); - String sessionID = cookie.substring(pos+strlen("ESPSESSIONID="),pos2); - IPAddress ip = web_server.client().remoteIP(); - //check if cookie can be reset and clean table in same time - return ResetAuthIP(ip,sessionID.c_str()); - } - } - return LEVEL_GUEST; -#else - return LEVEL_ADMIN; -#endif -} - -#ifdef AUTHENTICATION_FEATURE -//add the information in the linked list if possible -bool WEBINTERFACE_CLASS::AddAuthIP(auth_ip * item) -{ - if (_nb_ip>MAX_AUTH_IP) { - return false; - } - item->_next=_head; - _head=item; - _nb_ip++; - return true; -} - -//Session ID based on IP and time using 16 char -char * WEBINTERFACE_CLASS::create_session_ID() -{ - static char sessionID[17]; -//reset SESSIONID - for (int i=0; i<17; i++) { - sessionID[i]='\0'; - } -//get time - uint32_t now = millis(); -//get remote IP - IPAddress remoteIP=web_server.client().remoteIP(); -//generate SESSIONID - if (0>sprintf(sessionID,"%02X%02X%02X%02X%02X%02X%02X%02X",remoteIP[0],remoteIP[1],remoteIP[2],remoteIP[3],(uint8_t) ((now >> 0) & 0xff),(uint8_t) ((now >> 8) & 0xff),(uint8_t) ((now >> 16) & 0xff),(uint8_t) ((now >> 24) & 0xff))) { - strcpy(sessionID,"NONE"); - } - return sessionID; -} - - - -bool WEBINTERFACE_CLASS::ClearAuthIP(IPAddress ip, const char * sessionID){ - auth_ip * current = _head; - auth_ip * previous = NULL; - bool done = false; - while (current) { - if ((ip == current->ip) && (strcmp(sessionID,current->sessionID)==0)) { - //remove - done = true; - if (current ==_head) { - _head=current->_next; - _nb_ip--; - delete current; - current=_head; - } else { - previous->_next=current->_next; - _nb_ip--; - delete current; - current=previous->_next; - } - } else { - previous = current; - current=current->_next; - } - } - return done; -} - -//Get info -auth_ip * WEBINTERFACE_CLASS::GetAuth(IPAddress ip,const char * sessionID) -{ - auth_ip * current = _head; - auth_ip * previous = NULL; - //get time - //uint32_t now = millis(); - while (current) { - if (ip==current->ip) { - if (strcmp(sessionID,current->sessionID)==0) { - //found - return current; - } - } - previous = current; - current=current->_next; - } - return NULL; -} - -//Review all IP to reset timers -level_authenticate_type WEBINTERFACE_CLASS::ResetAuthIP(IPAddress ip,const char * sessionID) -{ - auth_ip * current = _head; - auth_ip * previous = NULL; - //get time - //uint32_t now = millis(); - while (current) { - if ((millis()-current->last_time)>180000) { - //remove - if (current==_head) { - _head=current->_next; - _nb_ip--; - delete current; - current=_head; - } else { - previous->_next=current->_next; - _nb_ip--; - delete current; - current=previous->_next; - } - } else { - if (ip==current->ip) { - if (strcmp(sessionID,current->sessionID)==0) { - //reset time - current->last_time=millis(); - return (level_authenticate_type)current->level; - } - } - previous = current; - current=current->_next; - } - } - return LEVEL_GUEST; -} -#endif - -//Check what is the content tye according extension file -String WEBINTERFACE_CLASS::getContentType(String filename) -{ - if(filename.endsWith(".htm")) { - return "text/html"; - } else if(filename.endsWith(".html")) { - return "text/html"; - } else if(filename.endsWith(".css")) { - return "text/css"; - } else if(filename.endsWith(".js")) { - return "application/javascript"; - } else if(filename.endsWith(".png")) { - return "image/png"; - } else if(filename.endsWith(".gif")) { - return "image/gif"; - } else if(filename.endsWith(".jpeg")) { - return "image/jpeg"; - } else if(filename.endsWith(".jpg")) { - return "image/jpeg"; - } else if(filename.endsWith(".ico")) { - return "image/x-icon"; - } else if(filename.endsWith(".xml")) { - return "text/xml"; - } else if(filename.endsWith(".pdf")) { - return "application/x-pdf"; - } else if(filename.endsWith(".zip")) { - return "application/x-zip"; - } else if(filename.endsWith(".gz")) { - return "application/x-gzip"; - } else if(filename.endsWith(".tpl")) { - return "text/plain"; - } else if(filename.endsWith(".inc")) { - return "text/plain"; - } else if(filename.endsWith(".txt")) { - return "text/plain"; - } - return "application/octet-stream"; -} - - -WEBINTERFACE_CLASS * web_interface; diff --git a/esp3d/webinterface.h b/esp3d/webinterface.h deleted file mode 100644 index de3874a9..00000000 --- a/esp3d/webinterface.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - webinterface.h - ESP3D configuration class - - 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 -*/ - -#ifndef WEBINTERFACE_h -#define WEBINTERFACE_h -#include -#include -#include -#ifndef FS_NO_GLOBALS -#define FS_NO_GLOBALS -#endif -#include -#ifdef ARDUINO_ARCH_ESP8266 -#include -#else -#include -#endif - - -#include "storestrings.h" - -#define MAX_EXTRUDERS 4 - -struct auth_ip { - IPAddress ip; - level_authenticate_type level; - char userID[17]; - char sessionID[17]; - uint32_t last_time; - auth_ip * _next; -}; - -class WEBINTERFACE_CLASS -{ -public: - WEBINTERFACE_CLASS (int port = 80); - ~WEBINTERFACE_CLASS(); -#ifdef ARDUINO_ARCH_ESP8266 - ESP8266WebServer web_server; -#else - WebServer web_server; -#endif - FS_FILE fsUploadFile; -#ifdef ERROR_MSG_FEATURE - STORESTRINGS_CLASS error_msg; -#endif -#ifdef INFO_MSG_FEATURE - STORESTRINGS_CLASS info_msg; -#endif -#ifdef STATUS_MSG_FEATURE - STORESTRINGS_CLASS status_msg; -#endif - bool restartmodule; - String getContentType(String filename); - level_authenticate_type is_authenticated(); - bool AddAuthIP(auth_ip * item); - bool blockserial; -#ifdef AUTHENTICATION_FEATURE - level_authenticate_type ResetAuthIP(IPAddress ip,const char * sessionID); - auth_ip * GetAuth(IPAddress ip,const char * sessionID); - bool ClearAuthIP(IPAddress ip, const char * sessionID); - char * create_session_ID(); -#endif - uint8_t _upload_status; - -private: - auth_ip * _head; - uint8_t _nb_ip; -}; - -extern WEBINTERFACE_CLASS * web_interface; - -#endif diff --git a/esp3d/wificonf.cpp b/esp3d/wificonf.cpp deleted file mode 100644 index de45a921..00000000 --- a/esp3d/wificonf.cpp +++ /dev/null @@ -1,505 +0,0 @@ -/* - wificonf.cpp - ESP3D configuration class - - 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 -*/ -#include "config.h" -#include "wificonf.h" -#include "bridge.h" -#include "webinterface.h" - -#ifdef ARDUINO_ARCH_ESP8266 -#include "ESP8266WiFi.h" -#ifdef MDNS_FEATURE -#include -#endif -#else -#include -#include "esp_wifi.h" -#ifdef MDNS_FEATURE -#include -#endif -#endif -#include "IPAddress.h" -#ifdef CAPTIVE_PORTAL_FEATURE -#include -DNSServer dnsServer; -const byte DNS_PORT = 53; -#endif -#ifdef ARDUINO_ARCH_ESP8266 -#include -#else -#include -#endif -#ifdef SSDP_FEATURE -#include -#endif -#ifdef NETBIOS_FEATURE -#ifdef ARDUINO_ARCH_ESP8266 -#include -#else -#include -#endif -#endif -#ifdef ARDUINO_ARCH_ESP8266 -extern "C" { -#include "user_interface.h" -} -#endif -#ifdef TIMESTAMP_FEATURE -#include -#endif - -WIFI_CONFIG::WIFI_CONFIG() -{ - iweb_port=DEFAULT_WEB_PORT; - idata_port=DEFAULT_DATA_PORT; - baud_rate=DEFAULT_BAUD_RATE; - sleep_mode=DEFAULT_SLEEP_MODE; - _hostname[0]=0; -} - -int32_t WIFI_CONFIG::getSignal(int32_t RSSI) -{ - if (RSSI <= -100) { - return 0; - } - if (RSSI >= -50) { - return 100; - } - return (2* (RSSI+100)); -} - -const char * WIFI_CONFIG::get_hostname() -{ - String hname; -#ifdef ARDUINO_ARCH_ESP8266 - hname = WiFi.hostname(); -#else - hname = WiFi.getHostname(); -#endif - if (hname.length()==0) { - if (!CONFIG::read_string(EP_HOSTNAME, _hostname, MAX_HOSTNAME_LENGTH)) { - strcpy(_hostname,get_default_hostname()); - } - } else { - strcpy(_hostname,hname.c_str()); - } - return _hostname; -} - -const char * WIFI_CONFIG::get_default_hostname() -{ - static char hostname[13]; - uint8_t mac [WL_MAC_ADDR_LENGTH]; - WiFi.macAddress(mac); - if (0>sprintf(hostname,"ESP_%02X%02X%02X",mac[3],mac[4],mac[5])) { - strcpy (hostname, "ESP8266"); - } - return hostname; -} - -//safe setup if no connection -void WIFI_CONFIG::Safe_Setup() -{ -#ifdef CAPTIVE_PORTAL_FEATURE - dnsServer.stop(); - delay(100); -#endif - - WiFi.disconnect(); - //setup Soft AP - WiFi.mode(WIFI_AP); - IPAddress local_ip (DEFAULT_IP_VALUE[0],DEFAULT_IP_VALUE[1],DEFAULT_IP_VALUE[2],DEFAULT_IP_VALUE[3]); - IPAddress gateway (DEFAULT_GATEWAY_VALUE[0],DEFAULT_GATEWAY_VALUE[1],DEFAULT_GATEWAY_VALUE[2],DEFAULT_GATEWAY_VALUE[3]); - IPAddress subnet (DEFAULT_MASK_VALUE[0],DEFAULT_MASK_VALUE[1],DEFAULT_MASK_VALUE[2],DEFAULT_MASK_VALUE[3]); - String ssid = FPSTR(DEFAULT_AP_SSID); - String pwd = FPSTR(DEFAULT_AP_PASSWORD); - WiFi.softAP(ssid.c_str(),pwd.c_str()); - delay(500); - WiFi.softAPConfig( local_ip, gateway, subnet); - delay(1000); - ESP_SERIAL_OUT.println(F("M117 Safe mode started")); -} - -//Read configuration settings and apply them -bool WIFI_CONFIG::Setup(bool force_ap) -{ - char pwd[MAX_PASSWORD_LENGTH+1]; - char sbuf[MAX_SSID_LENGTH+1]; - char hostname [MAX_HOSTNAME_LENGTH+1]; - //int wstatus; - IPAddress currentIP; - byte bflag=0; - byte bmode=0; - //system_update_cpu_freq(SYS_CPU_160MHZ); - //set the sleep mode - if (!CONFIG::read_byte(EP_SLEEP_MODE, &bflag )) { - LOG("Error read Sleep mode\r\n") - return false; - } -#ifdef ARDUINO_ARCH_ESP8266 - WiFi.setSleepMode ((WiFiSleepType_t)bflag); -#else - esp_wifi_set_ps((wifi_ps_type_t)bflag); -#endif - sleep_mode=bflag; - if (force_ap) { - bmode = AP_MODE; - } else { - //AP or client ? - if (!CONFIG::read_byte(EP_WIFI_MODE, &bmode ) ) { - LOG("Error read wifi mode\r\n") - return false; - } - } - if (!CONFIG::read_string(EP_HOSTNAME, hostname, MAX_HOSTNAME_LENGTH)) { - strcpy(hostname,get_default_hostname()); - } - //this is AP mode - if (bmode==AP_MODE) { - LOG("Set AP mode\r\n") - if(!CONFIG::read_string(EP_AP_SSID, sbuf, MAX_SSID_LENGTH)) { - return false; - } - if(!CONFIG::read_string(EP_AP_PASSWORD, pwd, MAX_PASSWORD_LENGTH)) { - return false; - } - ESP_SERIAL_OUT.print(FPSTR(M117_)); - ESP_SERIAL_OUT.print(F("SSID ")); - ESP_SERIAL_OUT.println(sbuf); - LOG("SSID ") - LOG(sbuf) - LOG("\r\n") - //DHCP or Static IP ? - if (!CONFIG::read_byte(EP_AP_IP_MODE, &bflag )) { - LOG("Error IP mode\r\n") - return false; - } - LOG("IP Mode: ") - LOG(CONFIG::intTostr(bflag)) - LOG("\r\n") - if (bflag==STATIC_IP_MODE) { - byte ip_buf[4]; - LOG("Static mode\r\n") - //get the IP - LOG("IP value:") - if (!CONFIG::read_buffer(EP_AP_IP_VALUE,ip_buf, IP_LENGTH)) { - LOG("Error\r\n") - return false; - } - IPAddress local_ip (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]); - LOG(local_ip.toString()) - LOG("\r\nGW value:") - //get the gateway - if (!CONFIG::read_buffer(EP_AP_GATEWAY_VALUE,ip_buf, IP_LENGTH)) { - LOG("Error\r\n") - return false; - } - IPAddress gateway (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]); - LOG(gateway.toString()) - LOG("\r\nMask value:") - //get the mask - if (!CONFIG::read_buffer(EP_AP_MASK_VALUE,ip_buf, IP_LENGTH)) { - LOG("Error Mask value\r\n") - return false; - } - IPAddress subnet (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]); - LOG(subnet.toString()) - LOG("\r\n") - //apply according active wifi mode - LOG("Set IP\r\n") - WiFi.softAPConfig( local_ip, gateway, subnet); - delay(100); - } - LOG("Disable STA\r\n") - WiFi.enableSTA(false); - delay(100); - LOG("Set phy mode\r\n") - //setup PHY_MODE - if (!CONFIG::read_byte(EP_AP_PHY_MODE, &bflag )) { - return false; - } -#ifdef ARDUINO_ARCH_ESP32 - esp_wifi_set_protocol(ESP_IF_WIFI_AP, bflag); -#endif - LOG("Set AP\r\n") - //setup Soft AP - WiFi.mode(WIFI_AP); - delay(50); - WiFi.softAP(sbuf, pwd); - delay(100); -#ifdef ARDUINO_ARCH_ESP8266 - WiFi.setPhyMode((WiFiPhyMode_t)bflag); -#endif - delay(100); - LOG("Get current config\r\n") - //get current config -#ifdef ARDUINO_ARCH_ESP32 - wifi_config_t conf; - esp_wifi_get_config(ESP_IF_WIFI_AP, &conf); -#else - struct softap_config apconfig; - wifi_softap_get_config(&apconfig); -#endif - //set the chanel - if (!CONFIG::read_byte(EP_CHANNEL, &bflag )) { - return false; - } -#ifdef ARDUINO_ARCH_ESP32 - conf.ap.channel=bflag; -#else - apconfig.channel=bflag; -#endif - //set Authentification type - if (!CONFIG::read_byte(EP_AUTH_TYPE, &bflag )) { - return false; - } -#ifdef ARDUINO_ARCH_ESP32 - conf.ap.authmode=(wifi_auth_mode_t)bflag; -#else - apconfig.authmode=(AUTH_MODE)bflag; -#endif - //set the visibility of SSID - if (!CONFIG::read_byte(EP_SSID_VISIBLE, &bflag )) { - return false; - } -#ifdef ARDUINO_ARCH_ESP32 - conf.ap.ssid_hidden=!bflag; -#else - apconfig.ssid_hidden=!bflag; -#endif - - //no need to add these settings to configuration just use default ones -#ifdef ARDUINO_ARCH_ESP32 - conf.ap.max_connection=DEFAULT_MAX_CONNECTIONS; - conf.ap.beacon_interval=DEFAULT_BEACON_INTERVAL; - if (esp_wifi_set_config(ESP_IF_WIFI_AP, &conf)!=ESP_OK){ - ESP_SERIAL_OUT.println(F("M117 Error Wifi AP!")); - delay(1000); - } -#else - apconfig.max_connection=DEFAULT_MAX_CONNECTIONS; - apconfig.beacon_interval=DEFAULT_BEACON_INTERVAL; - //apply settings to current and to default - if (!wifi_softap_set_config(&apconfig) || !wifi_softap_set_config_current(&apconfig)) { - ESP_SERIAL_OUT.println(F("M117 Error Wifi AP!")); - delay(1000); - } -#endif - } else { - LOG("Set STA mode\r\n") - if(!CONFIG::read_string(EP_STA_SSID, sbuf, MAX_SSID_LENGTH)) { - return false; - } - if(!CONFIG::read_string(EP_STA_PASSWORD, pwd, MAX_PASSWORD_LENGTH)) { - return false; - } - ESP_SERIAL_OUT.print(FPSTR(M117_)); - ESP_SERIAL_OUT.print(F("SSID ")); - ESP_SERIAL_OUT.println(sbuf); - LOG("SSID ") - LOG(sbuf) - LOG("\r\n") - if (!CONFIG::read_byte(EP_STA_IP_MODE, &bflag )) { - return false; - } - if (bflag==STATIC_IP_MODE) { - byte ip_buf[4]; - //get the IP - if (!CONFIG::read_buffer(EP_STA_IP_VALUE,ip_buf, IP_LENGTH)) { - return false; - } - IPAddress local_ip (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]); - //get the gateway - if (!CONFIG::read_buffer(EP_STA_GATEWAY_VALUE,ip_buf, IP_LENGTH)) { - return false; - } - IPAddress gateway (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]); - //get the mask - if (!CONFIG::read_buffer(EP_STA_MASK_VALUE,ip_buf, IP_LENGTH)) { - return false; - } - IPAddress subnet (ip_buf[0],ip_buf[1],ip_buf[2],ip_buf[3]); - //apply according active wifi mode - WiFi.config( local_ip, gateway, subnet); - } - WiFi.enableAP(false); - delay(100); - //setup PHY_MODE - if (!CONFIG::read_byte(EP_STA_PHY_MODE, &bflag )) { - return false; - } -#ifdef ARDUINO_ARCH_ESP32 - esp_wifi_set_protocol(ESP_IF_WIFI_STA, bflag); -#endif - //setup station mode - WiFi.mode(WIFI_STA); - delay(100); -#ifdef ARDUINO_ARCH_ESP8266 - WiFi.setPhyMode((WiFiPhyMode_t)bflag); -#endif - WiFi.begin(sbuf, pwd); - delay(100); - byte i=0; - //try to connect - byte dot = 0; - String msg; - while (WiFi.status() != WL_CONNECTED && i<40) { - switch(WiFi.status()) { - case 1: - ESP_SERIAL_OUT.print(FPSTR(M117_)); - ESP_SERIAL_OUT.println(F("No SSID found!")); - break; - - case 4: - ESP_SERIAL_OUT.print(FPSTR(M117_)); - ESP_SERIAL_OUT.println(F("No Connection!")); - break; - - default: - ESP_SERIAL_OUT.print(FPSTR(M117_)); - if (dot == 0)msg = F("Connecting"); - dot++; - msg.trim(); - msg +=F("."); - //for smoothieware to keep position - for (byte i= 0;i< 4-dot; i++)msg +=F(" "); - if (dot == 4)dot=0; - ESP_SERIAL_OUT.println(msg); - break; - } - delay(500); - i++; - } - if (WiFi.status() != WL_CONNECTED) { - ESP_SERIAL_OUT.print(FPSTR(M117_)); - ESP_SERIAL_OUT.println(F("Not Connectied!")); - return false; - } -#ifdef ARDUINO_ARCH_ESP8266 - WiFi.hostname(hostname); -#else - WiFi.setHostname(hostname); -#endif - } - - //Get IP - if (WiFi.getMode()==WIFI_STA) { - currentIP=WiFi.localIP(); - } else { - currentIP=WiFi.softAPIP(); - } - ESP_SERIAL_OUT.print(FPSTR(M117_)); - ESP_SERIAL_OUT.println(currentIP); - ESP_SERIAL_OUT.flush(); - return true; -} - -bool WIFI_CONFIG::Enable_servers() -{ - //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->web_server.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.setErrorReplyCode(DNSReplyCode::NoError); - dnsServer.start(DNS_PORT, "*", WiFi.softAPIP()); - } -#endif - web_interface->web_server.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 - // Set up mDNS responder: - //useless in AP mode and service consuming - if (WiFi.getMode()!=WIFI_AP ){ - char hostname [MAX_HOSTNAME_LENGTH+1]; - if (!CONFIG::read_string(EP_HOSTNAME, hostname, MAX_HOSTNAME_LENGTH)) { - strcpy(hostname,get_default_hostname()); - } - if (!mdns.begin(hostname)) { - ESP_SERIAL_OUT.print(FPSTR(M117_)); - ESP_SERIAL_OUT.println(F("Error with mDNS!")); - delay(1000); - } else { - // Check for any mDNS queries and send responses - delay(100); - 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"); - if (WiFi.getMode()!=WIFI_AP )SSDP.begin(); -#endif -#ifdef NETBIOS_FEATURE - //useless in AP mode and service consuming - if (WiFi.getMode()!=WIFI_AP )NBNS.begin(shost.c_str()); -#endif - - return true; -} - -bool WIFI_CONFIG::Disable_servers() -{ -#ifdef TCP_IP_DATA_FEATURE - data_server->stop(); -#endif -#ifdef CAPTIVE_PORTAL_FEATURE - if (WiFi.getMode()!=WIFI_STA ) { - dnsServer.stop(); - } -#endif -#ifdef NETBIOS_FEATURE - //useless in AP mode and service consuming - if (WiFi.getMode()!=WIFI_AP )NBNS.end(); -#endif - web_interface->web_server.stop(); - return true; -} - -WIFI_CONFIG wifi_config; diff --git a/esp3d/wificonf.h b/esp3d/wificonf.h deleted file mode 100644 index 603bbd4c..00000000 --- a/esp3d/wificonf.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - wificonf.h - ESP3D configuration class - - 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 -*/ - -#ifndef WIFICONF_H -#define WIFICONF_H -#include -#include "config.h" -#include "IPAddress.h" -#ifdef ARDUINO_ARCH_ESP8266 -#include "ESP8266WiFi.h" -#ifdef MDNS_FEATURE -#include -#endif -#else -#include -#ifdef MDNS_FEATURE -#include -#endif -#endif - -class WIFI_CONFIG -{ -public: - // multicast DNS responder feature -#ifdef MDNS_FEATURE - MDNSResponder mdns; -#endif - WIFI_CONFIG(); - int iweb_port; - int idata_port; - long baud_rate; - int sleep_mode; - int32_t getSignal(int32_t RSSI); - bool Setup(bool force_ap = false); - void Safe_Setup(); - bool Enable_servers(); - bool Disable_servers(); - const char * get_default_hostname(); - const char * get_hostname(); -private: - char _hostname[33]; -}; - -extern WIFI_CONFIG wifi_config; -#endif diff --git a/libraries/WebServer/.gitignore b/libraries/WebServer/.gitignore deleted file mode 100644 index 259148fa..00000000 --- a/libraries/WebServer/.gitignore +++ /dev/null @@ -1,32 +0,0 @@ -# Prerequisites -*.d - -# Compiled Object files -*.slo -*.lo -*.o -*.obj - -# Precompiled Headers -*.gch -*.pch - -# Compiled Dynamic libraries -*.so -*.dylib -*.dll - -# Fortran module files -*.mod -*.smod - -# Compiled Static libraries -*.lai -*.la -*.a -*.lib - -# Executables -*.exe -*.out -*.app diff --git a/libraries/WebServer/.travis.yml b/libraries/WebServer/.travis.yml deleted file mode 100644 index 3c0d1d70..00000000 --- a/libraries/WebServer/.travis.yml +++ /dev/null @@ -1,99 +0,0 @@ -sudo: false - -language: python -python: - - "2.7" - -os: - - linux - -env: - - TESTCASE="1.8.3|esp8266|stable|esp8266:esp8266:nodemcuv2:CpuFrequency=80,FlashSize=4M3M" - - TESTCASE="1.8.3|esp8266|devel|esp8266com:esp8266:nodemcuv2:CpuFrequency=80,FlashSize=4M3M" - - TESTCASE="1.8.3|esp32|devel|espressif:esp32:esp32:FlashFreq=40" - -script: - - echo -e "travis_fold:start:sketch_test_env_prepare" - - pip install pyserial - - IFS='|' read -r -a array <<< "${TESTCASE}" - - | - for index in "${!array[@]}" - do - case $index in - 0) IDEVER="${array[index]}" ;; - 1) PLATFORM="${array[index]}" ;; - 2) RELEASE="${array[index]}" ;; - 3) BOARD="${array[index]}" ;; - esac - done - - cd $HOME - - wget -O arduino.tar.xz https://downloads.arduino.cc/arduino-${IDEVER}-linux64.tar.xz - - tar xf arduino.tar.xz - - mv arduino-${IDEVER} $HOME/arduino_ide - - mkdir -p $HOME/Arduino/libraries - - IDEDIR="${HOME}/arduino_ide" - - export PATH="$IDEDIR:$PATH" - - cd ${IDEDIR} - - which arduino - - | - if [[ $PLATFORM == "esp8266" ]] && [[ $RELEASE == "stable" ]] - then - arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs - arduino --install-boards "esp8266:esp8266" - fi - - | - if [[ $PLATFORM == "esp8266" ]] && [[ $RELEASE == "devel" ]] - then - mkdir -p hardware/esp8266com - cd hardware/esp8266com - git clone https://github.com/esp8266/Arduino.git esp8266 - cd esp8266/tools - python get.py - fi - - | - if [[ $PLATFORM == "esp32" ]] && [[ $RELEASE == "devel" ]] - then - mkdir -p hardware/espressif - cd hardware/espressif - git clone https://github.com/espressif/arduino-esp32.git esp32 - cd esp32/tools/ - python get.py - fi - - arduino --pref "compiler.warning_level=all" --save-prefs - - echo -e "travis_fold:end:sketch_test_env_prepare" - - echo -e "travis_fold:start:install_library" - - cd $HOME/Arduino/libraries - - git clone https://github.com/bbx10/WebServer_tng ${HOME}/Arduino/libraries/WebServer - - echo -e "travis_fold:end:install_library" - - echo -e "travis_fold:start:AdvancedWebServer" - - cd ${HOME}/Arduino/libraries/WebServer/examples - - arduino --verbose-build --verify --board ${BOARD} AdvancedWebServer/AdvancedWebServer.ino - - echo -e "travis_fold:end:AdvancedWebServer" - - echo -e "travis_fold:start:HelloServer" - - arduino --verbose-build --verify --board ${BOARD} HelloServer/HelloServer.ino - - echo -e "travis_fold:end:HelloServer" - - echo -e "travis_fold:start:HttpBasicAuth" - - arduino --verbose-build --verify --board ${BOARD} HttpBasicAuth/HttpBasicAuth.ino - - echo -e "travis_fold:end:HttpBasicAuth" - - echo -e "travis_fold:start:SDWebServer" - - arduino --verbose-build --verify --board ${BOARD} SDWebServer/SDWebServer.ino - - echo -e "travis_fold:end:SDWebServer" - - echo -e "travis_fold:start:SimpleAuthentification" - - arduino --verbose-build --verify --board ${BOARD} SimpleAuthentification/SimpleAuthentification.ino - - echo -e "travis_fold:end:SimpleAuthentification" - - | - if [[ $PLATFORM == "esp8266" ]] - then - echo -e "travis_fold:start:FSBrowser" - arduino --verbose-build --verify --board ${BOARD} FSBrowser/FSBrowser.ino - echo -e "travis_fold:end:FSBrowser" - echo -e "travis_fold:start:WebUpdate" - arduino --verbose-build --verify --board ${BOARD} WebUpdate/WebUpdate.ino - echo -e "travis_fold:end:WebUpdate" - fi - -notifications: - email: - on_success: change - on_failure: change - diff --git a/libraries/WebServer/LICENSE b/libraries/WebServer/LICENSE deleted file mode 100644 index 19e30718..00000000 --- a/libraries/WebServer/LICENSE +++ /dev/null @@ -1,504 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -(This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.) - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - {description} - Copyright (C) {year} {fullname} - - 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 Street, Fifth Floor, Boston, MA 02110-1301 - USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random - Hacker. - - {signature of Ty Coon}, 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! diff --git a/libraries/WebServer/README.md b/libraries/WebServer/README.md deleted file mode 100644 index 5ec07c51..00000000 --- a/libraries/WebServer/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# WebServer -ESP8266/ESP32 WebServer library - -This is an experimental port of the ESP8266WebServer library that should work -on ESP8266 and ESP32. This is NOT an official repo supported by Espressif. Do -not depend on this code for anything important or expect it to be updated. Once -the official repo is created, this repo will be deleted. - -Added Travis CI diff --git a/libraries/WebServer/examples/AdvancedWebServer/AdvancedWebServer.ino b/libraries/WebServer/examples/AdvancedWebServer/AdvancedWebServer.ino deleted file mode 100644 index b46b101d..00000000 --- a/libraries/WebServer/examples/AdvancedWebServer/AdvancedWebServer.ino +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (c) 2015, Majenko Technologies - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * * Neither the name of Majenko Technologies nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef ESP8266 -#include -#include -#include -#include -ESP8266WebServer server ( 80 ); -#else -#include -#include -#include -#include -WebServer server ( 80 ); -#endif - -const char *ssid = "YourSSIDHere"; -const char *password = "YourPSKHere"; - -#ifdef LED_BUILTIN -const int led = LED_BUILTIN; -#else -const int led = 13; -#endif - -void handleRoot() { - digitalWrite ( led, 1 ); - char temp[400]; - int sec = millis() / 1000; - int min = sec / 60; - int hr = min / 60; - - snprintf ( temp, 400, - -"\ - \ - \ - ESP8266/ESP32 Demo\ - \ - \ - \ -

Hello from ESP8266/ESP32!

\ -

Uptime: %02d:%02d:%02d

\ - \ - \ -", - - hr, min % 60, sec % 60 - ); - server.send ( 200, "text/html", temp ); - digitalWrite ( led, 0 ); -} - -void handleNotFound() { - digitalWrite ( led, 1 ); - String message = "File Not Found\n\n"; - message += "URI: "; - message += server.uri(); - message += "\nMethod: "; - message += ( server.method() == HTTP_GET ) ? "GET" : "POST"; - message += "\nArguments: "; - message += server.args(); - message += "\n"; - - for ( uint8_t i = 0; i < server.args(); i++ ) { - message += " " + server.argName ( i ) + ": " + server.arg ( i ) + "\n"; - } - - server.send ( 404, "text/plain", message ); - digitalWrite ( led, 0 ); -} - -void setup ( void ) { - pinMode ( led, OUTPUT ); - digitalWrite ( led, 0 ); - Serial.begin ( 115200 ); - WiFi.begin ( ssid, password ); - Serial.println ( "" ); - - // Wait for connection - while ( WiFi.status() != WL_CONNECTED ) { - delay ( 500 ); - Serial.print ( "." ); - } - - Serial.println ( "" ); - Serial.print ( "Connected to " ); - Serial.println ( ssid ); - Serial.print ( "IP address: " ); - Serial.println ( WiFi.localIP() ); - -#ifdef ESP8266 - if ( MDNS.begin ( "esp8266" ) ) { -#else - if ( MDNS.begin ( "esp32" ) ) { -#endif - Serial.println ( "MDNS responder started" ); - } - - server.on ( "/", handleRoot ); - server.on ( "/test.svg", drawGraph ); - server.on ( "/inline", []() { - server.send ( 200, "text/plain", "this works as well" ); - } ); - server.onNotFound ( handleNotFound ); - server.begin(); - Serial.println ( "HTTP server started" ); -} - -void loop ( void ) { - server.handleClient(); -} - -void drawGraph() { - String out = ""; - char temp[100]; - out += "\n"; - out += "\n"; - out += "\n"; - int y = rand() % 130; - for (int x = 10; x < 390; x+= 10) { - int y2 = rand() % 130; - sprintf(temp, "\n", x, 140 - y, x + 10, 140 - y2); - out += temp; - y = y2; - } - out += "\n\n"; - - server.send ( 200, "image/svg+xml", out); -} diff --git a/libraries/WebServer/examples/FSBrowser/FSBrowser.ino b/libraries/WebServer/examples/FSBrowser/FSBrowser.ino deleted file mode 100644 index e4cea8a1..00000000 --- a/libraries/WebServer/examples/FSBrowser/FSBrowser.ino +++ /dev/null @@ -1,345 +0,0 @@ -/* - FSWebServer - Example WebServer with SPIFFS backend for esp8266 - Copyright (c) 2015 Hristo Gochkov. All rights reserved. - This file is part of the ESP8266/ESP32 WebServer library for Arduino environment. - - 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 - - upload the contents of the data folder with MkSPIFFS Tool ("ESP8266 Sketch Data Upload" in Tools menu in Arduino IDE) - or you can upload the contents of a folder if you CD in that folder and run the following command: - for file in `ls -A1`; do curl -F "file=@$PWD/$file" esp8266fs.local/edit; done - - access the sample web page at http://esp8266fs.local - edit the page by going to http://esp8266fs.local/edit -*/ -/* - * Uploading html, css, javascript, etc. - * Use curl to upload the files from the SPIFFS data directory. - * cd data/ - * curl -X POST -F "data=@index.htm" http:///edit >/dev/null - * curl -X POST -F "data=@graphs.js.gz" http:///edit >/dev/null - * curl -X POST -F "data=@favicon.ico" http:///edit >/dev/null - * curl -X POST -F "data=@edit.htm.gz" http:///edit >/dev/null - */ -#ifdef ESP8266 -#include -#include -#include -#include -#include -ESP8266WebServer server(80); -#else -#include -#include -#include -#include -#include -WebServer server(80); -#endif - -#define DBG_OUTPUT_PORT Serial - -const char* ssid = "wifi-ssid"; -const char* password = "wifi-password"; -const char* host = "esp8266fs"; - -//holds the current upload -File fsUploadFile; - -//format bytes -String formatBytes(size_t bytes){ - if (bytes < 1024){ - return String(bytes)+"B"; - } else if(bytes < (1024 * 1024)){ - return String(bytes/1024.0)+"KB"; - } else if(bytes < (1024 * 1024 * 1024)){ - return String(bytes/1024.0/1024.0)+"MB"; - } else { - return String(bytes/1024.0/1024.0/1024.0)+"GB"; - } -} - -String getContentType(String filename){ - if(server.hasArg("download")) return "application/octet-stream"; - else if(filename.endsWith(".htm")) return "text/html"; - else if(filename.endsWith(".html")) return "text/html"; - else if(filename.endsWith(".css")) return "text/css"; - else if(filename.endsWith(".js")) return "application/javascript"; - else if(filename.endsWith(".png")) return "image/png"; - else if(filename.endsWith(".gif")) return "image/gif"; - else if(filename.endsWith(".jpg")) return "image/jpeg"; - else if(filename.endsWith(".ico")) return "image/x-icon"; - else if(filename.endsWith(".xml")) return "text/xml"; - else if(filename.endsWith(".pdf")) return "application/x-pdf"; - else if(filename.endsWith(".zip")) return "application/x-zip"; - else if(filename.endsWith(".gz")) return "application/x-gzip"; - return "text/plain"; -} - -bool handleFileRead(String path){ - DBG_OUTPUT_PORT.println("handleFileRead: " + path); - if(path.endsWith("/")) path += "index.htm"; - String contentType = getContentType(path); - String pathWithGz = path + ".gz"; - if(SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)){ - if(SPIFFS.exists(pathWithGz)) - path += ".gz"; - File file = SPIFFS.open(path, "r"); - size_t sent = server.streamFile(file, contentType); - file.close(); - return true; - } - return false; -} - -void handleFileUpload(){ - if(server.uri() != "/edit") return; - HTTPUpload& upload = server.upload(); - if(upload.status == UPLOAD_FILE_START){ - String filename = upload.filename; - if(!filename.startsWith("/")) filename = "/"+filename; - DBG_OUTPUT_PORT.print("handleFileUpload Name: "); DBG_OUTPUT_PORT.println(filename); - fsUploadFile = SPIFFS.open(filename, "w"); - filename = String(); - } else if(upload.status == UPLOAD_FILE_WRITE){ - //DBG_OUTPUT_PORT.print("handleFileUpload Data: "); DBG_OUTPUT_PORT.println(upload.currentSize); - if(fsUploadFile) - fsUploadFile.write(upload.buf, upload.currentSize); - } else if(upload.status == UPLOAD_FILE_END){ - if(fsUploadFile) - fsUploadFile.close(); - DBG_OUTPUT_PORT.print("handleFileUpload Size: "); DBG_OUTPUT_PORT.println(upload.totalSize); - } -} - -void handleFileDelete(){ - if(server.args() == 0) return server.send(500, "text/plain", "BAD ARGS"); - String path = server.arg(0); - DBG_OUTPUT_PORT.println("handleFileDelete: " + path); - if(path == "/") - return server.send(500, "text/plain", "BAD PATH"); - if(!SPIFFS.exists(path)) - return server.send(404, "text/plain", "FileNotFound"); - SPIFFS.remove(path); - server.send(200, "text/plain", ""); - path = String(); -} - -void handleFileCreate(){ - if(server.args() == 0) - return server.send(500, "text/plain", "BAD ARGS"); - String path = server.arg(0); - DBG_OUTPUT_PORT.println("handleFileCreate: " + path); - if(path == "/") - return server.send(500, "text/plain", "BAD PATH"); - if(SPIFFS.exists(path)) - return server.send(500, "text/plain", "FILE EXISTS"); - File file = SPIFFS.open(path, "w"); - if(file) - file.close(); - else - return server.send(500, "text/plain", "CREATE FAILED"); - server.send(200, "text/plain", ""); - path = String(); -} - -void returnFail(String msg) { - server.send(500, "text/plain", msg + "\r\n"); -} - -#ifdef ESP8266 -void handleFileList() { - if(!server.hasArg("dir")) { - returnFail("BAD ARGS"); - return; - } - - String path = server.arg("dir"); - DBG_OUTPUT_PORT.println("handleFileList: " + path); - Dir dir = SPIFFS.openDir(path); - path = String(); - - String output = "["; - while(dir.next()){ - File entry = dir.openFile("r"); - if (output != "[") output += ','; - bool isDir = false; - output += "{\"type\":\""; - output += (isDir)?"dir":"file"; - output += "\",\"name\":\""; - output += String(entry.name()).substring(1); - output += "\"}"; - entry.close(); - } - - output += "]"; - server.send(200, "text/json", output); -} -#else -void handleFileList() { - if(!server.hasArg("dir")) { - returnFail("BAD ARGS"); - return; - } - String path = server.arg("dir"); - if(path != "/" && !SPIFFS.exists((char *)path.c_str())) { - returnFail("BAD PATH"); - return; - } - File dir = SPIFFS.open((char *)path.c_str()); - path = String(); - if(!dir.isDirectory()){ - dir.close(); - returnFail("NOT DIR"); - return; - } - dir.rewindDirectory(); - - String output = "["; - for (int cnt = 0; true; ++cnt) { - File entry = dir.openNextFile(); - if (!entry) - break; - - if (cnt > 0) - output += ','; - - output += "{\"type\":\""; - output += (entry.isDirectory()) ? "dir" : "file"; - output += "\",\"name\":\""; - // Ignore '/' prefix - output += entry.name()+1; - output += "\""; - output += "}"; - entry.close(); - } - output += "]"; - server.send(200, "text/json", output); - dir.close(); -} - -void listDir(fs::FS &fs, const char * dirname, uint8_t levels) { - DBG_OUTPUT_PORT.printf("Listing directory: %s\n", dirname); - - File root = fs.open(dirname); - if (!root) { - DBG_OUTPUT_PORT.println("Failed to open directory"); - return; - } - if (!root.isDirectory()) { - DBG_OUTPUT_PORT.println("Not a directory"); - return; - } - - File file = root.openNextFile(); - while (file) { - if (file.isDirectory()) { - DBG_OUTPUT_PORT.print(" DIR : "); - DBG_OUTPUT_PORT.println(file.name()); - if (levels) { - listDir(fs, file.name(), levels - 1); - } - } else { - DBG_OUTPUT_PORT.print(" FILE: "); - DBG_OUTPUT_PORT.print(file.name()); - DBG_OUTPUT_PORT.print(" SIZE: "); - DBG_OUTPUT_PORT.println(file.size()); - } - file = root.openNextFile(); - } -} -#endif - - -void setup(void){ - DBG_OUTPUT_PORT.begin(115200); - DBG_OUTPUT_PORT.print("\n"); - DBG_OUTPUT_PORT.setDebugOutput(true); - SPIFFS.begin(); - { -#ifdef ESP8266 - Dir dir = SPIFFS.openDir("/"); - while (dir.next()) { - String fileName = dir.fileName(); - size_t fileSize = dir.fileSize(); - DBG_OUTPUT_PORT.printf("FS File: %s, size: %s\n", fileName.c_str(), formatBytes(fileSize).c_str()); - } -#else - listDir(SPIFFS, "/", 0); -#endif - DBG_OUTPUT_PORT.printf("\n"); - } - - - //WIFI INIT - DBG_OUTPUT_PORT.printf("Connecting to %s\n", ssid); - if (String(WiFi.SSID()) != String(ssid)) { - WiFi.begin(ssid, password); - } - - while (WiFi.status() != WL_CONNECTED) { - delay(500); - DBG_OUTPUT_PORT.print("."); - } - DBG_OUTPUT_PORT.println(""); - DBG_OUTPUT_PORT.print("Connected! IP address: "); - DBG_OUTPUT_PORT.println(WiFi.localIP()); - - MDNS.begin(host); - DBG_OUTPUT_PORT.print("Open http://"); - DBG_OUTPUT_PORT.print(host); - DBG_OUTPUT_PORT.println(".local/edit to see the file browser"); - - - //SERVER INIT - //list directory - server.on("/list", HTTP_GET, handleFileList); - //load editor - server.on("/edit", HTTP_GET, [](){ - if(!handleFileRead("/edit.htm")) server.send(404, "text/plain", "FileNotFound"); - }); - //create file - server.on("/edit", HTTP_PUT, handleFileCreate); - //delete file - server.on("/edit", HTTP_DELETE, handleFileDelete); - //first callback is called after the request has ended with all parsed arguments - //second callback handles file uploads at that location - server.on("/edit", HTTP_POST, [](){ server.send(200, "text/plain", ""); }, handleFileUpload); - - //called when the url is not defined here - //use it to load content from SPIFFS - server.onNotFound([](){ - if(!handleFileRead(server.uri())) - server.send(404, "text/plain", "FileNotFound"); - }); - - //get heap status, analog input value and all GPIO statuses in one json call - server.on("/all", HTTP_GET, [](){ - String json = "{"; - json += "\"heap\":"+String(ESP.getFreeHeap()); - json += ", \"analog\":"+String(analogRead(A0)); -#ifdef ESP8266 - json += ", \"gpio\":"+String((uint32_t)(((GPI | GPO) & 0xFFFF) | ((GP16I & 0x01) << 16))); -#endif - json += "}"; - server.send(200, "text/json", json); - json = String(); - }); - server.begin(); - DBG_OUTPUT_PORT.println("HTTP server started"); - -} - -void loop(void){ - server.handleClient(); -} diff --git a/libraries/WebServer/examples/FSBrowser/data/edit.htm.gz b/libraries/WebServer/examples/FSBrowser/data/edit.htm.gz deleted file mode 100644 index 69ce414f..00000000 Binary files a/libraries/WebServer/examples/FSBrowser/data/edit.htm.gz and /dev/null differ diff --git a/libraries/WebServer/examples/FSBrowser/data/favicon.ico b/libraries/WebServer/examples/FSBrowser/data/favicon.ico deleted file mode 100644 index 71b25fe6..00000000 Binary files a/libraries/WebServer/examples/FSBrowser/data/favicon.ico and /dev/null differ diff --git a/libraries/WebServer/examples/FSBrowser/data/graphs.js.gz b/libraries/WebServer/examples/FSBrowser/data/graphs.js.gz deleted file mode 100644 index 72435445..00000000 Binary files a/libraries/WebServer/examples/FSBrowser/data/graphs.js.gz and /dev/null differ diff --git a/libraries/WebServer/examples/FSBrowser/data/index.htm b/libraries/WebServer/examples/FSBrowser/data/index.htm deleted file mode 100644 index 4e1dc7d9..00000000 --- a/libraries/WebServer/examples/FSBrowser/data/index.htm +++ /dev/null @@ -1,97 +0,0 @@ - - - - - - ESP Monitor - - - - -
- - - - -
-
-
-
- - \ No newline at end of file diff --git a/libraries/WebServer/examples/HelloServer/HelloServer.ino b/libraries/WebServer/examples/HelloServer/HelloServer.ino deleted file mode 100644 index f5390364..00000000 --- a/libraries/WebServer/examples/HelloServer/HelloServer.ino +++ /dev/null @@ -1,91 +0,0 @@ -#ifdef ESP8266 -#include -#include -#include -#include -ESP8266WebServer server(80); -#else -#include -#include -#include -#include -WebServer server(80); -#endif - -const char* ssid = "........"; -const char* password = "........"; - -#ifdef LED_BUILTIN -const int led = LED_BUILTIN; -#else -const int led = 13; -#endif - -void handleRoot() { - digitalWrite(led, 1); -#ifdef ESP8266 - server.send(200, "text/plain", "hello from esp8266!"); -#else - server.send(200, "text/plain", "hello from esp32!"); -#endif - digitalWrite(led, 0); -} - -void handleNotFound(){ - digitalWrite(led, 1); - String message = "File Not Found\n\n"; - message += "URI: "; - message += server.uri(); - message += "\nMethod: "; - message += (server.method() == HTTP_GET)?"GET":"POST"; - message += "\nArguments: "; - message += server.args(); - message += "\n"; - for (uint8_t i=0; i -#include -#include -#include -ESP8266WebServer server(80); -#else -#include -#include -#include -#include -WebServer server(80); -#endif - -const char* ssid = "........"; -const char* password = "........"; - -const char* www_username = "admin"; -const char* www_password = "esp8266esp32"; - -void setup() { - Serial.begin(115200); - WiFi.mode(WIFI_STA); - WiFi.begin(ssid, password); - if(WiFi.waitForConnectResult() != WL_CONNECTED) { - Serial.println("WiFi Connect Failed! Rebooting..."); - delay(1000); - ESP.restart(); - } - ArduinoOTA.begin(); - - server.on("/", [](){ - if(!server.authenticate(www_username, www_password)) - return server.requestAuthentication(); - server.send(200, "text/plain", "Login OK"); - }); - server.begin(); - - Serial.print("Open http://"); - Serial.print(WiFi.localIP()); - Serial.println("/ in your browser to see it working"); -} - -void loop() { - ArduinoOTA.handle(); - server.handleClient(); -} diff --git a/libraries/WebServer/examples/SDWebServer/SDWebServer.ino b/libraries/WebServer/examples/SDWebServer/SDWebServer.ino deleted file mode 100644 index 4234a880..00000000 --- a/libraries/WebServer/examples/SDWebServer/SDWebServer.ino +++ /dev/null @@ -1,290 +0,0 @@ -/* - SDWebServer - Example WebServer with SD Card backend for esp8266/esp32 - - Copyright (c) 2015 Hristo Gochkov. All rights reserved. - This file is part of the ESP8266/ESP32 WebServer library for Arduino environment. - - 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 - - Have a FAT Formatted SD Card connected to the SPI port of the ESP8266 - The web root is the SD Card root folder - File extensions with more than 3 charecters are not supported by the SD Library - File Names longer than 8 charecters will be truncated by the SD library, so keep filenames shorter - index.htm is the default index (works on subfolders as well) - - upload the contents of SdRoot to the root of the SDcard and access the editor by going to http://esp8266sd.local/edit - -*/ -#ifdef ESP8266 -#include -#include -#include -#include -#include -#include -ESP8266WebServer server(80); -#else -#include -#include -#include -#include -#include -#include -WebServer server(80); -#endif - -#define DBG_OUTPUT_PORT Serial - -const char* ssid = "**********"; -const char* password = "**********"; -const char* host = "esp8266sd"; - -static bool hasSD = false; -File uploadFile; - - -void returnOK() { - server.send(200, "text/plain", ""); -} - -void returnFail(String msg) { - server.send(500, "text/plain", msg + "\r\n"); -} - -bool loadFromSdCard(String path){ - String dataType = "text/plain"; - if(path.endsWith("/")) path += "index.htm"; - - if(path.endsWith(".src")) path = path.substring(0, path.lastIndexOf(".")); - else if(path.endsWith(".htm")) dataType = "text/html"; - else if(path.endsWith(".css")) dataType = "text/css"; - else if(path.endsWith(".js")) dataType = "application/javascript"; - else if(path.endsWith(".png")) dataType = "image/png"; - else if(path.endsWith(".gif")) dataType = "image/gif"; - else if(path.endsWith(".jpg")) dataType = "image/jpeg"; - else if(path.endsWith(".ico")) dataType = "image/x-icon"; - else if(path.endsWith(".xml")) dataType = "text/xml"; - else if(path.endsWith(".pdf")) dataType = "application/pdf"; - else if(path.endsWith(".zip")) dataType = "application/zip"; - - File dataFile = SD.open(path.c_str()); - if(dataFile.isDirectory()){ - path += "/index.htm"; - dataType = "text/html"; - dataFile = SD.open(path.c_str()); - } - - if (!dataFile) - return false; - - if (server.hasArg("download")) dataType = "application/octet-stream"; - - if (server.streamFile(dataFile, dataType) != dataFile.size()) { - DBG_OUTPUT_PORT.println("Sent less data than expected!"); - } - - dataFile.close(); - return true; -} - -void handleFileUpload(){ - if(server.uri() != "/edit") return; - HTTPUpload& upload = server.upload(); - if(upload.status == UPLOAD_FILE_START){ - if(SD.exists((char *)upload.filename.c_str())) SD.remove((char *)upload.filename.c_str()); - uploadFile = SD.open(upload.filename.c_str(), FILE_WRITE); - DBG_OUTPUT_PORT.print("Upload: START, filename: "); DBG_OUTPUT_PORT.println(upload.filename); - } else if(upload.status == UPLOAD_FILE_WRITE){ - if(uploadFile) uploadFile.write(upload.buf, upload.currentSize); - DBG_OUTPUT_PORT.print("Upload: WRITE, Bytes: "); DBG_OUTPUT_PORT.println(upload.currentSize); - } else if(upload.status == UPLOAD_FILE_END){ - if(uploadFile) uploadFile.close(); - DBG_OUTPUT_PORT.print("Upload: END, Size: "); DBG_OUTPUT_PORT.println(upload.totalSize); - } -} - -void deleteRecursive(String path){ - File file = SD.open((char *)path.c_str()); - if(!file.isDirectory()){ - file.close(); - SD.remove((char *)path.c_str()); - return; - } - - file.rewindDirectory(); - while(true) { - File entry = file.openNextFile(); - if (!entry) break; - String entryPath = path + "/" +entry.name(); - if(entry.isDirectory()){ - entry.close(); - deleteRecursive(entryPath); - } else { - entry.close(); - SD.remove((char *)entryPath.c_str()); - } - yield(); - } - - SD.rmdir((char *)path.c_str()); - file.close(); -} - -void handleDelete(){ - if(server.args() == 0) return returnFail("BAD ARGS"); - String path = server.arg(0); - if(path == "/" || !SD.exists((char *)path.c_str())) { - returnFail("BAD PATH"); - return; - } - deleteRecursive(path); - returnOK(); -} - -void handleCreate(){ - if(server.args() == 0) return returnFail("BAD ARGS"); - String path = server.arg(0); - if(path == "/" || SD.exists((char *)path.c_str())) { - returnFail("BAD PATH"); - return; - } - - if(path.indexOf('.') > 0){ - File file = SD.open((char *)path.c_str(), FILE_WRITE); - if(file){ -#ifdef ESP8266 - file.write((const char *)0); -#else - // TODO Create file with 0 bytes??? - file.write(NULL, 0); -#endif - file.close(); - } - } else { - SD.mkdir((char *)path.c_str()); - } - returnOK(); -} - -void printDirectory() { - if(!server.hasArg("dir")) return returnFail("BAD ARGS"); - String path = server.arg("dir"); - if(path != "/" && !SD.exists((char *)path.c_str())) return returnFail("BAD PATH"); - File dir = SD.open((char *)path.c_str()); - path = String(); - if(!dir.isDirectory()){ - dir.close(); - return returnFail("NOT DIR"); - } - dir.rewindDirectory(); - server.setContentLength(CONTENT_LENGTH_UNKNOWN); - server.send(200, "text/json", ""); - WiFiClient client = server.client(); - - server.sendContent("["); - for (int cnt = 0; true; ++cnt) { - File entry = dir.openNextFile(); - if (!entry) - break; - - String output; - if (cnt > 0) - output = ','; - - output += "{\"type\":\""; - output += (entry.isDirectory()) ? "dir" : "file"; - output += "\",\"name\":\""; -#ifdef ESP8266 - output += entry.name(); -#else - // Ignore '/' prefix - output += entry.name()+1; -#endif - output += "\""; - output += "}"; - server.sendContent(output); - entry.close(); - } - server.sendContent("]"); - // Send zero length chunk to terminate the HTTP body - server.sendContent(""); - dir.close(); -} - -void handleNotFound(){ - if(hasSD && loadFromSdCard(server.uri())) return; - String message = "SDCARD Not Detected\n\n"; - message += "URI: "; - message += server.uri(); - message += "\nMethod: "; - message += (server.method() == HTTP_GET)?"GET":"POST"; - message += "\nArguments: "; - message += server.args(); - message += "\n"; - for (uint8_t i=0; i - - - SD Editor - - - - - -
-
-
- - - - diff --git a/libraries/WebServer/examples/SDWebServer/SdRoot/index.htm b/libraries/WebServer/examples/SDWebServer/SdRoot/index.htm deleted file mode 100644 index 55fe5a66..00000000 --- a/libraries/WebServer/examples/SDWebServer/SdRoot/index.htm +++ /dev/null @@ -1,22 +0,0 @@ - - - - - ESP Index - - - - -

ESP8266 Pin Functions

- - - diff --git a/libraries/WebServer/examples/SDWebServer/SdRoot/pins.png b/libraries/WebServer/examples/SDWebServer/SdRoot/pins.png deleted file mode 100644 index ac7fc0f9..00000000 Binary files a/libraries/WebServer/examples/SDWebServer/SdRoot/pins.png and /dev/null differ diff --git a/libraries/WebServer/examples/SimpleAuthentification/SimpleAuthentification.ino b/libraries/WebServer/examples/SimpleAuthentification/SimpleAuthentification.ino deleted file mode 100644 index bf5310e6..00000000 --- a/libraries/WebServer/examples/SimpleAuthentification/SimpleAuthentification.ino +++ /dev/null @@ -1,137 +0,0 @@ -#ifdef ESP8266 -#include -#include -#include -ESP8266WebServer server(80); -#else -#include -#include -#include -WebServer server(80); -#endif - -const char* ssid = "........"; -const char* password = "........"; - -//Check if header is present and correct -bool is_authentified(){ - Serial.println("Enter is_authentified"); - if (server.hasHeader("Cookie")){ - Serial.print("Found cookie: "); - String cookie = server.header("Cookie"); - Serial.println(cookie); - if (cookie.indexOf("ESPSESSIONID=1") != -1) { - Serial.println("Authentification Successful"); - return true; - } - } - Serial.println("Authentification Failed"); - return false; -} - -//login page, also called for disconnect -void handleLogin(){ - String msg; - if (server.hasHeader("Cookie")){ - Serial.print("Found cookie: "); - String cookie = server.header("Cookie"); - Serial.println(cookie); - } - if (server.hasArg("DISCONNECT")){ - Serial.println("Disconnection"); - server.sendHeader("Location","/login"); - server.sendHeader("Cache-Control","no-cache"); - server.sendHeader("Set-Cookie","ESPSESSIONID=0"); - server.send(301); - return; - } - if (server.hasArg("USERNAME") && server.hasArg("PASSWORD")){ - if (server.arg("USERNAME") == "admin" && server.arg("PASSWORD") == "admin" ){ - server.sendHeader("Location","/"); - server.sendHeader("Cache-Control","no-cache"); - server.sendHeader("Set-Cookie","ESPSESSIONID=1"); - server.send(301); - Serial.println("Log in Successful"); - return; - } - msg = "Wrong username/password! try again."; - Serial.println("Log in Failed"); - } - String content = "
To log in, please use : admin/admin
"; - content += "User:
"; - content += "Password:
"; - content += "
" + msg + "
"; - content += "You also can go here"; - server.send(200, "text/html", content); -} - -//root page can be accessed only if authentification is ok -void handleRoot(){ - Serial.println("Enter handleRoot"); - String header; - if (!is_authentified()){ - server.sendHeader("Location","/login"); - server.sendHeader("Cache-Control","no-cache"); - server.send(301); - return; - } - String content = "

hello, you successfully connected to esp8266/esp32!


"; - if (server.hasHeader("User-Agent")){ - content += "the user agent used is : " + server.header("User-Agent") + "

"; - } - content += "You can access this page until you disconnect"; - server.send(200, "text/html", content); -} - -//no need authentification -void handleNotFound(){ - String message = "File Not Found\n\n"; - message += "URI: "; - message += server.uri(); - message += "\nMethod: "; - message += (server.method() == HTTP_GET)?"GET":"POST"; - message += "\nArguments: "; - message += server.args(); - message += "\n"; - for (uint8_t i=0; i -#include -#include -#include -ESP8266WebServer server(80); -const char* host = "esp8266-webupdate"; -#else -#include -#include -#include -#include -WebServer server(80); -const char* host = "esp32-webupdate"; -#endif - -const char* ssid = "........"; -const char* password = "........"; - -const char* serverIndex = "
"; - -void setup(void){ - Serial.begin(115200); - Serial.println(); - Serial.println("Booting Sketch..."); - WiFi.mode(WIFI_AP_STA); - WiFi.begin(ssid, password); - if(WiFi.waitForConnectResult() == WL_CONNECTED){ - MDNS.begin(host); - server.on("/", HTTP_GET, [](){ - server.sendHeader("Connection", "close"); - server.send(200, "text/html", serverIndex); - }); - server.on("/update", HTTP_POST, [](){ - server.sendHeader("Connection", "close"); - server.send(200, "text/plain", (Update.hasError())?"FAIL":"OK"); - ESP.restart(); - },[](){ - HTTPUpload& upload = server.upload(); - if(upload.status == UPLOAD_FILE_START){ - Serial.setDebugOutput(true); - WiFiUDP::stopAll(); - Serial.printf("Update: %s\n", upload.filename.c_str()); - uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000; - if(!Update.begin(maxSketchSpace)){//start with max available size - Update.printError(Serial); - } - } else if(upload.status == UPLOAD_FILE_WRITE){ - if(Update.write(upload.buf, upload.currentSize) != upload.currentSize){ - Update.printError(Serial); - } - } else if(upload.status == UPLOAD_FILE_END){ - if(Update.end(true)){ //true to set the size to the current progress - Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize); - } else { - Update.printError(Serial); - } - Serial.setDebugOutput(false); - } - yield(); - }); - server.begin(); - MDNS.addService("http", "tcp", 80); - - Serial.printf("Ready! Open http://%s.local in your browser\n", host); - } else { - Serial.println("WiFi Failed"); - } -} - -void loop(void){ - server.handleClient(); - delay(1); -} diff --git a/libraries/WebServer/keywords.txt b/libraries/WebServer/keywords.txt deleted file mode 100644 index 22e3d74e..00000000 --- a/libraries/WebServer/keywords.txt +++ /dev/null @@ -1,36 +0,0 @@ -####################################### -# Syntax Coloring Map For Ultrasound -####################################### - -####################################### -# Datatypes (KEYWORD1) -####################################### - -ESP8266WebServer KEYWORD1 -HTTPMethod KEYWORD1 - -####################################### -# Methods and Functions (KEYWORD2) -####################################### - -begin KEYWORD2 -handleClient KEYWORD2 -on KEYWORD2 -addHandler KEYWORD2 -uri KEYWORD2 -method KEYWORD2 -client KEYWORD2 -send KEYWORD2 -arg KEYWORD2 -argName KEYWORD2 -args KEYWORD2 -hasArg KEYWORD2 -onNotFound KEYWORD2 - -####################################### -# Constants (LITERAL1) -####################################### - -HTTP_GET LITERAL1 -HTTP_POST LITERAL1 -HTTP_ANY LITERAL1 diff --git a/libraries/WebServer/library.properties b/libraries/WebServer/library.properties deleted file mode 100644 index 1e9c0707..00000000 --- a/libraries/WebServer/library.properties +++ /dev/null @@ -1,9 +0,0 @@ -name=WebServer -version=1.0 -author=Ivan Grokhotkov -maintainer=Ivan Grokhtkov -sentence=Simple web server library -paragraph=The library supports HTTP GET and POST requests, provides argument parsing, handles one client at a time. -category=Communication -url= -architectures=esp8266,esp32 diff --git a/libraries/WebServer/src/ESP8266WebServer.h b/libraries/WebServer/src/ESP8266WebServer.h deleted file mode 100644 index d4330064..00000000 --- a/libraries/WebServer/src/ESP8266WebServer.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - ESP8266WebServer.h - Dead simple web-server. - Supports only one simultaneous client, knows how to handle GET and POST. - - Copyright (c) 2014 Ivan Grokhotkov. 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 - Modified 8 May 2015 by Hristo Gochkov (proper post and file upload handling) -*/ - - -#ifndef ESP8266WEBSERVER_H -#define ESP8266WEBSERVER_H - -#include - -#endif //ESP8266WEBSERVER_H diff --git a/libraries/WebServer/src/Parsing.cpp b/libraries/WebServer/src/Parsing.cpp deleted file mode 100644 index 542e41be..00000000 --- a/libraries/WebServer/src/Parsing.cpp +++ /dev/null @@ -1,610 +0,0 @@ -/* - Parsing.cpp - HTTP request parsing. - - Copyright (c) 2015 Ivan Grokhotkov. 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 - Modified 8 May 2015 by Hristo Gochkov (proper post and file upload handling) -*/ - -#include -#include "WiFiServer.h" -#include "WiFiClient.h" -#include "WebServer.h" - -//#define DEBUG_ESP_HTTP_SERVER -#ifdef DEBUG_ESP_PORT -#define DEBUG_OUTPUT DEBUG_ESP_PORT -#else -#define DEBUG_OUTPUT Serial -#endif - -static char* readBytesWithTimeout(WiFiClient& client, size_t maxLength, size_t& dataLength, int timeout_ms) -{ - char *buf = nullptr; - dataLength = 0; - while (dataLength < maxLength) { - int tries = timeout_ms; - size_t newLength; - while (!(newLength = client.available()) && tries--) delay(1); - if (!newLength) { - break; - } - if (!buf) { - buf = (char *) malloc(newLength + 1); - if (!buf) { - return nullptr; - } - } - else { - char* newBuf = (char *) realloc(buf, dataLength + newLength + 1); - if (!newBuf) { - free(buf); - return nullptr; - } - buf = newBuf; - } - client.readBytes(buf + dataLength, newLength); - dataLength += newLength; - buf[dataLength] = '\0'; - } - return buf; -} - -bool WebServer::_parseRequest(WiFiClient& client) { - // Read the first line of HTTP request - String req = client.readStringUntil('\r'); - client.readStringUntil('\n'); - //reset header value - for (int i = 0; i < _headerKeysCount; ++i) { - _currentHeaders[i].value =String(); - } - - // First line of HTTP request looks like "GET /path HTTP/1.1" - // Retrieve the "/path" part by finding the spaces - int addr_start = req.indexOf(' '); - int addr_end = req.indexOf(' ', addr_start + 1); - if (addr_start == -1 || addr_end == -1) { -#ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.print("Invalid request: "); - DEBUG_OUTPUT.println(req); -#endif - return false; - } - - String methodStr = req.substring(0, addr_start); - String url = req.substring(addr_start + 1, addr_end); - String versionEnd = req.substring(addr_end + 8); - _currentVersion = atoi(versionEnd.c_str()); - String searchStr = ""; - int hasSearch = url.indexOf('?'); - if (hasSearch != -1){ - searchStr = url.substring(hasSearch + 1); - url = url.substring(0, hasSearch); - } - _currentUri = url; - _chunked = false; - - HTTPMethod method = HTTP_GET; - if (methodStr == "POST") { - method = HTTP_POST; - } else if (methodStr == "DELETE") { - method = HTTP_DELETE; - } else if (methodStr == "OPTIONS") { - method = HTTP_OPTIONS; - } else if (methodStr == "PUT") { - method = HTTP_PUT; - } else if (methodStr == "PATCH") { - method = HTTP_PATCH; - } - _currentMethod = method; - -#ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.print("method: "); - DEBUG_OUTPUT.print(methodStr); - DEBUG_OUTPUT.print(" url: "); - DEBUG_OUTPUT.print(url); - DEBUG_OUTPUT.print(" search: "); - DEBUG_OUTPUT.println(searchStr); -#endif - - //attach handler - RequestHandler* handler; - for (handler = _firstHandler; handler; handler = handler->next()) { - if (handler->canHandle(_currentMethod, _currentUri)) - break; - } - _currentHandler = handler; - - String formData; - // below is needed only when POST type request - if (method == HTTP_POST || method == HTTP_PUT || method == HTTP_PATCH || method == HTTP_DELETE){ - String boundaryStr; - String headerName; - String headerValue; - bool isForm = false; - bool isEncoded = false; - uint32_t contentLength = 0; - //parse headers - while(1){ - req = client.readStringUntil('\r'); - client.readStringUntil('\n'); - if (req == "") break;//no moar headers - int headerDiv = req.indexOf(':'); - if (headerDiv == -1){ - break; - } - headerName = req.substring(0, headerDiv); - headerValue = req.substring(headerDiv + 1); - headerValue.trim(); - _collectHeader(headerName.c_str(),headerValue.c_str()); - - #ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.print("headerName: "); - DEBUG_OUTPUT.println(headerName); - DEBUG_OUTPUT.print("headerValue: "); - DEBUG_OUTPUT.println(headerValue); - #endif - - if (headerName.equalsIgnoreCase("Content-Type")){ - if (headerValue.startsWith("text/plain")){ - isForm = false; - } else if (headerValue.startsWith("application/x-www-form-urlencoded")){ - isForm = false; - isEncoded = true; - } else if (headerValue.startsWith("multipart/")){ - boundaryStr = headerValue.substring(headerValue.indexOf('=')+1); - isForm = true; - } - } else if (headerName.equalsIgnoreCase("Content-Length")){ - contentLength = headerValue.toInt(); - } else if (headerName.equalsIgnoreCase("Host")){ - _hostHeader = headerValue; - } - } - - if (!isForm){ - size_t plainLength; - char* plainBuf = readBytesWithTimeout(client, contentLength, plainLength, HTTP_MAX_POST_WAIT); - if (plainLength < contentLength) { - free(plainBuf); - return false; - } - if (contentLength > 0) { - if (searchStr != "") searchStr += '&'; - if(isEncoded){ - //url encoded form - String decoded = urlDecode(plainBuf); - size_t decodedLen = decoded.length(); - memcpy(plainBuf, decoded.c_str(), decodedLen); - plainBuf[decodedLen] = 0; - searchStr += plainBuf; - } - _parseArguments(searchStr); - if(!isEncoded){ - //plain post json or other data - RequestArgument& arg = _currentArgs[_currentArgCount++]; - arg.key = "plain"; - arg.value = String(plainBuf); - } - - #ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.print("Plain: "); - DEBUG_OUTPUT.println(plainBuf); - #endif - free(plainBuf); - } else { - // No content - but we can still have arguments in the URL. - _parseArguments(searchStr); - } - } - - if (isForm){ - _parseArguments(searchStr); - if (!_parseForm(client, boundaryStr, contentLength)) { - return false; - } - } - } else { - String headerName; - String headerValue; - //parse headers - while(1){ - req = client.readStringUntil('\r'); - client.readStringUntil('\n'); - if (req == "") break;//no moar headers - int headerDiv = req.indexOf(':'); - if (headerDiv == -1){ - break; - } - headerName = req.substring(0, headerDiv); - headerValue = req.substring(headerDiv + 2); - _collectHeader(headerName.c_str(),headerValue.c_str()); - - #ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.print("headerName: "); - DEBUG_OUTPUT.println(headerName); - DEBUG_OUTPUT.print("headerValue: "); - DEBUG_OUTPUT.println(headerValue); - #endif - - if (headerName.equalsIgnoreCase("Host")){ - _hostHeader = headerValue; - } - } - _parseArguments(searchStr); - } - client.flush(); - -#ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.print("Request: "); - DEBUG_OUTPUT.println(url); - DEBUG_OUTPUT.print(" Arguments: "); - DEBUG_OUTPUT.println(searchStr); -#endif - - return true; -} - -bool WebServer::_collectHeader(const char* headerName, const char* headerValue) { - for (int i = 0; i < _headerKeysCount; i++) { - if (_currentHeaders[i].key.equalsIgnoreCase(headerName)) { - _currentHeaders[i].value=headerValue; - return true; - } - } - return false; -} - -void WebServer::_parseArguments(String data) { -#ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.print("args: "); - DEBUG_OUTPUT.println(data); -#endif - if (_currentArgs) - delete[] _currentArgs; - _currentArgs = 0; - if (data.length() == 0) { - _currentArgCount = 0; - _currentArgs = new RequestArgument[1]; - return; - } - _currentArgCount = 1; - - for (int i = 0; i < (int)data.length(); ) { - i = data.indexOf('&', i); - if (i == -1) - break; - ++i; - ++_currentArgCount; - } -#ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.print("args count: "); - DEBUG_OUTPUT.println(_currentArgCount); -#endif - - _currentArgs = new RequestArgument[_currentArgCount+1]; - int pos = 0; - int iarg; - for (iarg = 0; iarg < _currentArgCount;) { - int equal_sign_index = data.indexOf('=', pos); - int next_arg_index = data.indexOf('&', pos); -#ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.print("pos "); - DEBUG_OUTPUT.print(pos); - DEBUG_OUTPUT.print("=@ "); - DEBUG_OUTPUT.print(equal_sign_index); - DEBUG_OUTPUT.print(" &@ "); - DEBUG_OUTPUT.println(next_arg_index); -#endif - if ((equal_sign_index == -1) || ((equal_sign_index > next_arg_index) && (next_arg_index != -1))) { -#ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.print("arg missing value: "); - DEBUG_OUTPUT.println(iarg); -#endif - if (next_arg_index == -1) - break; - pos = next_arg_index + 1; - continue; - } - RequestArgument& arg = _currentArgs[iarg]; - arg.key = data.substring(pos, equal_sign_index); - arg.value = urlDecode(data.substring(equal_sign_index + 1, next_arg_index)); -#ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.print("arg "); - DEBUG_OUTPUT.print(iarg); - DEBUG_OUTPUT.print(" key: "); - DEBUG_OUTPUT.print(arg.key); - DEBUG_OUTPUT.print(" value: "); - DEBUG_OUTPUT.println(arg.value); -#endif - ++iarg; - if (next_arg_index == -1) - break; - pos = next_arg_index + 1; - } - _currentArgCount = iarg; -#ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.print("args count: "); - DEBUG_OUTPUT.println(_currentArgCount); -#endif - -} - -void WebServer::_uploadWriteByte(uint8_t b){ - if (_currentUpload.currentSize == HTTP_UPLOAD_BUFLEN){ - if(_currentHandler && _currentHandler->canUpload(_currentUri)) - _currentHandler->upload(*this, _currentUri, _currentUpload); - _currentUpload.totalSize += _currentUpload.currentSize; - _currentUpload.currentSize = 0; - } - _currentUpload.buf[_currentUpload.currentSize++] = b; -} - -uint8_t WebServer::_uploadReadByte(WiFiClient& client){ - int res = client.read(); - if(res == -1){ - while(!client.available() && client.connected()) - yield(); - res = client.read(); - } - return (uint8_t)res; -} - -bool WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t len){ - (void) len; -#ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.print("Parse Form: Boundary: "); - DEBUG_OUTPUT.print(boundary); - DEBUG_OUTPUT.print(" Length: "); - DEBUG_OUTPUT.println(len); -#endif - String line; - int retry = 0; - do { - line = client.readStringUntil('\r'); - ++retry; - } while (line.length() == 0 && retry < 3); - - client.readStringUntil('\n'); - //start reading the form - if (line == ("--"+boundary)){ - RequestArgument* postArgs = new RequestArgument[32]; - int postArgsLen = 0; - while(1){ - String argName; - String argValue; - String argType; - String argFilename; - bool argIsFile = false; - - line = client.readStringUntil('\r'); - client.readStringUntil('\n'); - if (line.length() > 19 && line.substring(0, 19).equalsIgnoreCase("Content-Disposition")){ - int nameStart = line.indexOf('='); - if (nameStart != -1){ - argName = line.substring(nameStart+2); - nameStart = argName.indexOf('='); - if (nameStart == -1){ - argName = argName.substring(0, argName.length() - 1); - } else { - argFilename = argName.substring(nameStart+2, argName.length() - 1); - argName = argName.substring(0, argName.indexOf('"')); - argIsFile = true; -#ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.print("PostArg FileName: "); - DEBUG_OUTPUT.println(argFilename); -#endif - //use GET to set the filename if uploading using blob - if (argFilename == "blob" && hasArg("filename")) argFilename = arg("filename"); - } -#ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.print("PostArg Name: "); - DEBUG_OUTPUT.println(argName); -#endif - argType = "text/plain"; - line = client.readStringUntil('\r'); - client.readStringUntil('\n'); - if (line.length() > 12 && line.substring(0, 12).equalsIgnoreCase("Content-Type")){ - argType = line.substring(line.indexOf(':')+2); - //skip next line - client.readStringUntil('\r'); - client.readStringUntil('\n'); - } -#ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.print("PostArg Type: "); - DEBUG_OUTPUT.println(argType); -#endif - if (!argIsFile){ - while(1){ - line = client.readStringUntil('\r'); - client.readStringUntil('\n'); - if (line.startsWith("--"+boundary)) break; - if (argValue.length() > 0) argValue += "\n"; - argValue += line; - } -#ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.print("PostArg Value: "); - DEBUG_OUTPUT.println(argValue); - DEBUG_OUTPUT.println(); -#endif - - RequestArgument& arg = postArgs[postArgsLen++]; - arg.key = argName; - arg.value = argValue; - - if (line == ("--"+boundary+"--")){ -#ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.println("Done Parsing POST"); -#endif - break; - } - } else { - _currentUpload.status = UPLOAD_FILE_START; - _currentUpload.name = argName; - _currentUpload.filename = argFilename; - _currentUpload.type = argType; - _currentUpload.totalSize = 0; - _currentUpload.currentSize = 0; -#ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.print("Start File: "); - DEBUG_OUTPUT.print(_currentUpload.filename); - DEBUG_OUTPUT.print(" Type: "); - DEBUG_OUTPUT.println(_currentUpload.type); -#endif - if(_currentHandler && _currentHandler->canUpload(_currentUri)) - _currentHandler->upload(*this, _currentUri, _currentUpload); - _currentUpload.status = UPLOAD_FILE_WRITE; - uint8_t argByte = _uploadReadByte(client); -readfile: - while(argByte != 0x0D){ - if (!client.connected()) return _parseFormUploadAborted(); - _uploadWriteByte(argByte); - argByte = _uploadReadByte(client); - } - - argByte = _uploadReadByte(client); - if (!client.connected()) return _parseFormUploadAborted(); - if (argByte == 0x0A){ - argByte = _uploadReadByte(client); - if (!client.connected()) return _parseFormUploadAborted(); - if ((char)argByte != '-'){ - //continue reading the file - _uploadWriteByte(0x0D); - _uploadWriteByte(0x0A); - goto readfile; - } else { - argByte = _uploadReadByte(client); - if (!client.connected()) return _parseFormUploadAborted(); - if ((char)argByte != '-'){ - //continue reading the file - _uploadWriteByte(0x0D); - _uploadWriteByte(0x0A); - _uploadWriteByte((uint8_t)('-')); - goto readfile; - } - } - - uint8_t endBuf[boundary.length()]; - client.readBytes(endBuf, boundary.length()); - - if (strstr((const char*)endBuf, boundary.c_str()) != NULL){ - if(_currentHandler && _currentHandler->canUpload(_currentUri)) - _currentHandler->upload(*this, _currentUri, _currentUpload); - _currentUpload.totalSize += _currentUpload.currentSize; - _currentUpload.status = UPLOAD_FILE_END; - if(_currentHandler && _currentHandler->canUpload(_currentUri)) - _currentHandler->upload(*this, _currentUri, _currentUpload); -#ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.print("End File: "); - DEBUG_OUTPUT.print(_currentUpload.filename); - DEBUG_OUTPUT.print(" Type: "); - DEBUG_OUTPUT.print(_currentUpload.type); - DEBUG_OUTPUT.print(" Size: "); - DEBUG_OUTPUT.println(_currentUpload.totalSize); -#endif - line = client.readStringUntil(0x0D); - client.readStringUntil(0x0A); - if (line == "--"){ -#ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.println("Done Parsing POST"); -#endif - break; - } - continue; - } else { - _uploadWriteByte(0x0D); - _uploadWriteByte(0x0A); - _uploadWriteByte((uint8_t)('-')); - _uploadWriteByte((uint8_t)('-')); - uint32_t i = 0; - while(i < boundary.length()){ - _uploadWriteByte(endBuf[i++]); - } - argByte = _uploadReadByte(client); - goto readfile; - } - } else { - _uploadWriteByte(0x0D); - goto readfile; - } - break; - } - } - } - } - - int iarg; - int totalArgs = ((32 - postArgsLen) < _currentArgCount)?(32 - postArgsLen):_currentArgCount; - for (iarg = 0; iarg < totalArgs; iarg++){ - RequestArgument& arg = postArgs[postArgsLen++]; - arg.key = _currentArgs[iarg].key; - arg.value = _currentArgs[iarg].value; - } - if (_currentArgs) delete[] _currentArgs; - _currentArgs = new RequestArgument[postArgsLen]; - for (iarg = 0; iarg < postArgsLen; iarg++){ - RequestArgument& arg = _currentArgs[iarg]; - arg.key = postArgs[iarg].key; - arg.value = postArgs[iarg].value; - } - _currentArgCount = iarg; - if (postArgs) delete[] postArgs; - return true; - } -#ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.print("Error: line: "); - DEBUG_OUTPUT.println(line); -#endif - return false; -} - -String WebServer::urlDecode(const String& text) -{ - String decoded = ""; - char temp[] = "0x00"; - unsigned int len = text.length(); - unsigned int i = 0; - while (i < len) - { - char decodedChar; - char encodedChar = text.charAt(i++); - if ((encodedChar == '%') && (i + 1 < len)) - { - temp[2] = text.charAt(i++); - temp[3] = text.charAt(i++); - - decodedChar = strtol(temp, NULL, 16); - } - else { - if (encodedChar == '+') - { - decodedChar = ' '; - } - else { - decodedChar = encodedChar; // normal ascii char - } - } - decoded += decodedChar; - } - return decoded; -} - -bool WebServer::_parseFormUploadAborted(){ - _currentUpload.status = UPLOAD_FILE_ABORTED; - if(_currentHandler && _currentHandler->canUpload(_currentUri)) - _currentHandler->upload(*this, _currentUri, _currentUpload); - return false; -} diff --git a/libraries/WebServer/src/WebServer.cpp b/libraries/WebServer/src/WebServer.cpp deleted file mode 100644 index 951c6dce..00000000 --- a/libraries/WebServer/src/WebServer.cpp +++ /dev/null @@ -1,530 +0,0 @@ -/* - WebServer.cpp - Dead simple web-server. - Supports only one simultaneous client, knows how to handle GET and POST. - - Copyright (c) 2014 Ivan Grokhotkov. 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 - Modified 8 May 2015 by Hristo Gochkov (proper post and file upload handling) -*/ - - -#include -#include -#include "WiFiServer.h" -#include "WiFiClient.h" -#include "WebServer.h" -#include "FS.h" -#include "detail/RequestHandlersImpl.h" - -//#define DEBUG_ESP_HTTP_SERVER -#ifdef DEBUG_ESP_PORT -#define DEBUG_OUTPUT DEBUG_ESP_PORT -#else -#define DEBUG_OUTPUT Serial -#endif - -const char * AUTHORIZATION_HEADER = "Authorization"; - -WebServer::WebServer(IPAddress addr, int port) -: _server(addr, port) -, _currentMethod(HTTP_ANY) -, _currentVersion(0) -, _currentStatus(HC_NONE) -, _statusChange(0) -, _currentHandler(0) -, _firstHandler(0) -, _lastHandler(0) -, _currentArgCount(0) -, _currentArgs(0) -, _headerKeysCount(0) -, _currentHeaders(0) -, _contentLength(0) -, _chunked(false) -{ -} - -WebServer::WebServer(int port) -: _server(port) -, _currentMethod(HTTP_ANY) -, _currentVersion(0) -, _currentStatus(HC_NONE) -, _statusChange(0) -, _currentHandler(0) -, _firstHandler(0) -, _lastHandler(0) -, _currentArgCount(0) -, _currentArgs(0) -, _headerKeysCount(0) -, _currentHeaders(0) -, _contentLength(0) -, _chunked(false) -{ -} - -WebServer::~WebServer() { - if (_currentHeaders) - delete[]_currentHeaders; - _headerKeysCount = 0; - RequestHandler* handler = _firstHandler; - while (handler) { - RequestHandler* next = handler->next(); - delete handler; - handler = next; - } - close(); -} - -void WebServer::begin() { - _currentStatus = HC_NONE; - _server.begin(); - if(!_headerKeysCount) - collectHeaders(0, 0); -} - -bool WebServer::authenticate(const char * username, const char * password){ - if(hasHeader(AUTHORIZATION_HEADER)){ - String authReq = header(AUTHORIZATION_HEADER); - if(authReq.startsWith("Basic")){ - authReq = authReq.substring(6); - authReq.trim(); - char toencodeLen = strlen(username)+strlen(password)+1; - char *toencode = new char[toencodeLen + 1]; - if(toencode == NULL){ - authReq = String(); - return false; - } - char *encoded = new char[base64_encode_expected_len(toencodeLen)+1]; - if(encoded == NULL){ - authReq = String(); - delete[] toencode; - return false; - } - sprintf(toencode, "%s:%s", username, password); - if(base64_encode_chars(toencode, toencodeLen, encoded) > 0 && authReq.equals(encoded)){ - authReq = String(); - delete[] toencode; - delete[] encoded; - return true; - } - delete[] toencode; - delete[] encoded; - } - authReq = String(); - } - return false; -} - -void WebServer::requestAuthentication(){ - sendHeader("WWW-Authenticate", "Basic realm=\"Login Required\""); - send(401); -} - -void WebServer::on(const String &uri, WebServer::THandlerFunction handler) { - on(uri, HTTP_ANY, handler); -} - -void WebServer::on(const String &uri, HTTPMethod method, WebServer::THandlerFunction fn) { - on(uri, method, fn, _fileUploadHandler); -} - -void WebServer::on(const String &uri, HTTPMethod method, WebServer::THandlerFunction fn, WebServer::THandlerFunction ufn) { - _addRequestHandler(new FunctionRequestHandler(fn, ufn, uri, method)); -} - -void WebServer::addHandler(RequestHandler* handler) { - _addRequestHandler(handler); -} - -void WebServer::_addRequestHandler(RequestHandler* handler) { - if (!_lastHandler) { - _firstHandler = handler; - _lastHandler = handler; - } - else { - _lastHandler->next(handler); - _lastHandler = handler; - } -} - -void WebServer::serveStatic(const char* uri, FS& fs, const char* path, const char* cache_header) { - _addRequestHandler(new StaticRequestHandler(fs, path, uri, cache_header)); -} - -void WebServer::handleClient() { - if (_currentStatus == HC_NONE) { - WiFiClient client = _server.available(); - if (!client) { - return; - } - -#ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.println("New client"); -#endif - - _currentClient = client; - _currentStatus = HC_WAIT_READ; - _statusChange = millis(); - } - - if (!_currentClient.connected()) { - _currentClient = WiFiClient(); - _currentStatus = HC_NONE; - return; - } - - // Wait for data from client to become available - if (_currentStatus == HC_WAIT_READ) { - if (!_currentClient.available()) { - if (millis() - _statusChange > HTTP_MAX_DATA_WAIT) { - _currentClient = WiFiClient(); - _currentStatus = HC_NONE; - } - yield(); - return; - } - - if (!_parseRequest(_currentClient)) { - _currentClient = WiFiClient(); - _currentStatus = HC_NONE; - return; - } - _currentClient.setTimeout(HTTP_MAX_SEND_WAIT); - _contentLength = CONTENT_LENGTH_NOT_SET; - _handleRequest(); - - if (!_currentClient.connected()) { - _currentClient = WiFiClient(); - _currentStatus = HC_NONE; - return; - } else { - _currentStatus = HC_WAIT_CLOSE; - _statusChange = millis(); - return; - } - } - - if (_currentStatus == HC_WAIT_CLOSE) { - if (millis() - _statusChange > HTTP_MAX_CLOSE_WAIT) { - _currentClient = WiFiClient(); - _currentStatus = HC_NONE; - } else { - yield(); - return; - } - } -} - -void WebServer::close() { -#ifdef ESP8266 - _server.stop(); -#else - // TODO add ESP32 WiFiServer::stop() - _server.end(); -#endif -} - -void WebServer::stop() { - close(); -} - -void WebServer::sendHeader(const String& name, const String& value, bool first) { - String headerLine = name; - headerLine += ": "; - headerLine += value; - headerLine += "\r\n"; - - if (first) { - _responseHeaders = headerLine + _responseHeaders; - } - else { - _responseHeaders += headerLine; - } -} - -void WebServer::setContentLength(size_t contentLength) { - _contentLength = contentLength; -} - -void WebServer::_prepareHeader(String& response, int code, const char* content_type, size_t contentLength) { - response = "HTTP/1."+String(_currentVersion)+" "; - response += String(code); - response += " "; - response += _responseCodeToString(code); - response += "\r\n"; - - if (!content_type) - content_type = "text/html"; - - sendHeader("Content-Type", content_type, true); - if (_contentLength == CONTENT_LENGTH_NOT_SET) { - sendHeader("Content-Length", String(contentLength)); - } else if (_contentLength != CONTENT_LENGTH_UNKNOWN) { - sendHeader("Content-Length", String(_contentLength)); - } else if(_contentLength == CONTENT_LENGTH_UNKNOWN && _currentVersion){ //HTTP/1.1 or above client - //let's do chunked - _chunked = true; - sendHeader("Accept-Ranges","none"); - sendHeader("Transfer-Encoding","chunked"); - } - sendHeader("Connection", "close"); - - response += _responseHeaders; - response += "\r\n"; - _responseHeaders = String(); -} - -void WebServer::send(int code, const char* content_type, const String& content) { - String header; - // Can we asume the following? - //if(code == 200 && content.length() == 0 && _contentLength == CONTENT_LENGTH_NOT_SET) - // _contentLength = CONTENT_LENGTH_UNKNOWN; - _prepareHeader(header, code, content_type, content.length()); - _currentClient.write(header.c_str(), header.length()); - if(content.length()) - sendContent(content); -} - -void WebServer::send_P(int code, PGM_P content_type, PGM_P content) { - size_t contentLength = 0; - - if (content != NULL) { - contentLength = strlen_P(content); - } - - String header; - char type[64]; - memccpy_P((void*)type, (PGM_VOID_P)content_type, 0, sizeof(type)); - _prepareHeader(header, code, (const char* )type, contentLength); - _currentClient.write(header.c_str(), header.length()); - sendContent_P(content); -} - -void WebServer::send_P(int code, PGM_P content_type, PGM_P content, size_t contentLength) { - String header; - char type[64]; - memccpy_P((void*)type, (PGM_VOID_P)content_type, 0, sizeof(type)); - _prepareHeader(header, code, (const char* )type, contentLength); - sendContent(header); - sendContent_P(content, contentLength); -} - -void WebServer::send(int code, char* content_type, const String& content) { - send(code, (const char*)content_type, content); -} - -void WebServer::send(int code, const String& content_type, const String& content) { - send(code, (const char*)content_type.c_str(), content); -} - -void WebServer::sendContent(const String& content) { - const char * footer = "\r\n"; - size_t len = content.length(); - if(_chunked) { - char * chunkSize = (char *)malloc(11); - if(chunkSize){ - sprintf(chunkSize, "%x%s", len, footer); - _currentClient.write(chunkSize, strlen(chunkSize)); - free(chunkSize); - } - } - _currentClient.write(content.c_str(), len); - if(_chunked){ - _currentClient.write(footer, 2); - } -} - -void WebServer::sendContent_P(PGM_P content) { - sendContent_P(content, strlen_P(content)); -} - -void WebServer::sendContent_P(PGM_P content, size_t size) { - const char * footer = "\r\n"; - if(_chunked) { - char * chunkSize = (char *)malloc(11); - if(chunkSize){ - sprintf(chunkSize, "%x%s", size, footer); - _currentClient.write(chunkSize, strlen(chunkSize)); - free(chunkSize); - } - } - _currentClient.write_P(content, size); - if(_chunked){ - _currentClient.write(footer, 2); - } -} - - -String WebServer::arg(String name) { - for (int i = 0; i < _currentArgCount; ++i) { - if ( _currentArgs[i].key == name ) - return _currentArgs[i].value; - } - return String(); -} - -String WebServer::arg(int i) { - if (i < _currentArgCount) - return _currentArgs[i].value; - return String(); -} - -String WebServer::argName(int i) { - if (i < _currentArgCount) - return _currentArgs[i].key; - return String(); -} - -int WebServer::args() { - return _currentArgCount; -} - -bool WebServer::hasArg(String name) { - for (int i = 0; i < _currentArgCount; ++i) { - if (_currentArgs[i].key == name) - return true; - } - return false; -} - - -String WebServer::header(String name) { - for (int i = 0; i < _headerKeysCount; ++i) { - if (_currentHeaders[i].key.equalsIgnoreCase(name)) - return _currentHeaders[i].value; - } - return String(); -} - -void WebServer::collectHeaders(const char* headerKeys[], const size_t headerKeysCount) { - _headerKeysCount = headerKeysCount + 1; - if (_currentHeaders) - delete[]_currentHeaders; - _currentHeaders = new RequestArgument[_headerKeysCount]; - _currentHeaders[0].key = AUTHORIZATION_HEADER; - for (int i = 1; i < _headerKeysCount; i++){ - _currentHeaders[i].key = headerKeys[i-1]; - } -} - -String WebServer::header(int i) { - if (i < _headerKeysCount) - return _currentHeaders[i].value; - return String(); -} - -String WebServer::headerName(int i) { - if (i < _headerKeysCount) - return _currentHeaders[i].key; - return String(); -} - -int WebServer::headers() { - return _headerKeysCount; -} - -bool WebServer::hasHeader(String name) { - for (int i = 0; i < _headerKeysCount; ++i) { - if ((_currentHeaders[i].key.equalsIgnoreCase(name)) && (_currentHeaders[i].value.length() > 0)) - return true; - } - return false; -} - -String WebServer::hostHeader() { - return _hostHeader; -} - -void WebServer::onFileUpload(THandlerFunction fn) { - _fileUploadHandler = fn; -} - -void WebServer::onNotFound(THandlerFunction fn) { - _notFoundHandler = fn; -} - -void WebServer::_handleRequest() { - bool handled = false; - if (!_currentHandler){ -#ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.println("request handler not found"); -#endif - } - else { - handled = _currentHandler->handle(*this, _currentMethod, _currentUri); -#ifdef DEBUG_ESP_HTTP_SERVER - if (!handled) { - DEBUG_OUTPUT.println("request handler failed to handle request"); - } -#endif - } - - if (!handled) { - if(_notFoundHandler) { - _notFoundHandler(); - } - else { - send(404, "text/plain", String("Not found: ") + _currentUri); - } - } - - _currentUri = String(); -} - -String WebServer::_responseCodeToString(int code) { - switch (code) { - case 100: return F("Continue"); - case 101: return F("Switching Protocols"); - case 200: return F("OK"); - case 201: return F("Created"); - case 202: return F("Accepted"); - case 203: return F("Non-Authoritative Information"); - case 204: return F("No Content"); - case 205: return F("Reset Content"); - case 206: return F("Partial Content"); - case 300: return F("Multiple Choices"); - case 301: return F("Moved Permanently"); - case 302: return F("Found"); - case 303: return F("See Other"); - case 304: return F("Not Modified"); - case 305: return F("Use Proxy"); - case 307: return F("Temporary Redirect"); - case 400: return F("Bad Request"); - case 401: return F("Unauthorized"); - case 402: return F("Payment Required"); - case 403: return F("Forbidden"); - case 404: return F("Not Found"); - case 405: return F("Method Not Allowed"); - case 406: return F("Not Acceptable"); - case 407: return F("Proxy Authentication Required"); - case 408: return F("Request Time-out"); - case 409: return F("Conflict"); - case 410: return F("Gone"); - case 411: return F("Length Required"); - case 412: return F("Precondition Failed"); - case 413: return F("Request Entity Too Large"); - case 414: return F("Request-URI Too Large"); - case 415: return F("Unsupported Media Type"); - case 416: return F("Requested range not satisfiable"); - case 417: return F("Expectation Failed"); - case 500: return F("Internal Server Error"); - case 501: return F("Not Implemented"); - case 502: return F("Bad Gateway"); - case 503: return F("Service Unavailable"); - case 504: return F("Gateway Time-out"); - case 505: return F("HTTP Version not supported"); - default: return ""; - } -} diff --git a/libraries/WebServer/src/WebServer.h b/libraries/WebServer/src/WebServer.h deleted file mode 100644 index 40807867..00000000 --- a/libraries/WebServer/src/WebServer.h +++ /dev/null @@ -1,236 +0,0 @@ -/* - WebServer.h - Dead simple web-server. - Supports only one simultaneous client, knows how to handle GET and POST. - - Copyright (c) 2014 Ivan Grokhotkov. 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 - Modified 8 May 2015 by Hristo Gochkov (proper post and file upload handling) -*/ - - -#ifndef WEBSERVER_H -#define WEBSERVER_H - -#include -#ifdef ESP8266 -#define WebServer ESP8266WebServer -#include -#else -#include -#define write_P write -#endif - -enum HTTPMethod { HTTP_ANY, HTTP_GET, HTTP_POST, HTTP_PUT, HTTP_PATCH, HTTP_DELETE, HTTP_OPTIONS }; -enum HTTPUploadStatus { UPLOAD_FILE_START, UPLOAD_FILE_WRITE, UPLOAD_FILE_END, - UPLOAD_FILE_ABORTED }; -enum HTTPClientStatus { HC_NONE, HC_WAIT_READ, HC_WAIT_CLOSE }; - -#define HTTP_DOWNLOAD_UNIT_SIZE 1460 - -#ifndef HTTP_UPLOAD_BUFLEN -#define HTTP_UPLOAD_BUFLEN 2048 -#endif - -#define HTTP_MAX_DATA_WAIT 1000 //ms to wait for the client to send the request -#define HTTP_MAX_POST_WAIT 1000 //ms to wait for POST data to arrive -#define HTTP_MAX_SEND_WAIT 5000 //ms to wait for data chunk to be ACKed -#define HTTP_MAX_CLOSE_WAIT 2000 //ms to wait for the client to close the connection - -#define CONTENT_LENGTH_UNKNOWN ((size_t) -1) -#define CONTENT_LENGTH_NOT_SET ((size_t) -2) - -class WebServer; - -typedef struct { - HTTPUploadStatus status; - String filename; - String name; - String type; - size_t totalSize; // file size - size_t currentSize; // size of data currently in buf - uint8_t buf[HTTP_UPLOAD_BUFLEN]; -} HTTPUpload; - -#include "detail/RequestHandler.h" - -namespace fs { -class FS; -} - -class WebServer -{ -public: - WebServer(IPAddress addr, int port = 80); - WebServer(int port = 80); - ~WebServer(); - - void begin(); - void handleClient(); - - void close(); - void stop(); - - bool authenticate(const char * username, const char * password); - void requestAuthentication(); - - typedef std::function THandlerFunction; - void on(const String &uri, THandlerFunction handler); - void on(const String &uri, HTTPMethod method, THandlerFunction fn); - void on(const String &uri, HTTPMethod method, THandlerFunction fn, THandlerFunction ufn); - void addHandler(RequestHandler* handler); - void serveStatic(const char* uri, fs::FS& fs, const char* path, const char* cache_header = NULL ); - void onNotFound(THandlerFunction fn); //called when handler is not assigned - void onFileUpload(THandlerFunction fn); //handle file uploads - - String uri() { return _currentUri; } - HTTPMethod method() { return _currentMethod; } - WiFiClient client() { return _currentClient; } - HTTPUpload& upload() { return _currentUpload; } - - String arg(String name); // get request argument value by name - String arg(int i); // get request argument value by number - String argName(int i); // get request argument name by number - int args(); // get arguments count - bool hasArg(String name); // check if argument exists - void collectHeaders(const char* headerKeys[], const size_t headerKeysCount); // set the request headers to collect - String header(String name); // get request header value by name - String header(int i); // get request header value by number - String headerName(int i); // get request header name by number - int headers(); // get header count - bool hasHeader(String name); // check if header exists - - String hostHeader(); // get request host header if available or empty String if not - - // send response to the client - // code - HTTP response code, can be 200 or 404 - // content_type - HTTP content type, like "text/plain" or "image/png" - // content - actual content body - void send(int code, const char* content_type = NULL, const String& content = String("")); - void send(int code, char* content_type, const String& content); - void send(int code, const String& content_type, const String& content); - void send_P(int code, PGM_P content_type, PGM_P content); - void send_P(int code, PGM_P content_type, PGM_P content, size_t contentLength); - - void setContentLength(size_t contentLength); - void sendHeader(const String& name, const String& value, bool first = false); - void sendContent(const String& content); - void sendContent_P(PGM_P content); - void sendContent_P(PGM_P content, size_t size); - - static String urlDecode(const String& text); - -#ifdef ESP8266 -template size_t streamFile(T &file, const String& contentType){ - setContentLength(file.size()); - if (String(file.name()).endsWith(".gz") && - contentType != "application/x-gzip" && - contentType != "application/octet-stream"){ - sendHeader("Content-Encoding", "gzip"); - } - send(200, contentType, ""); - return _currentClient.write(file); -} -#else -template size_t streamFile(T &file, const String& contentType){ -#define STREAMFILE_BUFSIZE 2*1460 - setContentLength(file.size()); - if (String(file.name()).endsWith(".gz") && - contentType != "application/x-gzip" && - contentType != "application/octet-stream") { - sendHeader("Content-Encoding", "gzip"); - } - send(200, contentType, ""); - uint8_t *buf = (uint8_t *)malloc(STREAMFILE_BUFSIZE); - if (buf == NULL) { - //DBG_OUTPUT_PORT.printf("streamFile malloc failed"); - return 0; - } - size_t totalBytesOut = 0; - while (client().connected() && (file.available() > 0)) { - int bytesOut; - int bytesIn = file.read(buf, STREAMFILE_BUFSIZE); - if (bytesIn <= 0) break; - while (1) { - bytesOut = 0; - if (!client().connected()) break; - bytesOut = client().write(buf, bytesIn); - if (bytesIn == bytesOut) break; - - //DBG_OUTPUT_PORT.printf("bytesIn %d != bytesOut %d\r\n", - //bytesIn, bytesOut); - delay(1); - } - totalBytesOut += bytesOut; - yield(); - } - if (totalBytesOut != file.size()) { - //DBG_OUTPUT_PORT.printf("file size %d bytes out %d\r\n", - // file.size(), totalBytesOut); - } - free(buf); - return totalBytesOut; -} -#endif - -protected: - void _addRequestHandler(RequestHandler* handler); - void _handleRequest(); - bool _parseRequest(WiFiClient& client); - void _parseArguments(String data); - static String _responseCodeToString(int code); - bool _parseForm(WiFiClient& client, String boundary, uint32_t len); - bool _parseFormUploadAborted(); - void _uploadWriteByte(uint8_t b); - uint8_t _uploadReadByte(WiFiClient& client); - void _prepareHeader(String& response, int code, const char* content_type, size_t contentLength); - bool _collectHeader(const char* headerName, const char* headerValue); - - struct RequestArgument { - String key; - String value; - }; - - WiFiServer _server; - - WiFiClient _currentClient; - HTTPMethod _currentMethod; - String _currentUri; - uint8_t _currentVersion; - HTTPClientStatus _currentStatus; - unsigned long _statusChange; - - RequestHandler* _currentHandler; - RequestHandler* _firstHandler; - RequestHandler* _lastHandler; - THandlerFunction _notFoundHandler; - THandlerFunction _fileUploadHandler; - - int _currentArgCount; - RequestArgument* _currentArgs; - HTTPUpload _currentUpload; - - int _headerKeysCount; - RequestArgument* _currentHeaders; - size_t _contentLength; - String _responseHeaders; - - String _hostHeader; - bool _chunked; - -}; - - -#endif //WEBSERVER_H diff --git a/libraries/WebServer/src/detail/RequestHandler.h b/libraries/WebServer/src/detail/RequestHandler.h deleted file mode 100644 index c1cc909d..00000000 --- a/libraries/WebServer/src/detail/RequestHandler.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef REQUESTHANDLER_H -#define REQUESTHANDLER_H - -class RequestHandler { -public: - virtual ~RequestHandler() { } - virtual bool canHandle(HTTPMethod method, String uri) { (void) method; (void) uri; return false; } - virtual bool canUpload(String uri) { (void) uri; return false; } - virtual bool handle(WebServer& server, HTTPMethod requestMethod, String requestUri) { (void) server; (void) requestMethod; (void) requestUri; return false; } - virtual void upload(WebServer& server, String requestUri, HTTPUpload& upload) { (void) server; (void) requestUri; (void) upload; } - - RequestHandler* next() { return _next; } - void next(RequestHandler* r) { _next = r; } - -private: - RequestHandler* _next = nullptr; -}; - -#endif //REQUESTHANDLER_H diff --git a/libraries/WebServer/src/detail/RequestHandlersImpl.h b/libraries/WebServer/src/detail/RequestHandlersImpl.h deleted file mode 100644 index e337bc11..00000000 --- a/libraries/WebServer/src/detail/RequestHandlersImpl.h +++ /dev/null @@ -1,191 +0,0 @@ -#ifndef REQUESTHANDLERSIMPL_H -#define REQUESTHANDLERSIMPL_H - -#include "RequestHandler.h" - -#ifdef ESP8266 -// Table of extension->MIME strings stored in PROGMEM, needs to be global due to GCC section typing rules -static const struct {const char endsWith[16]; const char mimeType[32];} mimeTable[] ICACHE_RODATA_ATTR = { -#else -static const struct {const char endsWith[16]; const char mimeType[32];} mimeTable[] = { -#endif - { ".html", "text/html" }, - { ".htm", "text/html" }, - { ".css", "text/css" }, - { ".txt", "text/plain" }, - { ".js", "application/javascript" }, - { ".json", "application/json" }, - { ".png", "image/png" }, - { ".gif", "image/gif" }, - { ".jpg", "image/jpeg" }, - { ".ico", "image/x-icon" }, - { ".svg", "image/svg+xml" }, - { ".ttf", "application/x-font-ttf" }, - { ".otf", "application/x-font-opentype" }, - { ".woff", "application/font-woff" }, - { ".woff2", "application/font-woff2" }, - { ".eot", "application/vnd.ms-fontobject" }, - { ".sfnt", "application/font-sfnt" }, - { ".xml", "text/xml" }, - { ".pdf", "application/pdf" }, - { ".zip", "application/zip" }, - { ".gz", "application/x-gzip" }, - { ".appcache", "text/cache-manifest" }, - { "", "application/octet-stream" } }; - -class FunctionRequestHandler : public RequestHandler { -public: - FunctionRequestHandler(WebServer::THandlerFunction fn, WebServer::THandlerFunction ufn, const String &uri, HTTPMethod method) - : _fn(fn) - , _ufn(ufn) - , _uri(uri) - , _method(method) - { - } - - bool canHandle(HTTPMethod requestMethod, String requestUri) override { - if (_method != HTTP_ANY && _method != requestMethod) - return false; - - if (requestUri != _uri) - return false; - - return true; - } - - bool canUpload(String requestUri) override { - if (!_ufn || !canHandle(HTTP_POST, requestUri)) - return false; - - return true; - } - - bool handle(WebServer& server, HTTPMethod requestMethod, String requestUri) override { - (void) server; - if (!canHandle(requestMethod, requestUri)) - return false; - - _fn(); - return true; - } - - void upload(WebServer& server, String requestUri, HTTPUpload& upload) override { - (void) server; - (void) upload; - if (canUpload(requestUri)) - _ufn(); - } - -protected: - WebServer::THandlerFunction _fn; - WebServer::THandlerFunction _ufn; - String _uri; - HTTPMethod _method; -}; - -class StaticRequestHandler : public RequestHandler { -public: - StaticRequestHandler(FS& fs, const char* path, const char* uri, const char* cache_header) - : _fs(fs) - , _uri(uri) - , _path(path) - , _cache_header(cache_header) - { - _isFile = fs.exists(path); -#ifdef ESP8266 - DEBUGV("StaticRequestHandler: path=%s uri=%s isFile=%d, cache_header=%s\r\n", path, uri, _isFile, cache_header); -#else -#ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.printf("StaticRequestHandler: path=%s uri=%s isFile=%d, cache_header=%s\r\n", path, uri, _isFile, cache_header); -#endif -#endif - _baseUriLength = _uri.length(); - } - - bool canHandle(HTTPMethod requestMethod, String requestUri) override { - if (requestMethod != HTTP_GET) - return false; - - if ((_isFile && requestUri != _uri) || !requestUri.startsWith(_uri)) - return false; - - return true; - } - - bool handle(WebServer& server, HTTPMethod requestMethod, String requestUri) override { - if (!canHandle(requestMethod, requestUri)) - return false; - -#ifdef ESP8266 - DEBUGV("StaticRequestHandler::handle: request=%s _uri=%s\r\n", requestUri.c_str(), _uri.c_str()); -#else -#ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.printf("StaticRequestHandler::handle: request=%s _uri=%s\r\n", requestUri.c_str(), _uri.c_str()); -#endif -#endif - - String path(_path); - - if (!_isFile) { - // Base URI doesn't point to a file. - // If a directory is requested, look for index file. - if (requestUri.endsWith("/")) requestUri += "index.htm"; - - // Append whatever follows this URI in request to get the file path. - path += requestUri.substring(_baseUriLength); - } -#ifdef ESP8266 - DEBUGV("StaticRequestHandler::handle: path=%s, isFile=%d\r\n", path.c_str(), _isFile); -#else -#ifdef DEBUG_ESP_HTTP_SERVER - DEBUG_OUTPUT.printf("StaticRequestHandler::handle: path=%s, isFile=%d\r\n", path.c_str(), _isFile); -#endif -#endif - - String contentType = getContentType(path); - - // look for gz file, only if the original specified path is not a gz. So part only works to send gzip via content encoding when a non compressed is asked for - // if you point the the path to gzip you will serve the gzip as content type "application/x-gzip", not text or javascript etc... - if (!path.endsWith(".gz") && !_fs.exists(path)) { - String pathWithGz = path + ".gz"; - if(_fs.exists(pathWithGz)) - path += ".gz"; - } - - File f = _fs.open(path, "r"); - if (!f) - return false; - - if (_cache_header.length() != 0) - server.sendHeader("Cache-Control", _cache_header); - - server.streamFile(f, contentType); - return true; - } - - static String getContentType(const String& path) { - char buff[sizeof(mimeTable[0].mimeType)]; - // Check all entries but last one for match, return if found - for (size_t i=0; i < sizeof(mimeTable)/sizeof(mimeTable[0])-1; i++) { - strcpy_P(buff, mimeTable[i].endsWith); - if (path.endsWith(buff)) { - strcpy_P(buff, mimeTable[i].mimeType); - return String(buff); - } - } - // Fall-through and just return default type - strcpy_P(buff, mimeTable[sizeof(mimeTable)/sizeof(mimeTable[0])-1].mimeType); - return String(buff); - } - -protected: - FS _fs; - String _uri; - String _path; - String _cache_header; - bool _isFile; - size_t _baseUriLength; -}; - - -#endif //REQUESTHANDLERSIMPL_H