Heltec LoRa - javierre/nodemcu GitHub Wiki
TBD
Lora permite conectar los dispositivos en varias topologías: punto a punto y en estrella (un nodo hace de gateway).
Además, tiene mayor alcance que WiFi o Bluetooth, por lo que algunos fabricantes incorporan alguna de estas otras redes para dar cobertura a otros sensores que no tienen LoRa.
Así, podríamos tener capacidad de leer sensores a más distancia que la que permiten los protocolos WiFi o Bluetooth, [como se ve en este link.](https://randomnerdtutorials.com/esp32-lora-rfm95-transceiver-arduino-ide/)
Para usar LoRa en Arduino IDE es necesario installar la librería correspondiente:
Algunos proyectos:
Lora DHT11 Sender
#include <SPI.h>
#include <LoRa.h>
#include "SSD1306.h"
#include<Arduino.h>
#include <U8x8lib.h>
#include "DHT.h"
#define DHTTYPE DHT11
const int DHTPin = 23;
DHT dht(DHTPin, DHTTYPE);
//OLED pins to ESP32 GPIOs via this connecthin:
//OLED_SDA -- GPIO4
//OLED_SCL -- GPIO15
//OLED_RST -- GPIO16
SSD1306 display(0x3c, 4, 15);
// WIFI_LoRa_32 ports
// GPIO5 -- SX1278's SCK
// GPIO19 -- SX1278's MISO
// GPIO27 -- SX1278's MOSI
// GPIO18 -- SX1278's CS
// GPIO14 -- SX1278's RESET
// GPIO26 -- SX1278's IRQ(Interrupt Request)
#define SS 18
#define RST 14
#define DI0 26
#define BAND 868E6 //433E6 //915E6
U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=*/ 15, /* data=*/ 4, /* reset=*/ 16);
int counter = 0;
void setup() {
pinMode(DHTPin, INPUT);
dht.begin();
pinMode(25,OUTPUT); //Send success, LED will bright 1 second
pinMode(16,OUTPUT);
digitalWrite(16, LOW); // set GPIO16 low to reset OLED
delay(50);
digitalWrite(16, HIGH);
Serial.begin(115200);
while (!Serial); //If just the the basic function, must connect to a computer
// Initialising the UI will init the display too.
//display.init();
//display.flipScreenVertically();
//display.setFont(ArialMT_Plain_10);
//display.setTextAlignment(TEXT_ALIGN_LEFT);
//display.drawString(5,5,"LoRa Sender");
//display.display();
u8x8.begin();
u8x8.setFont(u8x8_font_chroma48medium8_r);
u8x8.drawString(0, 1, "LoRa Sender");
SPI.begin(5,19,27,18);
LoRa.setPins(SS,RST,DI0);
Serial.println("LoRa Sender");
if (!LoRa.begin(BAND)) {
Serial.println("Starting LoRa failed!");
while (1);
}
Serial.println("LoRa Initial OK!");
//display.drawString(5,20,"LoRa Initializing OK!");
u8x8.drawString(0, 1, "LoRa Initializing OK!");
//display.display();
delay(2000);
}
void loop() {
Serial.print("Sending packet: ");
Serial.println(counter);
//display.clear();
//display.setFont(ArialMT_Plain_16);
//display.drawString(3, 5, "Sending packet ");
//display.drawString(50, 30, String(counter));
//display.display();
u8x8.drawString(3, 5, "Sending packet ");
u8x8.setCursor(0, 6);
u8x8.print(counter);
u8x8.display();
float h = dht.readHumidity();
float t = dht.readTemperature();
Serial.println(t);
u8x8.setCursor(0, 7);
u8x8.print(t);
u8x8.display();
// send packet
LoRa.beginPacket();
LoRa.print("Temp: ");
LoRa.print(t);
LoRa.print(" // MSG: ");
LoRa.print(counter);
LoRa.endPacket();
counter++;
digitalWrite(25, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(25, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
//delay(1000);
}
Lora Receiver
#include <U8x8lib.h>
#include <LoRa.h>
String receivedText;
String receivedRssi;
// WIFI_LoRa_32 ports
// GPIO5 -- SX1278's SCK
// GPIO19 -- SX1278's MISO
// GPIO27 -- SX1278's MOSI
// GPIO18 -- SX1278's CS
// GPIO14 -- SX1278's RESET
// GPIO26 -- SX1278's IRQ(Interrupt Request)
#define SS 18
#define RST 14
#define DI0 26
#define BAND 433E6
// the OLED used
U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=*/ 15, /* data=*/ 4, /* reset=*/ 16);
void setup() {
SPI.begin(5, 19, 27, 18);
LoRa.setPins(SS, RST, DI0);
Serial.begin(115200);
while (!Serial); //if just the the basic function, must connect to a computer
delay(1000);
u8x8.begin();
u8x8.setFont(u8x8_font_chroma48medium8_r);
Serial.println("LoRa Receiver");
u8x8.drawString(0, 1, "LoRa Receiver");
if (!LoRa.begin(BAND)) {
Serial.println("Starting LoRa failed!");
u8x8.drawString(0, 1, "Starting LoRa failed!");
while (1);
}
}
void loop() {
// try to parse packet
int packetSize = LoRa.parsePacket();
if (packetSize) {
// received a packet
Serial.print("Received packet '");
u8x8.drawString(0, 4, "PacketID");
// read packet
while (LoRa.available()) {
receivedText = (char)LoRa.read();
Serial.print(receivedText);
char currentid[64];
receivedText.toCharArray(currentid, 64);
u8x8.drawString(9, 4, currentid);
}
// print RSSI of packet
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
u8x8.drawString(0, 5, "PacketRS");
receivedRssi = LoRa.packetRssi();
char currentrs[64];
receivedRssi.toCharArray(currentrs, 64);
u8x8.drawString(9, 5, currentrs);
}
}