First, we need to prepare the environment for ESP32 development board programming in Arduino, and you can check this guide.
RadioLib library is a wireless communication library. It supports a variety of wireless communication modules, including LoRa, NRF24L01, SX127x, and more. Using the RadioLib library, you can easily add wireless communication capabilities to your Arduino projects, whether it's for data transfer, remote control, or sensor networks.
#include<RadioLib.h>
The SPI.h header file enables your Arduino project to use the functionality provided by the SPI library to communicate with external SPI devices.
#include<SPI.h>
Define the pins used to connect to the LoRa module. Set the LoRa module frequency, bandwidth, spreading factor, coding rate, output power, and leading code length. Initialise "radio" to represent the LoRa module and pass the appropriate pins and parameters.
String str;
int state = radio.receive(str);
// you can also receive data as byte array/*
size_t len = 8;
byte byteArr[len];
int state = radio.receive(byteArr, len);
*/if (state == ERR_NONE) {
// packet was successfully received
Serial.println(F("success!"));
// print data of the packet
Serial.print(F("Data:\t\t\t"));
Serial.println(str);
// print RSSI (Received Signal Strength Indicator)// of the last received packet
Serial.print(F("RSSI:\t\t\t"));
Serial.print(radio.getRSSI());
Serial.println(F(" dBm"));
// print SNR (Signal-to-Noise Ratio)// of the last received packet
Serial.print(F("SNR:\t\t\t"));
Serial.print(radio.getSNR());
Serial.println(F(" dB"));
// print frequency error// of the last received packet
Serial.print(F("Frequency error:\t"));
Serial.print(radio.getFrequencyError());
Serial.println(F(" Hz"));
} elseif (state == ERR_RX_TIMEOUT) {
// timeout occurred while waiting for a packet//Serial.println(F("timeout!"));
} elseif (state == ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));
}
Extract the number from the received message and store it in an array, modify the write channel URL given by ThingSpeak according to the array data
String numbers[10];
intextractNumbers(String input, String numbers[]) {
int count = 0;
String number = "";
for (int i = 0; i < input.length(); i++) {
char c = input.charAt(i);
...
This gateway is composed of ESP32S3 4G LTE A7670 module and A LoRa radio expansion
Note: LoRa communication needs the sender& receiver to work at the same frequency. The frequency of the LoRa Soil Moisture Sensor is 915MHz, so the frequency of the LoRa Expansion Board needs to be 915MHz as well.