ESP32_LoRaWAN

*****************************

robotzero heltec-lora32-lorawan-node

Bibliotheksverwalter:
Typ: alle Thema: alle heltec

Bibliotheken einbinden:

ESP32_LoRaWAN

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.

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’

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.

(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:

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

Your node is now connected to The Things Network!