|
| 1 | +# LoRa API |
| 2 | + |
| 3 | +## Include Library |
| 4 | + |
| 5 | +```arduino |
| 6 | +#include <LoRa.h> |
| 7 | +``` |
| 8 | + |
| 9 | +## Setup |
| 10 | + |
| 11 | +### Begin |
| 12 | + |
| 13 | +Initialize the library with the specified frequency. |
| 14 | + |
| 15 | +```arduino |
| 16 | +LoRa.begin(frequency); |
| 17 | +``` |
| 18 | + * `frequency` - frequency in Hz (`433E6`, `866E6`, `915E6`) |
| 19 | + |
| 20 | +Returns `1` on success, `0` on failure. |
| 21 | + |
| 22 | +## Set pins |
| 23 | + |
| 24 | +Override the default `NSS` and `NRESET` pins used by the library. **Must** be called before `LoRa.begin()`. |
| 25 | + |
| 26 | +```arduino |
| 27 | +LoRa.setPins(ss, reset); |
| 28 | +``` |
| 29 | + * `ss` new slave select pin to use, defaults to `10` |
| 30 | + * `reset` new reset pin to use, defaults to `9` |
| 31 | + |
| 32 | +### End |
| 33 | + |
| 34 | +Stop the library |
| 35 | + |
| 36 | +```arduino |
| 37 | +LoRa.end() |
| 38 | +``` |
| 39 | + |
| 40 | +## Sending data |
| 41 | + |
| 42 | +### Begin packet |
| 43 | + |
| 44 | +Start the sequence of sending a packet. |
| 45 | + |
| 46 | +```arduino |
| 47 | +LoRa.beginPacket(); |
| 48 | +``` |
| 49 | + |
| 50 | +Returns `1` on success, `0` on failure. |
| 51 | + |
| 52 | +### Writing |
| 53 | + |
| 54 | +Write data to the packet. Each packet can contain up to 255 bytes. |
| 55 | + |
| 56 | +```arduino |
| 57 | +LoRa.write(byte); |
| 58 | +
|
| 59 | +LoRa.write(buffer, length); |
| 60 | +``` |
| 61 | +* `byte` single byte to write to packet |
| 62 | + |
| 63 | +or |
| 64 | + |
| 65 | +* `buffer` data to write to packet |
| 66 | +* `length` size of data to write |
| 67 | + |
| 68 | +Returns the number of bytes written. |
| 69 | + |
| 70 | +**Note:** Other Arduino `Print` API's can also be used to write data into the packet |
| 71 | + |
| 72 | +### End packet |
| 73 | + |
| 74 | +End the sequence of sending a packet. |
| 75 | + |
| 76 | +```arduino |
| 77 | +LoRa.endPacket() |
| 78 | +``` |
| 79 | + |
| 80 | +Returns `1` on success, `0` on failure. |
| 81 | + |
| 82 | +## Receiving data |
| 83 | + |
| 84 | +### Parsing packet |
| 85 | + |
| 86 | +Check if a packet has been received. |
| 87 | + |
| 88 | +```arduino |
| 89 | +int packetSize = LoRa.parsePacket(); |
| 90 | +``` |
| 91 | + |
| 92 | +Returns the packet size or `0` if no packet was received. |
| 93 | + |
| 94 | +### Packet RSSI |
| 95 | + |
| 96 | +```arduino |
| 97 | +int rssi = LoRa.packetRSSI(); |
| 98 | +``` |
| 99 | + |
| 100 | +Returns the RSSI of the received packet. |
| 101 | + |
| 102 | +### Available |
| 103 | + |
| 104 | +```arduino |
| 105 | +int availableBytes = LoRa.available() |
| 106 | +``` |
| 107 | + |
| 108 | +Returns number of bytes available for reading. |
| 109 | + |
| 110 | +### Peeking |
| 111 | + |
| 112 | +Peek at the next byte in the packet. |
| 113 | + |
| 114 | +```arduino |
| 115 | +byte b = LoRa.peek(); |
| 116 | +``` |
| 117 | + |
| 118 | +Returns the next byte in the packet or `-1` if no bytes available. |
| 119 | + |
| 120 | +### Reading |
| 121 | + |
| 122 | +Read the next byte from the packet. |
| 123 | + |
| 124 | +```arduino |
| 125 | +byte b = LoRa.read(); |
| 126 | +``` |
| 127 | + |
| 128 | +Returns the next byte in the packet or `-1` if no bytes available. |
| 129 | + |
| 130 | +**Note:** Other Arduino [`Stream` API's](https://www.arduino.cc/en/Reference/Stream) can also be used to read data from the packet |
| 131 | + |
0 commit comments