Send the data in Int format

I want to send the data in Int format and not in String with the LORA network with a SODAQ one

void sendPacket(String packet){
switch (LoRaBee.send(1, (uint8_t*)packet.c_str(), packet.length()))
{
case NoError:
SerialUSB.println(“Successful transmission.”);
break;
case NoResponse:
SerialUSB.println(“There was no response from the device.”);
setupLoRa();
break;
case Timeout:
SerialUSB.println(“Connection timed-out. Check your serial connection to the device! Sleeping for 20sec.”);
delay(20000);
break;
case PayloadSizeError:
SerialUSB.println(“The size of the payload is greater than allowed. Transmission failed!”);
break;
case InternalError:
SerialUSB.println(“Oh No! This shouldn’t happen. Something is really wrong! Try restarting the device!\r\nThe network connection will reset.”);
setupLoRa();
break;
case Busy:
SerialUSB.println(“The device is busy. Sleeping for 10 extra seconds.”);
delay(10000);
break;
case NetworkFatalError:
SerialUSB.println(“There is a non-recoverable error with the network connection. You should re-connect.\r\nThe network connection will reset.”);
setupLoRa();
break;
case NotConnected:
SerialUSB.println(“The device is not connected to the network. Please connect to the network before attempting to send data.\r\nThe network connection will reset.”);
setupLoRa();
break;
case NoAcknowledgment:
SerialUSB.println(“There was no acknowledgment sent back!”);
// When you this message you are probaly out of range of the network.
break;
default:
break;
}
}

In the LoRaBee.send() function, the second parameter is essentially a pointer to a byte buffer and the third parameter specifies the length of that buffer.

If you want to send other data, you should pack it into a buffer, (e.g. 2 x 16bit integers, a 4 byte buffer), and then pass that buffer and its size to the send function.

Hello,
Using this sketch I have to convert the value to a string, the string is converted to a hexadecimal value before it is send to the TTN server. This looks to me as a waste of bandwith, I would rather send the package directly as a hexidecimal number. Is this possible and what would be the code then?

best regards Arno

You can pass a pointer to any data you want, and just specify the data size.

e.g. If you have 16bit unsigned integer:

uint16_t someNumber = 65535;

Then you can send it to Port 3 with the following:

LoRaBee.send(3, &someNumber, sizeof(someNumber));

However, you probably want to prepare a larger buffer and pack in some other values as well. For example you can pass an array instead.