Hello, I am tinkering with a LoRa project with The Things Network. I am currently using the platformio example LMIC-node in conjunction with my Heltec LoRa32 WIF (V2) board. I am trying to save the downlink into an array and then convert that downlink value into an integer. I am attempting this in the "processDownlink" function of the LMIC-node.cpp file. I need some assistance on how to do this as I am an eternal newbie.
void processDownlink(ostime_t txCompleteTimestamp, uint8_t fPort, uint8_t* data, uint8_t dataLength)
{
// This function is called from the onEvent() event handler
// on EV_TXCOMPLETE when a downlink message was received.
// Implements a 'reset counter' command that can be sent via a downlink message.
// To send the reset counter command to the node, send a downlink message
// (e.g. from the TTN Console) with single byte value resetCmd on port cmdPort.
const uint8_t cmdPort = 100;
const uint8_t resetCmd= 0xC0;
for (int i = 0; i < dataLength; i++)
{
uint8_t rawData = (data[i]);
char num[5] = {data[0], data[1], data[2], data[3]};
int val;
sscanf(num, "%d", &val);
Serial.println(val);
}
I am sending the number "1500" down in The Things Network console window. I send it down in Hexadecimal format (31 35 30 30) and am trying to save it to the "int val" variable.
I get this as the output.
000001036488: Event: EV_TXCOMPLETE
Up: 2, Down: 2
Downlink received
RSSI: -36 dBm, SNR: 5.7 dB
Port: 1
Length: 4
Data: 31 35 30 30
1500
1500
1500
1500