For the last few days, I was trying to build LoRa P2P communication using LoRa E5. Finally, Hendra's documentation clears all my doubts. For this documentation, I use Wio Terminal LoRaWan Chassis as thesender and Grove - Wio-E5 as the receiver.
You can use any LoRa E5 module to implement this. For this, I connect Wio Terminal LoRaWan Chassis with XIAO RP2040 using grove connectors and XIAO shield as given below.
I use D1 and D2 as RX and TX.
Then Time to install the Boards manager in Arduino IDE,
When I install the board file for XIAO RP2040 in the usual manner by copying the link from seeedstudio official Wiki I face some Errors like the below.
After this Hendra suggests installing a Boards manager from earlephilhower.
Now you can install the board file by following the step below
Go to File > Preferences
In Additional Boards Manager, click add and paste the URL there:https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
After this click OK and go to Tools > Boards > Board Manager in the Arduino IDE and search for Pico.
After this, select all the highlighted selections below.
Then we can Upload the Code below to the transmitter device
#include <Arduino.h>
#include<SoftwareSerial.h>
SoftwareSerial e5(D1, D2);
static char recv_buf[512];
int counter = 0;
static int at_send_check_response(char *p_ack, int timeout_ms, char *p_cmd, ...)
{
int ch;
int num = 0;
int index = 0;
int startMillis = 0;
va_list args;
memset(recv_buf, 0, sizeof(recv_buf));
va_start(args, p_cmd);
e5.print(p_cmd);
Serial.print(p_cmd);
va_end(args);
delay(200);
startMillis = millis();
if (p_ack == NULL)
return 0;
do
{
while (e5.available() > 0)
{
ch = e5.read();
recv_buf[index++] = ch;
Serial.print((char)ch);
delay(2);
}
if (strstr(recv_buf, p_ack) != NULL)
return 1;
} while (millis() - startMillis < timeout_ms);
Serial.println();
return 0;
}
void setup(void)
{
Serial.begin(9600);
e5.begin(9600);
Serial.print("E5 LOCAL TEST\r\n");
at_send_check_response("+TEST: RFCFG", 1000, "AT+TEST=RFCFG,866,SF12,125,12,15,14,ON,OFF,OFF\r\n");
delay(200);
}
void loop(void)
{
char cmd[128];
counter=counter+1;
sprintf(cmd, "AT+TEST=TXLRPKT,\"%d\"\r\n", counter);
int ret = at_send_check_response("TX DONE", 5000, cmd);
}
For the understanding of the code, I highly recommend referring to the LoRa-E5 AT Command Specification. After uploading the above code you will get an Output like this.
Now you can move on to the Receiver setup, and install the Boards manager by following seeedstudio wiki
Then connect the RX and TX to 0 and 1 of the Wio terminal as below.
Then upload the program below to the Wio terminal.
#include <Arduino.h>
#include<SoftwareSerial.h>
SoftwareSerial e5(0, 1);
static char recv_buf[512];
static bool is_exist = false;
static int at_send_check_response(char *p_ack, int timeout_ms, char *p_cmd, ...)
{
int ch = 0;
int index = 0;
int startMillis = 0;
va_list args;
memset(recv_buf, 0, sizeof(recv_buf));
va_start(args, p_cmd);
e5.printf(p_cmd, args);
Serial.printf(p_cmd, args);
va_end(args);
delay(200);
startMillis = millis();
if (p_ack == NULL)
{
return 0;
}
do
{
while (e5.available() > 0)
{
ch = e5.read();
recv_buf[index++] = ch;
Serial.print((char)ch);
delay(2);
}
if (strstr(recv_buf, p_ack) != NULL)
{
return 1;
}
} while (millis() - startMillis < timeout_ms);
return 0;
}
static int recv_prase(void)
{
char ch;
int index = 0;
memset(recv_buf, 0, sizeof(recv_buf));
while (e5.available() > 0)
{
ch = e5.read();
recv_buf[index++] = ch;
Serial.print((char)ch);
delay(2);
}
if (index)
{
char *p_start = NULL;
char data[32] = {
0,
};
int rssi = 0;
int snr = 0;
p_start = strstr(recv_buf, "RSSI:");
if (p_start && (1 == sscanf(p_start, "RSSI:%d,", &rssi)))
p_start = strstr(recv_buf, "SNR:");
return 1;
}
return 0;
}
static int node_recv(uint32_t timeout_ms)
{
at_send_check_response("+TEST: RXLRPKT", 1000, "AT+TEST=RXLRPKT\r\n");
int startMillis = millis();
do
{
if (recv_prase())
{
return 1;
}
} while (millis() - startMillis < timeout_ms);
return 0;
}
void setup(void)
{
Serial.begin(115200);
// while (!Serial);
e5.begin(9600);
Serial.print("Receiver\r\n");
if (at_send_check_response("+AT: OK", 100, "AT\r\n"))
{
is_exist = true;
at_send_check_response("+MODE: TEST", 1000, "AT+MODE=TEST\r\n");
at_send_check_response("+TEST: RFCFG", 1000, "AT+TEST=RFCFG,866,SF12,125,12,15,14,ON,OFF,OFF\r\n");
delay(500);
}
else
{
is_exist = false;
Serial.print("No E5 module found.\r\n");
}
}
void loop(void)
{
if (is_exist)
{
node_recv(2000);
}
}
Then you will get an output like the one below.
I would like to thank Hendra Kusumah for his help, also I refer to this from his project Environment Data lora Node.
Comments