Device info
What this example shows
Asking the receiver who it is: its serial number, firmware version and device type, a connection test, the full list of its settings with their current values, and its built-in help text. The script also prints every raw line the receiver sends, so you can see the exchange as it happens, and then returns the receiver to RUN state.
The example code
This is Examples/ADSBReceiver-deviceInfo.py from the pinned module, without
the file's header comment. The script body is exactly as shipped. The UART1
wiring on IO17 and IO18 and the reset on IO21 are the board's own wiring.
from machine import UART
from ADSBReceiver import ADSBReceiver
uart = UART(1, baudrate=115200, rx=17, tx=18, rxbuf=4096)
adsb = ADSBReceiver(uart, reset_pin=21)
# Print every raw line the module sends, useful to see what is really happening.
adsb.onLine(lambda line: print("[module] " + line))
# Only in CONFIGURATION state can settings be read or written.
print("Entering CONFIGURATION state...")
if not adsb.enterConfiguration():
print("Failed to enter CONFIGURATION state.")
else:
# Read the module's serial number.
ok, value = adsb.getSerialNumber()
if ok:
print("Serial number: {}".format(value))
# Read the currently installed firmware version.
ok, value = adsb.getFirmwareVersion()
if ok:
print("Firmware version: {}".format(value))
# Read the device type string reported by the module.
ok, value = adsb.getDeviceType()
if ok:
print("Device type: {}".format(value))
# Simple connectivity check, the module should always answer AT+OK.
print("Connection test (AT+TEST): {}".format("OK" if adsb.test() else "FAILED"))
# Ask the module to list every setting and its current value.
print()
print("--- AT+SETTINGS? ---")
ok, settings = adsb.getAllSettings()
if ok:
print(settings)
# Ask the module for its full built-in help text.
print()
print("--- AT+HELP ---")
ok, help_text = adsb.getFullHelp()
if ok:
print(help_text)
# Leave CONFIGURATION and resume normal aircraft tracking.
print()
print("Returning to RUN state...")
adsb.exitConfiguration(115200) # must match the BAUDRATE setting printed above
Save it to a file on your computer, then run it on the board with
mpremote run <file.py>, putting your file's name in place of <file.py>. It
needs the module installed as shown on the
MicroPython Library page.
Expected result
The script runs once and exits. It prints Entering CONFIGURATION state...,
then the Serial number:, Firmware version: and Device type: lines, the
Connection test (AT+TEST): line, the settings listing under --- AT+SETTINGS? ---, the help text under --- AT+HELP --- and finally Returning to RUN state.... Each reply line from the receiver is also printed with a [module]
prefix, because of the onLine() function. The values come from the receiver
itself.
Entering CONFIGURATION state...
[module] AT+OK
[module] AT+CONFIG=1
[module] AT+SERIAL_NUMBER=33-0004127
Serial number: 33-0004127
[module] AT+FIRMWARE_VERSION=2.89.28.0
Firmware version: 2.89.28.0
[module] AT+DEVICE=TT-SC1
Device type: TT-SC1
[module] AT+OK
Connection test (AT+TEST): OK
--- AT+SETTINGS? ---
[module] AT+BAUDRATE=0
[module] AT+BOOT=0
[module] AT+CONFIG=1
[module] AT+DEVICE=TT-SC1
[module] AT+FIRMWARE_VERSION=2.89.28.0
[module] AT+LOCK=0
[module] AT+SERIAL_NUMBER=33-0004127
[module] AT+SYSTEM_LOG=0
[module] AT+SYSTEM_STATISTICS=0
[module] AT+ADSB_RX_PROTOCOL_DECODED=CSV
[module] AT+ADSB_RX_PROTOCOL_INC=0
[module] AT+ADSB_STATISTICS=CSV
AT+BAUDRATE=0
AT+BOOT=0
AT+CONFIG=1
AT+DEVICE=TT-SC1
AT+FIRMWARE_VERSION=2.89.28.0
AT+LOCK=0
AT+SERIAL_NUMBER=33-0004127
AT+SYSTEM_LOG=0
AT+SYSTEM_STATISTICS=0
AT+ADSB_RX_PROTOCOL_DECODED=CSV
AT+ADSB_RX_PROTOCOL_INC=0
AT+ADSB_STATISTICS=CSV
--- AT+HELP ---
[module] SETTINGS:
[module] SYSTEM:
[module] AT+BAUDRATE=0
[module] AT+BOOT=0
[module] AT+CONFIG=1
[module] AT+DEVICE=TT-SC1
[module] AT+FIRMWARE_VERSION=2.89.28.0
[module] AT+LOCK=0
[module] AT+SERIAL_NUMBER=33-0004127
[module] AT+SYSTEM_LOG=0
[module] AT+SYSTEM_STATISTICS=0
[module] ADSB:
[module] AT+ADSB_RX_PROTOCOL_DECODED=CSV
[module] AT+ADSB_RX_PROTOCOL_INC=0
[module] AT+ADSB_STATISTICS=CSV
[module] COMMANDS:
[module] AT+HELP
[module] AT+REBOOT
[module] AT+REBOOT_BOOTLOADER
[module] AT+SETTINGS_DEFAULT
[module] AT+TEST
AT+BAUDRATE=0
AT+BOOT=0
AT+CONFIG=1
AT+DEVICE=TT-SC1
AT+FIRMWARE_VERSION=2.89.28.0
AT+LOCK=0
AT+SERIAL_NUMBER=33-0004127
AT+SYSTEM_LOG=0
AT+SYSTEM_STATISTICS=0
AT+ADSB_RX_PROTOCOL_DECODED=CSV
AT+ADSB_RX_PROTOCOL_INC=0
AT+ADSB_STATISTICS=CSV
AT+HELP
AT+REBOOT
AT+REBOOT_BOOTLOADER
AT+SETTINGS_DEFAULT
AT+TEST
Returning to RUN state...
[module] AT+OK
[module] AT+CONFIG=0
If the receiver does not enter CONFIGURATION state, the script prints Failed to enter CONFIGURATION state. and stops.
Functions used
ADSBReceiver(uart, reset_pin=None)returns ADSBReceiverCreates the receiver object on a UART you have already opened. If you give a reset pin, the module makes it a high-impedance input, so the pin is only driven during hardwareReset().
ReturnsA receiver object ready for the other functions.
Parameters
| Type | Name | Description |
|---|---|---|
machine.UART | uart | An open UART connected to the receiver. Size its receive buffer when you create it, as the example does with rxbuf=4096: dense traffic can overflow the default buffer and corrupt lines. |
int or None | reset_pin | GPIO wired to the receiver's RESET pin. Optional, default None, which disables hardwareReset(). This board uses 21. |
onLine(cb)returns NoneRegisters a function that is called for every complete line received, before the line is parsed. It is handy for seeing exactly what is on the wire while you debug. Replies to AT commands reach it too.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
function or None | cb | The function to call, given the line as a string. None removes it. |
enterConfiguration()returns boolMoves the receiver from RUN to CONFIGURATION state. It sends AT+CONFIG=1, switches the UART to 115200 (the receiver's fixed CONFIGURATION baud rate) and confirms the new state with AT+CONFIG?. Settings can only be read and written in this state.
ReturnsTrue if the receiver reports being in CONFIGURATION state, False otherwise.
getSerialNumber()returns tuple(bool, str)Asks the receiver for its serial number (AT+SERIAL_NUMBER?).
Returns(True, serial number) on success, (False, empty string) otherwise.
getFirmwareVersion()returns tuple(bool, str)Asks the receiver for its installed firmware version (AT+FIRMWARE_VERSION?).
Returns(True, firmware version) on success, (False, empty string) otherwise.
getDeviceType()returns tuple(bool, str)Asks the receiver for its device type string (AT+DEVICE?).
Returns(True, device type) on success, (False, empty string) otherwise.
test()returns boolA connection check. It sends AT+TEST and expects the receiver to answer AT+OK.
ReturnsTrue if the receiver answered AT+OK, False otherwise.
getAllSettings()returns tuple(bool, str)Asks the receiver to list every setting and its current value (AT+SETTINGS?). The reply has several lines, and the function collects them until the receiver has been quiet for a moment.
Returns(True, the listing as one string) if any line arrived, False otherwise.
getFullHelp()returns tuple(bool, str)Asks the receiver for its full built-in help text (AT+HELP), collected the same way as the settings listing.
Returns(True, the help text as one string) if any line arrived, False otherwise.
exitConfiguration(run_baud=115200)returns boolMoves the receiver from CONFIGURATION back to RUN state. It sends AT+CONFIG=0, switches the UART to run_baud and confirms the new state with AT+CONFIG?.
ReturnsTrue if the receiver reports being in RUN state, False otherwise.
Parameters
| Type | Name | Description |
|---|---|---|
int | run_baud | The baud rate the receiver's BAUDRATE setting is stored as, for example 115200. Optional, default 115200. |
Putting it together
Enter CONFIGURATION state first: the identity and settings queries only work
there. Every query returns a pair, so check the first value before you use the
second. The comment on the last line of the example says the rate you pass to
exitConfiguration() must match the BAUDRATE setting in the listing the script
printed.