sbaratheon:
Is there a relatively simple way of doing this? At the moment, I've just using a simple data format which is a pain to work with e.g.
WAIT_PERIOD_SECS=5, EPOCH=838382, CALLSIGN=station283
Cant see how, apart from sending a packet for each variable.
A LoRa packet is just a series of bytes and the receiver has no way of knowing how to decode these bytes into meaningful data unless you define the variables you want to extract. A structure is the clearest and most obvious (when reading a program listing) way of how to achieve this.
Whilst I have produced example programs for my LoRa library using structures to send and receive data, I avoid structures in general as you cannot be sure the example will work across platforms.
On method I adopted to avoid the use of structures was to build a packet like this (it uses specific Library functions);
LoRa.startWriteSXBuffer(0); //start the write at SX12XX internal buffer location 0
LoRa.writeBufferChar(trackerID, sizeof(trackerID)); //+4 bytes (3 characters plus null (0) at end)
LoRa.writeFloat(latitude); //+4 = 8 bytes
LoRa.writeFloat(longitude); //+4 = 12 bytes
LoRa.writeUint16(altitude); //+2 = 14 bytes
LoRa.writeUint8(satellites); //+1 = 15 bytes
LoRa.writeUint16(voltage); //+2 = 17 bytes
LoRa.writeInt8(temperature); //+1 = 18 bytes total to send
TXPacketL = LoRa.endWriteSXBuffer(); //closes packet write and returns the length of the packet to send
At the receiver you need to read out the variables in the same type and order;
LoRa.startReadSXBuffer(0); //start buffer read at location 0
LoRa.readBufferChar(receivebuffer); //read in the character buffer
latitude = LoRa.readFloat(); //read in the latitude
longitude = LoRa.readFloat(); //read in the longitude
altitude = LoRa.readUint16(); //read in the altitude
satellites = LoRa.readUint8(); //read in the number of satellites
voltage = LoRa.readUint16(); //read in the voltage
temperature = LoRa.readInt8(); //read in the temperature
RXPacketL = LoRa.endReadSXBuffer(); //finish packet read, get received packet length
Accepted its not as clear as using a structure, but it has the very significant advantage of being platform agnostic.
One additional benefit is that the routines above do not use a memory buffer\array for building the packet, variables are written direct to the LoRa devices internal buffer.
The previously mentioned Cayenne uses identifier bytes to describe the type of data that follows, voltage, temperature, GPS co-ordinate etc. Thus the receiver does not actually need to know the structure or variable type of the data sent.