Added gps functionallity -> not tested, currently 0 satellites in reach (indoor)

This commit is contained in:
Ano-sys
2025-07-25 00:04:04 +02:00
parent a57d363220
commit 2945c89894
+32 -22
View File
@@ -3,7 +3,11 @@
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
// LORA Settings
#define SYNC_WORD 0xCE
#define RECEIVER_ID 0xAB // receiver
#define SELF_ID 0xAA // sender
@@ -16,11 +20,19 @@
#define LORA_IRQ 26
#define LORA_FREQ 868E6
// GPS Settings
#define _RX_GPS 23
#define _TX_GPS 22
#define _BAUDRATE_GPS 9600
// OLED Settings
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
SoftwareSerial gps_serial(_RX_GPS, _TX_GPS);
TinyGPSPlus gps;
void sendMessage(const String& msg) {
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.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(line1);
if (line2.length()) {
display.setCursor(0, 16);
display.println(line2);
@@ -82,16 +95,17 @@ void showOnOLED(const String& line1, const String& line2 = "", const String& lin
display.setCursor(0, 32);
display.println(line3);
}
display.display();
}
if (line4.length()) {
display.setCursor(0, 48);
display.println(line4);
}
String readGpsLine() {
static int counter = 1;
return String(counter++);
display.display();
}
void setup() {
Serial.begin(115200);
gps_serial.begin(_BAUDRATE_GPS);
// OLED init
Wire.begin(); // SDA/SCL Default
@@ -114,7 +128,12 @@ void setup() {
}
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)) {
String cmd;
@@ -128,22 +147,13 @@ void loop() {
Serial.println("Empfangen: " + cmd);
showOnOLED("Empfangen von:", "ID " + String(snd), "Cmd: " + cmd);
String gps = readGpsLine();
Serial.println("Sende GPS: " + gps);
showOnOLED("Sende GPS Koords:", gps);
String lat_str = "LAT: " + String(gps.location.lat());
String lng_str = "LON: " + String(gps.location.lng());
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);
/*
// Auf ACK warten
if (waitForAck()) {
Serial.println("ACK empfangen");
showOnOLED("ACK empfangen", "");
} else {
Serial.println("ACK fehlte!");
showOnOLED("WARNUNG:", "Kein ACK erhalten");
}
*/
sendMessage(lat_str + "\n\n" + lng_str + "\n\n" + satellites);
delay(1000);
}