Heltec LoRa 32 LoRaWAN Node on The Things Network

heltec-lora32-v2.jpg

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() {
Serial.begin(115200);
}

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.

delay(3000);

}

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!

References

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

18 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!
    +JOIN:STARTING…

    Tx Freq:907800000
    S0SSSSS
    First RxWindow Freq: 929900000
    SS
    Second RxWindow Freq: 923300000
    SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
    ———————————
    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 !!

    Configuration
    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.

    http://ge.tt/7GMLHOu2

    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.

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