Bluetooth Monitor WIP
This commit is contained in:
@@ -103,20 +103,16 @@ def filter_distance(dist: float):
|
||||
|
||||
|
||||
async def on_device_found_callback(irks, mqtt_client, room, device, advertising_data):
|
||||
decoded_device_id = decode_address(device.address, irks)
|
||||
#decoded_device_id = decode_address(device.address, irks)
|
||||
rssi = advertising_data.rssi
|
||||
tx_power = advertising_data.tx_power
|
||||
if decoded_device_id and tx_power is not None and rssi is not None:
|
||||
topic = f"my_btmonitor/devices/{decoded_device_id}/{room}"
|
||||
distance = estimate_distance(rssi, tx_power, {{my_btmonitor_pl0 | default('73')}} )
|
||||
filtered_distance = filter_distance(distance)
|
||||
data = {"id": decoded_device_id,
|
||||
"name": decoded_device_id,
|
||||
if tx_power is not None and rssi is not None:
|
||||
topic = f"my_btmonitor/raw_measurements/{room}"
|
||||
#distance = estimate_distance(rssi, tx_power, {{my_btmonitor_pl0 | default('73')}} )
|
||||
#filtered_distance = filter_distance(distance)
|
||||
data = {"address": device.address,
|
||||
"rssi": rssi,
|
||||
"tx_power": tx_power,
|
||||
"distance": filtered_distance,
|
||||
"unfiltered_distance": distance,
|
||||
}
|
||||
"tx_power": tx_power}
|
||||
try:
|
||||
await mqtt_client.publish(topic, json.dumps(data).encode())
|
||||
except Exception:
|
||||
@@ -132,8 +128,8 @@ async def main():
|
||||
while True:
|
||||
try:
|
||||
async with asyncio_mqtt.Client(hostname=mqtt_conf["hostname"],
|
||||
username=mqtt_conf["username"],
|
||||
password=mqtt_conf['password']) as mqtt_client:
|
||||
username=mqtt_conf["username"],
|
||||
password=mqtt_conf['password']) as mqtt_client:
|
||||
cb = partial(on_device_found_callback, config['irk_to_devicename'], mqtt_client, mqtt_conf['room'])
|
||||
active_scan = True
|
||||
if active_scan:
|
||||
|
||||
Reference in New Issue
Block a user