-
-
Save sarasantos/5a2b8af769e65b84de03ede8ac024a84 to your computer and use it in GitHub Desktop.
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
//Libraries for LoRa | |
#include <SPI.h> | |
#include <LoRa.h> | |
//Libraries for BME280 | |
#include <Adafruit_Sensor.h> | |
#include <Adafruit_BME280.h> | |
//Define the pins used by the transceiver module | |
#define ss 5 | |
#define rst 14 | |
#define dio0 2 | |
int delayTime = 10000; | |
//packet counter | |
int readingID = 0; | |
String LoRaMessage = ""; | |
//Initialize Sensor Parameters | |
float Temperature = 0; | |
float Pressure = 0; | |
float Humidity = 0; | |
float Altitude = 0; | |
#define SEALEVELPRESSURE_HPA (1013.25) | |
#define SCREEN_WIDTH 128 // OLED display width, in pixels | |
#define SCREEN_HEIGHT 64 // OLED display height, in pixels | |
Adafruit_BME280 bme; | |
#define SEALEVELPRESSURE_HPA (1013.25) | |
void setup() { | |
Serial.begin(115200); | |
while (!Serial); | |
Serial.println("LoRa Receiver"); | |
//setup LoRa transceiver module | |
LoRa.setPins(ss, rst, dio0); | |
//replace the LoRa.begin(---E-) argument with your location's frequency | |
//note: the frequency should match the sender's frequency | |
//433E6 for Asia | |
//866E6 for Europe | |
//915E6 for North America | |
if (!LoRa.begin(866E6)) { | |
Serial.println("Starting LoRa failed!"); | |
while (1); | |
} | |
Serial.println("LoRa Initializing OK!"); | |
//BME280 setup | |
bool status = bme.begin(0x76); | |
if (!status) { | |
Serial.println("Could not find a valid BME280 sensor, check wiring!"); | |
while (1); | |
} | |
} //End void setup | |
void getValues() { | |
Temperature = bme.readTemperature(); | |
Pressure = bme.readPressure()/100.0F; | |
Altitude = bme.readAltitude(SEALEVELPRESSURE_HPA); | |
Humidity = bme.readHumidity(); | |
} | |
void sendValues() { | |
//try to parse packet | |
LoRaMessage = String(readingID) + "/" + String(Temperature) + "&" + String(Humidity) + "#" + String(Pressure) + "%" + String(Altitude); | |
//Send LoRa packet to Receiver | |
LoRa.beginPacket(); | |
LoRa.print(LoRaMessage); | |
LoRa.endPacket(); | |
Serial.print("Sending packet: "); | |
Serial.println(readingID); | |
Serial.println(Temperature); | |
Serial.println(Humidity); | |
Serial.println(Pressure); | |
Serial.println(LoRaMessage); | |
readingID++; | |
} | |
void loop() { | |
getValues(); | |
sendValues(); | |
delay(delayTime); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment