
Wrapper CLI Python per Flipper Zero
Wrapper CLI Python per Flipper Zero

Questa release allinea il wrapper alla CLI corrente di Flipper Zero (validato su hardware reale, firmware unlshd-089e):
info: flipper.info.device_info() / power_info() / power_debug_info() (i comandi moderni info device / info power).power info → info power: flipper.power.info() continua a funzionare e ora legge info power internamente. Aggiunto flipper.power.otg_on()/otg_off().date: usa flipper.date.datetime(); il parsing è stato corretto per il formato di output corrente.KB che KiB, read() ora restituisce il contenuto completo del file su più righe, e le schede exFAT / con etichetta vuota vengono interpretate correttamente (risolve #21).NECext, Kaseikyo, RCA, Pioneer, … sono supportati automaticamente (risolve #15). Nuovo flipper.ir.protocols().debug → sysctl debug, subghz tx/rx ha acquisito l'argomento device richiesto, bt hci_info invariato.scan, dump, emulate, field, apdu, raw, mfu) con helper per la cache delle chiavi Mifare Classic per UID (import_nfc_keys, write_key_cache).ps (→ top), music_player, nfc detect.$ pip install pyflipper
unlshd-089e)from pyflipper import PyFlipper
# Local serial port
flipper = PyFlipper(com="/dev/ttyACM0")
# OR
# Remote serial2websocket server
flipper = PyFlipper(ws="ws://192.168.1.5:1337")
# TCP
flipper = PyFlipper(tcp='192.168.89.222:22170')
# Info (on current firmware this reads `info power` under the hood)
info = flipper.power.info()
# Poweroff
flipper.power.off()
# Reboot
flipper.power.reboot()
# Reboot in DFU mode
flipper.power.reboot2dfu()
# Toggle the 5V OTG pin on the GPIO header
flipper.power.otg_on()
flipper.power.otg_off()
# Install update from .fuf file
flipper.update.install(fuf_file="/ext/update.fuf")
# Backup Flipper to .tar file
flipper.update.backup(dest_tar_file="/ext/backup.tar")
# Restore Flipper from backup .tar file
flipper.update.restore(bak_tar_file="/ext/backup.tar")
# List installed apps
apps = flipper.loader.list()
# Open app
flipper.loader.open(app_name="Clock")
# Get flipper date (datetime object)
date = flipper.date.datetime()
# Get flipper timestamp
timestamp = flipper.date.timestamp()
# Get device info dict (current firmware `info device`, dot-separated keys)
device_info = flipper.info.device_info()
# Get power info dict (current firmware `info power`)
power_info = flipper.info.power_info()
# Extended power/gauge debug info
power_debug = flipper.info.power_debug_info()
# Legacy `device_info` command (underscore-separated keys, still supported)
legacy_info = flipper.device_info.info()
# Get heap info dict
heap = flipper.free.info()
# Get free_blocks string
free_blocks = flipper.free.blocks()
# Get bluetooth info
bt_info = flipper.bt.info()
Compatibilità firmware. Questa libreria è ora pensata per la CLI corrente di Flipper Zero (firmware 1.x, verificata su Unleashed
unlshd-089e). Alcuni comandi legacy sono stati rimossi dal firmware ufficiale e quindi non sono più disponibili:ps(sostituito datopinterattivo),music_playerenfc detect(NFC è ora una sub-shell interattiva).power infoè stato spostato suinfo power,debugsusysctl debugestorageora riporta le dimensioni inKiB— tutto gestito in modo trasparente dai wrapper sopra.
# Get the storage filesystem info
ext_info = flipper.storage.info(fs="/ext")
# Get the storage /ext dict
ext_list = flipper.storage.list(path="/ext")
# Get the storage /ext tree dict
ext_tree = flipper.storage.tree(path="/ext")
# Get file info
file_info = flipper.storage.stat(file="/ext/foo/bar.txt")
# Make directory
flipper.storage.mkdir(new_dir="/ext/foo")
# Read file
plain_text = flipper.storage.read(file="/ext/foo/bar.txt")
# Remove file
flipper.storage.remove(file="/ext/foo/bar.txt")
# Copy file
flipper.storage.copy(src="/ext/foo/source.txt", dest="/ext/bar/destination.txt")
# Rename file
flipper.storage.rename(file="/ext/foo/bar.txt", new_file="/ext/foo/rab.txt")
# MD5 Hash file
md5_hash = flipper.storage.md5(file="/ext/foo/bar.txt")
# Write file in one chunk
file = "/ext/bar.txt"
text = """There are many variations of passages of Lorem Ipsum available,
but the majority have suffered alteration in some form, by injected humour,
or randomised words which don't look even slightly believable.
If you are going to use a passage of Lorem Ipsum,
you need to be sure there isn't anything embarrassing hidden in the middle of text.
"""
flipper.storage.write.file(path=file, text=text)
# Write file using a listener
file = "/ext/foo.txt"
text_one = """There are many variations of passages of Lorem Ipsum available,
but the majority have suffered alteration in some form, by injected humour,
or randomised words which don't look even slightly believable.
If you are going to use a passage of Lorem Ipsum,
you need to be sure there isn't anything embarrassing hidden in the middle of text.
"""
flipper.storage.write.start(file)
time.sleep(2)
flipper.storage.write.send(text_one)
text_two = """All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as
necessary, making this the first true generator on the Internet.
It uses a dictionary of over 200 Latin words, combined with a handful of
model sentence structures, to generate Lorem Ipsum which looks reasonable.
The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.
"""
flipper.storage.write.send(text_two)
time.sleep(3)
# Don't forget to stop
flipper.storage.write.stop()
# Set generic led on (r,b,g,bl)
flipper.led.set(led='r', value=255)
# Set blue led off
flipper.led.blue(value=0)
# Set green led value
flipper.led.green(value=175)
# Set backlight on
flipper.led.backlight_on()
# Set backlight off
flipper.led.backlight_off()
# Turn off led
flipper.led.off()
# Set vibro True or False
flipper.vibro.set(True)
# Set vibro on
flipper.vibro.on()
# Set vibro off
flipper.vibro.off()
# Set gpio mode: 0 - input, 1 - output
flipper.gpio.mode(pin_name=PIN_NAME, value=1)
# Set gpio pin value: 0 - off, 1 - on
flipper.gpio.set(pin_name=PIN_NAME, value=1)
# Read gpio pin value
flipper.gpio.read(pin_name=PIN_NAME)