*Note: Do adjust the indentation accordingly in Keil as seen above
Testing it out - Click rebuild, load it into the 1SJ Board and click the reset button on the board. Next, head to Postman, enter and send as seen below.

Head to the Tera Term virtual terminal and the downlink message should be displayed.

The red LED on the 1SJ Board should be turned on as well.
To turn off the red LED, simply input 00 as the data and click send inside Postman as follows:
| |
*Note: Data sent as 01 turns on the red LED and data sent as 00 turns off the red LED
 |
Why is the downlink message sent to port 2? |

Let us take a look at the definition of the LORAWAN_USER_APP_PORT function by going to line 356 in lora_app.c, highlight the function, right click and click Go To Definition.

Keil brings us to lora_app.h file and under line 59, we can see the LORAWAN_USER_APP_PORT function is defined by port 2.

Setting 2 - Changing LoRaWAN Classes

Continuing from lora_app.h from Setting 1, we can see in line 65 that the LORAWAN_SWITCH_CLASS_PORT is port 3.


Let us head back to lora_app.c and go to line 330 where the LORAWAN_SWITCH_CLASS_PORT is defined. Modify and add the codes below.

Or, simply copy and replace the entire LORAWAN_SWITCH_CLASS_PORT function seen below:
| |
Testing it out - Click rebuild, load it into the 1SJ Board and click the reset button on the board. Next, head to Postman, enter and send as seen below.
| |
The change of class to Class C will be shown in the Tera Term Terminal as well.

*Note: As seen in the project file, sending downlink message 00 changes to Class A, 01 changes to Class B if it is enabled & 02 changes to Class C. Port 3 is used as defined earlier in lora_app.h
 |
How to enable Class B? (Disabled by default) |
Go to Postman and send downlink message as 01. You should be seeing this in the terminal.

This is because Class B is disabled in the project file by default.
To enable Class B, go to line 344 in lora_app.c, highlight LORAMAC_CLASSB_ENABLED, right click and click Go To Definition.

Keil brings us to lorawan_conf.h file where we can see Class B is disabled (0) by default. Change it to 1 if you want to enable Class B as seen below.

Setting 3 - Changing Transmission Interval of Sensor Data

First, let us head to lora_app.h to define a new function for our change transmission interval of sensor data. Go to line 67 and add in the following:

| |
*Note: In this case, we selected port 4 for the downlink messages to be sent later on

Next, head back to lora_app.c, navigate to OnRxData function and go to line 317. We will be adding a new variable called NewTxPeriod to change the transmission interval based on the downlink message.

Next, go to line 394 where we will add our LORAWAN_CHANGE_TX_PERIOD_PORT function. Add in the following or copy paste the code below.

| |
Ensure that the function is added within the switch (appData→Port) as seen below:

Rebuild all files, load it into 1SJ and click on the reset button. Next, head to Postman and send the following downlink message:
| |
The following downlink message should be shown in the terminal as seen.

*Note: 0x20 is 32 seconds in decimal notation
Note that if we input the downlink message as 01 (anything less than 5 or not a hex number), the error message will be shown on the terminal.


Lastly, we will add a final default case if the port from the downlink message received is not a valid port (in our case if the user sends anything other than port 2, 3 or 4)
Go to line 423 in lora_app.c and add in the following line.

Test it out - rebuild the files, load it into 1SJ, press reset button, go to Postman, send an invalid port and observe the error message in the terminal.

Note that this function will cause some confusion in Tera Terminal initially when 1SJ just joined the Antares IoT Platform as seen below.
Do allow some time for the uplinks to proceed and the initial downlink MCPS Indication will gone.

The new i-cube v2.1 has added to show the MCPS Indication log to show the RSSI of the downlink. Previously, in order to check the RSSI of the downlink, a payload had to be sent from Antares side to see the RSSI value.