So I've been getting a quite disappointing range of 150m or so on my Moteino LoRa modules, so I've started going the rabbit hole of changing power settings and Bandwidth etc.
First off I tried to set the transmit power to +20db using
And when I didn't see an increase in performance, I tried seeing if I'd actually changed the setting with this code:
(based on "#define RH_RF95_OUTPUT_POWER 0x0f" in RH_RF95.h).
Serial.println(RH_RF95_OUTPUT_POWER);
But it only returns "15".Of course I've now seen that 0x0f is 15 in decimal.
So I've now decided that I'm hopelessly lost and require help.
Does anyone know how to set all the parameters for the LoRa library, and how to read them back to confirm? Any hints on what settings to use is also very well received.
Here's my code in case it helps anyone to throw in a quick suggestion or two.
// rf95_reliable_datagram_client.pde
// -*- mode: C++ -*-
// Example sketch showing how to create a simple addressed, reliable messaging client
// with the RHReliableDatagram class, using the RH_RF95 driver to control a RF95 radio.
// It is designed to work with the other example rf95_reliable_datagram_server
// Tested with Anarduino MiniWirelessLoRa
// driver.setTxPower(20); //This apparantly sets the power of the transciever. max is 23 apparantly.
#include <RHReliableDatagram.h>
#include <RH_RF95.h>
#include <SPI.h>
#include <SoftwareSerial.h>
#define CLIENT_ADDRESS 1
#define SERVER_ADDRESS 2
// Singleton instance of the radio driver
RH_RF95 rf95;
// Class to manage message delivery and receipt, using the driver declared above
RHReliableDatagram manager(rf95, CLIENT_ADDRESS);
int data_to_send = 43;
int data_to_recieve = 0;
//variables used in formatting:
double P;
byte sendLen;
char Pstr[10];
char buffer[50]; //final byte array that gets passed to radio.send
float LATITUDE_CLIENT = 42.27460;
float LONGITUDE_CLIENT = 38.34542;
unsigned long timepassed = millis();
void setup()
{
Serial.begin(9600);
Serial.println(F("begin prog"));
if (!manager.init())
//Moteino LoRa setup
rf95.setTxPower(20); //high power -- originally 13, range= 5 to 23
Serial.println(F("init failed"));
// Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
}
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
static void doSomeWork()
{
dtostrf(LATITUDE_CLIENT, 9,6, Pstr); //Take LAT_CLI and store in the byte array "Pstr". total length inc decimal point, characters after d.point.
sprintf(buffer, "%s", Pstr);
sendLen = strlen(buffer); //get the length of buffer //looks at whatever is in "buffer" and gets its length and stores it in sendLen.
Serial.println(F("Sending this to rf95_reliable_datagram_server:"));
unsigned long currenttime = millis();
if (manager.sendtoWait((uint8_t*)buffer, sendLen, SERVER_ADDRESS)) //This sends "buffer", its length, and server its being sent to. The server uses this data to make sure it
{ //got all the data and it was meant for it.
Serial.println(buffer);
Serial.println("time taken to send (ms)");
Serial.println(millis()-currenttime);
uint8_t len = sizeof(buf);
uint8_t from;
unsigned long currenttime = millis();
if (manager.recvfromAckTimeout(buf, &len, 2000, &from))
{
Serial.println("time taken to recieve (ms)");
Serial.println(millis()-currenttime);
Serial.println("recieved this:");
Serial.println((char*)buf);
// lcd.println((char*)buf);
Serial.println(RH_RF95_OUTPUT_POWER);
}
else
{
Serial.println(F("No reply, is rf95_reliable_datagram_server running?"));
}
}
else
Serial.println(F("sendtoWait failed"));
} // doSomeWork
void loop()
{
doSomeWork();
} //end void loop