TTN_esp32 library for Arduino

I’ve made a library very similar with TheThingsNetwork/arduino-device-lib.
but for ESP32 plateform. The link : https://github.com/rgot-org/TheThingsNetwork_esp32.
This made lmic very easy to use.
The library recognizes automatically the heltec boards (Wifi lora 32 V1 & V2 and Wireless stick)
Tell me what you think…

2 Likes

Thanks, very useful! It nicely hides all the complicated lmic stuff. Your library makes a simple sketch much more readable.

So, you can now use your phone to provision the device. I developed a small application for Android which communicates in bluetooth low energy (BLE) with the device. You can download it at the following address: https://play.google.com/store/apps/details?id=org.rgot.BLE_TEST
and use the example ttn-otaa-BLE-provisioning

1 Like

Hi! I successfully tested the ttn-otaa example for sending messages to TTN with Heltec Wifi lora 32 V2. But I am having some problems with downlink messages: it seems that it’s not donwloading anything. Where can I find more infos on the onMessage method?
Thank you!

Hello, Have you found a solution for this, Im having the same issues with the downlink onMessage function as well.

i can’t reproduce your issue
here is a my code for the void message function

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],HEX));
	}
	Serial.println();
}

here is a snapshot for downlink message
image

and here is the result in Serial console after cick on Schedule downlink

-- MESSAGE
Received 3 bytes RSSI=-44db a2 12 34

Note referring back to issues 1-2 year gone gets tricky as the whole TTN infrastructure has changed with the Dec’21 move from V2 to V3. What was a problem may not be so now making replication/debug difficult, similarly what worked before may now be broken or misbehaves as the back end is now more demanding of LoRaWAN compliance and esp good MAC and download handling behaviour. Perhaps not an issue here just warning…

I just tried to do the same and received this in my serial monitor.

-- MESSAGE
Received 3 bytes RSSI=-42db 3 33 0
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],HEX));
  }
  Serial.println();
}

down1

down2

May I see your full sketch? How did you get the same thing you sent down? I tried to replicate your code but I’m not getting a2 12 34

Looking at an example (ttn-otaa-sleep) it looks like you join on every wake up from sleep. Is that correct? If so please fix this as does not work. After max 64K joins things will fail, not to mention the insane load it puts on the network as by requiring downlinks in evey wake-up.
Also it looks like you send evey 30 seconds which violates the fair use policy for TTN. Please fix this as well.

As it is based on Semtech’s abandoned BasicMac which was then abandoned by Lacuna, last update 4 years ago, have you patched in any of the changes from LMIC to bring it reasonably up to date particularly with expectations of MAC commands?

Porting to another platform is no mean feat, so kudos, but LW has gone hybrid with catalytic convertors now, the old gas guzzlers just ain’t good for the eco-system.

I am trying to use this library with Heltec Wifi Lora 32 v2 but I am having an error just in compling.

When I open the ttn-abp example, I modify the device address, the network session key and the application session key.

Then, I compile it and getting the next error, that seems to me strange because I didn’t modify any library at all:

Arduino:1.8.19 (Linux), Board:"WiFi LoRa 32(V2), 240MHz (WiFi/BT), 921600, None, REGION_EU868, None, CUSTOM, 8(default)"

/home/fmartinez/Arduino/libraries/TTN_esp32/src/TTN_BLE_esp32.cpp: In static member function 'static bool TTN_BLE_esp32::begin(std::__cxx11::string)':
/home/fmartinez/Arduino/libraries/TTN_esp32/src/TTN_BLE_esp32.cpp:114:29: error: 'size_t TTN_esp32::getAppKey(byte*)' is protected within this context
     len = ttn->getAppKey(buf);
                             ^
In file included from /home/fmartinez/Arduino/libraries/TTN_esp32/src/TTN_BLE_esp32.h:19,
                 from /home/fmartinez/Arduino/libraries/TTN_esp32/src/TTN_BLE_esp32.cpp:1:
/home/fmartinez/Arduino/libraries/TTN_esp32/src/TTN_esp32.h:438:9: note: declared protected here
  size_t getAppKey(byte* buf);
         ^~~~~~~~~
exit status 1
Error compiling for board WiFi LoRa 32(V2).

I’ve just fixed it.

I don’t why. But it works only if I use the board version 1.0.0. for heltec and the library version 0.1.6 of TTN_esp32.

Besides, I have added the pin mapping as it shows:

// HELTEC WIFI LORA V2 PINOUT
#define UNUSED_PIN 0xFF
#define SS 18
#define RST_LoRa 14
#define DIO0 26
#define DIO1 35
#define DIO2 34

And modify the ttb.begin() as following:

    ttn.begin(SS, UNUSED_PIN, RST_LoRa, DIO0, DIO1, DIO2);

Best regards.