How to send downlink data to LoRa node

Hi,
I am using RAK2243 LoRa gateway. As for the node, I am using WLR089 Xplained Pro.

I want to send a downlink command to turn on LED at my LoRa node. How can I do it with my LoRa application server?

Currently, I can send my sensor data from my node to the gateway and then display it on the application server platform and graph the data in Chronograf or Grafana with fluxDB.

Besides the application server’s side, do I need to do anything at my node’s side to prepare it to receive downlink data? What I need to do?

For your information, I am using Chirpstack platfrom.

Hope to hear from you soon.

Regards,

Welcome to RAK forum @nelky22 .

You can send downlink to your end-device WLR089 by using the web UI of chirpstack. You can also do it via http, mqtt or many built-in integration in ChirpStack.

For the end-device, if you are class A, you need to send an uplink first before receiving the downlink packets. If you are operating in class C, then your end device can receive the downlink anytime.

Hi @carlrowan,
Thanks for coming back to me.

I found out that I can go to Application → ApplicationName (I create myself) → Devices → DeviceName (I create myself)
Then at Details tab, Enqueue downlink payload, at BASE64 ENCODED tab, I can key in the base64 value of my hex value. Then I click on ENQUEUE PAYLOAD. My node will be able to receive the downlink data I send.

Is there a way to create a script for a layman person to just click and the data will be sent over to the node. My product will be used by someone who doesn’t know anything about the downlink, payload, etc. Is there anyway to do it?

Besides, at the JSON OBJECT tab, what should I fill in in order to send the downlink data? Is there any example?

When I tried to fill in as below, it just can’t go through. It just requires me to fill in the BASE64 ENCODED tab.

{
“confirmed”: false,
“fPort”: 1,
“data”: “aGVsbA==”
}

Hope to hear from you soon.

Regards,

Yes. You can do that but you need to use http, mqtt or any built-in integration/API in Chirpstack. There are lots of possible way/option but it is up to you what is easier for you to implement.

Please have a look on the Integration and API section in this link: Introduction - ChirpStack open-source LoRaWAN<sup>®</sup> Network Server

Here is an example of how I use the Python API to send a downlink via a python script. There is no frontend UI here but I can easily use Tkinter GUI of python to create a button. This is just an example but you can use other methods of course.

import os
import sys

import grpc
from chirpstack_api.as_pb.external import api

# Configuration.

# This must point to the API interface.
server = "192.168.1.20:8080"

# The DevEUI for which you want to enqueue the downlink.
dev_eui = bytes([0x1D, 0xFB, 0x41, 0xD3, 0x79, 0x77, 0x2C, 0x52])

# The API token (retrieved using the web-interface).
api_token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcGlfa2V5X2lkIjoiYzA3ZTBjYzktM2E1OC00NTVlLWFhYjItNGYxNjdiOTgwN2VkIiwiYXVkIjoiYXMiLCJpc3MiOiJhcyIsIm5iZiI6MTYzMDg5NDk1Nywic3ViIjoiYXBpX2tleSJ9.-aKVGILqrPmKLA__RApxxXUre3mt8kY2slzCG899jBI"

if __name__ == "__main__":
  # Connect without using TLS.
  channel = grpc.insecure_channel(server)

  # Device-queue API client.
  client = api.DeviceQueueServiceStub(channel)

  # Define the API key meta-data.
  auth_token = [("authorization", "Bearer %s" % api_token)]

  # Construct request.
  req = api.EnqueueDeviceQueueItemRequest()
  req.device_queue_item.confirmed = False
  req.device_queue_item.data = bytes([0x01, 0x02, 0x03])
  req.device_queue_item.dev_eui = dev_eui.hex()
  req.device_queue_item.f_port = 10

  resp = client.Enqueue(req, metadata=auth_token)

  # Print the downlink frame-counter value.
  print(resp.f_cnt)

Hi @carlrowan,
What is the javascript function Encode at the CODEC tab doing?

Do you have any example of implementing some code in the Encode function and its effect?

Regards,

Hi @carlrowan,
For the python code, after writing it, where should I put it to run?

Hope to hear from you soon.

Regards

Hi @nelky22 ,

Regarding Chirpstack downlink encode, I haven’t used it yet.

With the Python code, you just need to have Python installed on your machine. If you have no python yet, there are many ways how to have it. This guide might help you Download, Setup & Install Python on Windows[2021] | by Co-learning Lounge | Co-Learning Lounge | Medium. Personally, I use Anaconda on all my Python related stuff.

After having python, you need to install the ChirpStack Python API package via pip - chirpstack-api · PyPI

Then update the script I sent above with the right SERVER, API_TOKEN and DEVEUI.

Hi @carlrowan,
Thanks for coming back. If I use the http REST API method, can I create a button at the web UI to do the downlink?

At the Device → Details tab, I am able to key in the Port number, the BASE64 ENCODED value and click on ENQUEUE PAYLOAD. Then the downlink data will be sent over to my node.

My this has too many steps for a user who doesn’t know much about the programming. Am thinking of using the HTTP REST API method and create a button for the user just to click to send the downlink data over to the node. How can that be done?

Regards,

Yes. You can do that. I am more of hardware guy so I can’t give you a specific example with HTTP integration with button frontend.

You should be able to see the ChirpStack HTTP integration documentation here HTTP - ChirpStack open-source LoRaWAN<sup>®</sup> Network Server