2.1 KiB
LoRa API
Include Library
#include <LoRa.h>
Setup
Begin
Initialize the library with the specified frequency.
LoRa.begin(frequency);
frequency- frequency in Hz (433E6,866E6,915E6)
Returns 1 on success, 0 on failure.
Set pins
Override the default NSS and NRESET pins used by the library. Must be called before LoRa.begin().
LoRa.setPins(ss, reset, dio0);
ssnew slave select pin to use, defaults to10resetnew reset pin to use, defaults to9dio0new DIO0 pin to use, defaults to2
End
Stop the library
LoRa.end()
Sending data
Begin packet
Start the sequence of sending a packet.
LoRa.beginPacket();
Returns 1 on success, 0 on failure.
Writing
Write data to the packet. Each packet can contain up to 255 bytes.
LoRa.write(byte);
LoRa.write(buffer, length);
bytesingle byte to write to packet
or
bufferdata to write to packetlengthsize 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
End packet
End the sequence of sending a packet.
LoRa.endPacket()
Returns 1 on success, 0 on failure.
Receiving data
Parsing packet
Check if a packet has been received.
int packetSize = LoRa.parsePacket();
Returns the packet size or 0 if no packet was received.
Packet RSSI
int rssi = LoRa.packetRssi();
Returns the RSSI of the received packet.
Available
int availableBytes = LoRa.available()
Returns number of bytes available for reading.
Peeking
Peek at the next byte in the packet.
byte b = LoRa.peek();
Returns the next byte in the packet or -1 if no bytes available.
Reading
Read the next byte from the packet.
byte b = LoRa.read();
Returns the next byte in the packet or -1 if no bytes available.
Note: Other Arduino Stream API's can also be used to read data from the packet