Skip to content

Commit

Permalink
feat: add start ap button to help reconfigure wifi
Browse files Browse the repository at this point in the history
  • Loading branch information
rednblkx committed Jan 13, 2025
1 parent 770039c commit ac870b1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 27 deletions.
Binary file added data/assets/ap-icon.webp
Binary file not shown.
14 changes: 14 additions & 0 deletions data/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@
document.title = `HK-ESP32 - ${name.toUpperCase()}`
}
}
async function start_ap() {
if(confirm("Are you sure you want to start the AP?")){
let data = await fetch("/start_config_ap");
let string = await data.text();
alert(string);
}
}
async function reboot() {
if(confirm("Are you sure you want to reboot the device?")){
let data = await fetch("/reboot_device");
Expand Down Expand Up @@ -327,6 +334,13 @@ <h2 style="text-align: center;margin-bottom: 0;margin-top: 0;background: none;pa
</div>
</div>
<div id="top-btns" style="display: flex;gap: 8px;align-items: center;">
<button title="Start AP" type="button" id="restart-btn"
style="background-color: #ffffff2e;border: 1px solid white;padding: 0.5rem;cursor: pointer;gap: 8px;"
onclick="start_ap()" ontouchstart="this.style['background-color']='#4040402e'"
ontouchend="this.style['background-color']='#ffffff2e'">
<img src="assets/ap-icon.webp" width="25px" style="object-fit: contain;">
<p style="margin: 0;">Start AP</p>
</button>
<button title="Reboot" type="button" id="restart-btn"
style="background-color: #ffffff2e;border: 1px solid white;padding: 0.5rem;cursor: pointer;gap: 8px;"
onclick="reboot()" ontouchstart="this.style['background-color']='#4040402e'"
Expand Down
12 changes: 12 additions & 0 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,16 @@ void setupWeb() {
ESP.restart();
});
webServer.addHandler(rebootDeviceHandle);
auto startConfigAP = new AsyncCallbackWebHandler();
startConfigAP->setUri("/start_config_ap");
startConfigAP->setMethod(HTTP_GET);
startConfigAP->onRequest([](AsyncWebServerRequest* request) {
request->send(200, "text/plain", "Starting the AP...");
delay(1000);
webServer.end();
homeSpan.processSerialCommand("A");
});
webServer.addHandler(startConfigAP);
auto resetHkHandle = new AsyncCallbackWebHandler();
resetHkHandle->setUri("/reset_hk_pair");
resetHkHandle->setMethod(HTTP_GET);
Expand Down Expand Up @@ -1384,6 +1394,8 @@ void setupWeb() {
resetHkHandle->setAuthentication(espConfig::miscConfig.webUsername.c_str(), espConfig::miscConfig.webPassword.c_str());
resetWifiHandle->setAuthentication(espConfig::miscConfig.webUsername.c_str(), espConfig::miscConfig.webPassword.c_str());
getWifiRssi->setAuthentication(espConfig::miscConfig.webUsername.c_str(), espConfig::miscConfig.webPassword.c_str());
startConfigAP->setAuthentication(espConfig::miscConfig.webUsername.c_str(), espConfig::miscConfig.webPassword.c_str());
ethSuppportConfig->setAuthentication(espConfig::miscConfig.webUsername.c_str(), espConfig::miscConfig.webPassword.c_str());
}
webServer.onNotFound(notFound);
webServer.begin();
Expand Down
52 changes: 25 additions & 27 deletions sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,40 @@ CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="with_ota.csv"
CONFIG_ASYNC_TCP_USE_WDT=n
CONFIG_AUTOSTART_ARDUINO=y
CONFIG_ARDUHAL_LOG_COLORS=y
CONFIG_ARDUINO_SELECTIVE_COMPILATION=y
# CONFIG_ARDUINO_SELECTIVE_Wire is not set
# CONFIG_ARDUINO_SELECTIVE_ESP_SR is not set
# CONFIG_ARDUINO_SELECTIVE_EEPROM is not set
# CONFIG_ARDUINO_SELECTIVE_Ticker is not set
# CONFIG_ARDUINO_SELECTIVE_Zigbee is not set
# CONFIG_ARDUINO_SELECTIVE_SD is not set
# CONFIG_ARDUINO_SELECTIVE_SD_MMC is not set
# CONFIG_ARDUINO_SELECTIVE_SPIFFS is not set
# CONFIG_ARDUINO_SELECTIVE_FFat is not set
# CONFIG_ARDUINO_SELECTIVE_PPP is not set
# CONFIG_ARDUINO_SELECTIVE_HTTPClient is not set
# CONFIG_ARDUINO_SELECTIVE_Matter is not set
# CONFIG_ARDUINO_SELECTIVE_NetBIOS is not set
# CONFIG_ARDUINO_SELECTIVE_WebServer is not set
# CONFIG_ARDUINO_SELECTIVE_NetworkClientSecure is not set
# CONFIG_ARDUINO_SELECTIVE_BLE is not set
# CONFIG_ARDUINO_SELECTIVE_BluetoothSerial is not set
# CONFIG_ARDUINO_SELECTIVE_RainMaker is not set
# CONFIG_ARDUINO_SELECTIVE_OpenThread is not set
# CONFIG_ARDUINO_SELECTIVE_Insights is not set
CONFIG_ARDUINO_SELECTIVE_Wire=n
CONFIG_ARDUINO_SELECTIVE_ESP_SR=n
CONFIG_ARDUINO_SELECTIVE_EEPROM=n
CONFIG_ARDUINO_SELECTIVE_Ticker=n
CONFIG_ARDUINO_SELECTIVE_Zigbee=n
CONFIG_ARDUINO_SELECTIVE_SD=n
CONFIG_ARDUINO_SELECTIVE_SD_MMC=n
CONFIG_ARDUINO_SELECTIVE_SPIFFS=n
CONFIG_ARDUINO_SELECTIVE_FFat=n
CONFIG_ARDUINO_SELECTIVE_PPP=n
CONFIG_ARDUINO_SELECTIVE_HTTPClient=n
CONFIG_ARDUINO_SELECTIVE_Matter=n
CONFIG_ARDUINO_SELECTIVE_NetBIOS=n
CONFIG_ARDUINO_SELECTIVE_WebServer=n
CONFIG_ARDUINO_SELECTIVE_NetworkClientSecure=n
CONFIG_ARDUINO_SELECTIVE_BLE=n
CONFIG_ARDUINO_SELECTIVE_BluetoothSerial=n
CONFIG_ARDUINO_SELECTIVE_RainMaker=n
CONFIG_ARDUINO_SELECTIVE_OpenThread=n
CONFIG_ARDUINO_SELECTIVE_Insights=n
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y
CONFIG_ESP32_REV_MIN_3=y
CONFIG_ETH_SPI_ETHERNET_DM9051=y
CONFIG_ETH_SPI_ETHERNET_W5500=y
CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL=y
CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y
# CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 is not set
# CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 is not set
CONFIG_FREERTOS_HZ=1000
CONFIG_LOG_MAXIMUM_LEVEL_VERBOSE=y
CONFIG_LWIP_MAX_SOCKETS=16
CONFIG_MBEDTLS_PSK_MODES=y
CONFIG_MBEDTLS_KEY_EXCHANGE_PSK=y
CONFIG_MBEDTLS_HKDF_C=y
CONFIG_MQTT_SKIP_PUBLISH_IF_DISCONNECTED=y
CONFIG_ETH_SPI_ETHERNET_DM9051=y
CONFIG_ETH_SPI_ETHERNET_W5500=y
CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL=y
CONFIG_MQTT_SKIP_PUBLISH_IF_DISCONNECTED=y

0 comments on commit ac870b1

Please sign in to comment.