How to use ESP32 with LoRaBEE as a node in LoRAWAN

What is LoraWAN?

LoRaWAN is a media access control (MAC) protocol for wide area networks. It is designed to allow low-powered devices to communicate with Internet-connected applications over long-range wireless connections.

LoRaWAN can be mapped to the second and third layers of the OSI model. It is implemented on top of LoRa or FSK modulation in industrial, scientific, and medical (ISM) radio bands. The LoRaWAN protocols are defined by the LoRa Alliance and formalized in the LoRaWAN Specification which can be downloaded on the LoRa Alliance website

Material Required is as follows:

1.ESP32

2.LoRaBEE

3. Gateway

4.The Things NetworkΒ Account

Circuit Diagram

Pin Details

LoRe BEE

LoRe BEE

physical pin

ESP32 Pin

MISO

Β  4

Β  Β  Β  Β  D19(MISO)

RESET

Β 5

Β  Β  Β  Β  D14

MOSI

11

Β  Β  Β  Β  D23(MOSI)

D0 Β 

Β 12

Β  Β  Β  Β  D2

D1

13

Β  Β  Β  Β  D26

D2

14

Β  Β  Β  Β  D25

NSS

Β 17

Β  Β  Β  Β  D5

SCK

Β 18

Β  Β  Β  Β  D22(SCLK)

3V3

Β  1

Β  Β  Β  Β  Β 3V3

GND

Β 10

Β  Β  Β  Β  Β GND

Step 1: Installing ESP32 Add-on in Arduino IDE

  1. To install the ESP32 board in your Arduino IDE, follow below steps.
  2. In your Arduino IDE, go to File > Preferences.

  1. Enter https://dl.espressif.com/dl/package_esp32_index.jsonΒ into the β€œAdditional Board Manager URLs” field as shown in the figure below. Then, click the β€œOK” button.

  1. Go to Tools > Board > Boards Manager.

  1. Search ESP32 and Click on the install button.

  1. The installation may take a while depending on your network performance. Once done, close the board manager

Step 2: Setup the Things Network Console Server

To setup up the TTN Console, please check the steps given in the blog: <TODO: add link to Rpi lorawan blog>

Step 3: Code and Library

Β Download as Zip file of Arduino-lmic Library refer below link

Β  Β  https://github.com/matthijskooijman/arduino-lmic

Installing library

In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library.

Β At the top of the drop-down list, select the option to "Add. ZIP Library''.

Β  Β  Β  Β  Code: here we are using example sketch ttn-abp

navigate to ttn-abp example

Example sketch: File > Sketchbook > Examples > IBM LMIC framework>ttn-abp

Step 4: Pin Number Modification in Code

Change the pin numbers as shown in the code below

Step 5: Copy your Network Session Key, App Session Key and Device Address from TTN console into your code

You can find all Keys in your TTN console, go to Application > Devices > Your Devices

Make sure Network Session Key and App Session Key are copied in big-endian (MSB) format. To reverse the order, click on the reverse button to the left of the field.

Copy these details to the following lines in the code:

Step 6: Uploading code Β 

  1. In your Arduino IDE, go to Tools > Board>ESP32 Arduino

  1. Select the Port

  1. Click on the Upload button in the Arduino IDE
  2. After uploading code open Arduino Serial monitor

  1. After this go to the TTN console > Application > Device > Data
  2. Here uplink, downlink, and acknowledgment packets will be shownΒ 

Step 7: Scheduling Downlink

  1. Go to TTN console > Application > Device > Overview
  2. In Downlink section enter your payload in hex format
  3. Ensure that the β€œConfirmed” option is selected.
  4. Click on send
  5. Once the packet is received, you can see the downlink message in your Arduino Serial monitor
  6. After the downlink packet is received, you can see acknowledgment notification in the TTN console.

Troubleshooting

After uploading code if you get the Failure error on the Serial monitor

C:\Users\ShivCapoor\Pictures\lora temp.jpg

Check your connections to make sure they are correct and not loose. Also, check if all pin numbers are correct.

Leave a comment

Please note, comments must be approved before they are published