function to create a packet

Hi,

I'm would like to write an arduino function that creates a packet to be transmitter over a radio.

I don't have much experience with arduino. Could somebody point me in the general direction how to do this?

In the header I want to put

  • the baord ID (2 bytes)

and the payload

  • temperature value (2 bytes)
  • humidity value (2 bytes)

Appreciate any guidance.

Kind regards
Conor

How will the data be sent to the transmitter? Depending on how you need to send it, you might organize it as a structure. Then you could fill in the structure members of the packet, treating each one as a string. The sample below shows one way to package the data and display it on the Serial monitor:

struct messagePacket {
   char boardID[3];        // You need the extra byte for the null string termination character, '\0'
   char temperature[3];
   char humidity[3];
};

struct messagePacket myPacket;


void setup() {
  
  struct messagePacket myPacket;

  Serial.begin(9600);
  strcpy(myPacket.boardID, "01");
  strcpy(myPacket.temperature, "75");
  strcpy(myPacket.humidity, "90");

  Serial.print("ID = ");
  Serial.println(myPacket.boardID);
  Serial.print("temperature = ");
  Serial.println(myPacket.temperature);
  Serial.print("humidity = ");
  Serial.println(myPacket.humidity);
  
}

void loop() {

}

The advantage of a structure is that it can keep dissimilar data types within a single data item.

Hi,

I'm using the this arduino module for the radio

https://www.cooking-hacks.com/documentation/tutorials/extreme-range-lora-sx1272-module-shield-arduino-raspberry-pi-intel-galileo#step3_2

If you go the section - "Transmission without ACK" and expand the code.

Instead of message 1 and 2 in the example, I would like to pass the message.

Will this work?

Thanks

Do you have the hardware they suggested you buy? If so, have you tried their sample code? If so, what happened? Since I've never used this system, I have no idea what should/will happen.

Hi EcoJack,

If you had time, would you mind showing me how you unpack a structure when it is received and assign each bit to a variable?

Could I say for example:

ID = myPacket.boardID

Thanks