Skip to content

Latest commit

 

History

History

ESP32 - Basic

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

ESP32 - RN2483

Quick reference for the ESP32
In this example it is shown how to send "Hello world" to The Things Stack, with a ESP32 Devkit V1 and SODAQ LoraBee. LoraBee is a BEE formfactor board with the Microchip RN2483 LoRaWAN module.

This link contains instructions for adding devices on The Things Stack.

Serial connection

Pico LoraBee
VDD 3V3(OUT) -> 3.3V
GND GND -> GND
TX 17 -> RX
RX 16 -> TX

Implementation

Import and initialize modules

from machine import UART
from src.rn2xx3 import RN2xx3 as RN2483

ApplicationEUI = "INSERT APPEUI"
ApplicationKey = "INSERT APPKEY"

# Initialize serial connection for ESP32 Devkit V1
    uart = UART(2, baudrate=57600, tx=17, rx=16)

# Initialize module
module = RN2483(connection=uart)

End Device Activation method

Every end device must be registered with a network before sending and receiving messages. This procedure is known as activation. There are two activation methods available:

  • Over-The-Air-Activation (OTAA) - the most secure and recommended activation method for end devices. Devices perform a join procedure with the network, during which a dynamic device address is assigned and security keys are negotiated with the device.

  • Activation By Personalization (ABP) - requires hardcoding the device address as well as the security keys in the device. ABP is less secure than OTAA and also has the downside that devices can not switch network providers without manually changing keys in the device. Configure - Over The Air Authentication

For more information about activation, please read it on The Things Network

# Configure module
module.config_otaa(appeui=ApplicationEUI, appkey=ApplicationKey)

Configure - Authentication By Personalization

# Configure module
module.config_abp(devaddr=DeviceAddress, appskey=ApplicationSessionKey, nwskey=NetworkSessionKey)

Transmission

After successfully joined the network, it is possible to transmit data with the following function.

# Transmit a message
module.send("Hello world")

At your end device on The Things Stack, you can setup a "Custom Javascript formatter" in the tab "Payload formatters". The JavaScript decodeUplink() function is called when a data uplink message is received from a device. This function decodes the binary payload received from the end device to a human-readable JSON object that gets send upstream to the application.

function decodeUplink(input) {
  return {
    data: {
      Message: String.fromCharCode(...input.bytes)
    },
    warnings: [],
    errors: []
  };
}

Decoded-uplink