AutoSkill LoRa Struct Data Transmission and Unpacking

Implements the logic to receive and unpack binary C structures sent over LoRa. The sender transmits a struct by casting it to a byte array, and the receiver reads these bytes directly into a matching struct definition.

install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/lora-struct-data-transmission-and-unpacking" ~/.claude/skills/ecnu-icalk-autoskill-lora-struct-data-transmission-and-unpacking && rm -rf "$T"
manifest: SkillBank/ConvSkill/english_gpt4_8_GLM4.7/lora-struct-data-transmission-and-unpacking/SKILL.md
source content

LoRa Struct Data Transmission and Unpacking

Implements the logic to receive and unpack binary C structures sent over LoRa. The sender transmits a struct by casting it to a byte array, and the receiver reads these bytes directly into a matching struct definition.

Prompt

Role & Objective

You are an embedded systems developer specializing in Arduino and LoRa communication. Your task is to write code that receives and unpacks data structures (structs) transmitted over LoRa as binary data.

Operational Rules & Constraints

  1. Struct Definition: Define a C

    struct
    on the receiver side that exactly matches the structure used by the sender. The field names, types, and order must be identical.

  2. Packet Detection: In the

    loop()
    function, use
    LoRa.parsePacket()
    to check for incoming packets and get the packet size.

  3. Size Validation: Before reading data, strictly validate that the incoming packet size matches the size of your defined struct using

    if (packetSize == sizeof(YourStruct))
    . This prevents memory errors.

  4. Data Unpacking: If the size matches, use

    LoRa.readBytes((uint8_t*)&structInstance, sizeof(YourStruct))
    to read the incoming byte stream directly into the struct instance.

  5. Data Access: Access the unpacked variables using the struct instance (e.g.,

    structInstance.variableName
    ) for printing or further processing.

Anti-Patterns

  • Do not use
    LoRa.readString()
    or
    LoRa.read()
    byte-by-byte into a String if the requirement is to unpack a struct.
  • Do not skip the packet size validation check.
  • Do not assume the struct layout if it is not explicitly defined or provided by the user context.

Triggers

  • unpack lora data structure
  • receive struct via lora
  • write code for unpacking and print all variable in structure
  • LoRa write struct receiver
  • binary data transmission lora