Skip to content

Commit daa9664

Browse files
committed
fix: device discovery
1 parent 4802b0d commit daa9664

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ services:
1414
environment:
1515
- PORT=8080
1616
- FIRMWARE_DIR=/app/firmware
17-
- API_URL=http://localhost:5001
18-
- API_TOKEN=paste_your_token_here
1917
- RUST_LOG=none,backend=debug
2018
- DEVICE_LOGS=/logs
2119
- SOCKET_PATH=/app/sock/socket.sock

src/bluetooth.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use anyhow::Result;
22
use btleplug::api::{Central, Manager as _, Peripheral, ScanFilter};
33
use btleplug::platform::Manager;
44

5-
const FKM_UUID: uuid::Uuid = uuid::Uuid::from_u128(0xf254a578_ef88_4372_b5f5_5ecf87e65884);
6-
const SET_WIFI_UUID: uuid::Uuid = uuid::Uuid::from_u128(0xbcd7e573_b0b2_4775_83c0_acbf3aaf210c);
5+
//const FKM_UUID: uuid::Uuid = uuid::uuid!("f254a578-ef88-4372-b5f5-5ecf87e65884");
6+
const SET_WIFI_UUID: uuid::Uuid = uuid::uuid!("bcd7e573-b0b2-4775-83c0-acbf3aaf210c");
77

88
pub async fn start_bluetooth_task() -> Result<()> {
99
let manager = Manager::new().await?;
@@ -39,9 +39,7 @@ async fn bluetooth_task() -> Result<()> {
3939
loop {
4040
tokio::time::sleep(std::time::Duration::from_secs(5)).await;
4141

42-
let filter = ScanFilter {
43-
services: vec![FKM_UUID],
44-
};
42+
let filter = ScanFilter { services: vec![] };
4543
adapter.start_scan(filter).await?;
4644

4745
tokio::time::sleep(std::time::Duration::from_secs(5)).await;
@@ -51,7 +49,12 @@ async fn bluetooth_task() -> Result<()> {
5149
.await?
5250
.ok_or_else(|| anyhow::anyhow!("No device properties found!"))?;
5351

54-
let is_fkm = properties.services.contains(&FKM_UUID);
52+
//let is_fkm = properties.services.contains(&FKM_UUID);
53+
let is_fkm = properties
54+
.local_name
55+
.as_ref()
56+
.unwrap_or(&String::new())
57+
.starts_with("FKM-");
5558
if !is_fkm {
5659
continue;
5760
}
@@ -72,8 +75,11 @@ async fn bluetooth_task() -> Result<()> {
7275
}
7376

7477
async fn setup_bt_device(device: btleplug::platform::Peripheral) -> Result<()> {
75-
tracing::trace!("Connecting to device");
76-
device.connect().await?;
78+
if !device.is_connected().await? {
79+
tracing::trace!("Connecting to device");
80+
device.connect().await?;
81+
}
82+
7783
tracing::trace!("Connected to device");
7884
device.discover_services().await?;
7985
tracing::trace!("Discovered services");

0 commit comments

Comments
 (0)