Heltec LoRa 32 LoRaWAN Node on The Things Network


Creating a node on The Things Network with a Heltec LoRa 32 using the Arduino IDE

The Heltec Lora 32 is an ESP32 module with an SX1276 chip and a little 0.96″ OLED screen. These are available from the Heltec store on AliExpress. Be careful to buy the new version (V2) to get the new functionality like deep sleep, upgraded FLASH and better LoRa signal.

Heltec Lora 32 v2 in Packet

If you don’t already have the ESP32 boards set up in the Arduino IDE then connect the LoRa antenna and then follow the steps Setting Up the Arduino IDE for the ESP32 Range in this post.

Registering the Device at The Things Network

Sign up for an account here: https://account.thethingsnetwork.org/register
First a new Application has to be created at The Things Network: https://console.thethingsnetwork.org/applications, An example of an application could be a remote greenhouse monitoring system with several sensors that send readings to a gateway.

When the application is setup you need to register a device. On the Application Overview page for your new Application, click ‘register device’

New Device

In the page that opens, type a Device ID, click the arrows icon  on the left of the Device EUI field to automatically create the EUI and then click Register.

In the Device Overview section click the <> symbols next to the  Device EUI, Application EUI and App Key to see data you will use later.

Things Device Overview

Installing the LoRaWAN Library

Download the ESP32_LoRaWAN library: https://github.com/HelTecAutomation/ESP32_LoRaWAN/archive/master.zip

Add the downloaded library to the Arduino IDE using the menu: Sketch > Include Library > Add .ZIP Library

Include Zip Library

(If you need the library in the future you can include it by navigating Sketch > Include Library > ESP32_LoRaWAN)

Two files in the new library need to be edited for this to work correctly. These files are most likely in the src folder of the library (C:\Users\**yourusername**\Documents\Arduino\libraries\ESP32_LoRaWAN-master\src)

Open Commissioning.h and around line 59 replace the following data with the data from The Things Network device overview above.

#define LORAWAN_DEVICE_EUI { IEEE_OUI, 0x00, 0x00, 0x88, 0x88, 0x02 }

#define LORAWAN_APPLICATION_EUI { 0x70, 0xB3, 0xD5, 0x7E, 0xD0, 0x01, 0x6B, 0xB7 }

#define LORAWAN_APPLICATION_KEY { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x66, 0x01 }
Save the file.
Open LoRaMac-definitions.h and change the line:
#define USE_BAND_470
to the correct band for your region. In Europe it is USE_BAND_868.
Save the file.

The Lora32 device needs a license key for this library. To get the key, paste the following into a new Sketch (file > new):

uint64_t chipid;

void setup() {

void loop() {
chipid=ESP.getEfuseMac();//The chip ID is essentially its MAC address(length: 6 bytes).
Serial.printf("ESP32 Chip ID = %04X",(uint16_t)(chipid>>32));//print High 2 bytes
Serial.printf("%08X\n",(uint32_t)chipid);//print Low 4bytes.



Before you power the module, connect the antenna. The unit can be damaged if you try to transmitted data without an antenna. When the Lora32 is connected to power or USB it starts a demo which includes transmitting LoRa packets so connect an antenna first!

Once connected to USB, upload the sketch above to the board and open the serial monitor. You’ll see something like this:

Chip ID
Copy the Chip ID and paste it into the form here to get a license key: http://www.heltec.cn/search/

Connecting with an Example Sketch

Open the example sketch: File > Examples > ESP32_LoRaWAN > OTAA

Paste the new license in this line:

uint32_t LICENSE[4] = {0xC1670CF8,0x19C71AD5,0x6CE47540,0x8CF267EC};

Upload the Sketch, open the serial monitor and you should see something like this:

Serial LoRaWAN Start Up

In The Things Network website navigate to Applications > **your_application** > Devices > **your_device** and you should see something like this:

Device Status

Your node is now connected to The Things Network!


I used the following to help me set up the node:
Heltec ESP32_LoraWAN library on Github: https://github.com/HelTecAutomation/ESP32_LoRaWAN

37 Replies to “Heltec LoRa 32 LoRaWAN Node on The Things Network”

  1. Marcel says:

    Hi, Congratulations on the tutorial !! Really very good!!
    I’m from Brazil and I’m starting to study IOT and thank you for the tutorial, but I have a problem, could you help me?
    When you open the arduino serial monitor after loading the code, it appears letter by letter and very slow.

    ESP32 LoraWan Started OK!

    Tx Freq:907800000
    First RxWindow Freq: 929900000
    Second RxWindow Freq: 923300000
    What will be the problem?

  2. WordBot says:

    Hi, Thanks!
    Do you have a Things Network Gateway close to you?

  3. Marcel says:

    Hello, I have yes !! I configured it that way !! Like the seller’s tutorial !!

    GW_ID “CC50E30C8513”
    GW_HOSTNAME “SafeTeste”
    GW_NTP_SERVER “br.pool.ntp.org”
    GW_ROUTER “router.eu.thethings.network”
    GW_PORT “1700”
    GW_FREQ 915000000
    GW_BW “BW250”
    GW_SF “SF7”
    GW_LAT “-25.410966”
    GW_LON “-49.223382”
    GW_ALT 935
    GW_NSS 0
    GW_DIO0 1
    GW_DIO1 2
    GW_PWD 878787

    thank you again

    1. WordBot says:

      Try router.us.thethings.network for the GW_ROUTER I think you need to use this one for your frequency.

  4. Marcel says:

    I modified, but so far nothing. Strange is he operate so slow, see the video I made.


    thanks again

    1. WordBot says:

      I’m not sure why it’s so slow. I tried mine without a connection and it doesn’t do the same thing. However I’ve noticed something. The node looks like it’s working on the US902-928 frequencies and the gateway on the AU915-928 frequencies https://www.thethingsnetwork.org/docs/lorawan/frequency-plans.html

      What do you have set for “Open LoRaMac-definitions.h and change the line: #define USE_BAND_470”?

  5. Marcel says:

    2 problems

    # related to frequency
    in “definitions.h” I did so: #define USE_BAND_915
    As no packet info appears on my gateway !! Could that be the problem?

    # did you see the video? after a while, it falls into “SSSS ..”
    I’m sorry, I just saw it now. My WiF LoRa 32is not V2, she is version 1!!!

    Can you continue to help me?
    thanks again

    1. WordBot says:

      You could try: router.au.thethings.network for the GW_ROUTER . I’m a bit confused about which frequency you are on. If nothing appears on the gateway though it probably isn’t that. I have a V1 but I can’t test it at the moment with this library as I don’t have a key for it. You could ask in the TTN forums about setting up the node and gateway in Brazil. I think it’s slow just because it can’t connect.

  6. Marcel says:

    I’ll try!!
    If it works out with your (v1), please help me !!

    Thank you very much!!!

    1. Dio says:

      Hi Marcel, any luck so far?

      1. Marcel says:

        Hi Dio, not yet !!! I’m taking my project to a friend next week, if I can, I’ll let you know!

        1. WordBot says:

          Hi. Did you guys get the connection working in the end?

  7. Dio says:

    I encountered the same issue as well, I’m using #define USE_BAND_915

    1. Marcel says:

      In other frequencies does it work?

      1. Dio says:

        I can only use 915MHz..I switched to other LMIC library and Implemented it differently but unfortunately it is still unable to join the gateway. I noticed pin outs from V1 and V2 are different so you may check on that as well especially on the DIO1 and DIO2. I will try again using the approach stated in this article.

        1. Jonatas Ribeiro says:

          Hello Dio, did it work? I’m having the same problem, can’t connect to 915MHz frequency, it just get stuck at the JOINING loop, but no signal or anything on my gateway.

  8. Dean Marsh says:

    Works fine on my V2. Although the range is utterly appalling compared to my other commercial nodes.

    Max range from my Gateway only a few meters. EU868 band.

    Any ideas??

    1. WordBot says:

      Do you have any way of testing with just LoRa to another node like this – https://robotzero.one/heltec-wifi-lora-32/ ? I had one working at 2.9km at the weekend with the Heltec Gateway. Maybe ask in the TTN forums if anyone can suggest tests.

  9. Someone dead says:

    i have problems with the OTAA example at the end, when i upload the example code (with the new license provided) it says the following

    OTAA:64:28: error: no matching function for call to ‘LoRaClass::DeviceStateInit()’


  10. zumax says:

    I have the same problem with de OTAA example:
    OTAA:64:28: error: no matching function for call to ‘LoRaClass::DeviceStateInit()’
    ………………………………………………………..src/LoRa.h:87:8: note: candidate: void LoRaClass::DeviceStateInit(DeviceClass_t)
    ……………………………………………………………\src/LoRa.h:87:8: note: candidate expects 1 argument, 0 provided
    OTAA:94:24: error: ‘IsLowPowerOn’ was not declared in this scope
    exit status 1
    no matching function for call to ‘LoRaClass::DeviceStateInit()’

  11. WordBot says:

    Looks like the same bug is in the issues on Github: https://github.com/HelTecAutomation/ESP32_LoRaWAN/issues/13

    Hopefully someone will come up with a fix.

  12. Saber says:

    Updating to the latest version of the library can solve this problem.

  13. Phil Rogers says:

    Hi Guys
    I have 2 x Heltec Wifi OLED Lora 32 V2 using AU915.

    I have really struggled to get these to work with the things network. They communicate fine via lora to each other but using lorawan via both the lmic library as documented and the Heltec ESP32_LoRaWAN-master library I cannot get the gateways to receive a packet from the node and send to the things network. I have read all the articles I could find and burnt at least 100 hrs on this in my spare time without success. I also have tried the pins dIO = 16 Dio1 = 35 dio2 = 34 as per the V2 board notes tried all that.

    I have an LG01 Dragino single channel with the single_pkt_fwd_v004 which is connecting to the things network but has never received a packet from the Heltec board, but I have seen the LG01 gateway receive other devices data and push it to my things network gateway.

    I also build one of the Heltec’s into a single channel gateway and followed all the instructions for https://github.com/things4u/ESP-1ch-Gateway-v5.0. This gateway did connect to the things network but again has never received a packet from my esp32 wifi v2 lorawan node.

    I am finally now asking for help.

    What I would like is a step by step known working example for the Esp32 Wifi v2 as a node that transmits on AU915 I am in Australia. All it needs to do is send a packet to the gateway and have that end up on my gateway in the things network and I will be happy.

    Thanks in Advance

  14. Tom says:

    thanks for your great tutorial – I did exactly as described, unfortunately i’m getting this error:
    board.h: No such file or directory

    Any idea what’s wrong?

    1. WordBot says:

      Hi, I think you’ve missed this step: Add the downloaded library to the Arduino IDE using the menu: Sketch > Include Library > Add .ZIP Library

  15. David says:

    When compiling the example program OTTA throws this error at me … I hope you can help me. Thank you.

    C:\Users\****\Documents\Arduino\libraries\ESP32_LoRaWAN-master\src\LoRaMac.c: In function ‘SetNextChannel’:

    C:\Users\****\Documents\Arduino\libraries\ESP32_LoRaWAN-master\src\LoRaMac.c:2038:60: error: expected expression before ‘==’ token

    if( ( JOIN_CHANNELS & ( 1 << j ) ) == 0 )


    C:\Users\****\Documents\Arduino\libraries\ESP32_LoRaWAN-master\src\LoRaMac.c:2038:65: error: expected statement before ')' token

    if( ( JOIN_CHANNELS & ( 1 << j ) ) == 0 )


    1. WordBot says:

      Looks like the code is bad in the repository. Fix here: https://github.com/HelTecAutomation/ESP32_LoRaWAN/issues/19

  16. David says:

    Thanks for the quick response.

  17. gerard says:


    I try the pgrogram ota-oled sample with my configuration ttn abp and otaa and my license number.
    But its doesn’t work the display stay in “joining…” and the serial data show:

    14:00:01.102 -> Firstets Jun 8 2016 00:22:57
    14:00:02.407 ->
    14:00:02.407 -> rst:0x1 (POWERON_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
    14:00:02.407 -> configsip: 0, SPIWP:0xee
    14:00:02.407 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
    14:00:02.407 -> mode:DIO, clock div:2
    14:00:02.407 -> load:0x3fff0018,len:4
    14:00:02.407 -> load:0x3fff001c,len:1216
    14:00:02.407 -> ho 0 tail 12 room 4
    14:00:02.407 -> load:0x40078000,len:9720
    14:00:02.407 -> ho 0 tail 12 room 4
    14:00:02.407 -> load:0x40080400,len:6364
    14:00:02.407 -> entry 0x400806b8
    14:00:02.909 -> ESP32 LoraWan Starting…
    14:00:04.461 -> ESP32 LoraWan Started OK!
    14:00:04.562 -> +JOIN:STARTING…
    14:00:04.615 ->
    14:00:04.615 -> Tx Freq:868300000
    14:00:09.669 ->
    14:00:10.618 -> First RxWindow Freq: 868300000
    14:00:23.587 ->
    14:00:24.591 -> Second RxWindow Freq: 869525000

    Can you help me please!

    I have two WIFI LORA shield heltc which work with sending and receiving sample program.

    Best regard.

    1. WordBot says:

      Hi, I’m not sure. Maybe ask on the TTN forum?

  18. Laszlo says:


    what it means:

    OTAA_OLED:89:22: error: ‘LoRaWAN_DEBUG_LEVEL’ was not declared in this scope

    uint8_t debugLevel = LoRaWAN_DEBUG_LEVEL;


    OTAA_OLED:92:33: error: ‘ACTIVE_REGION’ was not declared in this scope

    LoRaMacRegion_t loraWanRegion = ACTIVE_REGION;


    exit status 1
    ‘LoRaWAN_DEBUG_LEVEL’ was not declared in this scope

  19. Laszlo says:

    An older version of GitHub did this for me in OTTA mode, but it works fine in ABP mode. The new GitHub gives an error. I can’t set the country code inr the Arduino IDE

    1. WordBot says:

      Hi, It would be better to open an issue in Github if you think there’s an error in the code.

  20. Bienenbube says:

    Same problem here. I can not set the region.
    Even the file LoRaMac-definitions.h does not exist in the library anymore.
    And the file ” Commissioning.h and around line 59″ ends with line 34.

    Does anyone have an older version?

    1. WordBot says:

      I’m not sure if it will work but go here: https://github.com/HelTecAutomation/ESP32_LoRaWAN/commits/master and try and find the last version that worked and click the <> button to see the code at that point. Looks like there was a code update yesterday so maybe they are working on it now.

  21. scjerry says:

    Contents of Commissioning.h doesn’t match instructions. It only has 34 lines.
    Quote from instruction:
    “Commissioning.h and around line 59 replace the following data with the data from The Things Network device overview above.”
    Also where’s LoRaMac-definitions.h?
    I’ve installed ESP32_LoRaWAN-master\src
    Do I have the wrong library?

    1. WordBot says:

      Hi, I’ve just looked at this and it seems all the settings are made in the ino (Arduino sketch). You can see this in the example here: https://github.com/HelTecAutomation/ESP32_LoRaWAN/blob/master/examples/OTAA/OTAA.ino
      Oddly it looks like this setting: #define USE_BAND_470 is made in the Arduino IDE Tools menu.
      Can you you let me know if it works for you and I’ll update the tutorial.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

scroll to top