esp32 lora RYLR890
chrome-extension://efaidnbmnnnibpcajpcglclefindmkaj/https://reyax.com/upload/products_download/download_file/LoRa-AT-Command-RYLR40x_RYLR89x_EN-8.pdf
send lora at command message esp32
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
#include <HardwareSerial.h> HardwareSerial LoRaSerial(1); // Using UART 1 on ESP32 int messageCount = 0; // Initialize a message counter void setup() { Serial.begin(115200); // Start the Serial Monitor at 115200 baud while (!Serial); // Wait for the serial port to connect LoRaSerial.begin(115200, SERIAL_8N1, 16, 17); // Initialize LoRaSerial with RX=16, TX=17 // Initialize RYLR400 sendCommand("AT+RESET"); // Set device address sendCommand("AT+ADDRESS=1"); // Set device address sendCommand("AT+NETWORKID=4"); // Set network ID // sendCommand("AT+MODE=0"); // Set mode to normal sendCommand("AT+BAND=868500000"); // Set frequency to 868.5 MHz (corrected from 915 MHz in your setup if needed) sendCommand("AT+PARAMETER?"); // Set network ID // Additional settings sendCommand("AT+PARAMETER=7,8,1,7"); // Example: Spreading factor, Bandwidth, Coding rate, Preamble length sendCommand("AT+CRFOP=15"); // Set power level max 22 sendCommand("AT+VER"); // Get firmware version sendCommand("AT+MODEL"); // Get model information (if supported) sendCommand("AT+ADDRESS?"); // Get current device address sendCommand("AT+BAND?"); // Get current frequency band sendCommand("AT+NETWORKID?"); // Get current network ID Serial.println("Module information retrieval completed."); //while(1); } void loop() { // Prepare message with the counter String message = " Msg Count: " + String(messageCount); // Construct the full AT command to send the message String command = "AT+SEND=2," + String(message.length()) + "," + message; // Send the message sendCommand(command.c_str()); // Convert String object to C-string messageCount++; // Increment the message counter after sending delay(100); // Wait for 10 seconds between messages } void sendCommand(const char* command) { Serial.print("Sending Command: "); Serial.println(command); LoRaSerial.println(command); delay(1000); // Delay to allow for command processing readLoRaResponse(); } void readLoRaResponse() { while (LoRaSerial.available()) { String response = LoRaSerial.readStringUntil('\n'); Serial.println(response); // Print the response to the Serial Monitor } } |
receive lora message rss and snr
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
#include <HardwareSerial.h> HardwareSerial LoRaSerial(1); // Using UART 1 on ESP32 void setup() { Serial.begin(115200); // Start the Serial Monitor at 115200 baud while (!Serial); // Wait for the serial port to connect LoRaSerial.begin(115200, SERIAL_8N1, 16, 17); // Initialize LoRaSerial with RX=16, TX=17 // Initialize RYLR890 sendCommand("AT+RESET"); // Set device address delay(2500); sendCommand("AT+ADDRESS=2"); // Set receiver device address delay(2500); sendCommand("AT+NETWORKID=4"); // Set network ID delay(2500); sendCommand("AT+BAND=868500000"); // Set frequency to 868.5 MHz (adjust as needed) sendCommand("AT+PARAMETER=7,8,1,7"); sendCommand("AT+PARAMETER?"); // Set network ID delay(2500); // Check if any additional settings are specific to RYLR890 //sendCommand("AT+PARAMETER=7,125,1,8"); // Spreading factor, bandwidth, coding rate, preamble length (if supported) sendCommand("AT+VER"); // Get firmware version sendCommand("AT+MODEL"); // Get model information (if supported) sendCommand("AT+ADDRESS?"); // Get current device address sendCommand("AT+BAND?"); // Get current frequency band sendCommand("AT+NETWORKID?"); // Get current network ID Serial.println("Module information retrieval completed."); Serial.println("RYLR890 LoRa receiver..."); } void loop() { while (LoRaSerial.available()) { String receivedData = LoRaSerial.readStringUntil('\n'); if (receivedData.length() > 0) { Serial.print("Received Data: "); Serial.print(receivedData); if (receivedData.startsWith("+RCV=")) { // Remove the "+RCV=" prefix and split the string by commas receivedData = receivedData.substring(5); // Remove "+RCV=" String parts[5]; // Array to hold the split parts int partIndex = 0; while (receivedData.length() > 0 && partIndex < 5) { int commaIndex = receivedData.indexOf(','); if (commaIndex != -1) { parts[partIndex++] = receivedData.substring(0, commaIndex); receivedData = receivedData.substring(commaIndex + 1); } else { parts[partIndex++] = receivedData; break; } } // Print the array parts for real-time monitoring /* for (int i = 0; i < partIndex; i++) { Serial.print("Part "); Serial.print(i); Serial.print(": "); Serial.println(parts[i]); } */ // Optional: Process specific parts, such as RSSI or message content // Serial.print("Message Content: "); // Serial.println(parts[2]); // Adjust index as needed for specific parts Serial.print(" RSSI: "); Serial.print(parts[3]); // RSSI value Serial.print( " SNR: "); Serial.println(parts[4]); // RSSI value } else { // Print other non-RCV responses for monitoring Serial.println(""); } } } } void sendCommand(const char* command) { Serial.print("Sending Command: "); Serial.println(command); LoRaSerial.println(command); delay(100); // Delay to allow for command processing readLoRaResponse(); } void readLoRaResponse() { while (LoRaSerial.available()) { String response = LoRaSerial.readStringUntil('\n'); Serial.println(response); // Print the response to the Serial Monitor } } |