Skip to content

Commit

Permalink
Added RSSI report when in client mode. Require min. WEP encryption
Browse files Browse the repository at this point in the history
  • Loading branch information
seeul8er committed Feb 18, 2024
1 parent f5ac98a commit df0e164
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 8 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ Defaults: UART2 (RX2, TX2 on GPIO 16, 17)
- `WiFi Client Mode`
ESP32 will connect to the specified WiFi Access Point. After 50 failed connection retries (~60 seconds) the ESP32 will temporarily switch to WiFi Access Point Mode with SSID `Failsafe DroneBridge ESP32` and password `dronebridge`. This mode allows you to check and change the configuration. On reboot the stored configuration will be loaded.
In this mode the ESP32 can connect to WiFi and ESP-NOW (LR-Mode) devices.
- `ESP-NOW Access Point Mode`
- `(In future release) ESP-NOW Access Point Mode`
Launches an access point that is ESP-NOW enabled. ESP-NOW Access Point Mode makes the device invisible for non-ESP-NOW enabled devices. You will not be able to change the config!
You will have to manually erase the flash memory of the ESP32 and re-flash DroneBridge for ESP32 to get back into normal Wi-Fi Mode!
- `Wifi SSID`: Up to 31 character long
- `Wifi password`: Up to 63 character long
- `Wifi password`: Min. 8 characters, max 63 character long. WiFi must be at least WEP encrypted. No support for unencrypted networks!
- `UART baud rate`: Same as you configured on your flight controller
- `GPIO TX PIN Number` & `GPIO RX PIN Number`: The pins you want to use for TX & RX (UART). See pin out of manufacturer of your ESP32 device **Flight controller UART must be 3.3V or use an inverter.** If pins are the same for TX & RX the UART will not be opened.
- `GPIO TX PIN Number` & `GPIO RX PIN Number`: The pins you want to use for TX & RX (UART). See pin out of manufacturer of your ESP32 device **Flight controller UART must be 3.3V or use an inverter.** If pins are the same for TX & RX the UART connection will not be established.
- `UART serial protocol`: MultiWii based or MAVLink based - configures the parser
- `Transparent packet size`: Only used with 'serial protocol' set to transparent. Length of UDP packets in transparent mode
- `Transparent packet size`: Only used with 'serial protocol' set to transparent. Length of UDP packets in transparent mode. **ESP-NOW only supports packets <250bytes**
- `LTM frames per packet`: Buffer the specified number of packets and send them at once in one packet
- `Gateway IP address`: IPv4 address you want the ESP32 access point to have

Expand Down
3 changes: 1 addition & 2 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
</script>
<!--Minified version of dronebridge.js-->
<script type="text/javascript">
const ROOT_URL=window.location.href;let conn_status=0;function change_ap_ip_visibility(){var e=document.getElementById("ap_ip_div"),t=document.getElementById("ap_channel_div"),n=document.getElementById("esp-now-ap-disclaimer");"2"===document.getElementById("esp32_mode").value?(e.style.display="none",t.style.display="none"):(e.style.display="block",t.style.display="block"),"3"===document.getElementById("esp32_mode").value?n.style.display="block":n.style.display="none"}function change_msp_ltm_visibility(){var e=document.getElementById("msp_ltm_div"),t=document.getElementById("trans_pack_size_div");"1"===document.getElementById("telem_proto").value?(e.style.display="block",t.style.display="none"):(e.style.display="none",t.style.display="block")}function toJSONString(e){let t={},n=e.querySelectorAll("input, select");for(let e=0;e<n.length;++e){let s=n[e],o=s.name,i=s.value;isNaN(Number(i))||0===o.localeCompare("wifi_ssid")||0===o.localeCompare("wifi_pass")?o&&(t[o]=i):o&&(t[o]=parseInt(i))}return JSON.stringify(t)}async function get_json(e){let t=ROOT_URL+e;const n=new AbortController,s=(setTimeout((()=>{n.abort()}),1e3),await fetch(t,{signal:n.signal}));if(!s.ok){const e=`An error has occured: ${s.status}`;throw conn_status=0,new Error(e)}return await s.json()}async function send_json(e,t){let n=ROOT_URL+e;const s=await fetch(n,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:t});if(!s.ok){conn_status=0;const e=`An error has occured: ${s.status}`;throw new Error(e)}return await s.json()}function get_system_info(){return get_json("api/system/info").then((e=>{console.log("Received settings: "+e),document.getElementById("about").innerHTML="DroneBridge for ESP32 - v"+e.major_version+"."+e.minor_version+" - esp-idf "+e.idf_version})).catch((e=>(conn_status=0,e.message,-1))),0}function update_conn_status(){conn_status?document.getElementById("web_conn_status").innerHTML='<span class="dot_green"></span> connected to ESP32':(document.getElementById("web_conn_status").innerHTML='<span class="dot_red"></span> disconnected from ESP32',document.getElementById("current_client_ip").innerHTML="")}function get_stats(){get_json("api/system/stats").then((e=>{conn_status=1;let t=parseInt(e.read_bytes);!isNaN(t)&&t>1e3?document.getElementById("read_bytes").innerHTML=t/1e3+" kb":isNaN(t)||(document.getElementById("read_bytes").innerHTML=t+" bytes");let n=parseInt(e.tcp_connected);!isNaN(n)&&n>1?document.getElementById("tcp_connected").innerHTML=n+" clients":isNaN(n)||(document.getElementById("tcp_connected").innerHTML=n+" client");let s=parseInt(e.udp_connected);!isNaN(s)&&s>1?document.getElementById("udp_connected").innerHTML=s+" clients":isNaN(s)||(document.getElementById("udp_connected").innerHTML=s+" client"),document.getElementById("current_client_ip").innerHTML="IP Address: "+e.current_client_ip})).catch((e=>{conn_status=0,e.message}))}function get_settings(){return get_json("api/settings/request").then((e=>{console.log("Received settings: "+e),conn_status=1;for(const t in e)if(e.hasOwnProperty(t)){document.getElementById(t).value=e[t]+""}})).catch((e=>(conn_status=0,e.message,show_toast(e.message),-1))),change_ap_ip_visibility(),change_msp_ltm_visibility(),0}function show_toast(e){Toastify({text:e,duration:5e3,newWindow:!0,close:!0,gravity:"top",position:"center",backgroundColor:"linear-gradient(to right, #b6e026, #abdc28)",stopOnFocus:!0}).showToast()}function save_settings(){send_json("api/settings/change",toJSONString(document.getElementById("settings_form"))).then((e=>{console.log(e),conn_status=1,show_toast(e.msg),get_settings()})).catch((e=>{show_toast(e.message)}))}function trigger_reboot(){get_json("api/system/reboot").then((e=>{show_toast(e.msg)})).catch((e=>{e.message,show_toast(e.message)}))}
</script>
const ROOT_URL=window.location.href;let conn_status=0;function change_ap_ip_visibility(){var e=document.getElementById("ap_ip_div"),t=document.getElementById("ap_channel_div"),n=document.getElementById("esp-now-ap-disclaimer");"2"===document.getElementById("esp32_mode").value?(e.style.display="none",t.style.display="none"):(e.style.display="block",t.style.display="block"),"3"===document.getElementById("esp32_mode").value?n.style.display="block":n.style.display="none"}function change_msp_ltm_visibility(){var e=document.getElementById("msp_ltm_div"),t=document.getElementById("trans_pack_size_div");"1"===document.getElementById("telem_proto").value?(e.style.display="block",t.style.display="none"):(e.style.display="none",t.style.display="block")}function toJSONString(e){let t={},n=e.querySelectorAll("input, select");for(let e=0;e<n.length;++e){let s=n[e],o=s.name,i=s.value;isNaN(Number(i))||0===o.localeCompare("wifi_ssid")||0===o.localeCompare("wifi_pass")?o&&(t[o]=i):o&&(t[o]=parseInt(i))}return JSON.stringify(t)}async function get_json(e){let t=ROOT_URL+e;const n=new AbortController,s=(setTimeout((()=>{n.abort()}),1e3),await fetch(t,{signal:n.signal}));if(!s.ok){const e=`An error has occured: ${s.status}`;throw conn_status=0,new Error(e)}return await s.json()}async function send_json(e,t){let n=ROOT_URL+e;const s=await fetch(n,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",charset:"UTF-8"},body:t});if(!s.ok){conn_status=0;const e=`An error has occured: ${s.status}`;throw new Error(e)}return await s.json()}function get_system_info(){return get_json("api/system/info").then((e=>{console.log("Received settings: "+e),document.getElementById("about").innerHTML="DroneBridge for ESP32 - v"+e.major_version+"."+e.minor_version+" - esp-idf "+e.idf_version})).catch((e=>(conn_status=0,e.message,-1))),0}function update_conn_status(){conn_status?document.getElementById("web_conn_status").innerHTML='<span class="dot_green"></span> connected to ESP32':(document.getElementById("web_conn_status").innerHTML='<span class="dot_red"></span> disconnected from ESP32',document.getElementById("current_client_ip").innerHTML="")}function get_stats(){get_json("api/system/stats").then((e=>{conn_status=1;let t=parseInt(e.read_bytes);!isNaN(t)&&t>1e3?document.getElementById("read_bytes").innerHTML=t/1e3+" kb":isNaN(t)||(document.getElementById("read_bytes").innerHTML=t+" bytes");let n=parseInt(e.tcp_connected);!isNaN(n)&&n>1?document.getElementById("tcp_connected").innerHTML=n+" clients":isNaN(n)||(document.getElementById("tcp_connected").innerHTML=n+" client");let s=parseInt(e.udp_connected);!isNaN(s)&&s>1?document.getElementById("udp_connected").innerHTML=s+" clients":isNaN(s)||(document.getElementById("udp_connected").innerHTML=s+" client");let o=parseInt(e.rssi);!isNaN(o)&&o<0?document.getElementById("current_client_ip").innerHTML="IP Address: "+e.current_client_ip+"<br />RSSI: "+o+"dBm":isNaN(o)||(document.getElementById("current_client_ip").innerHTML="IP Address: "+e.current_client_ip)})).catch((e=>{conn_status=0,e.message}))}function get_settings(){return get_json("api/settings/request").then((e=>{console.log("Received settings: "+e),conn_status=1;for(const t in e)if(e.hasOwnProperty(t)){document.getElementById(t).value=e[t]+""}})).catch((e=>(conn_status=0,e.message,show_toast(e.message),-1))),change_ap_ip_visibility(),change_msp_ltm_visibility(),0}function show_toast(e){Toastify({text:e,duration:5e3,newWindow:!0,close:!0,gravity:"top",position:"center",backgroundColor:"linear-gradient(to right, #b6e026, #abdc28)",stopOnFocus:!0}).showToast()}function save_settings(){send_json("api/settings/change",toJSONString(document.getElementById("settings_form"))).then((e=>{console.log(e),conn_status=1,show_toast(e.msg),get_settings()})).catch((e=>{show_toast(e.message)}))}function trigger_reboot(){get_json("api/system/reboot").then((e=>{show_toast(e.msg)})).catch((e=>{e.message,show_toast(e.message)}))} </script>
</head>
<body>
<div class="container">
Expand Down
7 changes: 6 additions & 1 deletion frontend_src/dronebridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,12 @@ function get_stats() {
document.getElementById("udp_connected").innerHTML = udp_clients + " client"
}

document.getElementById("current_client_ip").innerHTML = "IP Address: " + json_data["current_client_ip"]
let rssi = parseInt(json_data["rssi"])
if (!isNaN(rssi) && rssi < 0) {
document.getElementById("current_client_ip").innerHTML = "IP Address: " + json_data["current_client_ip"] + "<br />RSSI: " + rssi + "dBm"
} else if (!isNaN(rssi)) {
document.getElementById("current_client_ip").innerHTML = "IP Address: " + json_data["current_client_ip"]
}
}).catch(error => {
conn_status = 0
error.message;
Expand Down
8 changes: 8 additions & 0 deletions main/db_esp32_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <esp_vfs_dev.h>
#include <lwip/inet.h>
#include <esp_timer.h>
#include <esp_wifi.h>
#include "esp_log.h"
#include "lwip/sockets.h"
#include "driver/uart.h"
Expand All @@ -32,6 +33,7 @@
#include "db_protocol.h"
#include "tcp_server.h"
#include "db_esp32_control.h"
#include "main.h"

#define UART_NUM UART_NUM_1

Expand Down Expand Up @@ -387,6 +389,12 @@ void control_module_udp_tcp() {
// read: https://esp32developer.com/programming-in-c-c/tasks/tasks-vs-co-routines for reference
vTaskDelay(10/portTICK_PERIOD_MS);
delay_timer_cnt = 0;
if (DB_WIFI_MODE == DB_WIFI_MODE_STA) {
// update rssi variable - set to 0 when not available
if (esp_wifi_sta_get_rssi(&station_rssi) != ESP_OK) {
station_rssi = 0;
}
}
} else {
delay_timer_cnt++;
}
Expand Down
1 change: 1 addition & 0 deletions main/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ extern int DB_UART_BAUD_RATE;
extern uint16_t TRANSPARENT_BUF_SIZE;
extern uint8_t LTM_FRAME_NUM_BUFFER; // Number of LTM frames per UDP packet (min = 1; max = 5)
extern uint8_t MSP_LTM_SAMEPORT; // 0 = no (1607 MSP, 1604 LTM); >0 = yes (1604)
extern int station_rssi; // updated when ESP32 is in station mode and connected to an access point

extern uint32_t uart_byte_count;
extern int8_t num_connected_tcp_clients;
Expand Down
1 change: 1 addition & 0 deletions main/http_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ static esp_err_t system_stats_get_handler(httpd_req_t *req) {
cJSON_AddNumberToObject(root, "tcp_connected", num_connected_tcp_clients);
cJSON_AddNumberToObject(root, "udp_connected", udp_conn_list->size);
cJSON_AddStringToObject(root, "current_client_ip", CURRENT_CLIENT_IP);
cJSON_AddNumberToObject(root, "rssi", station_rssi);
const char *sys_info = cJSON_Print(root);
httpd_resp_sendstr(req, sys_info);
free((void *) sys_info);
Expand Down
3 changes: 2 additions & 1 deletion main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ int32_t DB_UART_BAUD_RATE = 115200;
uint16_t TRANSPARENT_BUF_SIZE = 64;
uint8_t LTM_FRAME_NUM_BUFFER = 1;
uint8_t MSP_LTM_SAMEPORT = 0;
int station_rssi = 0;

struct udp_conn_list_t *udp_conn_list;

Expand Down Expand Up @@ -284,7 +285,7 @@ int init_wifi_clientmode() {
.sta = {
.ssid = "DroneBridge_ESP32_Init",
.password = "dronebridge",
.threshold.authmode = WIFI_AUTH_OPEN
.threshold.authmode = WIFI_AUTH_WEP
},
};
strncpy((char *)wifi_config.sta.ssid, (char *)DEFAULT_SSID, 32);
Expand Down

0 comments on commit df0e164

Please sign in to comment.