Skip to content

Commit

Permalink
Hide UART settings when serial via JTAG is activated. Added default W…
Browse files Browse the repository at this point in the history
…iFi SSID on short boot button press
  • Loading branch information
seeul8er committed Jun 21, 2024
1 parent b3ab67b commit eb76934
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
29 changes: 28 additions & 1 deletion frontend/dronebridge.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// const ROOT_URL = "http://localhost:3000/" // for testing with local json server
const ROOT_URL = window.location.href // for production code
let conn_status = 0;
let conn_status = 0; // connection status to the ESP32
let old_conn_status = 0; // connection status before last update of UI to know when it changed
let serial_via_JTAG = 0; // set to 1 if ESP32 is using the USB interface as serial interface for data and not using the UART. If 0 we set UART config to invisible for the user.

function change_ap_ip_visibility(){
var ap_ip_div = document.getElementById("ap_ip_div");
Expand Down Expand Up @@ -32,6 +34,21 @@ function change_msp_ltm_visibility(){
}
}

function change_uart_visibility() {
var tx_rx_div = document.getElementById("tx_rx_div");
var rts_cts_div = document.getElementById("rts_cts_div");
var rts_thresh_div = document.getElementById("rts_thresh_div");
if (serial_via_JTAG === 0) {
rts_cts_div.style.display = "block";
tx_rx_div.style.display = "block";
rts_thresh_div.style.display = "block";
} else {
rts_cts_div.style.display = "none";
tx_rx_div.style.display = "none";
rts_thresh_div.style.display = "none";
}
}

/**
* Convert a form into a JSON string
* @param form The HTML form to convert
Expand Down Expand Up @@ -116,6 +133,7 @@ function get_system_info() {
document.getElementById("about").innerHTML = "DroneBridge for ESP32 - v" + json_data["major_version"] +
"." + json_data["minor_version"] + " - esp-idf " + json_data["idf_version"]
document.getElementById("esp_mac").innerHTML = json_data["esp_mac"]
serial_via_JTAG = json_data["serial_via_JTAG"];
}).catch(error => {
conn_status = 0
error.message;
Expand All @@ -131,6 +149,15 @@ function update_conn_status() {
document.getElementById("web_conn_status").innerHTML = "<span class=\"dot_red\"></span> disconnected from ESP32"
document.getElementById("current_client_ip").innerHTML = ""
}
if (conn_status !== old_conn_status) {
// connection status changed. Update settings and UI
get_system_info();
get_settings();
setTimeout(change_msp_ltm_visibility, 500);
setTimeout(change_ap_ip_visibility, 500);
setTimeout(change_uart_visibility, 500);
}
old_conn_status = conn_status
}

/**
Expand Down
7 changes: 4 additions & 3 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ <h3>Wi-Fi</h3>
</div>
</div>
<h3>Serial</h3>
<div class="row">
<div class="row" id="tx_rx_div">
<div class="six columns">
<label for="tx_pin">UART TX Pin</label>
<input type="text" name="tx_pin" value="" id="tx_pin">
Expand All @@ -98,7 +98,7 @@ <h3>Serial</h3>
<input type="text" name="rx_pin" value="" id="rx_pin">
</div>
</div>
<div class="row">
<div class="row" id="rts_cts_div">
<div class="six columns">
<label for="rts_pin">UART RTS Pin</label>
<input type="text" name="rts_pin" value="" id="rts_pin">
Expand All @@ -108,7 +108,7 @@ <h3>Serial</h3>
<input type="text" name="cts_pin" value="" id="cts_pin">
</div>
</div>
<div class="row">
<div class="row" id="rts_thresh_div">
<div class="six columns">
<label for="rts_thresh">UART RTS threshold</label>
<input type="number" id="rts_thresh" name="rts_thresh" min="1" max="128">
Expand Down Expand Up @@ -213,6 +213,7 @@ <h3>Serial</h3>
setInterval(update_conn_status, 500)
setTimeout(change_msp_ltm_visibility, 500)
setTimeout(change_ap_ip_visibility, 500)
setTimeout(change_uart_visibility, 500)
</script>
</body>
</html>
5 changes: 5 additions & 0 deletions main/http_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,11 @@ static esp_err_t system_info_get_handler(httpd_req_t *req) {
sprintf(mac_str, "%02X:%02X:%02X:%02X:%02X:%02X",
LOCAL_MAC_ADDRESS[0], LOCAL_MAC_ADDRESS[1], LOCAL_MAC_ADDRESS[2], LOCAL_MAC_ADDRESS[3], LOCAL_MAC_ADDRESS[4], LOCAL_MAC_ADDRESS[5]);
cJSON_AddStringToObject(root, "esp_mac", mac_str);
#ifdef CONFIG_DB_SERIAL_OPTION_JTAG
cJSON_AddNumberToObject(root, "serial_via_JTAG", 1);
#else
cJSON_AddNumberToObject(root, "serial_via_JTAG", 0);
#endif
const char *sys_info = cJSON_Print(root);
httpd_resp_sendstr(req, sys_info);
free((void *) sys_info);
Expand Down
1 change: 1 addition & 0 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ void read_settings_nvs() {
void short_press_callback(void *arg,void *usr_data) {
ESP_LOGW(TAG, "Short press detected setting wifi mode to access point with password: dronebridge");
DB_WIFI_MODE = DB_WIFI_MODE_AP;
strncpy((char *) DB_WIFI_SSID, "DroneBridge for ESP32", sizeof(DB_WIFI_SSID) - 1);
strncpy((char *) DB_WIFI_PWD, "dronebridge", sizeof(DB_WIFI_PWD) - 1);
write_settings_to_nvs();
esp_restart();
Expand Down

0 comments on commit eb76934

Please sign in to comment.