#include <LoRaNow.h>
Initialize the library.
LoRaNow.begin();
Returns 1
on success, 0
on failure.
Override the default SS
, and DIO0
pins used by the library. Must be called before LoRaNow.begin()
.
LoRaNow.setPins(ss, dio0);
ss
- new slave select pin to use, defaults to10
orgpio16
dio0
- new DIO0 pin to use, defaults to2
orgpio15
. Must be interrupt capable via attachInterrupt(...).
This call is optional and only needs to be used if you need to change the default pins used.
Override the SPI pins and the default SS
, and DIO0
pins used by the library. Must be called before LoRaNow.begin()
.
LoRaNow.setPinsSPI(sck, miso, mosi, ss, dio0);
sck
- new sck pin to use for SPI communicationmiso
- new miso pin to use for SPI communicationmosi
- new mosi pin to use for SPI communicationss
- new slave select pin to use, defaults to10
orgpio16
dio0
- new DIO0 pin to use, defaults to2
orgpio15
. Must be interrupt capable via attachInterrupt(...).
This call is optional and only works on ESP32 platform.
Stop the library
LoRaNow.end()
Clear the payload buffer.
LoRaNow.clear();
Write data to the payload buffer. Each packet can contain up to 128 bytes.
LoRaNow.write(byte);
LoRaNow.write(buffer, length);
byte
- single byte to write to packet
or
buffer
- data to write to packetlength
- size of data to write
Returns the number of bytes written.
Note: Other Arduino Print
API's can also be used to write data into the packet
Send the payload buffer to the LoRa Module.
LoRaNow.send();
Register a callback function for when a valid payload is received.
LoRaNow.onMessage(onMessage);
void onMessage(uint8_t *buffer, size_t size) {
// ...
}
onMessage
- function to call when a valid payload is received.
Register a callback function for when a the protocol is on sleep mode.
LoRaNow.onSleep(onSleep);
void onSleep() {
// ...
}
onSleep
- function to call when a protocol is on sleep mode.
This function need to be on the loop to work properly
- This function uses
millis()
- All callback is called by
LoRaNow.loop()
LoRaNow.loop();
Change the frequency of the radio.
LoRaNow.setFrequency(frequency);
frequency
- frequency in Hz (433E6
,866E6
,915E6
)
LoRaNow.setFrequencyCN()
- Select the frequency 486.5 MHz - Used in ChinaLoRaNow.setFrequencyEU()
- Select the frequency 868.3 MHz - Used in EuropeLoRaNow.setFrequencyUS()
- Select the frequency 904.1 MHz - Used in USA, Canada and South AmericaLoRaNow.setFrequencyAU()
- Select the frequency 917.0 MHz - Used in Australia, Brazil and Chile
Change the spreading factor of the radio.
LoRaNow.setSpreadingFactor(spreadingFactor);
spreadingFactor
- spreading factor, defaults to7
Supported values are between 6
and 12
.
Identification of the node, build in number using the serial number ArduinoUniqueID of the chip (AVR) or the mac adress (ESP)
unsigned long id = LoRaNow.id();
LoRaNow.setId(id);
id
- identification number (4 bytes)
The count number, always increment by one when a message is send.
byte count = LoRaNow.count();
This function defines the board to work like a gateway, this means always listen for messages from the nodes.
LoRaNow.gateway();