Controlling Relay and LED via Downlink Command

In this section, you will use the Antares Workshop Shield on the Lynx-32 Antares Development Board module. The Antares Workshop Shield contains temperature and humidity sensors (DHT11), relays, LEDs and push buttons. In this tutorial, you will control the relays and LEDs via downlink. The process of sending this downlink uses POSTMAN software which performs a HIT API downlink to the Antares Platform.

Image of Development Board Lynx-32 and Shield Workshop Antares.

Prerequisites

The required materials follow the General Prerequisites on the previous page. If you have not prepared the requirements on that page, then you can visit the following page.

General Prerequisites ESP32 LoRa

The additional materials specific to this project are as follows.

  1. Shield Workshop Antares

  2. Postman Software

If you have not installed POSTMAN Software, you can follow the steps in the following link.

Postman Installation

Follow These Steps

1. Launch the Arduino IDE application

2. Opening Sample Programme

You can open the programme code in the Arduino IDE via File > Examples > Antares LoRaWAN > Lynx32-Simple-Project > Class A > DOWNLINK_RELAY_LED_CLASS_A

Here is the programme code of the DOWNLINK_RELAY_LED_CLASS_A example

3. Set LoRaWAN Parameters in Antares

On the Antares Device console page, set the LoRa by pressing the Set LoRa button as shown below.

Image of Antares Console Page for LoRa Set.

Input LoRaWAN parameters with Lora Device Class A, Activation Mode ABP, ABP Parameters Inherit as shown below.

When selecting ABP Parameters Inherit, the LoRa parameters will be generated by Antares. From the device side, the Lynx32 Development Board needs to adjust the LoRa parameters.

The Form image contains the LoRa Class A Parameter Set.

4. Set LoRaWAN Parameters in Programme Code

Change the LoRaWAN ABP parameters in the following variables *devAddr , *nwkSkey and *appSKey. Adjust to the parameters in the Antares console.

The *devAddr parameter that has been generated by Antares can be seen on the device page after completing the LoRa Set.

The parameters *nwkSKey and *appSKey are obtained during Set LoRa in the previous step.

Figure Antares Console Page After successful LoRa Set

5. Compile and Upload Program

Connect the Lynx-32 Development Board to your computer and make sure the Communication Port is read.

On Windows operating systems the check can be done via Device Manager. If your Lynx-32 Development Board is read, the USB-Serial CH340 will appear with the port adjusting the port availability (in this case it reads COM4).

Device Manager image on Windows.

Set up the Lynx-32 Board by clicking Tools > Board > ESP32 Arduino in the Arduino IDE, then make sure the board used is the ESP32 Dev Module. Select the port according to the communicaion port that is read (in this case COM4). The result will look like the following picture.

Image of the Tools Menu in the Arduino IDE.

After all the setup is complete, upload the programme by pressing the arrow icon as shown below. Wait for the compile and upload process to finish.

Image of the Verify and Upload Icon in the Arduino IDE.

The Tick icon on the Arduino IDE is just the verify process. Usually used to Compile the programme to find out whether there are errors or not. The Arrow icon on the Arduino IDE is the verify and upload process. Usually used to Compile the programme as well as Flash the programme to the target board.

If the programme upload is successful, it will look like the following image.

Arduino IDE page image after successful upload.

After uploading the programme, you can view the serial monitor to debug the programme. The serial monitor icon is shown in the following image.

Image of the Serial Monitor Icon in the Arduino IDE.

Set the serial baud rate to 115200 and select BothNL & CR. The result will look like the following image.

Serial Monitor Display

6. Setup POSTMAN Software

In this step, you need POSTMAN software. You can input the end-point, request header, and request body first by following the following format.

End Point

Methode

POST

URL

https://platform.antares.id:8443/~/antares-cse/antares-id/your-application-name/your-device-name

Customise your-application-name and your-device-name to the names registered to your Antares account.

Request Header

Key

Value

X-M2M-Origin

your-access-key

Content-Type

application/json;ty=4

Accept

application/json

Customise your-access-key with your Antares account access key.

The result is as shown in the following image.

Image of end-point and header settings in POSTMAN software.

Next you need to input the request body to follow the following format.

Request Body

In the POSTMAN software, select the Body tab then select raw and enter the payload according to the request body you want to use as shown below.

Image of the contents of the payload request body in the POSTMAN software

Customise the contents of the "data" field according to the downlink command you want to send.

After the POSTMAN software setup is complete, it's time to send the downlink command. The "data" field is filled with a hexadecimal number of 4 Inputs as a message to be sent via the downlink lorawan. If you have finished filling in the "data" field, then press the Send button on the POSTMAN software.

There are 4 Hexadecimal Inputs to control the Relay and LEDs listed in the table below.

Input Hexadecimal

Relay

LED

AA00

OFF

OFF

AA01

OFF

ON

AA10

ON

OFF

AA11

ON

ON

Image of downlink message content in POSTMAN software.

If the HTTP request through POSTMAN software is successful, the POSTMAN software response section will display a message as shown below.

Downlink API hit response image in POSTMAN software.

8.Check Data in Antares

After the step of sending the downlink message in the POSTMAN software is successful, then open the Antares device page and see if the downlink command has entered Antares.

The form of downlink data received by the antares will be in JSON format as follows.

The data sent from POSTMAN is in the form of "type": "downlink" and "data". The downlink message passed to the Lynx-32 Development Board is in the "data" field.

The downlink messages forwarded from Antares to the Lynx-32 Development Board can be seen in the Serial Monitor as shown below.

Image of the downlink message received on the Serial Monitor.

In LoRaWAN Class A, the downlink message will be received by Lynx-32 after Lynx-32 performs an uplink.

The received downlink message commands the Relay and LED to Switch Off or On

Relay Picture of LED Turning On

Last updated