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.From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill lora-struct-data-transmission-and-unpackingAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
SKILL.md
2.4 KB, 404 tokens by cl100k_base, as published. Nobody here has run it
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
-
Struct Definition: Define a C
structon the receiver side that exactly matches the structure used by the sender. The field names, types, and order must be identical. -
Packet Detection: In the
loop()function, useLoRa.parsePacket()to check for incoming packets and get the packet size. -
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. -
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. -
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()orLoRa.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
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.