Documentation / Integrate / Python scripts

Python scripts

Small command-line tools for every supported host-side operation.

Setup

Place all Python files in one directory. They share opentag_serial.py.

python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install -r requirements.txt

Download all scripts · requirements.txt · opentag_serial.py

Discover ports

Lists serial paths, descriptions, and hardware identifiers.

Download list_ports.py
python3 list_ports.py

Read device info

Requests role, firmware, ID, PHY configuration, counters, and calibration.

Download info.py
python3 info.py /dev/tty.usbmodem1101

Monitor live distance

Prints live range and RSSI. Add --csv for a flat log.

Download monitor.py
python3 monitor.py /dev/tty.usbmodem1201
python3 monitor.py /dev/tty.usbmodem1201 --csv live.csv

Calibrate a pair

Uses the responder stream, trims the outer 10%, writes the new DTU offset, and saves it by hardware ID.

Download calibrate.py
python3 calibrate.py /dev/tty.usbmodem1201 \
  --true-mm 1000 --samples 100
Persistence

The firmware command changes RAM. This script also stores the offset in ~/.config/opentags/calibration.json; the other host scripts reapply it whenever they connect.

Run a static test

Collects a timed responder stream and writes metadata, summary metrics, every sample, exchange time, and RSSI.

Download static_test.py
python3 static_test.py /dev/tty.usbmodem1201 \
  --true-mm 5000 --seconds 60 --output test-5m.csv

Flash firmware

Downloads the current role image and flashes one STM32 DFU device with dfu-util.

Download flash.sh
chmod +x flash.sh
./flash.sh initiator
./flash.sh responder
Responder calibration

The downloaded image contains the default offset. Run calibrate.py, or reconnect through the browser console, after flashing the responder.