-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f2863e4
Showing
15 changed files
with
2,511 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Prerequisites | ||
*.d | ||
|
||
# Compiled Object files | ||
*.slo | ||
*.lo | ||
*.o | ||
*.obj | ||
|
||
# Precompiled Headers | ||
*.gch | ||
*.pch | ||
|
||
# Compiled Dynamic libraries | ||
*.so | ||
*.dylib | ||
*.dll | ||
|
||
# Fortran module files | ||
*.mod | ||
*.smod | ||
|
||
# Compiled Static libraries | ||
*.lai | ||
*.la | ||
*.a | ||
*.lib | ||
|
||
# Executables | ||
*.exe | ||
*.out | ||
*.app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
# LoRaNow API | ||
|
||
## Include Library | ||
|
||
```c | ||
#include <LoRaNow.h> | ||
``` | ||
|
||
### Begin | ||
|
||
Initialize the library. | ||
|
||
```c | ||
LoRaNow.begin(); | ||
``` | ||
Returns `1` on success, `0` on failure. | ||
|
||
### Set pins | ||
|
||
Override the default `SS`, and `DIO0` pins used by the library. **Must** be called before `LoRaNow.begin()`. | ||
|
||
```c | ||
LoRaNow.setPins(ss, dio0); | ||
``` | ||
* `ss` - new slave select pin to use, defaults to `10` or `gpio16` | ||
* `dio0` - new DIO0 pin to use, defaults to `2` or `gpio15`. **Must** be interrupt capable via [attachInterrupt(...)](https://www.arduino.cc/en/Reference/AttachInterrupt). | ||
|
||
This call is optional and only needs to be used if you need to change the default pins used. | ||
|
||
### End | ||
|
||
Stop the library | ||
|
||
```c | ||
LoRaNow.end() | ||
``` | ||
|
||
## Sending data | ||
|
||
### Clear | ||
|
||
Clear the payload buffer. | ||
|
||
```c | ||
LoRaNow.clear(); | ||
``` | ||
|
||
### Writing | ||
|
||
Write data to the payload buffer. Each packet can contain up to 128 bytes. | ||
|
||
```c | ||
LoRaNow.write(byte); | ||
|
||
LoRaNow.write(buffer, length); | ||
``` | ||
* `byte` - single byte to write to packet | ||
|
||
or | ||
|
||
* `buffer` - data to write to packet | ||
* `length` - 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 | ||
|
||
Send the payload buffer to the LoRa Module. | ||
|
||
```c | ||
LoRaNow.send(); | ||
``` | ||
|
||
#### Register callback | ||
|
||
Register a callback function for when a valid payload is received. | ||
|
||
```c | ||
LoRaNow.onMessage(onMessage); | ||
|
||
void onMessage(uint8_t *buffer, size_t size) { | ||
// ... | ||
} | ||
``` | ||
* `onMessage` - function to call when a valid payload is received. | ||
## State machine | ||
### Loop | ||
This function need to be on the loop to work properly | ||
```c | ||
LoRaNow.loop(); | ||
``` | ||
|
||
### Is sleep | ||
|
||
Function used on the loop to detect when the protocol is on sleep mode. | ||
|
||
```c | ||
if (LoRaNow.isSleep()) { | ||
... | ||
} | ||
``` | ||
Returns true when the protocol is on the sleep mode. | ||
|
||
## Radio parameters | ||
|
||
### Frequency | ||
|
||
Change the frequency of the radio. | ||
|
||
```c | ||
LoRaNow.setFrequency(frequency); | ||
``` | ||
* `frequency` - frequency in Hz (`433E6`, `866E6`, `915E6`) | ||
|
||
## Frequency by country | ||
|
||
* `LoRaNow.setFrequencyCN()` - Select the frequency 486.5 MHz - Used in China | ||
* `LoRaNow.setFrequencyEU()` - Select the frequency 868.3 MHz - Used in Europe | ||
* `LoRaNow.setFrequencyUS()` - Select the frequency 904.1 MHz - Used in USA, Canada and South America | ||
* `LoRaNow.setFrequencyAU()` - Select the frequency 917.0 MHz - Used in Australia, Brazil and Chile | ||
|
||
### Spreading Factor | ||
|
||
Change the spreading factor of the radio. | ||
|
||
```c | ||
LoRaNow.setSpreadingFactor(spreadingFactor); | ||
``` | ||
* `spreadingFactor` - spreading factor, defaults to `7` | ||
|
||
Supported values are between `6` and `12`. | ||
|
||
## Protocol parameters | ||
|
||
### Id | ||
|
||
Identification of the node, build in number using the serial number [ArduinoUniqueID](https://github.com/ricaun/ArduinoUniqueID) of the chip (AVR) or the mac adress (ESP) | ||
|
||
```c | ||
unsigned long id = LoRaNow.id(); | ||
``` | ||
|
||
```c | ||
LoRaNow.setId(id); | ||
``` | ||
|
||
### Count | ||
|
||
The count number, always increment by one when a message is send. | ||
|
||
```c | ||
byte count = LoRaNow.count(); | ||
``` | ||
|
||
* `id` - identification number (4 bytes) | ||
|
||
### Gateway | ||
|
||
This function defines the board to work like a gateway, this means always listen for messages from the nodes. | ||
|
||
```c | ||
LoRaNow.gateway(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 Luiz H. Cassettari | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# LoRaNow | ||
|
||
LoRaNow is a open source communication protocol to make easier to understand the concept of Node / Gateway communication using LoRa technology. | ||
|
||
This library was design using the [Arduino LoRa](https://github.com/sandeepmistry/arduino-LoRa) Library by [Sandeep Mistry](https://github.com/sandeepmistry). | ||
|
||
## Compatible Hardware | ||
|
||
The main focus hardware is Arduino and ESP boards with [RFM95W](http://www.hoperf.com/rf_transceiver/lora/RFM95W.html) LoRa module. | ||
|
||
### RFM95W | ||
|
||
| RFM95W | Arduino | ESP8266 | | ||
| :----: | :-----: | :-----: | | ||
| VCC | 3.3V | 3.3V | | ||
| GND | GND | GND | | ||
| SCK | SCK | SCK | | ||
| MISO | MISO | MISO | | ||
| MOSI | MOSI | MOSI | | ||
| SS | 10 | gpio16 | | ||
| DIO0 | 2 | gpio15 | | ||
|
||
|
||
`SS`, and `DIO0` pins can be changed by using `LoRaNow.setPins(ss, dio0)`. `DIO0` pin is needed, it **must** be interrupt capable via [`attachInterrupt(...)`](https://www.arduino.cc/en/Reference/AttachInterrupt). | ||
|
||
# Ferquency | ||
|
||
You can use [this table](https://www.thethingsnetwork.org/wiki/LoRaWAN/Frequencies/By-Country) to lookup the available frequencies by your country. The selectable frequency also depends on your hardware. | ||
|
||
You can select the frequency using `LoRaNow.setFrequency(frequency)` or you can select the frequency by country. | ||
|
||
* `LoRaNow.setFrequencyCN()` - Select the frequency 486.5 MHz - Used in China | ||
* `LoRaNow.setFrequencyEU()` - Select the frequency 868.3 MHz - Used in Europe | ||
* `LoRaNow.setFrequencyUS()` - Select the frequency 904.1 MHz - Used in USA, Canada and South America | ||
* `LoRaNow.setFrequencyAU()` - Select the frequency 917.0 MHz - Used in Australia, Brazil and Chile | ||
|
||
# Protocol Payload | ||
|
||
This is the payload format. | ||
|
||
| Protocol | Device ID | Count | Length | CheckSum | Payload | | ||
| :-------: | :------: | :------:| :------:| :------:| :------:| | ||
| 1 Byte | 4 Bytes | 1 Byte | 1 Byte | 1 Byte | N Bytes | | ||
|
||
# State Machine | ||
|
||
`TO DO` | ||
|
||
## Installation | ||
|
||
* Install the library by [Using the Library Manager](https://www.arduino.cc/en/Guide/Libraries#toc3) | ||
* **OR** by [Importing the .zip library](https://www.arduino.cc/en/Guide/Libraries#toc4) using either the [master](https://github.com/ricaun/LoRaNow/archive/1.0.0.zip) or one of the [releases](https://github.com/ricaun/LoRaNow/releases) ZIP files. | ||
|
||
## Examples | ||
|
||
The library comes with [examples](examples). After installing the library you need to restart the Arduino IDE before they can be found under **File > Examples > LoRaNow**. | ||
|
||
## API | ||
|
||
See [API.md](API.md). | ||
|
||
## License | ||
|
||
This libary is [licensed](LICENSE) under the [MIT Licence](https://en.wikipedia.org/wiki/MIT_License). | ||
|
||
## To do | ||
|
||
- [x] Example for ESP8266 board | ||
- [ ] Example for ESP32 board | ||
- [ ] Improve documentation | ||
- [ ] State machine | ||
|
||
Do you like this library? Please [star this project on GitHub](https://github.com/ricaun/LoRaNow/stargazers)! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
LoRaNow Simple Gateway | ||
This code receives messages form the node and sends a message back. | ||
created 01 04 2019 | ||
by Luiz H. Cassettari | ||
*/ | ||
|
||
#include <LoRaNow.h> | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
Serial.println("LoRaNow Simple Gateway"); | ||
|
||
// LoRaNow.setFrequencyCN(); // Select the frequency 486.5 MHz - Used in China | ||
// LoRaNow.setFrequencyEU(); // Select the frequency 868.3 MHz - Used in Europe | ||
// LoRaNow.setFrequencyUS(); // Select the frequency 904.1 MHz - Used in USA, Canada and South America | ||
// LoRaNow.setFrequencyAU(); // Select the frequency 917.0 MHz - Used in Australia, Brazil and Chile | ||
|
||
// LoRaNow.setFrequency(frequency); | ||
// LoRaNow.setSpreadingFactor(sf); | ||
// LoRaNow.setPins(ss, dio0); | ||
|
||
if (!LoRaNow.begin()) { | ||
Serial.println("LoRa init failed. Check your connections."); | ||
while (true); | ||
} | ||
|
||
LoRaNow.onMessage(onMessage); | ||
LoRaNow.gateway(); | ||
} | ||
|
||
void loop() { | ||
LoRaNow.loop(); | ||
} | ||
|
||
void onMessage(uint8_t *buffer, size_t size) | ||
{ | ||
unsigned long id = LoRaNow.id(); | ||
byte count = LoRaNow.count(); | ||
|
||
Serial.print("Node Id: "); | ||
Serial.println(id, HEX); | ||
Serial.print("Count: "); | ||
Serial.println(count); | ||
Serial.print("Message: "); | ||
Serial.write(buffer, size); | ||
Serial.println(); | ||
Serial.println(); | ||
|
||
// Send data to the node | ||
LoRaNow.clear(); | ||
LoRaNow.print("LoRaNow Gateway Message "); | ||
LoRaNow.print(millis()); | ||
LoRaNow.send(); | ||
} |
Oops, something went wrong.