In LoRa based system we can transmit the information to Another LoRa, then we can use that information and display it on the Local LCD Display or somewhere. if we need the data to be transmitted far longer distances than the LoRa Coverage? What do we have to do?
There are two methods available here
- If any other networks(4G,2G,3G) are available in the particular area we can use LoRa Gateways.
- If there are no networks available, we can use the Another LoRa Module as Repeaters
The Above Two methods have their Respective Advantages and Disadvantages.
The LoRaWAN Gateways are Not pocket friendly and Requires Subscriptions to connect the devices and transfer data to the cloud.
The LoRa Repeaters Implementation Requires More Number Transceiver modules to Transfer the data to the Receivers. And it can’t store details on the cloud it can store the data locally.
In this Project, I am building Single channel LoRa gateway using Seeed studio Wio-E5 Module, ESP8266, And Blynk.
Before briefly Explaining, Let's know a few basics about LoRafollow the link to learn more about What are LoRa® and LoRaWAN®?
LoRaWAN Gateways are one of four key components of the LoRa network architecture:
- End Nodes– Represents edge devices or sensors
- Gateway – Collects or concentrates data from several end nodes
- Network Server – Consolidates data from gateways for upload to the application server
- Application Server – Processes or displays consolidated data
Let's know more about the Seeed studio Wio-E5 LoRa module.
Wio-E5 is a low-cost, ultra-low power, extremely compact, and high-performance LoRaWAN® Module designed by Seeed Technology Co., Ltd. It contains ST system-level package chip STM32WLE5JC, which is the world's first SoC integrated with the combo of LoRa® RF and MCU chip. For More detailed Information on the LoRa-E5 Visit https://www.seeedstudio.com/LoRa-E5-Wireless-Module-p-4745.html
This module is also embedded with ARM Cortex M4 ultra-low-power MCU and LoRa® SX126X and therefore supports (G)FSK mode and LoRa®. 62.5kHz, 125kHz, 250kHz, and 500kHz bandwidth can be used in LoRa® mode, making it suitable for the design of various IoT nodes, supporting EU868 and US915.
This Wio E5 module is designed with industrial standards, hence it's highly suitable to be used in designing industrial IoT products, with a wide working temperature at -40℃ ~ 85℃.
Features
- Ultra-low Power Consumption: as low as 2.1uA sleep current (WOR mode)
- Extremely Compacted Size: 12mm * 12mm * 2.5mm 28 pins SMT
- High Performance: TXOP=22dBm@868/915MHz; -136.5dBm sensitivity for SF12 with 125KHz BW
- Long Distance Use: 158dB link budget
- Wireless Connectivity: Embedded LoRaWAN® protocol, AT command, support global LoRaWAN® frequency plan
- Worldwide Compatibility: wide frequency range; EU868 / US915 / AU915 / AS923 / KR920 / IN865
- Great Flexibility: For users who want to develop software on the MCU of the module, other GPIOs of the MCU can be easily manipulated, including UART, I2C, ADC, etc. These rich GPIO interfaces are useful for users who need to expand peripherals.
Simple Comparisons Of LoRa E5 and RFM95
Here I am using Wio-E5 Factory AT Firmware to communicate with Host Microcontroller. Let's start learning with the AT Commands.
Wio-E5 series has a built-in AT command firmware, which supports LoRaWAN® Class A/B/C protocol and a wide frequency plan: EU868/US915/AU915/AS923/KR920/IN865. With this AT command firmware, developers can easily and quickly build their prototype or application.
The AT command firmware contains a bootloader for DFU and the AT application. The "PB13/SPI_SCK/BOOT" pin is used to control Wio-E5 to stay in the bootloader or jump to the AT application. When PB13 is HIGH, the module will jump to AT application after reset, with a default baud rate of 9600. When PB13 is LOW (press the "Boot" button on Wio-E5 mini/ Wio-E5 Development Kit), the module will stay in the bootloader, and keep transmitting a "C" character every 1S at baud rate 115200.
AT Commands
All command lines must start with "AT" and end with a carriage return character. We will use <CR> to represent a carriage return character
- The command is case insensitive
- All commands have a response
- Command length never exceeds a total of 528 characters
- One valid AT Command must end with '\n', "\r\n" is also valid
- If the command timeout feature is enabled, end '\n' will not be mandatory
- means the newline character. means carriage return
- UART2 configuration "9600, 8, n 1" (8 bits data, no parity, 1 stop bit);
AT Commands Symbols
Symbol |
Meaning of the symbols In the AT mode |
= |
Set value for the command |
? |
Query |
: |
Start a list input parameter |
+ |
Prefix of command |
, |
Separator of parameters |
Space |
An empty character could be used to format the command |
AT Commands Format
All commands in this document end with<CR><LF>. To facilitate the description, all is intentionally omitted in this document. <CR> and <LF> represent a carriage return character and a linefeed character respectively.
Query Commands
query command to check LoRaWAN modem configuration, such as channel configuration, ADR status, TX power, etc.
Example: AT+MODE=? //Querying the mode of work
Configure / Control
configure/control command to set new configuration or control transaction.
RETURN Data
Return data is in the format like "+CMD: RETURN DATA"
Example +MODE: TEST
AT Commands
Command |
Description |
AT |
Test command |
HELP |
Print command list |
FDEFAULT |
Factory data reset |
RESET |
Software reset |
DFU |
Force the bootloader to enter dfu mode |
LOWPOWER |
Enter sleep mode |
VER |
Version[Major.Minor.Patch] |
MSG |
LoRaWAN unconfirmed data |
MSGHEX |
LoRaWAN unconfirmed data IN HEX |
CMSG |
LoRaWAN confirmed data |
CMSGHEX |
LoRaWAN confirmed data in hex |
PMSG |
LoRaWAN proprietary |
PMSGHEX |
LoRaWAN proprietary in hex |
CH |
LoRaWAN channel frequency |
DR |
LoRaWAN data rate |
ADR |
LoRaWAN ADR control |
REPT |
Unconfirmed message repetition |
RETRY |
Confirmed message retry |
POWER |
LoRaWAN TX power |
RXWIN2 |
LoRaWAN RX window2 |
RXWIN1 |
Customized RXWIN1 frequency |
PORT |
LoRaWAN communication port |
MODE |
LWABP, LWOTAA, TEST |
ID |
LoRaWAN DevAddr/DevEui/AppEui |
KEY |
Set NWKSKEY/APPSKEY/APPKEY |
CLASS |
Choose LoRaWAN modem class(A/B/C) |
JOIN |
LoRaWAN OTAA JOIN |
LW |
LoRaWAN misc configuration (CDR, ULDL, NET, DC, MC, THLD) |
TEST |
Send test serious command |
UART |
UART configure |
REG |
Control RF Chip |
DELAY |
RX window delay |
VDD |
Get VDD |
RTC |
RTC time get/set |
EEPROM |
Write/Read EEPROM |
Error Codes
This error code list applies to all LoRaWAN-supported commands. Users could refer to this list to know what is happening to the LoRaWAN modem when gets errors.
Code |
Description |
-1 |
The number of parameters is invalid |
-2 |
The content of the parameter is invalid |
-3 |
API function returns an error when a user parameter is passed to it |
-4 |
LoRaWAN modem can't save parameters to EEPROM |
-5 |
The command is disabled currently |
-6 |
Unknown error occurs |
-7 |
There is not enough HEAP to execute user operation |
-10 |
Command unknown |
-11 |
The command is in the wrong format |
-12 |
The command is unavailable in current mode (Check with "AT+MODE") |
-20 |
Too many parameters. LoRaWAN modem support max 15 parameters |
-21 |
The length of the command is too long (exceeds 528 bytes) |
-22 |
Receive end symbol timeout, command must end with |
-23 |
Invalid character received |
-24 |
Either -21, -22 or -23 |
Example: The number of parameters is invalid
AT+mode=1
+MODE: ERROR(-1)
In the above example, we are getting an Error number of -1, which means we are setting the invalid command.
How to resolve the error: in the at command, it is mentioned when the prefix command is entered respective value need to enter. In the above example, we have to select work mode, based on the work mode command we can only three values LWABP, LWOTAA, and TEST. But the entered value is 1, which means it is not a valid value
Let's enter the Correct value and what will be the Return Data
AT+mode=TEST
+MODE: TEST
AT+mode=LWABP
+MODE: LWABP
AT+mode=LWOTAA
+MODE: LWOTAA
For creating this project I am using Two Wio-E5 Development Kit
Wio E5 Development kit is based on STM32WLE5JC.
Wio-E5 Dev Board has a long-distance transmission range of Wio-E5 up to 10km in an open area. The sleep current of Wio-E5 modules on board is as low as 2.1 uA(WOR mode). It is designed with industrial standards with a wide working temperature at -40 ℃ ~ 85℃, high sensitivity between -116.5 dBm ~ -136 dBm, and power output up to +20.8dBm at 3.3V.
Wio-E5 Dev Board also has rich interfaces. Developed to unlock the full functionality of the Wio-E5 module, Wio-E5 Dev Board has led out the full 28 pins of Wio-E5 and provides rich interfaces including Grove connectors, RS-485 terminal, male/female pin headers for you to connect sensors and modules with different connectors and data protocols, saving your time on wire soldering. You could also easily power the board by connecting the battery holder with 2 AA batteries, enabling temporary use when lacking an external power source. It is a user-friendly board for easy testing and rapid prototyping.
Since Wio-E5 is a LoRaWAN® chip with an MCU, there are three main ways to utilize the Wio-E5 Dev Board:
1: Connect Wio-E5 Dev Board to PC via USB and control by AT commands
There is a built-in USB to UART function on board, you could just simply connect the Wio-E5 Dev Board to your PC with a USB type C cable, and use serial communication software to send AT commands and read data from the board
2: Connect Wio-E5 Dev Board to another mainboard via UART and control by AT commands
For example, connect Wio-E5 Dev Board to Seeeduino XIAO and the Expansion Board via UART, send AT commands, and read data from Seeeduino XIAO through Arduino IDE serial monitor.
3: Develop user applications by using SDK
Develop your LoRa® development board with MCU function by using STM32Cube Programmer, which is the SDK officially provided by STMicroelectronics. To download this SDK resource, please find the resources in learning and document down below.
With all the outstanding features listed above, the Wio-E5 Dev Board will be a superior choice for IoT device development, testing, prototyping, and applications in long-distance, ultra-low power consumption IoT scenarios like smart agriculture, smart office, and smart industry.
In this project, I will explain only The AT Command which is utilized. For a detailed AT Commands description follow this link
Communicating The LoRa Modules using AT Commands
- We need two LoRa Module Here to test the basic AT commands require to complete the project.
- These two modules are connected to the Computer using a Type C USB connector.
- To send and receive the data we require serial terminal software on the PC.
- One LoRa Module Is Used as a Transmitter and Another LoRa Module Is used as a receiver to test the AT Commands
Transmitter Side
- Enter TEST mode:
TEST command is not like other commands, it is a serious command, and includes several sub-commands, refer to the table below. With test mode, the user could do an RF performance test quickly without any knowledge of the LoRa chip. Commands which are related to RF configuration are disabled in test mode.LWABP7, LWOTAA8, and TEST are supported. LoRaWAN modem can only work with one mode at a time. By default, LWABP is enabled, all test commands are unavailable, and LoRaWAN will return an error(-12) if it receives the test command in non-test mode.
The "AT+MODE" command will reset the LoRaWAN stack when first entering LWABP/LWOTTA mode and reset the LoRa chip when first entering test mode.LWABP/LWOTAA mode status is remembered by the LoRaWAN modem, each time the LoRaWAN modem starts, it will enter the previous working mode before resetting or repower.
Here to test the modules I will select the Test Mode
AT+MODE=TEST
+MODE: TEST ← once the work mode is successfully configured the return data will indicate the mode we selected.
←LoRaWAN Modem Enter Test mode successfully
Test Sub-Command
Sub-command |
Comment |
HELP |
Print test command help information, make LoRa transceiver to standby mode |
STOP |
Set LoRaWAN Modem to TEST stop mode |
TXCW |
Transmit continuous wave |
TXCLORA |
Transmit continuous LoRa signal |
RFCFG |
Set RF configuration in TEST mode |
RXLRPKT |
Continuous receive pure LoRa packet, print once there is a new packet received |
TXLRPKT |
Send one HEX format packet out |
TXLRSTR |
Send one string format packet |
RSSI |
Get the RSSI value of the specified channel |
LWDL |
Send LoRaWAN downlink packet, a useful tool to test CLASS C device |
2. Set RF Configuration: RFCFG supports set frequency, SF, bandwidth, TX preamble, RX preamble, and TX power settings.
TX and RX share all configurations except "preamble length", the user could choose a different preamble length. For LoRa communication, it is strongly recommended to set RX preamble length longer than TX's. Bandwidth only supports 125KHz / 250KHz / 500KHz. Depending on Semtech SX1276 (PA_BOOST/RFO) and the design solution of the module, the MAX output power of different band LoRaWAN modems could be different.
The syntax for RF Configuration
AT+TEST=RFCFG,[FREQUENCY],[SF],[BANDWIDTH],[TX PR],[RX PR],[TX POWER] ,[CRC],[IQ],[NET]
Where,
SF: Spreading Factor
TX PR: TX Preamble
RX PR: RX Preamble
IQ: Inverted IQ
NET: Choosing Public Or Private Network
EX: AT+TEST=RFCFG,866,SF12,125,12,15,14,ON,OFF,OFF
+TEST: RFCFG F:866000000, SF12, BW125K, TXPR:12, RXPR:15, POW:14dBm, CRC: ON, IQ: OFF, NET: OFF
FREQUENCY: 866MHz
SpreadFactor: SF12
Bandwidth: 125KHz
TX Preamble: 12
RX Preamble: 15
Power: 14dBm
3. TX LoRa Packet: After entering test mode, the user could send the LoRa packet through the "AT+TEST=TXLRPKT" sub-command. The command format is like the below:
AT+TEST=TXLRPKT, "AB"
+TEST: TXLRPKT "AB"
+TEST: TX DONE ← when the data is sent successfully it will acknowledge as Done
Command sequence to send LoRa packet:
AT+MODE=TEST /// Set test mode
AT+TEST=? //// Query test mode, check RF configuration
AT+TEST=RFCFG,[FREQUENCY],[SF],[BANDWIDTH],[TXPR],[RXPR],[POW],[CRC],[IQ],[NET]// / Set RF Configuration
AT+TEST=TXLRPKT, "HEX String"// Send HEX format packet
Receiver side
On the receiver side, the few basic configuration commands are the same as the transmitter, I will Again List those here.
- Enter TEST mode
- Set RF Configuration
- RX LoRa Packet: After entering test mode, the user could enter LoRa packet continuous RX mode through the RXLRPKT subcommand (AT+TEST=RXLRPK). Like below:
AT+TEST=RXLRPKT
+TEST: RXLRPKT
Command sequence to receive LoRa packet:
AT+MODE=TEST // Set test mode
AT+TEST=?// Query test mode, check RF configuration
AT+TEST=RFCFG,866,SF12,125,12,15,14,ON,OFF,OFF//Set RF Configuration
AT+TEST=RXLRPKT // Enter RX continuous mode
LoRa Transmitter and Receiver AT Commands Testing
Now I will give details of the main project, in the transmitter part I am using XIAO SAMD21 Microcontroller, Wio E5 LoRa Dev Kit, SI7051 temperature sensor, and MPU 6050 Accelerometer gyroscope sensors, along with the 2X AA Battery .in the receiver part I am using Wio E5 LoRa Dev Kit, ESP8266 NodeMCU, OLED Display.
The transmitter part collects the temperature details, accelerometer, and gyroscope sensor collects the various movements of the device. if there is a change in the Position of the transmitter, the microcontroller transfers the alert data to the receiver using LoRa along with the surrounding temperature details. The transmitter Part is powered by two AA Size batteries that can run the transmitter for up to a couple of months.
Fig . Transmitter Section Block Diagram
Fig. Transmitter section connection diagram
In the receiver part The LoRa receives the data and the microcontroller processes the data and then displays the data in OLED Display. In Parallel transfers the details to the Blynk cloud servers using Wi-Fi to display them in the android app. The android app will display the Temperature, position of the Transmitter, RSSI, and Status of the Transmitter and Receiver connection.
Fig. Receiver Block diagram
Fig Receiver Connection Diagram
Project Demo Video
Transmitter Code
#include <Arduino.h>
#include <Wire.h>
#include "ClosedCube_Si7051.h"
#include "MPU6050.h"
ClosedCube_Si7051 si7051;
MPU6050 accelgyro;
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#include "Wire.h"
#endif
int data1=0;
int data2=0;
int data3=0;
int data4=0;
int16_t ax, ay, az;
int16_t gx, gy, gz;
#define OUTPUT_READABLE_ACCELGYRO
static char recv_buf[512];
static bool is_exist = false;
int a_x,a_y,a_z;
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);
Serial1.printf(p_cmd, args);
Serial.printf(p_cmd, args);
va_end(args);
delay(200);
startMillis = millis();
if (p_ack == NULL)
{
return 0;
}
do
{
while (Serial1.available() > 0)
{
ch = Serial1.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 node_send(uint32_t timeout)
{
static uint16_t count = 0;
int ret = 0;
char data[32];
char cmd[128];
memset(data, 0, sizeof(data));
sprintf(data, "%04X,%04X,%04X,%04X", data1, data2, data3,data4);
sprintf(cmd, "AT+TEST=TXLRPKT,\"5345454544%s\"\r\n", data);
ret = at_send_check_response("TX DONE", 2000, cmd);
if (ret == 1)
{
Serial.print("Sent successfully!\r\n");
}
else
{
Serial.print("Send failed!\r\n");
}
data1 = si7051.readTemperature();
data2 = a_z;
data3 = 100;
data4 = 200;
return ret;
}
void setup(void)
{
Serial.begin(115200);
si7051.begin(0x40); // default I2C address is 0x40 and 14-bit measurement resolution
Serial1.begin(9600);
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
Wire.begin();
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
Fastwire::setup(400, true);
#endif
accelgyro.initialize();
uint16_t error;
char errorMessage[256];
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(200);
}
else
{
is_exist = false;
Serial.print("No E5 module found.\r\n");
}
}
void loop(void)
{
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
Serial.print("Sensor data");
Serial.print(ax);
Serial.print(",");
Serial.print(ay);
Serial.print(",");
Serial.print(az);
Serial.println();
a_x = (ax+ay+az);
a_y = sqrt(a_x);
a_z = ((az)/ay);
Serial.print("x:");
Serial.print(a_z);
Serial.println();
if (is_exist)
{
node_send(2000);
delay(500);
}
}
Receiver Code
#include <Arduino.h>
#define BLYNK_TEMPLATE_ID "Your Blynk Template ID"
#define BLYNK_DEVICE_NAME "Your Blynk Device Name"
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <SoftwareSerial.h>
static char recv_buf[512];
static bool is_exist = false;
int RXPin = D6;
int TXPin = D5;
SoftwareSerial E5(RXPin, TXPin);
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
char auth[] = "Blynk Device authentication code";
char ssid[] = "Your Wi-Fi Name";
char pass[] = "Your Wi-Fi Password";
BlynkTimer timer;
WidgetLCD lcd(V1);
WidgetLCD lcd2(V3);
//////////////////////////////////////////////////////////////////////////////////////////
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, "+TEST: RX \"5345454544");
if (p_start)
{
p_start = strstr(recv_buf, "5345454544");
if (p_start && (1 == sscanf(p_start, "5345454544%s,", data)))
{
data[16] = 0;
int data1,data2,data3,data4;
char *endptr,*endptr1,*endpt2,*endptr3;
char dataarray1[5] = {data[0], data[1],data[2], data[3]};
char dataarray2[5] = {data[4], data[5], data[6], data[7]};
char dataarray3[5] = {data[8], data[9], data[10], data[11]};
char dataarray4[5] = {data[12], data[13],data[14], data[15]};
data1 = strtol(dataarray1, &endptr, 16);
data2 = strtol(dataarray2, &endptr1, 16);
data3 = strtol(dataarray3, &endptr, 16);
data4 = strtol(dataarray4, &endptr1, 16);
lcd2.clear();
Serial.print("data1:");
Serial.print(data1);
Serial.println();
Serial.print("data2:");
Serial.print(data2);
Serial.println();
Serial.print("data3:");
Serial.print(data3);
Serial.println();
Serial.print("data received displaying on the wio terminal");
Serial.print("\r\n");
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.print("Temperature:");
display.print(data1);
display.print(" C");
Blynk.virtualWrite(V0,data1);
if(data2 <=10)
{
display.setCursor(0,20);
display.print("The device Position had Changed");
lcd.clear(); //Use it to clear the LCD Widget
lcd.print(0, 0, "The device Posi"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
lcd.print(0, 1, "tion had Changed"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
}
else
{
display.setCursor(0,20);
display.print("The device is in a constant position");
lcd.clear(); //Use it to clear the LCD Widget
lcd.print(0, 0, "The device is in"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
lcd.print(0, 1, "constant position"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
}
}
p_start = strstr(recv_buf, "RSSI:");
if (p_start && (1 == sscanf(p_start, "RSSI:%d,", &rssi)))
{
String newrssi = String(rssi);
Serial.print(rssi);
Serial.print("\r\n");
Blynk.virtualWrite(V2,newrssi);
display.setCursor(0,50);
display.print("RSSI:");
display.print(rssi);
display.print(" dB");
display.display();
delay(100);
display.clearDisplay();
}
p_start = strstr(recv_buf, "SNR:");
if (p_start && (1 == sscanf(p_start, "SNR:%d", &snr)))
{
Serial.print(snr);
Serial.print("\r\n");
}
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);
Serial.print("No data");
Serial.println("");
display.clearDisplay();
display.setCursor(0,50);
display.print("Transmitter Not found");
display.display();
lcd.clear();
lcd2.clear(); //Use it to clear the LCD Widget
lcd2.print(0, 0, "Transmitter Not"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
lcd2.print(0, 1, "Found"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
Blynk.virtualWrite(V0,0);
Blynk.virtualWrite(V2,0);
return 0;
//
}
/////////////////////////////////////////////////////////
void setup() {
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
{
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
delay(2000);
display.clearDisplay();
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(200);
}
else
{
is_exist = false;
Serial.print("No E5 module found.\r\n");
}
}
void loop()
{
if (is_exist)
{
node_recv(2000);
}
Blynk.run();
timer.run();
}
Top Comments