Packet format error... what am I doing wrong..

Im trying to send int values from my node but it does not matter what i try it seems the packets get cut off or does not understand the data type.

the Node test code is below

void do_send(osjob_t* j)
{

  // Init declaration
  int val0 = 0;
  int val1 = 9999;
  int val2 = 9999;
  int val3 = 9999;
 
  byte buffer[10] = { val0, val1, val0, val2, val0, val3};

  // Prepare upstream data transmission at the next possible time.
  LMIC_setTxData2(1, buffer, sizeof(buffer) / sizeof(buffer[0]), 0);

  //Serial output of message
  //Serial.println(F("Sending: "));
  for (byte b = 0; b < (sizeof(buffer) / sizeof(buffer[0])); b++) {
    //Serial.print(buffer[b]);
  }


}//do_send()

and the resulted answer after looks like this

0 28675 0 28672 0 0

I am assuming i’m doing something wrong with the data types or they why the buffer is sent?

byte buffer[10]

byte range is 0-255. You cant store 9999 in it.

Correct, I agree but this is what is confusing

this code

void do_send(osjob_t* j)
{

  // Init declaration
  int val0 = 9;
  int val1 = 254;
  int val2 = 254;
  int val3 = 254;
 
  byte buffer[10] = { val0, val1, val0, val2, val0, val3};

  // Prepare upstream data transmission at the next possible time.
  LMIC_setTxData2(1, buffer, sizeof(buffer) / sizeof(buffer[0]), 0);

  //Serial output of message
  //Serial.println(F("Sending: "));
  for (byte b = 0; b < (sizeof(buffer) / sizeof(buffer[0])); b++) {
    //Serial.print(buffer[b]);
  }


}//do_send()

result

9 57982 9 57344 0 0

Have you tried initialising the buffer with the same number of elements as you say it is going to have?

I Have yes that makes no difference, when I add extra "space" in the buffer they come out as zeros in the resulting window.

i have also tried this code but get compile error which i do not know what it means

void do_send(osjob_t* j)
{
  int myArray[4]; 
      myArray[0] = 9;
      myArray[1] = 999;
      myArray[2] = 9;
      myArray[3] = 999;
  // Prepare upstream data transmission at the next possible time.
  LMIC_setTxData2(1,myArray[4],4, 0);

}//do_send()

Error

cannot convert 'int*' to 'xref2u1_t {aka unsigned char*}' for argument '2' to 'int LMIC_setTxData2(u1_t, xref2u1_t, u1_t, u1_t)'

I dont know what xref2u1_t is....

Its data type required by function. But it says its actually unsigned char. It seems you cant pass values greater than 255 to the function.

mmmm Well thats a usefull library...... :frowning: i got an array sent finally with the this code

void do_send(osjob_t* j)
{
  int myArray[4]; 
      myArray[0] = 9;
      myArray[1] = 255;
      myArray[2] = 9;
      myArray[3] = 255;
  // Prepare upstream data transmission at the next possible time.
  LMIC_setTxData2(1,myArray[4],4,0);

}//do_send()

but the result is just " 0 0 0 0" so I guess your correct...

  LMIC_setTxData2(1,myArray[4],4,0);The second parameter of that function call is a node of the array that does not exist. That cannot be right

this is what the function is expecting int LMIC_setTxData2(u1_t, xref2u1_t, u1_t, u1_t)

I have attached the library “How To PDF” page 18 deals with Transmit.

LMiC-v1.5.pdf (818 KB)

xref2ul_t is actually unsigned char*, as compiler error said, which in this case is your array, because this pointer points to first element of the array. You send myArray[4], which is actually 5th element of 4 elements array and of wrong datatype. First thing I would change your datatype from int to unsigned char to avoid further errors. Then you need to send an array, which in this case would be just "myArray", since name of the array is a pointer to its 1st element

Iv done what you said but still does not make make sense.

When running

void do_send(osjob_t* j)
{
  unsigned char myArray[4]; 
                myArray[0] = 9;
                myArray[1] = 255;
                myArray[2] = 9;
                myArray[3] = 255;
  // Prepare upstream data transmission at the next possible time.
  LMIC_setTxData2(1,myArray,4,0);

}//do_send()

the code compiles but the resulting packet received looks like this

9 62079

How do you receive the data?