Skip to content

Instantly share code, notes, and snippets.

@thebentern
Last active August 5, 2024 11:25
Show Gist options
  • Save thebentern/2385f1e7a62d17808665faace9e38df3 to your computer and use it in GitHub Desktop.
Save thebentern/2385f1e7a62d17808665faace9e38df3 to your computer and use it in GitHub Desktop.
Meshtastic BLE device sniffer python
import argparse
import asyncio
import json
import time
from bleak import BleakScanner
SERVICE_UUID = "6ba1b218-15a8-461f-9fa8-5dcae273eafd"
async def main():
while True:
f = open("ble_devices.json", "r+")
jsonDevices = json.load(f)
f.close()
devices = await BleakScanner.discover(
return_adv=True,
service_uuids=[SERVICE_UUID]
)
for d, a in devices.values():
print(d)
found = False
for device in jsonDevices:
if device['mac'] == d.address:
found = True
if found == False:
newDevice = {}
newDevice['mac'] = d.address
newDevice['name'] = d.name
newDevice['rssi'] = d.rssi
jsonDevices.append(newDevice)
with open("ble_devices.json", "w") as f:
json.dump(jsonDevices, f)
time.sleep(3)
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
[Unit]
Description=BLE Sniffer
After=multi-user.target
[Service]
Type=simple
Restart=always
User={user}
ExecStart=python /home/{user}/ble_sniffer.py
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment