A complete guide to using the edLoRa protocol library in Python.
The edlora library is a Python library for ground stations communicating with rockets using the edLoRa binary protocol.
edlora)MsgType EnumDefines the structure and intention of the message payload:
MsgType.HEARTBEAT (0x00)MsgType.GPS (0x01)MsgType.ALTIMETER (0x02)MsgType.IMU (0x03)MsgType.COMMAND (0x04)MsgType.SYS_STATE (0x05)MsgType.ORIENTATION (0x06)MsgType.EVENT (0x07)MsgType.VELOCITY (0x08)MsgType.ACK (0xFD)MsgType.ERROR_MSG (0xFE)MsgType.CUSTOM (0xFF)Packet ClassThe core data structure encapsulating a message. It handles the framing, validation, and payload.
Constants:
Packet.SYNC_BYTE = 0xEDPacket.BROADCAST_ID = 0xFFPacket.MAX_PAYLOAD_SIZE = 240Initialization:
from edlora import Packet, MsgType
packet = Packet(
sender_id=0, # ID of sender (0-255)
receiver_id=0, # Target ID or 0xFF for broadcast (0-255)
version=0x02, # Protocol Version (Fixed per spec)
flags=0, # Bitwise attributes (e.g. ACK_REQUIRED)
msg_type=MsgType.CUSTOM, # The message type (MsgType enum)
seq_num=0, # Packet sequence number (0-255)
timestamp=0, # Timestamp in milliseconds (32-bit uint)
payload=b"" # Raw payload bytes
)
Packing & Unpacking (Binary Serialization):
packet.pack() -> bytes
Returns the full packet bytes ready for transmission, including sync byte, header, payload, and the Little Endian CRC16 checksum. Validates fields before packing.Packet.unpack(buffer: bytes) -> Packet
Class method that parses received bytes back into a Packet object. Automatically validates the SYNC_BYTE, payload length, and the CRC16 checksum. Raises ValueError on bad packets.Helpful Methods:
packet.is_targeted_to(my_id: int) -> bool
Checks if the packet receiver_id matches my_id or 0xFF (broadcast).packet.create_ack(my_id: int, current_timestamp: int) -> Packet
Generates an acknowledgment packet targeted back to the sender containing the original seq_num as a 1-byte payload.packet.set_payload_string(text: str)
Encodes a UTF-8 string directly into the payload bytes, truncating to MAX_PAYLOAD_SIZE.packet.get_payload_string() -> str
Decodes the payload bytes back to a UTF-8 string (uses errors='replace').XorCipher ClassA lightweight cryptographic cipher for obfuscating payloads.
from edlora.crypto import XorCipher
# Note: depending on imports, it might also be accessed as `from edlora_crypto import XorCipher` as shown in README docs.
cipher = XorCipher(key=0xAA)
encrypted_packet = cipher.process(packet) # Processes payload IN-PLACE
process() mutates packet.payload and returns the same packet object.
import time
from edlora import Packet, MsgType
# 1. Create a packet
tx_packet = Packet(
sender_id=0xFF, # Ground Station ID
receiver_id=0x10, # Target Rocket ID
msg_type=MsgType.COMMAND,
seq_num=42,
timestamp=int(time.time() * 1000) % 0xFFFFFFFF
)
# 2. Set the payload
tx_packet.set_payload_string("DEPLOY PARACHUTE")
# 3. Get bytes for transmission
bytes_to_send = tx_packet.pack()
# Write `bytes_to_send` to your serial/USB LoRa module
# serial_port.write(bytes_to_send)
from edlora import Packet, MsgType
import struct
# Receive raw bytes from your LoRa module
# rx_bytes = serial_port.read(...)