CodeAir stream of data to computer

Hi,

It is clear, that CodeAir can run the code inside and execute commands per program uploaded. I wonder if there is a way to keep the connection to computer while off the ground (wifi or bluetooth) and stream data to it (telemetry protocols or similar). Not for control purpose, but rather get proximity measurements, height or other parameters detected by sensors. So that other program can analyse the data from the bots and make use of then (or debug).

Thanks for answering.

Great question! Here’s what CodeAIR can do for telemetry today, and where the limits are:

1. Built-in streaming to CodeSpace (the easy path)

CodeAIR has an “embedded data pipe” that streams sensor values, camera images, and text status to CodeSpace IDE while your program runs. In Python it looks like:

from codeair import pipe, camera
from flight import fly, get_data, RANGERS

get_data(RANGERS, rate=10)   # subscribe to ranger data at 10 Hz

pipe.chart("altitude", height_m)       # live chart in CodeSpace
pipe.chart("prox", front_dist, series="front")
pipe.text("state: hovering")
pipe.image(camera.capture())           # send a camera frame

The catch: this stream goes out over the USB serial connection to the host computer, so it works while the drone is tethered (e.g. on-desk testing, or when you want the drone to process data and log it, then review after a flight). For untethered flight it’s not the right tool on its own.

2. Untethered options

  • 2.4 GHz radio (peer-to-peer): CodeAIR has a radio module that talks to other CodeAIR/CodeX devices — it’s not a standard Wi-Fi/Bluetooth stack a laptop can see directly. A common pattern is to use a second CodeAIR or a CodeX that is connected to the computer as a “ground station” relay: the flying drone radio.send(...) tells the ground unit, which prints/logs to the PC via USB (and can use pipe.chart(...) to visualize).
# On the flying drone
import radio
radio.on(); radio.config(channel=5)
radio.send(f"h={height:.2f},fr={front_mm}")

# On the ground unit (CodeAIR or CodeX tethered to PC)
import radio
radio.on(); radio.config(channel=5)
msg = radio.receive()
if msg:
    print(msg)   # shows up in CodeSpace serial
  • Onboard logging: CodeAIR has an SD card slot (from codeair import sdcard) and a flight recorder. If you just need to analyze data after the flight, logging to /sd and pulling the file afterward is usually the most reliable option.

3. Streaming to an arbitrary custom program (outside CodeSpace)

I’m not sure there’s a documented, supported way to stream live CodeAIR telemetry into a third-party program over Wi-Fi/Bluetooth directly — that’s outside what the drone exposes as a public API today. The closest answers are the radio-relay pattern above plus post-flight SD log analysis. @Kathy @dewing would know best whether there’s anything else in the works or any lower-level hooks worth pointing you at.

Relevant docs:

cc @Kathy @dewing for visibility

Thanks for super fast response. Got it.

It is interesting, that the drones can talk to each other while flying. Nice.

Thanks for the question! Getting real-time telemetry data is very helpful indeed… Let me give a little more information on some methods that @Sam touched on.

In the Fly with Python “Attitude” mission we cover streaming using the `pipe` interface embedded_data – Embedded Data Pipe — Firia Labs 1.4 documentation - as well as how to connect it to the flight data recorder using pipe.connect(). Together those modules give you a really nice way to log telemetry during flight, and play it back in CodeSpace when you reconnect.

But sometimes you want realtime logging… As Sam mentioned, the radio can be used for this!

We have an example project in our Demo Repo that shows how to use a CodeX as a remote monitor to receive telemetry data. Run this on a CodeX: Bitbucket

And then on the CodeAIR you need a snippet of Python code that sends JSON formatted log messages over the radio. The following will enable your CodeAIR to call log_radio(“Hello!”) and see a timestamped message appear on the CodeX:

import json

rf_chan = 0
rf_id = 0

def radio_send(op, args=()):
    """Transmit a CodeAIR packet (ch, id, op, args) to paired CodeAIR"""
    msg = json.dumps((rf_chan, rf_id, op, args))
    radio.send(msg)

def log_radio(message):
    radio_send("prt", message)

Glad you’re exploring this. Keep us posted on how it goes!

Thanks,

  • David