Issue Summary
Integrating a FLIR Lepton 3.5 via a PureThermal breakout board onto a headless 1588g drone presents a critical failure point. If the Python radiometric script encounters a fatal error or is killed unexpectedly, it leaves the SPI file descriptor open. The sensor locks the bus, the stream dies, and the headless Pi cannot re-establish the connection without a physical power cycle mid-flight.
Hardware & Software
- Hardware: Raspberry Pi 3 A+, FLIR Lepton 3.5, Custom AeroTherm Chassis
- Software Stack: Python, spidev library, systemd, Linux
Fault Tolerance Protocol
- Initialize the Bus: Open the SPI port and explicitly define the max speed (16MHz) for the VoSPI stream.
- Isolate Execution: Wrap the core extraction logic inside a dedicated daemonized thread utilizing a strict try/except block.
- Enforce Hardware Release: Utilize a
finallyblock to guarantee thespi.close()command executes, even on a fatal crash, releasing the bus for immediate systemd restart.
Example
This is the bare-metal logic used to ensure the sensor re-initializes successfully during a mid-flight daemon crash:
import spidev
def thermal_capture_thread():
spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 16000000
try:
while True:
frame = get_lepton_frame(spi)
process_thermal_data(frame)
except Exception as e:
log_fatal_error(e)
finally:
# Guaranteed execution to release hardware
spi.close()
print("SPI bus released. Ready for safe restart.")