This tutorial is aimed at makers who want to get their hands dirty with the latest RAK811 lora node board made by RAK Wireless. The board works stand alone and can also work as a uart slave for a host board like Arduino uno or Mega. For this tutorial, ill be working with an Arduino mega as the UART host board.
Before proceeding make sure you have a functioning LoRA gateway nearby or make your own one by following this Hakcster.io tutorial:
https://www.hackster.io/naresh-krish/getting-started-with-the-rak811-lora-node-67f157
The Board:Here is a pic of the RAK811 Board with some of the important pin definitions:
There is an additional port of jumpers called P6 (green color: not shown in the pic above) which we will discuss in depth in the coming section. It is right next to the P5 port (blue color)
And here is an Arduino Mega:
It is essential that you get the checklist belo done before moving on to the connection section:
- On the RAk811 board, make sure that the antennae provided has been connected to the gold screw terminal
- Make sure that you short the jumpers on the Port P6 as follows
5_3R to TXD
5_3T to RXD
This is done to ensure that the 5v UART on the Arduino doesn't damage the 3.3v based rak811 module.Connection:
Between the Arduino Mega and the RAK 811 module connect the following ports:
5v TO RAK811 5v pin
GND to RAK811 GND
RX1 on MEGA to RX on the RAK811
TX1 on MEGA to TX on the RAK811
//yes this same-pin connection is correct and intentional as internally on the board rx/tx are connected to txd/rxd of rak811
Here is a pic showing these ports in detail:
You can also power the two boards individually using their own USB power ports.
Now its time to power on the board. Connect the MEGA to the computer via the USB cable and note down the Port on the Device manager app in Windows.
you should see the power LED on both the MEGA and the RAK811 light up bright RED. If not check the cabling and the connection between the MEGA as the RAK811 module.
Getting the code ready:Open up the Arduino board and make sure that the Corect board is selected in the boards menu and the correct serial port is selected in the serial port menu.
Once done copy paste the code below as an example:
void setup() {
//configure Serial1, this could also be a
//software serial.
Serial1.begin(115200);
//configure the mail RX0 and TX0 port on arduino
Serial.begin(115200);
}
//string to hold the response of a command in rak811
String response = "";
//the famous arduino loop function. runs continuosly
void loop() {
//try getting the version of the board firmware
sendCommand("at+version\r\n");
//set conn config
setConnConfig("dev_eui", "your_dev_eui_here");
setConnConfig("app_eui", "your_app_eui_here");
setConnConfig("app_key", "your_app_key_here");
//join the connection
sendJoinReq();
//send data too gateway
sendData(1,2,"000000000000007F0000000000000000");
delay(3000);
}
/**
* Function to send a command to the
* lora node and wait for a response
*/
void sendCommand(String atComm){
response = "";
Serial1.print(atComm);
while(Serial1.available()){
char ch = Serial1.read();
response += ch;
}
Serial.println(response);
}
/**
* send the rak811 to sleep for time
* specified in millis paramteer
*/
void sleep(unsigned long milliseconds){
sendCommand("at+sleep\r\n");
delay(milliseconds);
//send any charcater to wakeup;
sendCommand("***\r\n");
}
/**
* reset board after the specified time delay millisenconds
* <mode> = 0 Reset and restart module
= 1 Reset LoRaWAN or LoraP2P stack and Module will reload LoRa
configuration from EEPROM
*/
void resetChip(int mode, unsigned long delaySec=0){
delay(delaySec);
String command = (String)"at+reset=" + mode + (String)"\r\n";
sendCommand(command);
}
/**
* Reload the default parameters of LoraWAN or LoraP2P setting
*/
void reload(unsigned long delaySec){
delay(delaySec);
sendCommand("at+reload\r\n");
}
/**
* Function to set module mode
* <mode> = 0 LoraWAN Mode (default mode)
= 1 LoraP2P Mode
*/
void setMode(int mode){
String command = (String)"at+mode=" + mode + (String)"\r\n";
sendCommand(command);
}
/**
* Function to send data to a lora gateway;
* <type> = 0 send unconfirmed packets
= 1 send confirmed packets
<port> = 1-223 port number from 1 to 223
<data>= <hex value> hex value(no space). The Maximum length of <data> 64 bytes
*/
void sendData(int type, int port, String data){
String command = (String)"at+send=" + type + "," + port + "," + data + (String)"\r\n";
sendCommand(command);
}
/**
* Function to send a join request
* allowed methods "otaa" and "abp"
*/
void sendJoinReq(String method){
String command = (String)"at+join=" + method + "\r\n";
sendCommand(command);
}
/**
* Function to set the connection config
* < dev_addr >:<address>
<address>-------------------4 bytes hex number representing the
device address from 00000001 –
FFFFFFFE
<dev_eui>:<eui>
<eui>-------------------------- 8-byte hexadecimal number
representing the device EUI
<app_eui>:<eui>
<eui>----------------------------8-byte hexadecimal number
representing the application EUI
<app_key>:<key>
- 11 -
<key>----------------------------16-byte hexadecimal number
representing the application key
<nwks_key>:<key>
<key>-------------------------16-byte hexadecimal number
representing the network session key
<apps_key>:<key>
<key>------------------------ 16-byte hexadecimal number representing
the application session key
<tx_power>:<dbm>
<dbm>------------------- LoRaWAN Tx Power
<adr>:<status>
<status>----------------------------- string value representing
the state, either “on” or “off”.
<dr>:<data rate>
<data rate>-----------------------decimal number representing the
data rate, from 0 and 4, but within
the limits of the data rate range for
the defined channels.
< public_net >:<status>
<status>------------------- string value representing
the state, either “on” or “off”.
< rx_delay1 >:<delay>
<delay>-------------------decimal number representing
the delay between the transmission
and the first Reception window
in milliseconds, from 0 to 65535.
*/
void setConnConfig(String key, String value){
sendCommand("at+set_config=" + key + ":" + value + "\r\n");
}
The Code goes like so:
- Get the Serial and the Serial1 objects initialized with 115200 as the baud rate. We will be using the Serial1 connection to talk to the RAK811 and Serial to send debug response messages from RAK811
- Then we create a String object called response to store the response from RAK811 after every command provided
- In the loop function we call the sendCommand function to first send a at+version command to check the version
- Considering an OTAA based connection It will then set three importatnt parameters:
1) DEV_EUI
2) app_EUI
3) app_key
Refer to the tutorial here: https://www.hackster.io/naresh-krish/getting-started-with-the-rak811-lora-node-67f157 to know how to get these values from TheThingsNetwork console page.
- One you have these value: we will call the setConnConfig function to set the various confguration.
- Next we will initiate a join by calling the at+join command
- This should show OK + 3,0,0 as the response string.
- Now we can send data that as shown in the loop function;
A sample of the Serial terminal would show up like so:
The code is crude and not an ideal production ready sample. This is just to get you started on the arduino aspect of the RAK811 board.
I will be posting a link to a complete library for the RAK811 board soon. Next tutorial we will see how to use CoIDE to programm the STM32 board which is part of the RAK811 module.
Comments