Something went wrong. Try again.
BLE/WiFi guardian USB stick.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687use bt_hci::cmd::le::LeSetScanParams;use bt_hci::controller::ControllerCmdSync;use core::cell::RefCell;use core::default::Default;use embassy_futures::join::join;use embassy_time::{Duration, Timer};use esp_println::println;use heapless::Deque;use trouble_host::prelude::*;
/// Max number of connectionsconst CONNECTIONS_MAX: usize = 1;const L2CAP_CHANNELS_MAX: usize = 1;
pub async fn run<C>(controller: C)where C: Controller + ControllerCmdSync<LeSetScanParams>,{ // Using a fixed "random" address can be useful for testing. In real scenarios, one would // use e.g. the MAC 6 byte array as the address (how to get that varies by the platform). let address: Address = Address::random([0xff, 0x8f, 0x1b, 0x05, 0xe4, 0xff]);
println!("Our address = {:?}", address);
let mut resources: HostResources<DefaultPacketPool, CONNECTIONS_MAX, L2CAP_CHANNELS_MAX> = HostResources::new(); let stack = trouble_host::new(controller, &mut resources).set_random_address(address); let host = stack.build(); let central = host.central; let mut runner = host.runner;
let printer = Printer { seen: RefCell::new(Deque::new()), }; let mut scanner = Scanner::new(central); println!("Running BT scan..."); let _ = join(runner.run_with_handler(&printer), async { let mut config = ScanConfig::default(); config.active = false; config.phys = PhySet::M1; config.interval = Duration::from_secs(2); config.window = Duration::from_millis(50); let mut _session = scanner.scan(&config).await.unwrap(); // Scan forever loop { Timer::after(Duration::from_secs(1)).await; } }) .await;}
struct Printer { seen: RefCell<Deque<BdAddr, 128>>,}
impl EventHandler for Printer { fn on_adv_reports(&self, mut it: LeAdvReportsIter<'_>) { let mut seen = self.seen.borrow_mut(); while let Some(Ok(report)) = it.next() { if seen.iter().find(|b| b.raw() == report.addr.raw()).is_none() { let ad_structure = AdStructure::decode(report.data); println!("New device advertising"); for ad in ad_structure { if let Ok(adv) = ad { match adv { AdStructure::ManufacturerSpecificData { company_identifier, payload: _, } => { // flipper = 3625 if company_identifier == 3625 { println!("flipper found!!!!!"); } } _ => (), } } } if seen.is_full() { seen.pop_front(); } seen.push_back(report.addr).unwrap(); } } }}