All Collections
Connect your Devices
Connect Seeed Studio’s LoRa-E5 to Ubidots [LoRa]
Connect Seeed Studio’s LoRa-E5 to Ubidots [LoRa]

This guide explores how to use two LoRa-E5 modules, one acting as a gateway and the other as a node to send data to Ubidots

S
Written by Sergio M
Updated over a week ago
image.png

Seeed Studio’s LoRa-E5 series is a powerful line of LoRaWAN modules embedding STM32WLE5JC MCU and SX126X RF module in a single chip. It can be used in a LoRaWAN network as well as to setup your own LoRa network. This guide is about the latter.

Requirements

  • Two LoRa-E5 modules. It can be any of the Wio-E5 series such as Wio-E5 Development Kit, Wio-E5 Mini board or Groove-Wio-E5

  • Any Arduino board with at least two serial interfaces

  • A ESP32 or ESP8266

  • Jumper wires

  • A Ubidots account

  • Arduino IDE installed

  • Ubidots library running on Arduino

  • Arduino library “ArduinoJson” installed

Table of Contents

  1. Set up connections for the module acting as node

  2. Set up connections for the module acting as a gateway

  3. Visualize data on Ubidots

  4. Feedback, Suggestions, and Related Articles

1. Set Up the Module Acting as Gateway

  • Connect the ESP32 or ESP8266 module to the Wio-E5 Groove module in the following way:

image.png
  • If you are using Wio-E5 mini:

    • Connect the ESP32’s “RX” terminal to “TX” on the LoRa-E5 mini (the one with the green label)

    • Connect the ESP32’s “TX” terminal to “RX” on the LoRa-E5 mini (the one with the green label)

    • Connect ESP32’s “3V3” terminal to “V+” on the LoRa-E5 mini

    • Connect ESP32’s “GND” terminal to “V-” on the LoRa-E5 mini

image974.png
  • If you are using Wio-E5 DevKit:

    • Connect the ESP32’s “RX” terminal to “TX” on the LoRa-E5 DevKit

    • Connect the ESP32’s “TX” terminal to “RX” on the LoRa-E5 DevKit

    • Connect ESP32’s “3V3” terminal to “Vin” on the LoRa-E5 DevKit

    • Connect ESP32’s “GND” terminal to “GND” on the LoRa-E5 DevKit

image164.png

Pro Tip: Remember to connect the antenna to your Wio-E5 device before operation in order to avoid chip damages.


The following step requires you to have installed the Ubidots library for either ESP32 or ESP8266. Follow the given links in you haven’t done so yet

  • Launch the Arduino IDE

  • Connect the ESP32 or ESP8266 to the PC via USB cable

  • Go to “Tools” → "Board" and select the device that you are using\

image10071.png
  • Select the appropriate “Port” to which your device is connected

image11667.png
  • Upload the following code to the ESP32 taking into account that you must change the following settings:

    • const char* UBIDOTS_TOKEN = "your-token"; set this variable to your Ubidots token

    • const char* WIFI_SSID = "SSID"; set this variable to match your WIFi SSID

    • const char* WIFI_PASS = "PASS"; set this variable so it matches your WIFi password

#include <ArduinoJson.h>
#define LoRaSerial Serial2
#include "Ubidots.h"

const char* UBIDOTS_TOKEN = "your-token";
const char* WIFI_SSID = "SSID";
const char* WIFI_PASS = "PASS"; // Put here your Wi-Fi password

Ubidots ubidots (UBIDOTS_TOKEN, UBI_HTTP);

static char receiverBuffer[512];
char tempBuffer[128];

static int sendCommandWithACK(char *p_ack, int timeout_ms, char *p_cmd, ...)
{
int responseChar;
int index = 0;
int startMillis = 0;
va_list args;
memset(receiverBuffer, 0, sizeof(receiverBuffer));
va_start(args, p_cmd);
Serial2.print(p_cmd);
Serial.print(p_cmd);
va_end(args);
delay(200);
startMillis = millis();

if (p_ack == NULL)
return 0;

do
{
while (Serial2.available() > 0)
{
responseChar = Serial2.read();
receiverBuffer[index++] = responseChar;
Serial.print((char)responseChar);
delay(2);
}

if (strstr(receiverBuffer, p_ack) != NULL)
return 1;

} while (millis() - startMillis < timeout_ms);
Serial.println();
return 0;
}

static void recv_prase(char *p_msg, char *dum)
{
if (p_msg == NULL)
{
Serial.println("Received null");
return;
}
char *p_start = NULL;
char data[128]; // To hold the received bytes as characters

int bytes_len=0;
p_start = strstr(p_msg, "RX");
if (p_start && (1 == sscanf(p_start, "RX \"%s\"", &data)))
{
for (int i=0; i<sizeof(data); i++) {
if(int(data[i+1])==0) {
bytes_len = i;
break;
}
}

// Convert the characters to a byteArray
int message_len = bytes_len/2+1;
char out[message_len];
auto getNum = [](char c){ return c > '9' ? c - 'A' + 10 : c - '0'; };
for (int x=0, y=0; x<bytes_len; ++x, ++y)
out[y] = (getNum(data[x++]) << 4) + getNum(data[x]);
out[message_len] = '\0';
snprintf(dum, 128, "%s", out);
}
}
bool setModuleListening(void)
{
Serial.print("Checking if the module is connected\r\n");
sendCommandWithACK("+AT: OK", 100, "AT\r\n");
sendCommandWithACK("+MODE: TEST", 1000, "AT+MODE=TEST\r\n");
bool temp = sendCommandWithACK("+TEST: RXLRPKT", 5000, "AT+TEST=RXLRPKT\r\n");
delay(200);
return temp;
}
void setup(void)
{
bool LoRaSetup = false;
Serial.begin(9600);
LoRaSerial.begin(9600);
ubidots.wifiConnect(WIFI_SSID, WIFI_PASS);
while(!LoRaSetup)
{
LoRaSetup = setModuleListening();
}
}

void loop(void)
{
char cmd[128];

// Transmit HEX Value
sprintf(cmd, "");
int ret = sendCommandWithACK("+TEST: RX", 1000, "");
if (ret)
{
recv_prase(receiverBuffer, dum);
DynamicJsonDocument doc(1024);
deserializeJson(doc, tempBuffer);
JsonObject obj = doc.as<JsonObject>();
long temperature = obj[String("temperature")];
Serial.print(temperature);
ubidots.add("temperature", temperature);
bool bufferSent = false;
bufferSent = ubidots.send("wio-e5-gateway");

if(bufferSent){
Serial.println("sent succesfull");
}
else Serial.println("not sent");


}
else
Serial.println("Receive failed!\r\n\r\n");

delay(500);
}

2. Set up Connections for the Module Acting as a Node

This guide uses an Arduino Mega board, however you can use any of your choice, just keep in mind that you should use the “TX1” and “RX1” instead of “TX0” and “RX0” since the latter serial interface is used for the communication with the PC. E.g. On a Arduino Uno board, the “TX1” and “RX1” are the pins labeled as “~6” and “~7” respectively.

  • Connect the Wio-E5 series device to the Arduino board in the following way

image974.png
  • If you are using either the Wio-E5 DevKit or Wio-E5 groove, you can make the connections based on the information from section 1.

  • Launch the Arduino IDE

  • Connect the Arduino board to the PC via USB cable

  • Select the appropriate board and port just as in the previous section

  • Upload the following code to the Arduino

#include <ArduinoJson.h>
#define LoRa Serial1


static char receiverBuffer[512];

static int sendCommandWithACK(char *ACKMsg, int timeoutMS, char *CMD, ...)
{
int responseChar;
int receivedMsgIndex = 0;
int startMillis = 0;

va_list args;
memset(receiverBuffer, 0, sizeof(receiverBuffer));
va_start(args, CMD);

Serial.print("Sending command: ");
Serial.print("\n\r\t");
Serial.println(CMD);
LoRa.print(CMD);


va_end(args);
delay(200);
startMillis = millis();

if (ACKMsg == NULL)
return 0;

Serial.println("module response: ");
Serial.print("\t");
do
{
while (LoRa.available() > 0)
{
responseChar = LoRa.read();
receiverBuffer[receivedMsgIndex++] = responseChar;
Serial.print((char)responseChar);
delay(2);
}
if (strstr(receiverBuffer, ACKMsg) != NULL)
return 1;

} while (millis() - startMillis < timeoutMS);
Serial.println();
return 0;
}

void setup(void)
{
bool LoRaSetup = false;
Serial.begin(9600);
LoRa.begin(9600);
while(!LoRaSetup)
{
LoRaSetup = setModuleBroadcasting();
}

}

bool setModuleBroadcasting(void)
{
Serial.print("Checking if the module is connected\r\n");
sendCommandWithACK("+AT: OK", 100, "AT\r\n");
return sendCommandWithACK("+MODE: TEST", 1000, "AT+MODE=TEST\r\n");
}


void loop(void)
{
int sensorValue = random(20,80);
char cmdBuffer[512];
char payloadBuffer[256];
char ACKBuffer[256];

snprintf(payloadBuffer, sizeof(payloadBuffer), "%s%d%s", "{'temperature':", sensorValue, "}");
snprintf(ACKBuffer, sizeof(ACKBuffer), "%s%s%s%s", "+TEST: TXLRSTR ", "\"", payloadBuffer, "\"");
snprintf(cmdBuffer, sizeof(cmdBuffer), "AT+TEST=TXLRSTR,\"%s\"\r\n", payloadBuffer);

int ret = sendCommandWithACK(ACKBuffer, 1000, cmdBuffer);

if (ret)
Serial.println("Sent succesfull");
else
Serial.println("Send failed!\r\n\r\n");
delay(5000);

}

  • If everything is wired correctly, you should be able to see both devices communicating to each other using LoRa. The following is Arduino’s Serial monitor output:

3. Visualize data on Ubidots

  • Go to your Ubidots account → “Devices” and you’ll see a newly created device with data being ingested

image11701.png

The code was based on the one found here.

4. Feedback, Suggestions, and Related Articles

Feel free to post questions or suggestions in our community portal, or contact us via support@ubidots.com.

Other users also found helpful...

Did this answer your question?