Remote radios¶
Host radios on one machine and use them from another, or share one radio between several programs on the same
machine (pip install pysdrlib[remote]). A remote device is a normal Device. The reference (ownership, need/want
matching, shared memory, relays, wire formats, monitoring counters, security) is the
pysdrlib.remote page.
Warning
There is no authentication or encryption. Anyone who can reach a server can list its devices, receive samples
and claim any uncontrolled device. The server binds to 127.0.0.1 unless told otherwise; bind it to a network
only if you trust that network, or tunnel the ports (SSH, a VPN).
Quick start¶
On the machine with the radios:
From anywhere that can reach it:pysdrlib client tcp://host:5555 list
pysdrlib client tcp://host:5555 rx hackrf --freq 100e6 --rate 10e6 -t 5 -o out.cfile
From Python (here with the server in the same process, on the simulated radio):
server = Server("tcp://127.0.0.1:0", devices=["sim"]) # port 0: any free one (server.endpoint says which)
server.start() # or server.serve_forever()
sdr = pysdrlib.connect(address, "sim", program="example") # a new device on the server: you control it
sdr.initialize(cf=100e6, Fs=2e6)
sdr.start_rx()
x = sdr.read(65536) # complex64, like any device
view = pysdrlib.connect(address, sdr.id) # another program attaches to the same device
y, m = view.read(65536, meta=True) # the same stream, at its own pace; it can't retune it
with Client(address) as c:
print(c.types()) # device types the server can open
print(c.list()) # the devices it hosts, who controls each
print(c.metrics(sdr.id)["devices"]) # what it has published, to whom (`pysdrlib client ... stats`)
The first client to open a device type controls it. Others attach to its id (sim-0, hackrf-0) as viewers:
they receive the same stream but can't change it. claim=True (or sdr.claim()) takes control of a device nobody
controls. A program on the server's machine takes samples through shared memory, so five readers cost little more than
one.
A controller the server stops hearing from (longer than --lease) loses control: it logs that, is_controller turns
False and write raises err.NotController. sdr.claim() takes control again if nobody else has.
Letting the server pick¶
sdr = pysdrlib.connect(addr, program="pyspecan",
need={"freq": 433e6, "rate": 2e6}, # a radio that cannot do this is no use to me
want={"freq": 433.92e6, "rate": 10e6}) # and of those, the nearest to this is best
sdr.id, sdr.granted # which radio, and what it can do nearest to `want`
sdr = pysdrlib.connect(addr, "hackrf", serial="0000...c3", program="recorder") # a specific unit
sdr = pysdrlib.connect(addr, label="RX-888", program="recorder") # a unit whose label contains this
program is shown next to the radio you control (pysdrlib client ADDRESS list), so someone who finds a radio busy can
see who has it.
Finding servers¶
pysdrlib server --bind tcp://0.0.0.0:5555 --advertise # announce over mDNS (--advertise-name NAME)
pysdrlib discover --list # every server announcing itself, and what each has
for s in pysdrlib.remote.discover(timeout=2): # [{"name", "address", "addresses", "kind", ...}]
with Client(s["address"]) as c:
print(s["name"], c.types(), c.list(), c.available())
sdr = pysdrlib.connect(need={"freq": 433e6, "rate": 2e6}) # no address: the best radio of every server found
sdr = pysdrlib.connect(device="hackrf") # a server with a HackRF attached
Sharing a radio between programs on one machine¶
Run pysdrlib server next to the radio and let each program connect to it. One controls it; the others watch.
sdr = pysdrlib.connect("ipc:///tmp/pysdrlib", "hackrf") # the one that tunes and records
sdr.initialize(cf=100e6, Fs=10e6); sdr.start_rx()
view = pysdrlib.connect("ipc:///tmp/pysdrlib", sdr.id) # another program: a spectrum display, say
x = view.read(65536) # the same stream, at its own pace
Relaying a radio on another machine¶
Several programs on a machine that is not the radio's would each pull their own copy of the stream across the network. A relay takes it once and shares it locally:
sdr = pysdrlib.connect("tcp://127.0.0.1:5556", "hackrf-0", claim=True) # the relay is at 127.0.0.1:5556 (--bind)
Command line¶
pysdrlib server [--bind ENDPOINT] [--port-range LOW-HIGH] [--devices a,b] [--open TYPE[:KEY=VALUE,...]]... [--allow-arg TYPE:KEY,KEY]... [--max-devices N] [--frontends FILE] [--wire FMT] [--lease S] [--no-shm] [--advertise [--advertise-name NAME]] [--stats-interval S] [-v]
pysdrlib relay ADDRESS (DEVICE | --open TYPE) [--bind ENDPOINT] [--control auto|yes|no] [--name ID] [--timeout S] [--lease S] [--no-shm] [--advertise [--advertise-name NAME]] [-v]
pysdrlib client ADDRESS [--timeout S] COMMAND
pysdrlib discover [--timeout S] [--list] [--all-versions]
| Client command | What it does |
|---|---|
list |
Device types the server allows and the devices it hosts |
stats [DEVICE] [--json] |
What each hosted device has published, to how many subscribers, and what was lost |
info DEVICE |
A hosted device's capabilities, as JSON |
rx TYPE -o FILE [-f FORMAT] [--sigmf] (-n SAMPLES \| -t SECONDS) |
Open a device (--arg KEY=VALUE for its open()), configure it (--freq, --rate, --rx-gain, --set KEY=VALUE) and record |
watch DEVICE -o FILE (-n \| -t) |
Record from an already hosted device without controlling it |
set DEVICE KEY=VALUE... |
Change settings on a hosted device (takes control briefly) |
tx TYPE -i FILE |
Open a device, configure it (--freq, --rate, --tx-gain, --set) and transmit; --loop repeats |
- Recordings are raw
complex64(GNU Radio.cfile) unless-f FORMATpicks another (ci16,ci8,cu8...). Integer formats saturate at full scale. - An output ending in
.sigmf, or--sigmf, records SigMF, with the sample rate, the frequency, every retune and where samples were lost. - Transmit files are raw
complex64. --open TYPE:KEY=VALUE,...(server) passes arguments to a device'sopen(): a recording to serve (--open file:path=cap.sigmf,loop=true), or a TCP stream's address (--open tcpiq:host=10.0.0.5,port=1234).--arg KEY=VALUE(client) does the same from a client, but a server refuses what names a host or a file unless its operator allows it (--allow-arg tcpiq:host,port,sample_format): see Security in thepysdrlib.remotepage.- A
serialoraddris taken as text (--arg serial=00000001keeps its zeros) and may not contain,or=. --port-rangelimits the ports the per-device sockets use, which is what you open in a firewall.python -m pysdrlibis the same as thepysdrlibcommand.
Transmitting is a real RF emission: start with --tx-gain 0, into a load or an antenna you are licensed to use.