This document details the Python application designed to interface with LD-350 lightning detectors. The application reads data, converts it to NMEA format, and transmits it over MQTT.
- Python Version: 3.10+
- Dependencies:
usb.core
usb.util
paho.mqtt.client
threading
sys
time
- Hardware: LD-350 Lightning Detector with a USB connection.
- Device Identification: Uses vendor ID (
0x0403
) and product ID (0xf241
). - Kernel Driver Handling: Detaches the kernel driver if active to allow direct USB communication.
- Interface Management: Claims interface 0 for exclusive device access.
- Endpoint Configuration: Sets up endpoints for sending and receiving data.
- Broker Configuration: Connects to the MQTT broker at
broker.mqtt.cool
on port 1883. - Client Initialization: Sets up the MQTT client with a unique ID derived from the current timestamp.
- Callbacks: Establishes functions to handle connections and message publishing events.
- Continuous Reading: Reads data packets from the USB continuously.
- Error Handling: Implements robust error handling to manage USB communication errors.
- Format Conversion: Converts raw USB data to ASCII, excluding null bytes, and formats into NMEA sentences.
- MQTT Publishing: Sends formatted data to a specified MQTT topic, managing message queuing and asynchronous delivery.
- File Writing: Periodically writes NMEA data to
nmea_output.txt
for logging purposes. - File Maintenance: Uses a daemon thread to clear the output file every 120 seconds to manage data storage effectively.
- USB Connection Maintenance: Sends a keep-alive packet every second to maintain the USB connection. This is ESSENTIAL for continued output, and has to be sent in HEX to the LD-350.
- Background File Clearing: A daemon thread clears the output file at regular intervals, preventing application termination due to this thread.
- USB Communication Issues: Addressed through comprehensive error handling and retry strategies.
- MQTT Connection Stability: Implemented reconnection mechanisms for network connectivity issues.
This application integrates hardware interfacing, real-time data processing, and network communication to monitor and analyze lightning data effectively. Future enhancements could include dynamic configuration features and broader device support.