Sending Data From Node to The Things Stack

Sending Data From Node to The Things Stack

Hardware:

lora web home lorawan

 

To receive uplinks and send downlinks to your end device, you first need to add your device to The Things Stack Community Edition. Devices are added within applications. Applications are useful for grouping devices by purpose or location, for example.

 

Registering your device can be done in two ways, via The Things Stack Console or via the CLI. Before adding your end device, make sure you know which type your device is - ABP (Activation By Personalization) or OTAA (Over-The-Air-Activation). Depending on the type, some steps differ during the registration procedure. Learn why using OTAA devices is highly recommended.

 

For this tutorial, I register the device via The Things Stack Console and this Shield-LoRa-RFM is an OTAA device.

 

 

Step 1: Hardware Setup

Attach the Shield-LoRa-RFM to Arduino UNO board. I am using the CT-Uno from Cytron Technologies.

ALWAYS remember to connect an antenna to the Shield-LoRa-RFM before powering up the Arduino board.

photo 2021 12 07 09 29 43

Make sure a LoRa gateway is active in your area and the LoRa node can send messages to that gateway. You can build your own gateway or use any available gateway from this map. Kindly refer to this tutorial if you want to build your own gateway.

ghj

 

Step 2: Arduino IDE Setup

Install the latest open-source Arduino IDE here.

Install the MCCI LoRaWAN LMIC library.

  • In the Arduino IDE, select menu Sketch | Include Library | Manage Libraries
  • In the search box enter: MCCI
  • Click the MCCI LoRaWAN LMIC library by Terry Moore.
  • Select the latest version and press the Install button.
  • For this tutorial, I installed version 4.1.0

 sd

 

Configure the MCCI LoRaWAN LMIC Library according to your situation.

Edit file lmic_project_config.h. This file can be found at:

.../libraries/MCCI_LoRaWAN_LMIC_library/project_config

gnb

I made the following changes to MY lmic_project_config.h file.

Make changes according to YOUR situation by uncomment your related region.

d

 

Step 3: The Things Stack Setup

Create an account on The Things Stack Sandbox (TTS S).

Login to The Things Stack Sandbox console.

 

Make sure you select a cluster (Europe, North America, Australia) near your location.

 

 

Add an application. For example:

Application ID: new-application (must be unique)

Application name: new-application (can be anything)

 

Then, register the end device (choose manually) :

  • Frequency plan: Choose based on your region
  • LoRaWAN version: LoRaWAN Specification 1.0.2
  • Regional Parameters version: RP001 Regional Parameters 1.0.2 Revision B
  • Activation mode: Over The Air Activation (OTAA)
  • Additional LoRaWAN class capabilities: None (Class A only)

Note: Why use LoRaWAN Specification 1.0.2?

Because the MCCI LoRaWAN LMIC Library has only been tested with LoRaWAN 1.0.2/1.0.3 networks.

 

 

The HopeRF RFM95 LoRa transceiver module does not have a built-in DevEUI or AppEUI. In such a case you should let the TTSS console generate the required DevEUI or AppEUI. Here below is an example of generated AppEUI, DevEUI, and AppKey in the TTSS console.

Note : JoinEUI is formerly called AppEUI as a 64 bit extended unique identifier used to identify the Join Server during activation.

 

 

AppEUI, DevEUI, and AppKey are used in the Arduino sketch. In this Arduino sketch, the DevEUI or AppEUI must be converted to an array of 16 bytes in LSB order.  The AppKey must be converted to an array of 32 bytes in MSB order. I have found an online tool that converts these values to a bytes array in its correct order (LSB/MSB). Kindly use this online tool to prevent any negligence.

 

Step 4: Upload The Code to Arduino

In the Arduino IDE, select menu File | Examples | MCCI LoRaWAN LMIC library and select the ttn-otaa sketch. Re-save the ttn-otaa sketch and call it ttsce-otaa-helloworld or anything that you want.

From the online tool, copy DevEUIAppEUI, and AppKey that you had converted and paste them to the ttsce-otaa-helloworld sketch.

 

Modify the ttsce-otaa-helloworld sketch. For this part, you can double-check by checking on the shield board itself to find the correct pin mapping. This is the pin mapping for Cytron Shield-LoRa-RFM board.

 

 

In this sketch, the message “Hello World” will be transmitted every 60 seconds.

See variables: mydata[] and TX_INTERVAL. You can change to any other messages or increase/decrease the transmission interval if you want to. 

 

 

Connect the Arduino board to your computer using the USB cable.

In the Arduino IDE, select menu Tools > Board and select Arduino Uno. Then, select menu Tools > Portyour port.

 

 

Compile ttsce-otaa-helloworld sketch. You should not see any errors (but there are warnings).

Upload the ttsce-otaa-helloworld sketch to the Arduino board. You should not see any errors.

 

 

Step 5: Display Data on The Things Stack

In The Things Stack Community Edition console, the “Hello, world” message (in hex) is received every 60 seconds.

If you want to convert the payload into readable text:

  • Select your application in the “Application Overview” screen.
  • Select “Payload formatters”.
  • Select “Uplink”.
  • Select “Formatter type: Javascript”.

 

Copy and paste the decode uplink payload formatter in the textbox.

On the bottom of the page press the “Save changes” button.

 

 

Finally, if both your node and gateway functioning well, you should see the number of sent uplinks and received downlinks updated each minute with the message "Hello World" displayed in the live data.

 

 

 

References

 




Chat hỗ trợ
Chat ngay