Hello, I recently made a post about setting Lora parameters with the Lora.h library but was unsuccessfull so I am trying the Radiohead library. As was the case for Lora.h my radios worked well with the example code rf95_server and rf95_client.
I now wish to change parameters so I tried the example from comments in the sketch.
// Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
// You can change the modulation parameters with eg
// rf95.setModemConfig(RH_RF95::Bw500Cr45Sf128);
From the RH_RF95.h I found available "canned" configurations.
Bw125Cr45Sf128 = 0, ///< Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Default medium range
Bw500Cr45Sf128, ///< Bw = 500 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Fast+short range
Bw31_25Cr48Sf512, ///< Bw = 31.25 kHz, Cr = 4/8, Sf = 512chips/symbol, CRC on. Slow+long range
Bw125Cr48Sf4096, ///< Bw = 125 kHz, Cr = 4/8, Sf = 4096chips/symbol, low data rate, CRC on. Slow+long range
Bw125Cr45Sf2048, ///< Bw = 125 kHz, Cr = 4/5, Sf = 2048chips/symbol, CRC on. Slow+long range
} ModemConfigChoice;
I chose this one Bw125Cr45Sf2048 and set tx and rx radios then compared the rssi to the rssi using the default parameters set in the example code. (tx power=2 with rx in the opposite end of the building) I got exactly the same average rssi (-84) .
// rf95_client.pde
// -*- mode: C++ -*-
// Example sketch showing how to create a simple messaging client
// with the RH_RF95 class. RH_RF95 class does not provide for addressing or
// reliability, so you should only use RH_RF95 if you do not need the higher
// level messaging abilities.
// It is designed to work with the other example rf95_server
// Tested with Anarduino MiniWirelessLoRa, Rocket Scream Mini Ultra Pro with
// the RFM95W, Adafruit Feather M0 with RFM95
#include <SPI.h>
#include <RH_RF95.h>
// lilygo T3 v2.1.6
// lora SX1276/8
#define LLG_SCK 5
#define LLG_MISO 19
#define LLG_MOSI 27
#define LLG_CS 18
#define LLG_RST 23
#define LLG_DI0 26
#define LLG_DI1 33
#define LLG_DI2 32
#define LED 25
// oled
#define LLG_OLED_SDA 21
#define LLG_OLED_SCL 22
// Singleton instance of the radio driver
RH_RF95 rf95(LLG_CS, LLG_DI0); // slave select pin and interrupt pin, [heltec|ttgo] ESP32 Lora OLED with sx1276/8
void setup()
{
pinMode(LED, OUTPUT);
// Ensure serial flash is not interfering with radio communication on SPI bus
// pinMode(4, OUTPUT);
Serial.begin(9600);
rf95.init();
//Serial.println("init failed");
// Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
// You can change the modulation parameters with egPredefined configurations( bandwidth, coding rate, spread factor ):sf7= sf10=1024 sf11=2048 sf12=4096
// Bw125Cr45Sf128 Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Default medium range
// Bw500Cr45Sf128 Bw = 500 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Fast+short range
// Bw31_25Cr48Sf512 Bw = 31.25 kHz, Cr = 4/8, Sf = 512chips/symbol, CRC on. Slow+long range
// Bw125Cr48Sf4096 Bw = 125 kHz, Cr = 4/8, Sf = 4096chips/symbol, low data rate, CRC on. Slow+long range
// Bw125Cr45Sf2048 Bw = 125 kHz, Cr = 4/5, Sf = 2048chips/symbol, CRC on. Slow+long range ********************** SF11
rf95.setModemConfig(RH_RF95::Bw125Cr45Sf2048);
rf95.setTxPower(2, false); // with false output is on PA_BOOST, power from 2 to 20 dBm, use this
setting for high power demos/real usage
rf95.setFrequency(915.0);
//rf95.setCADTimeout(500);
// The default transmitter power is 13dBm, using PA_BOOST.
// If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
// you can set transmitter powers from 2 to 20 dBm:
// rf95.setTxPower(20, false);
SPI.begin(LLG_SCK,LLG_MISO,LLG_MOSI,LLG_CS);
}
void loop()
{
digitalWrite(LED, HIGH); //turn on LED for tx indicator
delay(500);
digitalWrite(LED, LOW);
Serial.println("Sending to rf95_server");
// Send a message to rf95_server
uint8_t data[] = "Hello World!";
rf95.send(data, sizeof(data));
rf95.waitPacketSent();
// Now wait for a reply
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (rf95.waitAvailableTimeout(3000))
{
// Should be a reply message for us now
if (rf95.recv(buf, &len))
{
Serial.print("got reply: ");
Serial.println((char*)buf);
// Serial.print("RSSI: ");
// Serial.println(rf95.lastRssi(), DEC);
}
else
{
Serial.println("recv failed");
}
}
else
{
Serial.println("No reply, is rf95_server running?");
}
digitalWrite(LED, LOW);
delay(6000);
Serial.println(RH_RF95_OUTPUT_POWER);
}