Skip to content

Commit

Permalink
fix(wifi): wifi form fixed
Browse files Browse the repository at this point in the history
after webserver refactoring, form for wifi credentials was broken
minor optimizations
  • Loading branch information
Renato Bonomini committed Dec 11, 2020
1 parent 899c742 commit 54039f9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Within the Arduino IDE, from `Tools > Partition Scheme`
- add battery and expose battery level via BLE and/or web interface
- log to SD https://randomnerdtutorials.com/esp32-data-logging-temperature-to-microsd-card/
- test https://apps.apple.com/us/app/espressif-esptouch/id1071176700 or https://apps.apple.com/in/app/esp-ble-provisioning/id1473590141
- OTA via browser or from internet location https://lastminuteengineers.com/esp32-ota-web-updater-arduino-ide/ https://github.com/chrisjoyce911/esp32FOTA or https://github.com/platformio/bintray-secure-ota
- OTA via browser or from internet location https://lastminuteengineers.com/esp32-ota-web-updater-arduino-ide/ https://github.com/chrisjoyce911/esp32FOTA or https://github.com/platformio/bintray-secure-ota or https://github.com/ayushsharma82/AsyncElegantOTA
- use ootb library at https://os.mbed.com/teams/ublox/code/gnss/ or https://github.com/ldab/u-blox_GNSS
- use packed binary format with custom binary parser for HLT
- use https with https://github.com/fhessel/esp32_https_server and https://github.com/fhessel/esp32_https_server_compat
Expand Down
22 changes: 9 additions & 13 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,39 @@ description = GPS module for GPS mobile apps used on track to time laps
[env]
platform = espressif32
board = esp32dev
; https://docs.platformio.org/en/latest/boards/espressif32/esp32dev.html#board-espressif32-esp32dev
framework = arduino
; Nimble-Arduino is not compatible with the git version, so skipping
; platform_packages =
; platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git
lib_deps =
h2zero/NimBLE-Arduino@^1.0.2
yiannisbourkelis/Uptime Library @ ^1.0.0
evert-arias/EasyButton @ ^2.0.1
arkhipenko/TaskScheduler @ ^3.2.0
board_build.partitions = min_spiffs.csv
monitor_speed = 115200
; monitor_port = /dev/cu.SLAB_USBtoUART ; for MacOS Catalina
monitor_port = /dev/cu.usbserial-0001 ; for MacOS BigSur
monitor_port = /dev/cu.usbserial-0001
monitor_filters = colorize, esp32_exception_decoder
; upload_port = /dev/cu.SLAB_USBtoUART ; for MacOS Catalina
upload_port = /dev/cu.usbserial-0001 ; for MacOS BigSur
upload_port = /dev/cu.usbserial-0001
upload_speed = 921600
build_flags = !python git_rev_macro.py
lib_ldf_mode = chain+

[env:debug]
build_type = debug
; option below need to be multi-line otherwise platformio does not consider them - perhaps a defect in how they are defined, not sure
build_flags =
build_flags =
${env.build_flags}
-D LOG_LOCAL_LEVEL=ESP_LOG_DEBUG
-D CORE_DEBUG_LEVEL=4
-D OTA_AVAILABLE=-1
-D BUILD_ENV_NAME='"test build"'
-D BUILD_ENV_NAME='"test build"'
-D MYNEWT_VAL_BLE_MAX_CONNECTIONS=1

[env:release]
; option below need to be multi-line otherwise platformio does not consider them - perhaps a defect in how they are defined, not sure
build_flags =
build_flags =
${env.build_flags}
-D LOG_LOCAL_LEVEL=ESP_LOG_NONE
-D CORE_DEBUG_LEVEL=0
-D BUILD_ENV_NAME='"production build"'
-D NO_GLOBAL_ARDUINOOTA
-D MYNEWT_VAL_BLE_MAX_CONNECTIONS=1

[ota]
upload_protocol = espota
Expand Down
16 changes: 9 additions & 7 deletions src/bonogps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#define BONOGPS_FIRMWARE_VER GIT_REV
#else
// the following define is needed to display version when building this with the Arduino IDE
#define BONOGPS_FIRMWARE_VER "v0.4"
#define BONOGPS_FIRMWARE_VER "v0.4.1"
#endif
// Bonjour DNS name, access the GPS configuration page by appending .local as DNS
#define BONOGPS_MDNS "bonogps"
Expand Down Expand Up @@ -771,7 +771,7 @@ const char WEBPORTAL_FOOTER[] PROGMEM = "\n<footer>Version: <a style='font-size:
#else
const char WEBPORTAL_FOOTER[] PROGMEM = "\n<footer>Version: " BONO_GPS_VERSION "</footer>\n</body>\n</html>";
#endif
const char WEBPORTAL_ROOT_OPTIONS[] PROGMEM = "\n</details>\n<details><summary>Device</summary>\n<article>Suspend GPS for <a href='/powersave/1800'>30'</a> <a href='/powersave/3600'>1 hr</a></article>\n<article><a href='/preset'>Load Preset</a></article>\n<article><a href='/status'>Information</a></article>\n<article><a href='/restart'>Restart</a></article>\n<article><a href='/savecfg'>Save config</a></article>\n<article><a href='/savewificreds'>Save WiFi credentials</a></article></details>";
const char WEBPORTAL_ROOT_OPTIONS[] PROGMEM = "\n</details>\n<details><summary>Device</summary>\n<article>Suspend GPS for <a href='/powersave/1800'>30'</a> <a href='/powersave/3600'>1 hr</a></article>\n<article><a href='/preset'>Load Preset</a></article>\n<article><a href='/savecfg'>Save config</a></article>\n<article><a href='/status'>Information</a></article>\n<article><a href='/savewificreds'>Set WiFi credentials</a></article>\n<article><a href='/restart'>Restart</a><br><br></article></details>";

// Helpers to populate a page with style sheet
String generate_html_header(bool add_menu = true)
Expand Down Expand Up @@ -1589,7 +1589,7 @@ void handle_wifi_mode()

void handle_restart()
{
webserver.send(200, html_text, generate_html_body(F("Please confirm <form action='/restart_execute' method='post'><input type='submit' value='Restart'></form>")));
webserver.send(200, html_text, generate_html_body(F("Please confirm <form action='/restart' method='post'><input type='submit' value='Restart'></form>")));
}
void handle_restart_execute()
{
Expand Down Expand Up @@ -1724,12 +1724,14 @@ void handle_clients()
webserver.send(200, html_text, generate_html_body(message));
}

const char WEBPORTAL_SAVECONFIG[] PROGMEM = "<article><form action='/savewificreds'>SSID<br><input style='background: none' name='ssid' maxlength='32'><p>WPA Key<br><input style='background: none' type='password' name='key' maxlength='64'><p><input type='submit' value='Save'></form></article>";
const char WEBPORTAL_SAVECONFIG[] PROGMEM = "<article><form action='/savewificreds' method='post'>WiFi SSID<br><input style='background: none; color: black' name='ssid' maxlength='32'><p>WiFi Key<br><input style='background: none; color: black' type='password' name='key' maxlength='64'><p><input type='submit' value='Save'></form></article>";
void handle_saveconfig_wifi_creds()
{
log_d("Form to save wifi credentials");
webserver.setContentLength(CONTENT_LENGTH_UNKNOWN);
webserver.send_P(200, html_text, WEBPORTAL_HEADER);
webserver.sendContent(generate_html_header(true));
webserver.sendContent_P(WEBPORTAL_SAVECONFIG);
webserver.sendContent_P(WEBPORTAL_FOOTER);
}

Expand Down Expand Up @@ -1816,8 +1818,8 @@ void WebConfig_start()
#endif
webserver.on("/hlt/{}", handle_hlt);
webserver.on("/wifi/{}", handle_wifi_mode);
webserver.on("/restart", handle_restart);
webserver.on("/restart_execute", handle_restart_execute);
webserver.on("/restart", HTTP_GET, handle_restart);
webserver.on("/restart", HTTP_POST, handle_restart_execute);
webserver.on("/savecfg", handle_saveconfig);
webserver.on("/savecfg/{}", handle_saveconfig_wifi);
webserver.on("/savewifi/{}", handle_saveconfig_wifimode);
Expand Down Expand Up @@ -2178,7 +2180,7 @@ void setup()
WiFi.setHostname(BONOGPS_MDNS);
WiFi.setSleep(false);

// WifiAP or STA will also start the NMEA server on port 1818
// WifiAP or STA will also start the NMEA server on port 1818, if the service is turned on (starting with v0.4)
switch (stored_preferences.wifi_mode)
{
case WIFI_AP:
Expand Down

0 comments on commit 54039f9

Please sign in to comment.