-
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.
Add setPinsSPI function to help config SPI on ESP32 patform.
- Loading branch information
Showing
9 changed files
with
198 additions
and
18 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
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
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
150 changes: 150 additions & 0 deletions
150
examples/LoRaNow_Gateway_ESP32_setPins/LoRaNow_Gateway_ESP32_setPins.ino
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,150 @@ | ||
/* | ||
LoRaNow Simple Gateway with ESP32 setPins | ||
This code creates a webServer to show the LoRa messages. | ||
created 27 04 2019 | ||
by Luiz H. Cassettari | ||
*/ | ||
|
||
#include <LoRaNow.h> | ||
#include <WiFi.h> | ||
#include <WebServer.h> | ||
#include <StreamString.h> | ||
|
||
#define SCK 5 | ||
#define MISO 19 | ||
#define MOSI 27 | ||
#define SS 18 | ||
#define DIO0 26 | ||
|
||
const char *ssid = ""; | ||
const char *password = ""; | ||
|
||
WebServer server(80); | ||
|
||
const char *script = "<script>function loop() {var resp = GET_NOW('loranow'); var area = document.getElementById('area').value; document.getElementById('area').value = area + resp; setTimeout('loop()', 1000);} function GET_NOW(get) { var xmlhttp; if (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest(); else xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); xmlhttp.open('GET', get, false); xmlhttp.send(); return xmlhttp.responseText; }</script>"; | ||
|
||
void handleRoot() | ||
{ | ||
String str = ""; | ||
str += "<html>"; | ||
str += "<head>"; | ||
str += "<title>ESP32 - LoRaNow</title>"; | ||
str += "<meta name='viewport' content='width=device-width, initial-scale=1'>"; | ||
str += script; | ||
str += "</head>"; | ||
str += "<body onload='loop()'>"; | ||
str += "<center>"; | ||
str += "<textarea id='area' style='width:800px; height:400px;'></textarea>"; | ||
str += "</center>"; | ||
str += "</body>"; | ||
str += "</html>"; | ||
server.send(200, "text/html", str); | ||
} | ||
|
||
static StreamString string; | ||
|
||
void handleLoRaNow() | ||
{ | ||
server.send(200, "text/plain", string); | ||
while (string.available()) // clear | ||
{ | ||
string.read(); | ||
} | ||
} | ||
|
||
void setup(void) | ||
{ | ||
|
||
Serial.begin(115200); | ||
|
||
WiFi.mode(WIFI_STA); | ||
if (ssid != "") | ||
WiFi.begin(ssid, password); | ||
WiFi.begin(); | ||
Serial.println(""); | ||
|
||
// Wait for connection | ||
while (WiFi.status() != WL_CONNECTED) | ||
{ | ||
delay(500); | ||
Serial.print("."); | ||
} | ||
|
||
Serial.println(""); | ||
Serial.print("Connected to "); | ||
Serial.println(ssid); | ||
Serial.print("IP address: "); | ||
Serial.println(WiFi.localIP()); | ||
|
||
server.on("/", handleRoot); | ||
server.on("/loranow", handleLoRaNow); | ||
server.begin(); | ||
Serial.println("HTTP server started"); | ||
|
||
// 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); | ||
|
||
LoRaNow.setPinsSPI(SCK, MISO, MOSI, SS, DIO0); // Only works with ESP32 | ||
|
||
if (!LoRaNow.begin()) | ||
{ | ||
Serial.println("LoRa init failed. Check your connections."); | ||
while (true) | ||
; | ||
} | ||
|
||
LoRaNow.onMessage(onMessage); | ||
LoRaNow.gateway(); | ||
} | ||
|
||
void loop(void) | ||
{ | ||
LoRaNow.loop(); | ||
server.handleClient(); | ||
} | ||
|
||
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(); | ||
|
||
if (string.available() > 512) | ||
{ | ||
while (string.available()) | ||
{ | ||
string.read(); | ||
} | ||
} | ||
|
||
string.print("Node Id: "); | ||
string.println(id, HEX); | ||
string.print("Count: "); | ||
string.println(count); | ||
string.print("Message: "); | ||
string.write(buffer, size); | ||
string.println(); | ||
string.println(); | ||
|
||
// Send data to the node | ||
LoRaNow.clear(); | ||
LoRaNow.print("LoRaNow Gateway Message "); | ||
LoRaNow.print(millis()); | ||
LoRaNow.send(); | ||
} |
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
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name=LoRaNow | ||
version=1.0.3 | ||
version=1.0.4 | ||
author=Luiz Henrique Cassettari | ||
maintainer=Luiz Henrique Cassettari <[email protected]> | ||
sentence=LoRaNow Library is a simple LoRa Node <> Gateway communication protocol. | ||
|
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
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