MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / upsert_network

Method upsert_network

wardriving.py:362–483  ·  view source on GitHub ↗

Insert or update a discovered network (thread-safe).

(self, bssid, ssid, security, channel, frequency,
                       rssi, lat, lon, alt, speed, hdop, interface='')

Source from the content-addressed store, hash-verified

360 mcc TEXT DEFAULT '',
361 mnc TEXT DEFAULT '',
362 lac TEXT DEFAULT '',
363 tech TEXT DEFAULT '',
364 provider TEXT DEFAULT '',
365 signal_dbm INTEGER DEFAULT -120,
366 band_freq TEXT DEFAULT '',
367 latitude REAL,
368 longitude REAL,
369 first_seen TEXT NOT NULL,
370 last_seen TEXT NOT NULL,
371 scan_count INTEGER DEFAULT 1,
372 gps_backfilled INTEGER DEFAULT 0
373 )
374 """)
375 conn.execute("""
376 CREATE UNIQUE INDEX IF NOT EXISTS idx_cell ON cell_towers(cell_id)
377 """)
378 # Zigbee / IEEE 802.15.4 devices seen by a companion with a
379 # 2.4 GHz 802.15.4 radio (e.g. HuginnESP on an ESP32-C5). Keyed by
380 # the device identity: its 64-bit extended address (EUI-64) when the
381 # frame carries one, otherwise "<panid>:<short>" as a fallback.
382 conn.execute("""
383 CREATE TABLE IF NOT EXISTS zigbee_devices (
384 id INTEGER PRIMARY KEY AUTOINCREMENT,
385 addr TEXT NOT NULL,
386 panid TEXT DEFAULT '',
387 short_addr TEXT DEFAULT '',
388 device_type TEXT DEFAULT '',
389 proto TEXT DEFAULT 'zigbee',
390 rssi INTEGER DEFAULT -100,
391 best_rssi INTEGER DEFAULT -100,
392 lqi INTEGER DEFAULT 0,
393 channel INTEGER DEFAULT 0,
394 latitude REAL,
395 longitude REAL,
396 altitude REAL,
397 best_lat REAL,
398 best_lon REAL,
399 first_seen TEXT NOT NULL,
400 last_seen TEXT NOT NULL,
401 scan_count INTEGER DEFAULT 1,
402 gps_backfilled INTEGER DEFAULT 0
403 )
404 """)
405 conn.execute("""
406 CREATE UNIQUE INDEX IF NOT EXISTS idx_zigbee_addr ON zigbee_devices(addr)
407 """)
408 # Migrate older networks / cell_towers tables that predate the
409 # GPS-backfill flag. Table names here are hardcoded literals, so
410 # the f-string interpolation carries no injection risk.
411 for _tbl in ('networks', 'cell_towers'):
412 try:
413 cols = {r[1] for r in conn.execute(f"PRAGMA table_info({_tbl})").fetchall()}
414 if 'gps_backfilled' not in cols:
415 conn.execute(f"ALTER TABLE {_tbl} ADD COLUMN gps_backfilled INTEGER DEFAULT 0")
416 except Exception:
417 pass
418 # Add the 802.15.4 protocol column (zigbee/thread/802.15.4) to
419 # zigbee_devices tables created before Thread classification existed.

Callers 4

import_wigle_csvMethod · 0.95
_scan_loopMethod · 0.80
_parse_serial_lineMethod · 0.80
_flush_serial_entryMethod · 0.80

Calls 5

addMethod · 0.80
errorMethod · 0.80
connectMethod · 0.45
fetchoneMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected