From ee0d5168678cabdde34779089f882cb66caec797 Mon Sep 17 00:00:00 2001 From: Jenny Paxian Date: Sun, 29 Dec 2024 18:23:45 +0100 Subject: [PATCH] Add last seen to ibeacon fakemobileclient --- tools/fakemobileclient.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/fakemobileclient.py b/tools/fakemobileclient.py index 198e2b66..8c78f34b 100644 --- a/tools/fakemobileclient.py +++ b/tools/fakemobileclient.py @@ -22,6 +22,8 @@ from bleak.backends.scanner import AdvertisementData PORT = int(sys.argv[1]) if sys.argv[1:] else 8042 +last_bt_time = {} + ibeacon_format = Struct( "type_length" / Const(b"\x02\x15"), "uuid" / Array(16, Byte), @@ -63,7 +65,15 @@ async def ble_scan(): apple_data = advertisement_data.manufacturer_data[0x004C] ibeacon = ibeacon_format.parse(apple_data) uuid = UUID(bytes=bytes(ibeacon.uuid)) - beacons.append({'uuid': str(uuid), 'major': ibeacon.major, 'minor': ibeacon.minor, 'distance': calc_distance(ibeacon.power, advertisement_data.rssi), 'last_seen_ago': 0 }) + + now = time.time() + if str(uuid) in last_bt_time: + lastTime = last_bt_time[str(uuid)] + else: + lastTime = now + + last_bt_time[str(uuid)] = now + beacons.append({'uuid': str(uuid), 'major': ibeacon.major, 'minor': ibeacon.minor, 'distance': calc_distance(ibeacon.power, advertisement_data.rssi), 'last_seen_ago': lastTime }) except KeyError: # Apple company ID (0x004c) not found pass