Skip to content

Commit

Permalink
expose LoRaFrequency and spreadingFactor in public functions, related…
Browse files Browse the repository at this point in the history
  • Loading branch information
paidforby committed Jan 20, 2020
1 parent 2f6ecd1 commit 8509821
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,29 @@ This library consists of two closely related classes. The Layer1 class and the L

### Layer1

Initialize your Layer 1 interface,
Prior to initializing your Layer1 interface, you can choose to set the following values,
```
Layer1.setPins(int cs, int reset, int dio);
```
Corresponds to the GPIO pins of your ESP32 board that are conencted to chip select, reset and DIO0 pins of the LoRa transceiver. Defaults to cs = 18, reset = 23, dio = 26.

```
Layer1.setSPIFrequency(uint32_t frequency);
```
Sets the frequency of the SPI bus connected to the LoRa transceiver. Defaults to 100E3.

```
Layer1.setLoRaFrequency(uint32_t frequency);
```
Sets the frequency at which the LoRa transceiver transmits. Typically 915E6 for NA/SA/AU/NZ or 866E6 for EU, 433E6 is also an option. Defaults to 915E6.

```
Layer1.setSpreadingFactor(uint8_t spreadingFactor);
```
Sets the spreading factor for the LoRa transceiver. Defaults to 9.


To initialize your Layer 1 interface,
```
Layer1.init();
```
Expand Down
4 changes: 4 additions & 0 deletions src/Layer1.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class Layer1Class {

void setPins(int cs, int reset, int dio);
void setSPIFrequency(uint32_t frequency);
void setLoRaFrequency(uint32_t frequency);
void setSpreadingFactor(uint8_t spreadingFactor);

private:
uint8_t hex_digit(char ch);
Expand All @@ -57,6 +59,8 @@ class Layer1Class {
int _resetPin;
int _DIOPin;
uint32_t _spiFrequency;
uint32_t _loraFrequency;
uint8_t _spreadingFactor;
};

extern Layer1Class Layer1;
Expand Down
16 changes: 13 additions & 3 deletions src/Layer1_LoRa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ Layer1Class::Layer1Class() :
_csPin(L1_DEFAULT_CS_PIN),
_resetPin(L1_DEFAULT_RESET_PIN),
_DIOPin(L1_DEFAULT_DIO0_PIN),
_spiFrequency(100E3)
_spiFrequency(100E3),
_loraFrequency(915E6),
_spreadingFactor(9)

{

Expand Down Expand Up @@ -142,16 +144,24 @@ void Layer1Class::setSPIFrequency(uint32_t frequency){
_spiFrequency = frequency;
}

void Layer1Class::setLoRaFrequency(uint32_t frequency){
_loraFrequency = frequency;
}

void Layer1Class::setSpreadingFactor(uint8_t spreadingFactor){
_spreadingFactor = spreadingFactor;
}

int Layer1Class::init(){ // maybe this should take the pins and spreading factor as inputs?

LoRa.setPins(_csPin, _resetPin, _DIOPin); // set CS, reset, DIO pin
LoRa.setSPIFrequency(_spiFrequency);

if (!LoRa.begin(915E6)) { // initialize ratio at 915 MHz
if (!LoRa.begin(_loraFrequency)) { // initialize ratio at 915 MHz
return _loraInitialized;
}

LoRa.setSpreadingFactor(9); // ranges from 6-12,default 7 see API docs
LoRa.setSpreadingFactor(_spreadingFactor); // ranges from 6-12,default 7 see API docs
LoRa.onReceive(onReceive);
LoRa.receive();

Expand Down

0 comments on commit 8509821

Please sign in to comment.