Added gps functionallity -> not tested, currently 0 satellites in reach (indoor)
This commit is contained in:
+31
-21
@@ -3,7 +3,11 @@
|
|||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <Adafruit_GFX.h>
|
#include <Adafruit_GFX.h>
|
||||||
#include <Adafruit_SSD1306.h>
|
#include <Adafruit_SSD1306.h>
|
||||||
|
#include <SoftwareSerial.h>
|
||||||
|
#include <TinyGPS++.h>
|
||||||
|
|
||||||
|
|
||||||
|
// LORA Settings
|
||||||
#define SYNC_WORD 0xCE
|
#define SYNC_WORD 0xCE
|
||||||
#define RECEIVER_ID 0xAB // receiver
|
#define RECEIVER_ID 0xAB // receiver
|
||||||
#define SELF_ID 0xAA // sender
|
#define SELF_ID 0xAA // sender
|
||||||
@@ -16,11 +20,19 @@
|
|||||||
#define LORA_IRQ 26
|
#define LORA_IRQ 26
|
||||||
#define LORA_FREQ 868E6
|
#define LORA_FREQ 868E6
|
||||||
|
|
||||||
|
// GPS Settings
|
||||||
|
#define _RX_GPS 23
|
||||||
|
#define _TX_GPS 22
|
||||||
|
#define _BAUDRATE_GPS 9600
|
||||||
|
|
||||||
// OLED Settings
|
// OLED Settings
|
||||||
#define SCREEN_WIDTH 128
|
#define SCREEN_WIDTH 128
|
||||||
#define SCREEN_HEIGHT 64
|
#define SCREEN_HEIGHT 64
|
||||||
#define OLED_RESET -1
|
#define OLED_RESET -1
|
||||||
|
|
||||||
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||||
|
SoftwareSerial gps_serial(_RX_GPS, _TX_GPS);
|
||||||
|
TinyGPSPlus gps;
|
||||||
|
|
||||||
void sendMessage(const String& msg) {
|
void sendMessage(const String& msg) {
|
||||||
LoRa.beginPacket();
|
LoRa.beginPacket();
|
||||||
@@ -68,12 +80,13 @@ bool waitForAck(unsigned long timeout_ms = 1000) {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void showOnOLED(const String& line1, const String& line2 = "", const String& line3 = "") {
|
void showOnOLED(const String& line1, const String& line2 = "", const String& line3 = "", const String& line4 = "") {
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
display.setTextColor(SSD1306_WHITE);
|
display.setTextColor(SSD1306_WHITE);
|
||||||
display.setCursor(0, 0);
|
display.setCursor(0, 0);
|
||||||
display.println(line1);
|
display.println(line1);
|
||||||
|
|
||||||
if (line2.length()) {
|
if (line2.length()) {
|
||||||
display.setCursor(0, 16);
|
display.setCursor(0, 16);
|
||||||
display.println(line2);
|
display.println(line2);
|
||||||
@@ -82,16 +95,17 @@ void showOnOLED(const String& line1, const String& line2 = "", const String& lin
|
|||||||
display.setCursor(0, 32);
|
display.setCursor(0, 32);
|
||||||
display.println(line3);
|
display.println(line3);
|
||||||
}
|
}
|
||||||
display.display();
|
if (line4.length()) {
|
||||||
|
display.setCursor(0, 48);
|
||||||
|
display.println(line4);
|
||||||
}
|
}
|
||||||
|
|
||||||
String readGpsLine() {
|
display.display();
|
||||||
static int counter = 1;
|
|
||||||
return String(counter++);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
gps_serial.begin(_BAUDRATE_GPS);
|
||||||
|
|
||||||
// OLED init
|
// OLED init
|
||||||
Wire.begin(); // SDA/SCL Default
|
Wire.begin(); // SDA/SCL Default
|
||||||
@@ -114,7 +128,12 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// showOnOLED("Status:", "Warten");
|
if(gps_serial.available()){
|
||||||
|
gps.encode(gps_serial.read());
|
||||||
|
if(gps.location.isUpdated()){
|
||||||
|
Serial.println("GPS Update!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (waitForPacket(10)) {
|
if (waitForPacket(10)) {
|
||||||
String cmd;
|
String cmd;
|
||||||
@@ -128,22 +147,13 @@ void loop() {
|
|||||||
Serial.println("Empfangen: " + cmd);
|
Serial.println("Empfangen: " + cmd);
|
||||||
showOnOLED("Empfangen von:", "ID " + String(snd), "Cmd: " + cmd);
|
showOnOLED("Empfangen von:", "ID " + String(snd), "Cmd: " + cmd);
|
||||||
|
|
||||||
String gps = readGpsLine();
|
String lat_str = "LAT: " + String(gps.location.lat());
|
||||||
Serial.println("Sende GPS: " + gps);
|
String lng_str = "LON: " + String(gps.location.lng());
|
||||||
showOnOLED("Sende GPS Koords:", gps);
|
String satellites = "Satelliten: " + String(gps.satellites.value());
|
||||||
|
Serial.println("Sende GPS:\n" + lat_str + "\n" + lng_str);
|
||||||
|
showOnOLED("Sende GPS Koords:", lat_str, lng_str, satellites);
|
||||||
|
|
||||||
sendMessage(gps);
|
sendMessage(lat_str + "\n\n" + lng_str + "\n\n" + satellites);
|
||||||
|
|
||||||
/*
|
|
||||||
// Auf ACK warten
|
|
||||||
if (waitForAck()) {
|
|
||||||
Serial.println("ACK empfangen");
|
|
||||||
showOnOLED("ACK empfangen", "");
|
|
||||||
} else {
|
|
||||||
Serial.println("ACK fehlte!");
|
|
||||||
showOnOLED("WARNUNG:", "Kein ACK erhalten");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user