Here is quickly written code that works with my C Bluetooth library. It finds devices on the approved[] list.
https://github.com/petzval/btferret
https://github.com/petzval/btferret
Code:
Download btlib.c btlib.h devices.txtSave code below as tag.cCompile gcc tag.c btlib.c -o tag Run sudo ./tag
Code:
#include <stdio.h>#include <stdlib.h>#include "btlib.h"#include <string.h>int main() { int n,k,scan,getout,foundk,foundnode; char *approved[10] = { "00:00:00:00:00:00", // 1st entry must be all 0 "34:78:A3:18:77:08", // list of known addresses "18:EE:69:15:D7:AE", NULL }; if(init_blue("devices.txt") == 0) return(0); for(scan = 0 ; scan < 5 ; ++scan) { // Scan 5 times - each one takes 10 seconds le_scan(); getout = 0; for(n = 1000 ; getout == 0 ; ++n) { foundnode = 0; foundk = -1; k = 0; while(approved[k] != NULL && foundnode == 0) { if(strcmp(device_address(n),approved[k]) == 0) { foundnode = n; foundk = k; } ++k; } if(foundk >= 0) { getout = 1; // foundk = 0 means no match found if(foundk > 0) { // found a known device printf("MATCH FOUND %s\n",device_address(foundnode)); // open device //connect_node(foundnode,CHANNEL_LE,0); // close device //disconnect_node(foundnode); } } } } close_all(); }
Statistics: Posted by petzval — Tue Aug 27, 2024 5:08 pm