Arduino + LoRa - sending 0x00

Hello! I am new to Arduino and LoRa and need some help.
I managed to transmit data from an Arduino to a Raspberry Pi and back, so communication works.
I want to transmit 1 byte ID, 2 bytes sensor data and 2 bytes counter variable (int) in hex format.

byte data[5];
byte temp1 = byte(temperature);
byte temp2 = (temperature - temp1) *100;

data[0] = ID; // ID = 0x4B
data[1] = temp1;
data[2] = temp2;
data[3] = counter >> 8;
data[4] = counter;

My problem is that the first 3 bytes are transmitted and received correctly, but the counter variable is ignored. If I set any byte to 0x00 the data after is ignored and not sent.

What am I doing wrong here or is it not allowed to transmit 0x00?
Thanks for your help!

My problem is that the first 3 bytes are transmitted and received correctly, but the counter variable is ignored. If I set any byte to 0x00 the data after is ignored and not sent.

That depends a lot on how the content is sent and received. Post complete code (and use code tags)!

Thanks for your reply, that’s my sender code:

#include <SPI.h>
#include <LoRa.h>

int counter = 0;
uint8_t data[9];      

void setup() {
  Serial.begin(9600);
  while (!Serial);

  Serial.println("LoRa Sender");

  if (!LoRa.begin(434E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }

  LoRa.setSpreadingFactor(12);
  LoRa.setSignalBandwidth(250000);
  LoRa.setCodingRate4(8);
  LoRa.enableCrc();
}

void loop() {
  Serial.print("Sending packet: ");
  Serial.println(counter);

  data[0] = 0x1E;
  data[1] = 0x41;
  data[2] = 0x42;
  data[3] = 0x43;
  data[4] = 0x44;
  data[5] = 0x45; 
  data[6] = 0x46;
  data[7] = 0x47;
  data[8] = 0x48;

  // send packet
  LoRa.beginPacket();
  LoRa.print((char*)data);
  LoRa.endPacket();

  counter++;

  delay(3000);
}

and my receiver code:

#include <SPI.h>
#include <LoRa.h>

void setup() {
  Serial.begin(9600);
  while (!Serial);

  Serial.println("LoRa Receiver");

  if (!LoRa.begin(434E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }

  LoRa.setSpreadingFactor(12);
  LoRa.setSignalBandwidth(250000);
  LoRa.setCodingRate4(8);
  LoRa.enableCrc();
}

void loop() {
  // try to parse packet
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    // received a packet
    Serial.print("Received packet '");

    // read packet
    while (LoRa.available()) {
      uint8_t input = (uint8_t)LoRa.read();
      Serial.print(input);
      Serial.print("(0x");
      Serial.print(input, HEX);
      Serial.print(")");
    }

    
    // print RSSI of packet
    Serial.print("' with RSSI ");
    Serial.println(LoRa.packetRssi());
  }
}

The output in putty from the receiver is:

Received packet ‘30(0x1E)65(0x41)66(0x42)67(0x43)68(0x44)69(0x45)70(0x46)71(0x47)72(0x48)’ with RSSI -39
Received packet ‘30(0x1E)65(0x41)66(0x42)67(0x43)68(0x44)69(0x45)70(0x46)71(0x47)72(0x48)1(0x1)’ with RSSI -39
Received packet ‘30(0x1E)65(0x41)66(0x42)67(0x43)68(0x44)69(0x45)70(0x46)71(0x47)72(0x48)2(0x2)’ with RSSI -38
Received packet ‘30(0x1E)65(0x41)66(0x42)67(0x43)68(0x44)69(0x45)70(0x46)71(0x47)72(0x48)3(0x3)’ with RSSI -38

If I write data[5] = 0x00 the receiver output is:

Received packet ‘30(0x1E)65(0x41)66(0x42)67(0x43)68(0x44)’ with RSSI -29
Received packet ‘30(0x1E)65(0x41)66(0x42)67(0x43)68(0x44)’ with RSSI -28
Received packet ‘30(0x1E)65(0x41)66(0x42)67(0x43)68(0x44)’ with RSSI -28

Looks like I solved the problem by using the LoRa.write function instead of the Lora.print function to transmit the data.

  data[0] = 0x1E;
  data[1] = 0x41;
  data[2] = 0x42;
  data[3] = 0x43;
  data[4] = 0x44;
  data[5] = 0x45;
  data[6] = 0x46;
  data[7] = 0x47;
  data[8] = 0x48;

  // send packet
  LoRa.beginPacket();
  LoRa.print((char*)data);
  LoRa.endPacket();

The print method expects a null byte terminated string (character array). Your data hasn't that format so it will send more data until it finds a null byte in memory.

As you found out yourself, the write method allows you to specify the length of the provided data and that way you can transmit any data you like.