I’m using the ttn-otaa sketch in Arduino, and I’m connected to The Things Network. I am sending downlink in bytes. I am trying to test sensing down the phrase “Hello World” by sending down “48 65 6C 6C 6F 20 57 6F 72 6C 64” but using the ttn.onMessage function I get the message as “3 51 0 0 115 3 51 255 0 3 1”
The library states that
Method: onMessage
Sets a function which will be called to process incoming messages. You'll want to do this in your setup() function and then define a void (*cb)(const byte* payload, size_t length, port_t port) function somewhere else in your sketch.
void onMessage(void (*cb)(const uint8_t *payload, size_t size, int rssi));
const uint8_t* payload: Bytes received.
size_t size: Number of bytes.
int rssi: the rssi in dB.
I’m not sure how to define the “void (cb)(const byte payload, size_t length, port_t port)” function to use the port. As of now I’m using the example sketch below, and I’m not getting the “Hello World” downlink in plain text.
This is a link to the library
GitHub - rgot-org/TheThingsNetwork_esp32
and here is the sketch I’m using
#include <TTN_esp32.h>
#include "TTN_CayenneLPP.h"
/***************************************************************************
* Go to your TTN console register a device then the copy fields
* and replace the CHANGE_ME strings below
****************************************************************************/
const char* devEui = "FILLMEIN"; // TTN Device EUI but removed for this post
const char* appEui = "FILLMEIN"; // TTN Application EUI but removed for this post
const char* appKey = "FILLMEIN"; // TTN Application Key but removed for this post
TTN_esp32 ttn ;
TTN_CayenneLPP lpp;
void message(const uint8_t* payload, size_t size, int rssi)
{
Serial.println("-- MESSAGE");
Serial.print("Received " + String(size) + " bytes RSSI=" + String(rssi) + "db");
for (int i = 0; i < size; i++)
{
Serial.print(" " + String(payload[i]));
// Serial.write(payload[i]);
}
Serial.println();
}
void setup()
{
Serial.begin(115200);
Serial.println("Starting");
ttn.begin();
ttn.onMessage(message); // Declare callback function for handling downlink
// messages from server
ttn.join(devEui, appEui, appKey);
Serial.print("Joining TTN ");
while (!ttn.isJoined())
{
Serial.print(".");
delay(500);
}
Serial.println("\njoined !");
ttn.showStatus();
}
void loop()
{
static float nb = 18.2;
nb += 0.1;
lpp.reset();
lpp.addTemperature(1, nb);
if (ttn.sendBytes(lpp.getBuffer(), lpp.getSize()))
{
Serial.printf("Temp: %f TTN_CayenneLPP: %d %x %02X%02X\n", nb, lpp.getBuffer()[0], lpp.getBuffer()[1],
lpp.getBuffer()[2], lpp.getBuffer()[3]);
}
delay(10000);
}
Does anyone know a solution to this or where to find out how to properly use this library/example?
Thanks in advance!