Author Topic: How to set and read LoRa settings for better range.  (Read 12620 times)

dave_sausages

  • NewMember
  • *
  • Posts: 49
How to set and read LoRa settings for better range.
« on: March 13, 2016, 07:08:16 PM »
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
Code: [Select]
rf95.setTxPower(20);

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).

Code: [Select]
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.

Code: [Select]
// 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

WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: How to set and read LoRa settings for better range.
« Reply #1 on: March 13, 2016, 07:15:20 PM »
I think you may just be printing a constant, which happens to be 15.

Try:
Code: [Select]
  rf95.setTxPower(20);  //set for 100mw
  rf95.printRegisters();  //Print all the RFM95 register values

Then look in the datasheet to see which register has the transmit power, and see if if its value  (printed above) matches 20.

Warning: setting Tx power to 20 runs the risk of making your chip very hot!  Datasheet cautions not to use a duty cycle of more than 1%.
« Last Edit: March 13, 2016, 07:29:56 PM by WhiteHare »

dave_sausages

  • NewMember
  • *
  • Posts: 49
Re: How to set and read LoRa settings for better range.
« Reply #2 on: March 13, 2016, 08:35:10 PM »
the print registers command worked well thanks.

So I think I've found the correct table in the datasheet


I'd I think I've deduced that the register is 0x09? with bits 3 to 0? Meaning that it should be the value in register in 9.

But the value is "88" and it never changes when I change "rf95.setTxPower(xx);"

So I set the power to 20 and looked for that to appear anywhere in the registers when I print them, and it didn't (or it's hex equivalent of 14).
« Last Edit: March 13, 2016, 08:38:36 PM by dave_sausages »

WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: How to set and read LoRa settings for better range.
« Reply #3 on: March 13, 2016, 09:18:48 PM »
I don't see where you're initializing your radio.  You need to do that before you set the transmit power.

You might try:
Code: [Select]
  
  if (!rf95.init())
    Serial.println("init failed");
  else Serial.println("init OK - 915mhz");
  rf95.setFrequency(915);  //just to be certain. 
  rf95.setModemConfig(RH_RF95::Bw31_25Cr48Sf512);  //set for pre-configured long range
  rf95.setTxPower(20);  //set for 100mw

 I suggest you start by tweaking the given examples to work the way you want.  They should work right out of the box.  :)
« Last Edit: March 13, 2016, 09:30:29 PM by WhiteHare »