Prof. J. Walter - Informationstechnik, Mikrocomputertechnik, Digitale Medien Quellcode
Hochschule Karlsruhe Logo Informationstechnik
Zeitmessung LoRa-WAN
Wintersemester 2017/18
Sitepu, Rama Akhira Vedaalana
Tchuisse Nyangang Adrien

Quellcode

IDE-Version:
Die folgenden Bibliothek müssen in die Arduino IDE instaliert und eingebunden werden:
1) LoRa by Sandeep Minsty
2) Adafruit GFX Library by Adafruit
3) Adafruit SSD1306 by Adafruit
LoRa-Receiver
#include <SPI.h>
#include <LoRa.h>
#include <Wire.h> // I2C
#include <Adafruit_GFX.h> // OLED
#include <Adafruit_SSD1306.h> // Graphic
#define OLED_RESET 4 // not used / nicht genutzt bei diesem Display
Adafruit_SSD1306 display(OLED_RESET);

int ledPin = 17; // the pin for the LED
int count=1; // Messung Nr
int inPin = 12; // the input pin (for a pushbutton)
unsigned MessungNr=1;
int reci=0;
int operate=0;


unsigned long Zeit=0;
unsigned long Start=0;
unsigned long Start1=0;
unsigned long Ende=0;
unsigned long s=0;

void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inPin, INPUT); // declare pushbutton as input


display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.display();
delay(5);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(INVERSE);

while (!Serial);

Serial.println("LoRa Receiver");

if (!LoRa.begin(866E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
}

void loop() {
// try to parse packet


int packetSize = LoRa.parsePacket(); //Packet declaration
/*************************************************************************************
READY
Sistem on Stand by
**************************************************************************************/
digitalWrite(ledPin, HIGH); // turn LED OFF

display.clearDisplay();
display.setCursor(0,0); //Position 1 at OLED
display.setTextSize(1);
display.print("!System On Stand By!");
//delay (2000);
display.setCursor(0,20); //Position 2 at OLED
display.print("Test Nr: ");
display.print(count); //Number of Test
display.display();

reci=digitalRead(inPin);

if (reci==HIGH){
operate=1;} //Convert to Pulse
/*************************************************************************************
READY
Sistem Start
**************************************************************************************/
if (operate==1){

Start=micros(); //Time stample Start time
operate=0;
Serial.print("Operation Status: ");
Serial.print(operate);
Serial.println();

Serial.print("System calculating: ");
Serial.println(MessungNr); //Test number
Serial.print("Start: ");
Serial.println(Start);
// started send to display
// gestartet auf Display senden
display.clearDisplay();
display.setCursor(0,0); //Position 1 at OLED
display.print("T-Nr: ");
display.print(MessungNr); //Test number
display.setCursor(0,20); //Position 2 at OLED
display.print("Starting");
display.display();

}
/*************************************************************************************
READY
Sistem stop
**************************************************************************************/
if (packetSize) {
Ende = micros(); //Time stample End time

Serial.print("Received packet: '");

// read packet
while (LoRa.available()) {
Serial.print((char)LoRa.read());
}
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
// print RSSI of packet
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
Serial.print("End: ");
Serial.println(Ende);
Serial.println();
delay(500);
/*************************************************************************************
READY
Sistem result
**************************************************************************************/
//ERGEBNIS

Serial.print("Start check: ");
Serial.println(Start); //Show Start time stample
Serial.print("End Check: ");
Serial.println(Ende); //Show End time stample
Zeit = Ende-Start;
delay(500);
Serial.print("Result ");
Serial.print(MessungNr); //Test number
Serial.print(": ");
Serial.print(Zeit); //Show Result
Serial.println("µs"); // Result in micro second
Serial.println();
Serial.println();
Serial.println();
// Result send to display
// Zeit auf Display senden
display.clearDisplay();
display.setCursor(0,0); //Position 1 OLED
display.print("E-Nr: ");
display.print(MessungNr); //Test number
display.setCursor(0,20); //Position 2 OLED
display.print(Zeit); //Show Result at OLED
display.print("µs");
display.display();

delay (50);

delay(10000);
// Warten an Display senden
display.clearDisplay();
display.setCursor(0,0);
display.print("WARTEN");
display.display();
delay(2000);
MessungNr++;
count++;

}
}


LoRa-Sender
#include <SPI.h>
#include <LoRa.h>
int ledPin = 17; // the pin for the LED
int count = 0;
int inPin = 27; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
int operate=0;


void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inPin, INPUT); // declare pushbutton as input
while (!Serial);

Serial.println("LoRa Sender");

if (!LoRa.begin(866E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
}

void loop() {
val = digitalRead(inPin); // read input value
digitalWrite(ledPin,HIGH);// LED ON ready to send
int packetReply=LoRa.parsePacket();
if (val==HIGH){
operate=1;
}
if (operate==1){
Serial.print("Sending packet: ");
Serial.println(count);

// send packet
LoRa.beginPacket();
LoRa.print("Packet: ");
LoRa.print(count);
LoRa.endPacket();

count++;
digitalWrite(ledPin,LOW);// LED OFF ...sending
delay(15000);

operate=0;

digitalWrite(ledPin,HIGH);// LED ON ready to send
}

}
-

  Mit Unterstützung von Prof. J. Walter Wintersemester 2017/18