Hardware components | ||||||
| × | 1 | ||||
| × | 2 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
Software apps and online services | ||||||
| ||||||
Hand tools and fabrication machines | ||||||
| ||||||
| ||||||
| ||||||
|
We want to be able to create our own lora-gateway! We want to understand systems, capabilities and possibilities. People have built it, but detailed information is hard to find. That's why we created this project. It's a work in progress, we're working on it right now.
#include <SPI.h>
#include <LoRa.h>
#include <NewPing.h>
//Ultrasonic sensor
#define TRIGGER_PIN 3
#define ECHO_PIN 4
#define MAX_DISTANCE 200
//Water level sensor
#define sensor A0
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
int distance;
int dummyValue;
long randNumber; //Create Random Number To Avoid Transmission Loss For First Digit
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
while(!Serial);
if (!LoRa.begin(915E6)){
Serial.println("Starting LoRa Failed!");
while(1);
}else{
Serial.println("LoRa Sender!");
}
}
void loop() {
// put your main code here, to run repeatedly:
randNumber = random(1000);
int randNumber = random(100); dummyValue = randNumber;
int wlvl = analogRead(sensor);
int distance = sonar.ping_cm();
Serial.println(wlvl);
Serial.println(distance);
if (isnan(wlvl)){
Serial.println(F("Failed to read from Water Level sensor!"));
return;
}
if (isnan(distance)){
Serial.println(F("Failed to read from Ultrasonic sensor!"));
}
String dataString = String(dummyValue) + (";") + String(wlvl) + (";") + String(distance);
Serial.println(dataString);
LoRa.beginPacket();
LoRa.print(dataString);
LoRa.endPacket();
delay(100);
}
#include <SPI.h>
#include <LoRa.h>
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
if (!LoRa.begin(915E6)){
Serial.println("Starting LoRa failed!");
while(1);
}else{
Serial.println("LoRa Receiver!");
}
}
void loop() {
// put your main code here, to run repeatedly:
String packet = "";
int packetSize = LoRa.parsePacket();
if (packetSize) {
Serial.print("Received packet :-- ");
while (LoRa.available()){
packet = LoRa.readString();
}
Serial.println(packet);
Serial.println();
int firstcommaIndex = packet.indexOf(';');
int secondCommaIndex = packet.indexOf(';', firstcommaIndex+1);
int thirdCommaIndex = packet.indexOf(';', secondCommaIndex+1);
int fourthCommaIndex = packet.indexOf(';', thirdCommaIndex+1);
String firstValue = packet.substring( 0, firstcommaIndex);
String secondValue = packet.substring(firstcommaIndex+1, secondCommaIndex);
String thirdValue = packet.substring(secondCommaIndex+1, thirdCommaIndex);
Serial.print("Wlvl:-"); Serial.println(secondValue);
Serial.print("Sonar:-"); Serial.println(thirdValue);
Serial.println();
}
}
Comments