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 Heltec Development Framework

Heltec have created a ‘framework’ to support their boards within the Arduino IDE. Follow the instructions in Step 1 in the page linked below to install it. Optionally install the Heltec ESP32 Library (Step 2) and test with the Example Sketches.

https://heltec-automation-docs.readthedocs.io/en/latest/esp32/quick_start.html#via-arduino-board-manager

Installing the LoRaWAN Library

The ESP32_LoRaWAN library can be installed using the Arduino Library manager Sketch >  Include Library > Manage Libraries and search for ESP32_LoRaWAN

Previously the settings for The Things Network were stored in the library files but these are now found in the Sketches themselves. For example

The OTAA.ino example:

/* OTAA para*/
uint8_t DevEui[] = { 0x22, 0x32, 0x33, 0x00, 0x00, 0x88, 0x88, 0x02 };
uint8_t AppEui[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
uint8_t AppKey[] = { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x66, 0x01 };

The band for your region is now chosen using the Tools Menu. This will only appear if you have installed the Heltec Framework mentioned above.
Region Settings

License

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

Heltec Development Environment: https://github.com/Heltec-Aaron-Lee/WiFi_Kit_series (Doc – https://heltec-automation-docs.readthedocs.io/en/latest/esp32/quick_start.html)

Heltec ESP32_LoraWAN library on Github: https://github.com/HelTecAutomation/ESP32_LoRaWAN

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

  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”?

  2. jucom says:

    hi,
    I don’t have the options for LoRaWAN debuglevel and LoRaWAN region in the tools menu, but you need to choose an option in them to make the code work.

    1. WordBot says:

      Hi, I’ve just rewritten the tutorial for the changes Heltec have made in their code. You can have to install a ‘Framework’ to get the new menu items.

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