Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Altering default radio settings and sleeping / ending the library #52

Open
BrendonHills opened this issue Jul 10, 2020 · 0 comments
Open

Comments

@BrendonHills
Copy link

Hi all, I hope you can shed a little light on two issues concerning radio settings in this library please.

I am a relatively new beginner programmer and have been having some success building on the example libraries. But I have come across some issues I cannot understand and implement. I have read, read again, and read some more, the relevant documentation on the library, but I think my relative inexperience means that I either don't understand it all, or implementation of some features evades me.

I want to achieve two main things:

  1. I want to be able to amend modem settings for BW, CR, SF etc. in the Reliable Datagram Client and Server examples. I am happy to use one of the available recommended settings - I just can't seem to implement any of them, other than the default of course.

  2. I want to put the library / radio module to sleep, at the same time as my controller, pending hardware interrupts.

I have attached my reliable datagram server code below, as an example, and have commented the error messages I am getting (highlighted) with modem settings within void setup() - what am I doing wrong please?

In relation to sleep - not in the example - how is this called? Do I use driver.sleep(); manager.sleep(); or something else?
Finally, in relation to sleep - is sleeping the radio the most power efficient thing to do when putting the main board to sleep? When I used another library, by Sandeep Mistry, calling LoRa.end() was more power efficient that LoRa.sleep() by some margin. Is there an end() function in this library - I cant see it!!

I am using Arduino Feather 32u4 LoRa boards, the RadioHead LoRa library and lowPower.h for sleep mode in the client code

Thank you in anticipation for your comments.

Daimon. G4USI.

`#include <RHReliableDatagram.h>
#include <RH_RF95.h>
#include <SPI.h>
#define RFM95_CS 8
#define RFM95_RST 4
#define RFM95_INT 7
#define CLIENT_ADDRESS 1
#define SERVER_ADDRESS 2
RH_RF95 driver(RFM95_CS, RFM95_INT);
RHReliableDatagram manager(driver, SERVER_ADDRESS);
#define waterLowPin 9
#define waterHighPin 10
#define healthOKPin 11
#define rechargePin 12

void setup()
{
pinMode(RFM95_RST, OUTPUT);
digitalWrite(RFM95_RST, HIGH);
delay(100);
// manual reset
digitalWrite(RFM95_RST, LOW);
delay(10);
digitalWrite(RFM95_RST, HIGH);
delay(10);

Serial.begin(9600);
if (!manager.init())
Serial.println("init failed");
else Serial.println("Sensor Acknowledgement Test RX");
// Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on

// you can set transmitter powers from 5 to 23 dBm:
driver.setFrequency(870.0);
driver.setTxPower(14, false);
//driver.setModemConfig(Bw125Cr48Sf4096);// error msg - Bw125Cr48Sf4096 not declared in this scope
//driver.setSpreadingFactor(12);// error msg - Class RH_RF95 has no member named 'setSpreadingFactor'
//driver.setSignalBandwidth(125000);//error msg - Class RH_RF95 has no member named 'setSignalBandwidth'
//driver.setCodingRate4(8);//error msg - Class RH_RF95 has no member named 'setCodingRate4'

pinMode (waterLowPin, OUTPUT);
pinMode (waterHighPin, OUTPUT);
pinMode (healthOKPin, OUTPUT);
pinMode (rechargePin, OUTPUT);
}

uint8_t data[] = "Received";
// Dont put this on the stack:
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];

void loop()
{
if (manager.available())
{
// Wait for a message addressed to us from the client
uint8_t len = sizeof(buf);
uint8_t from;
if (manager.recvfromAck(buf, &len, &from))
{
//Serial.print("message from : 0x");
// Serial.print(from, HEX);
//Serial.print(": ");
// Serial.println((char*)buf);
switch (buf[0]) {
case 48:
Serial.println("Water LOW");
digitalWrite (waterLowPin, HIGH);
delay (1000);
digitalWrite (waterLowPin, LOW);
break;
case 49:
Serial.println("Water HIGH");
digitalWrite (waterHighPin, HIGH);
delay (1000);
digitalWrite (waterHighPin, LOW);
break;
case 50:
Serial.println("Health OK");
digitalWrite (healthOKPin, HIGH);
delay (1000);
digitalWrite (healthOKPin , LOW);
break;
case 51:
Serial.println("Recharge battery");
digitalWrite (rechargePin, HIGH);
delay (1000);
digitalWrite (rechargePin , LOW);
break;
}

  // Send a reply back to the originator client
  if (!manager.sendtoWait(data, sizeof(data), from))
    Serial.println("sendtoWait failed");
}

}
}

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant