2024-10-14 22:04:28 +02:00
|
|
|
#include <TinyGPS++.h>
|
2023-06-04 20:54:11 +02:00
|
|
|
#include <WiFi.h>
|
2023-06-06 17:21:59 +02:00
|
|
|
#include "configuration.h"
|
2023-06-18 00:28:40 +02:00
|
|
|
#include "station_utils.h"
|
2023-07-06 07:01:10 +02:00
|
|
|
#include "battery_utils.h"
|
2023-07-30 23:12:50 +02:00
|
|
|
#include "aprs_is_utils.h"
|
2024-11-05 22:20:44 +01:00
|
|
|
#include "board_pinout.h"
|
2023-06-13 05:36:39 +02:00
|
|
|
#include "syslog_utils.h"
|
2024-04-23 19:57:21 +02:00
|
|
|
#include "A7670_utils.h"
|
2024-05-29 21:43:23 +02:00
|
|
|
#include "lora_utils.h"
|
2023-06-07 23:25:50 +02:00
|
|
|
#include "wifi_utils.h"
|
2023-06-20 01:44:55 +02:00
|
|
|
#include "gps_utils.h"
|
2024-10-05 13:48:08 +02:00
|
|
|
#include "wx_utils.h"
|
2023-06-08 05:55:31 +02:00
|
|
|
#include "display.h"
|
2023-06-04 20:18:30 +02:00
|
|
|
#include "utils.h"
|
2023-06-11 02:17:10 +02:00
|
|
|
|
2024-10-14 22:04:28 +02:00
|
|
|
|
2023-06-17 17:10:44 +02:00
|
|
|
extern Configuration Config;
|
2024-05-14 05:30:15 +02:00
|
|
|
extern WiFiClient espClient;
|
2024-10-14 22:04:28 +02:00
|
|
|
extern TinyGPSPlus gps;
|
2023-06-17 17:10:44 +02:00
|
|
|
extern String versionDate;
|
|
|
|
|
extern String firstLine;
|
|
|
|
|
extern String secondLine;
|
|
|
|
|
extern String thirdLine;
|
|
|
|
|
extern String fourthLine;
|
|
|
|
|
extern String fifthLine;
|
|
|
|
|
extern String sixthLine;
|
|
|
|
|
extern String seventhLine;
|
|
|
|
|
extern String iGateBeaconPacket;
|
2024-01-12 03:22:58 +01:00
|
|
|
extern String iGateLoRaBeaconPacket;
|
2023-06-20 01:44:55 +02:00
|
|
|
extern int rssi;
|
|
|
|
|
extern float snr;
|
|
|
|
|
extern int freqError;
|
|
|
|
|
extern String distance;
|
2024-02-24 14:09:05 +01:00
|
|
|
extern bool WiFiConnected;
|
2024-05-13 20:00:07 +02:00
|
|
|
extern int wxModuleType;
|
2024-05-22 21:29:00 +02:00
|
|
|
extern bool backUpDigiMode;
|
2024-05-24 20:24:40 +02:00
|
|
|
extern bool shouldSleepLowVoltage;
|
2024-05-29 21:46:07 +02:00
|
|
|
extern bool transmitFlag;
|
2024-12-06 16:03:37 +01:00
|
|
|
extern bool passcodeValid;
|
2023-06-04 20:18:30 +02:00
|
|
|
|
2024-09-10 19:06:10 +02:00
|
|
|
extern std::vector<LastHeardStation> lastHeardStations;
|
|
|
|
|
|
2024-05-14 05:30:15 +02:00
|
|
|
bool statusAfterBoot = true;
|
2024-09-22 18:34:13 +02:00
|
|
|
bool sendStartTelemetry = true;
|
2024-12-06 16:03:37 +01:00
|
|
|
bool beaconUpdate = false;
|
2024-05-14 05:30:15 +02:00
|
|
|
uint32_t lastBeaconTx = 0;
|
2024-05-22 22:19:45 +02:00
|
|
|
uint32_t lastScreenOn = millis();
|
2024-10-21 13:28:35 +02:00
|
|
|
String beaconPacket;
|
|
|
|
|
String secondaryBeaconPacket;
|
2024-05-14 05:30:15 +02:00
|
|
|
|
2023-12-20 04:53:04 +01:00
|
|
|
|
2023-06-12 07:31:18 +02:00
|
|
|
namespace Utils {
|
2023-06-04 20:18:30 +02:00
|
|
|
|
2023-10-08 15:16:12 +02:00
|
|
|
void processStatus() {
|
2024-05-30 22:27:07 +02:00
|
|
|
String status = Config.callsign;
|
2024-06-08 20:39:15 +02:00
|
|
|
status.concat(">APLRG1");
|
|
|
|
|
if (Config.beacon.path.indexOf("WIDE") == 0) {
|
|
|
|
|
status.concat(",");
|
|
|
|
|
status.concat(Config.beacon.path);
|
|
|
|
|
}
|
2024-04-09 18:20:31 +02:00
|
|
|
if (WiFi.status() == WL_CONNECTED && Config.aprs_is.active && Config.beacon.sendViaAPRSIS) {
|
2023-10-08 15:16:12 +02:00
|
|
|
delay(1000);
|
2024-05-30 22:27:07 +02:00
|
|
|
status.concat(",qAC:>https://github.com/richonguzman/LoRa_APRS_iGate ");
|
|
|
|
|
status.concat(versionDate);
|
2024-01-24 15:13:34 +01:00
|
|
|
APRS_IS_Utils::upload(status);
|
2024-05-30 21:12:34 +02:00
|
|
|
SYSLOG_Utils::log(2, status, 0, 0.0, 0); // APRSIS TX
|
2024-04-09 18:20:31 +02:00
|
|
|
statusAfterBoot = false;
|
|
|
|
|
}
|
|
|
|
|
if (statusAfterBoot && !Config.beacon.sendViaAPRSIS && Config.beacon.sendViaRF) {
|
2024-05-30 22:27:07 +02:00
|
|
|
status.concat(":>https://github.com/richonguzman/LoRa_APRS_iGate ");
|
|
|
|
|
status.concat(versionDate);
|
2024-04-20 16:06:22 +02:00
|
|
|
STATION_Utils::addToOutputPacketBuffer(status);
|
2024-04-09 18:20:31 +02:00
|
|
|
statusAfterBoot = false;
|
2023-06-08 23:09:05 +02:00
|
|
|
}
|
2023-06-08 06:44:13 +02:00
|
|
|
}
|
2023-06-17 01:08:25 +02:00
|
|
|
|
2024-06-08 20:12:20 +02:00
|
|
|
String getLocalIP() {
|
2024-10-08 06:03:58 +02:00
|
|
|
if (Config.digi.ecoMode) {
|
2024-10-07 04:23:22 +02:00
|
|
|
return "** WiFi AP Killed **";
|
|
|
|
|
} else if (!WiFiConnected) {
|
2024-02-25 16:00:44 +01:00
|
|
|
return "IP : 192.168.4.1";
|
2024-05-22 21:29:00 +02:00
|
|
|
} else if (backUpDigiMode) {
|
2024-05-22 21:41:25 +02:00
|
|
|
return "- BACKUP DIGI MODE -";
|
2024-02-24 14:09:05 +01:00
|
|
|
} else {
|
|
|
|
|
return "IP : " + String(WiFi.localIP()[0]) + "." + String(WiFi.localIP()[1]) + "." + String(WiFi.localIP()[2]) + "." + String(WiFi.localIP()[3]);
|
2024-11-06 16:47:42 +01:00
|
|
|
}
|
2023-06-19 06:52:40 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-08 15:16:12 +02:00
|
|
|
void setupDisplay() {
|
2024-08-14 18:32:34 +02:00
|
|
|
displaySetup();
|
2024-04-24 04:25:20 +02:00
|
|
|
#ifdef INTERNAL_LED_PIN
|
2024-05-11 18:59:07 +02:00
|
|
|
digitalWrite(INTERNAL_LED_PIN,HIGH);
|
2024-01-03 05:13:44 +01:00
|
|
|
#endif
|
2024-02-24 14:09:05 +01:00
|
|
|
Serial.println("\nStarting Station: " + Config.callsign + " Version: " + versionDate);
|
2024-10-08 17:19:22 +02:00
|
|
|
Serial.println((Config.digi.ecoMode) ? "(DigiEcoMode: ON)" : "(DigiEcoMode: OFF)");
|
2024-08-14 18:32:34 +02:00
|
|
|
displayShow(" LoRa APRS", "", "", " ( iGATE & DIGI )", "", "" , " CA2RXU " + versionDate, 4000);
|
2024-04-24 04:25:20 +02:00
|
|
|
#ifdef INTERNAL_LED_PIN
|
2024-05-11 18:59:07 +02:00
|
|
|
digitalWrite(INTERNAL_LED_PIN,LOW);
|
2024-01-03 05:13:44 +01:00
|
|
|
#endif
|
2023-10-08 15:16:12 +02:00
|
|
|
firstLine = Config.callsign;
|
|
|
|
|
seventhLine = " listening...";
|
2023-06-08 05:55:31 +02:00
|
|
|
}
|
2023-10-08 15:16:12 +02:00
|
|
|
|
|
|
|
|
void activeStations() {
|
2025-02-12 18:15:36 +01:00
|
|
|
char buffer[30]; // Adjust size as needed
|
|
|
|
|
sprintf(buffer, "Stations (%dmin) = %2d", Config.rememberStationTime, lastHeardStations.size());
|
|
|
|
|
fourthLine = buffer;
|
2023-10-08 15:16:12 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-22 18:34:13 +02:00
|
|
|
void sendInitialTelemetryPackets() {
|
2025-02-12 18:15:36 +01:00
|
|
|
char sender[10]; // 9 characters + null terminator
|
|
|
|
|
snprintf(sender, sizeof(sender), "%-9s", Config.callsign.c_str()); // Left-align with spaces
|
|
|
|
|
|
2024-09-22 18:34:13 +02:00
|
|
|
String baseAPRSISTelemetryPacket = Config.callsign;
|
|
|
|
|
baseAPRSISTelemetryPacket += ">APLRG1,TCPIP,qAC::";
|
|
|
|
|
baseAPRSISTelemetryPacket += sender;
|
|
|
|
|
baseAPRSISTelemetryPacket += ":";
|
|
|
|
|
|
|
|
|
|
String baseRFTelemetryPacket = Config.callsign;
|
2024-11-06 16:47:42 +01:00
|
|
|
baseRFTelemetryPacket += ">APLRG1";
|
|
|
|
|
if (Config.beacon.path.indexOf("WIDE") != -1) {
|
|
|
|
|
baseRFTelemetryPacket += ",";
|
|
|
|
|
baseRFTelemetryPacket += Config.beacon.path;
|
|
|
|
|
}
|
|
|
|
|
baseRFTelemetryPacket += "::";
|
2024-09-22 18:34:13 +02:00
|
|
|
baseRFTelemetryPacket += sender;
|
|
|
|
|
baseRFTelemetryPacket += ":";
|
|
|
|
|
|
|
|
|
|
String telemetryPacket1 = "EQNS.";
|
|
|
|
|
if (Config.battery.sendInternalVoltage) {
|
|
|
|
|
telemetryPacket1 += "0,0.01,0";
|
|
|
|
|
}
|
|
|
|
|
if (Config.battery.sendExternalVoltage) {
|
2025-02-12 18:15:36 +01:00
|
|
|
telemetryPacket1 += String(Config.battery.sendInternalVoltage ? ",0,0.02,0" : "0,0.02,0");
|
2024-09-22 18:34:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String telemetryPacket2 = "UNIT.";
|
|
|
|
|
if (Config.battery.sendInternalVoltage) {
|
|
|
|
|
telemetryPacket2 += "VDC";
|
|
|
|
|
}
|
|
|
|
|
if (Config.battery.sendExternalVoltage) {
|
2025-02-12 18:15:36 +01:00
|
|
|
telemetryPacket2 += String(Config.battery.sendInternalVoltage ? ",VDC" : "VDC");
|
2024-09-22 18:34:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String telemetryPacket3 = "PARM.";
|
|
|
|
|
if (Config.battery.sendInternalVoltage) {
|
|
|
|
|
telemetryPacket3 += "V_Batt";
|
|
|
|
|
}
|
|
|
|
|
if (Config.battery.sendExternalVoltage) {
|
2025-02-12 18:15:36 +01:00
|
|
|
telemetryPacket3 += String(Config.battery.sendInternalVoltage ? ",V_Ext" : "V_Ext");
|
2024-09-22 18:34:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Config.beacon.sendViaAPRSIS) {
|
|
|
|
|
#ifdef HAS_A7670
|
|
|
|
|
A7670_Utils::uploadToAPRSIS(baseAPRSISTelemetryPacket + telemetryPacket1);
|
|
|
|
|
delay(300);
|
|
|
|
|
A7670_Utils::uploadToAPRSIS(baseAPRSISTelemetryPacket + telemetryPacket2);
|
|
|
|
|
delay(300);
|
|
|
|
|
A7670_Utils::uploadToAPRSIS(baseAPRSISTelemetryPacket + telemetryPacket3);
|
|
|
|
|
delay(300);
|
|
|
|
|
#else
|
|
|
|
|
APRS_IS_Utils::upload(baseAPRSISTelemetryPacket + telemetryPacket1);
|
|
|
|
|
delay(300);
|
|
|
|
|
APRS_IS_Utils::upload(baseAPRSISTelemetryPacket + telemetryPacket2);
|
|
|
|
|
delay(300);
|
|
|
|
|
APRS_IS_Utils::upload(baseAPRSISTelemetryPacket + telemetryPacket3);
|
|
|
|
|
delay(300);
|
|
|
|
|
#endif
|
|
|
|
|
delay(300);
|
|
|
|
|
} else if (Config.beacon.sendViaRF) {
|
|
|
|
|
LoRa_Utils::sendNewPacket(baseRFTelemetryPacket + telemetryPacket1);
|
|
|
|
|
delay(3000);
|
|
|
|
|
LoRa_Utils::sendNewPacket(baseRFTelemetryPacket + telemetryPacket2);
|
|
|
|
|
delay(3000);
|
|
|
|
|
LoRa_Utils::sendNewPacket(baseRFTelemetryPacket + telemetryPacket3);
|
|
|
|
|
delay(3000);
|
|
|
|
|
}
|
|
|
|
|
sendStartTelemetry = false;
|
2024-11-06 16:47:42 +01:00
|
|
|
}
|
2024-09-22 18:34:13 +02:00
|
|
|
|
2023-10-08 15:16:12 +02:00
|
|
|
void checkBeaconInterval() {
|
|
|
|
|
uint32_t lastTx = millis() - lastBeaconTx;
|
2025-01-07 18:19:06 +01:00
|
|
|
if (lastBeaconTx == 0 || lastTx >= Config.beacon.interval * 60 * 1000) {
|
2023-10-08 15:16:12 +02:00
|
|
|
beaconUpdate = true;
|
2023-07-06 07:08:01 +02:00
|
|
|
}
|
2024-03-07 17:46:38 +01:00
|
|
|
|
2024-10-21 13:28:35 +02:00
|
|
|
#ifdef HAS_GPS
|
2024-10-21 16:16:31 +02:00
|
|
|
if (Config.beacon.gpsActive && gps.location.lat() == 0.0 && gps.location.lng() == 0.0 && Config.beacon.latitude == 0.0 && Config.beacon.longitude == 0.0) {
|
2024-10-21 13:28:35 +02:00
|
|
|
GPS_Utils::getData();
|
|
|
|
|
beaconUpdate = false;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-10-08 15:16:12 +02:00
|
|
|
if (beaconUpdate) {
|
2025-01-07 18:19:06 +01:00
|
|
|
if (!Config.display.alwaysOn && Config.display.timeout != 0) displayToggle(true);
|
2024-09-22 18:34:13 +02:00
|
|
|
|
2024-10-05 13:48:08 +02:00
|
|
|
if (sendStartTelemetry && Config.battery.sendVoltageAsTelemetry && !Config.wxsensor.active && (Config.battery.sendInternalVoltage || Config.battery.sendExternalVoltage)) {
|
2024-09-22 18:34:13 +02:00
|
|
|
sendInitialTelemetryPackets();
|
|
|
|
|
}
|
2024-11-06 16:47:42 +01:00
|
|
|
|
2023-10-08 15:16:12 +02:00
|
|
|
STATION_Utils::deleteNotHeard();
|
2024-03-07 17:46:38 +01:00
|
|
|
|
2023-10-08 15:16:12 +02:00
|
|
|
activeStations();
|
2024-03-07 17:46:38 +01:00
|
|
|
|
2024-10-21 13:28:35 +02:00
|
|
|
beaconPacket = iGateBeaconPacket;
|
|
|
|
|
secondaryBeaconPacket = iGateLoRaBeaconPacket;
|
2024-10-14 22:04:28 +02:00
|
|
|
#ifdef HAS_GPS
|
|
|
|
|
if (Config.beacon.gpsActive && !Config.digi.ecoMode) {
|
|
|
|
|
GPS_Utils::getData();
|
2024-10-21 13:28:35 +02:00
|
|
|
if (gps.location.isUpdated() && gps.location.lat() != 0.0 && gps.location.lng() != 0.0) {
|
2024-10-14 22:04:28 +02:00
|
|
|
GPS_Utils::generateBeaconFirstPart();
|
|
|
|
|
String encodedGPS = GPS_Utils::encodeGPS(gps.location.lat(), gps.location.lng(), Config.beacon.overlay, Config.beacon.symbol);
|
|
|
|
|
beaconPacket = iGateBeaconPacket + encodedGPS;
|
|
|
|
|
secondaryBeaconPacket = iGateLoRaBeaconPacket + encodedGPS;
|
|
|
|
|
}
|
2024-10-21 13:28:35 +02:00
|
|
|
}
|
|
|
|
|
#endif
|
2024-10-14 22:04:28 +02:00
|
|
|
|
2025-02-12 18:15:36 +01:00
|
|
|
if (Config.wxsensor.active) {
|
|
|
|
|
const char* sensorData = (wxModuleType == 0) ? ".../...g...t..." : WX_Utils::readDataSensor().c_str();
|
|
|
|
|
beaconPacket += sensorData;
|
|
|
|
|
secondaryBeaconPacket += sensorData;
|
2023-06-19 06:52:40 +02:00
|
|
|
}
|
2024-06-21 03:12:54 +02:00
|
|
|
beaconPacket += Config.beacon.comment;
|
|
|
|
|
secondaryBeaconPacket += Config.beacon.comment;
|
2024-03-07 17:46:38 +01:00
|
|
|
|
2024-05-27 17:46:14 +02:00
|
|
|
#if defined(BATTERY_PIN) || defined(HAS_AXP192) || defined(HAS_AXP2101)
|
2024-05-24 20:24:40 +02:00
|
|
|
if (Config.battery.sendInternalVoltage || Config.battery.monitorInternalVoltage) {
|
2024-05-24 19:05:28 +02:00
|
|
|
float internalVoltage = BATTERY_Utils::checkInternalVoltage();
|
2024-09-22 18:34:13 +02:00
|
|
|
if (Config.battery.monitorInternalVoltage && internalVoltage < Config.battery.internalSleepVoltage) {
|
|
|
|
|
beaconPacket += " **IntBatWarning:SLEEP**";
|
|
|
|
|
secondaryBeaconPacket += " **IntBatWarning:SLEEP**";
|
|
|
|
|
shouldSleepLowVoltage = true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-24 20:24:40 +02:00
|
|
|
if (Config.battery.sendInternalVoltage) {
|
2025-02-12 18:15:36 +01:00
|
|
|
char internalVoltageInfo[10]; // Enough to hold "xx.xxV\0"
|
|
|
|
|
snprintf(internalVoltageInfo, sizeof(internalVoltageInfo), "%.2fV", internalVoltage);
|
|
|
|
|
|
|
|
|
|
char sixthLineBuffer[25]; // Enough to hold " (Batt=xx.xxV)"
|
|
|
|
|
snprintf(sixthLineBuffer, sizeof(sixthLineBuffer), " (Batt=%s)", internalVoltageInfo);
|
|
|
|
|
sixthLine = sixthLineBuffer;
|
|
|
|
|
|
2024-09-22 18:34:13 +02:00
|
|
|
if (!Config.battery.sendVoltageAsTelemetry) {
|
|
|
|
|
beaconPacket += " Batt=";
|
|
|
|
|
beaconPacket += internalVoltageInfo;
|
|
|
|
|
secondaryBeaconPacket += " Batt=";
|
|
|
|
|
secondaryBeaconPacket += internalVoltageInfo;
|
|
|
|
|
}
|
2024-11-06 16:47:42 +01:00
|
|
|
}
|
2024-05-11 18:59:07 +02:00
|
|
|
}
|
2023-12-26 21:27:36 +01:00
|
|
|
#endif
|
2024-03-07 17:46:38 +01:00
|
|
|
|
2024-08-19 16:41:46 +02:00
|
|
|
#ifndef HELTEC_WP
|
|
|
|
|
if (Config.battery.sendExternalVoltage || Config.battery.monitorExternalVoltage) {
|
|
|
|
|
float externalVoltage = BATTERY_Utils::checkExternalVoltage();
|
|
|
|
|
if (Config.battery.monitorExternalVoltage && externalVoltage < Config.battery.externalSleepVoltage) {
|
|
|
|
|
beaconPacket += " **ExtBatWarning:SLEEP**";
|
|
|
|
|
secondaryBeaconPacket += " **ExtBatWarning:SLEEP**";
|
|
|
|
|
shouldSleepLowVoltage = true;
|
|
|
|
|
}
|
2024-09-22 18:34:13 +02:00
|
|
|
|
|
|
|
|
if (Config.battery.sendExternalVoltage) {
|
2025-02-12 18:15:36 +01:00
|
|
|
char externalVoltageInfo[10]; // "xx.xxV\0" (max 7 chars)
|
|
|
|
|
snprintf(externalVoltageInfo, sizeof(externalVoltageInfo), "%.2fV", externalVoltage);
|
|
|
|
|
|
|
|
|
|
char sixthLineBuffer[25]; // Ensure enough space
|
|
|
|
|
snprintf(sixthLineBuffer, sizeof(sixthLineBuffer), " (Ext V=%s)", externalVoltageInfo);
|
|
|
|
|
sixthLine = sixthLineBuffer;
|
|
|
|
|
|
2024-09-22 18:34:13 +02:00
|
|
|
if (!Config.battery.sendVoltageAsTelemetry) {
|
|
|
|
|
beaconPacket += " Ext=";
|
|
|
|
|
beaconPacket += externalVoltageInfo;
|
|
|
|
|
secondaryBeaconPacket += " Ext=";
|
|
|
|
|
secondaryBeaconPacket += externalVoltageInfo;
|
2024-11-06 16:47:42 +01:00
|
|
|
}
|
|
|
|
|
}
|
2024-05-24 19:05:28 +02:00
|
|
|
}
|
2024-08-19 16:41:46 +02:00
|
|
|
#endif
|
2024-03-07 17:46:38 +01:00
|
|
|
|
2024-10-05 13:48:08 +02:00
|
|
|
if (Config.battery.sendVoltageAsTelemetry && !Config.wxsensor.active && (Config.battery.sendInternalVoltage || Config.battery.sendExternalVoltage)){
|
2024-09-22 18:34:13 +02:00
|
|
|
String encodedTelemetry = BATTERY_Utils::generateEncodedTelemetry();
|
|
|
|
|
beaconPacket += encodedTelemetry;
|
|
|
|
|
secondaryBeaconPacket += encodedTelemetry;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-07 18:19:06 +01:00
|
|
|
if (Config.beacon.sendViaAPRSIS && Config.aprs_is.active && passcodeValid && !backUpDigiMode) {
|
2024-08-15 20:54:26 +02:00
|
|
|
Utils::println("-- Sending Beacon to APRSIS --");
|
2024-11-06 16:47:42 +01:00
|
|
|
displayShow(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "SENDING IGATE BEACON", 0);
|
2023-07-30 23:12:50 +02:00
|
|
|
seventhLine = " listening...";
|
2024-06-19 01:55:33 +02:00
|
|
|
#ifdef HAS_A7670
|
2024-05-11 18:59:07 +02:00
|
|
|
A7670_Utils::uploadToAPRSIS(beaconPacket);
|
2024-04-23 19:57:21 +02:00
|
|
|
#else
|
2024-05-11 18:59:07 +02:00
|
|
|
APRS_IS_Utils::upload(beaconPacket);
|
2024-04-23 19:57:21 +02:00
|
|
|
#endif
|
2024-03-07 17:46:38 +01:00
|
|
|
}
|
|
|
|
|
|
2024-05-22 21:29:00 +02:00
|
|
|
if (Config.beacon.sendViaRF || backUpDigiMode) {
|
2024-08-15 20:54:26 +02:00
|
|
|
Utils::println("-- Sending Beacon to RF --");
|
2024-08-14 18:32:34 +02:00
|
|
|
displayShow(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "SENDING DIGI BEACON", 0);
|
2023-07-30 17:34:20 +02:00
|
|
|
seventhLine = " listening...";
|
2024-04-20 16:06:22 +02:00
|
|
|
STATION_Utils::addToOutputPacketBuffer(secondaryBeaconPacket);
|
2023-09-21 07:08:10 +02:00
|
|
|
}
|
2024-03-07 17:46:38 +01:00
|
|
|
|
2023-10-08 15:16:12 +02:00
|
|
|
lastBeaconTx = millis();
|
|
|
|
|
lastScreenOn = millis();
|
|
|
|
|
beaconUpdate = false;
|
2023-06-08 05:55:31 +02:00
|
|
|
}
|
2024-03-07 17:46:38 +01:00
|
|
|
|
2023-10-08 15:16:12 +02:00
|
|
|
if (statusAfterBoot) {
|
|
|
|
|
processStatus();
|
2023-06-08 05:55:31 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-08 15:16:12 +02:00
|
|
|
void checkDisplayInterval() {
|
|
|
|
|
uint32_t lastDisplayTime = millis() - lastScreenOn;
|
2024-04-28 15:30:56 +02:00
|
|
|
if (!Config.display.alwaysOn && lastDisplayTime >= Config.display.timeout * 1000) {
|
2024-08-14 18:32:34 +02:00
|
|
|
displayToggle(false);
|
2023-10-08 15:16:12 +02:00
|
|
|
}
|
2023-07-31 00:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
2024-03-07 17:46:38 +01:00
|
|
|
void validateFreqs() {
|
|
|
|
|
if (Config.loramodule.txFreq != Config.loramodule.rxFreq && abs(Config.loramodule.txFreq - Config.loramodule.rxFreq) < 125000) {
|
|
|
|
|
Serial.println("Tx Freq less than 125kHz from Rx Freq ---> NOT VALID");
|
2024-08-14 18:32:34 +02:00
|
|
|
displayShow("Tx Freq is less than ", "125kHz from Rx Freq", "device will autofix", "and then reboot", 1000);
|
2024-03-07 17:46:38 +01:00
|
|
|
Config.loramodule.txFreq = Config.loramodule.rxFreq; // Inform about that but then change the TX QRG to RX QRG and reset the device
|
|
|
|
|
Config.writeFile();
|
|
|
|
|
ESP.restart();
|
2023-06-17 17:10:44 +02:00
|
|
|
}
|
|
|
|
|
}
|
2023-10-08 15:16:12 +02:00
|
|
|
|
2024-06-06 05:49:16 +02:00
|
|
|
void typeOfPacket(const String& packet, const uint8_t packetType) {
|
2024-05-30 22:27:07 +02:00
|
|
|
String sender = packet.substring(0,packet.indexOf(">"));
|
2024-05-15 23:47:29 +02:00
|
|
|
switch (packetType) {
|
|
|
|
|
case 0: // LoRa-APRS
|
|
|
|
|
fifthLine = "LoRa Rx ----> APRS-IS";
|
|
|
|
|
break;
|
|
|
|
|
case 1: // APRS-LoRa
|
|
|
|
|
fifthLine = "APRS-IS ----> LoRa Tx";
|
|
|
|
|
break;
|
2024-11-06 16:47:42 +01:00
|
|
|
case 2: // Digipeater
|
2024-05-15 23:47:29 +02:00
|
|
|
fifthLine = "LoRa Rx ----> LoRa Tx";
|
|
|
|
|
break;
|
2023-06-17 17:10:44 +02:00
|
|
|
}
|
2025-02-12 18:15:36 +01:00
|
|
|
|
|
|
|
|
int firstColonIndex = packet.indexOf(":");
|
|
|
|
|
char nextChar = packet[firstColonIndex + 1];
|
|
|
|
|
|
2024-03-27 19:28:27 +01:00
|
|
|
for (int i = sender.length(); i < 9; i++) {
|
2023-10-08 15:16:12 +02:00
|
|
|
sender += " ";
|
2023-06-20 01:44:55 +02:00
|
|
|
}
|
2024-05-30 22:27:07 +02:00
|
|
|
sixthLine = sender;
|
|
|
|
|
|
2025-02-12 18:15:36 +01:00
|
|
|
if (nextChar == ':') {
|
2024-05-30 22:27:07 +02:00
|
|
|
sixthLine += "> MESSAGE";
|
2025-02-12 18:15:36 +01:00
|
|
|
} else if (nextChar == '>') {
|
2024-05-30 22:27:07 +02:00
|
|
|
sixthLine += "> NEW STATUS";
|
2025-02-12 18:15:36 +01:00
|
|
|
} else if (nextChar == '!' || nextChar == '=' || nextChar == '@') {
|
2024-05-30 22:27:07 +02:00
|
|
|
sixthLine += "> GPS BEACON";
|
2025-02-12 18:15:36 +01:00
|
|
|
if (!Config.syslog.active) GPS_Utils::getDistanceAndComment(packet); // to be checked!!!
|
2024-05-30 22:27:07 +02:00
|
|
|
seventhLine = "RSSI:";
|
|
|
|
|
seventhLine += String(rssi);
|
|
|
|
|
seventhLine += "dBm";
|
2025-02-12 18:15:36 +01:00
|
|
|
seventhLine += (rssi <= -100) ? " " : " ";
|
|
|
|
|
if (distance.indexOf(".") == 1) seventhLine += " ";
|
2024-05-30 22:27:07 +02:00
|
|
|
seventhLine += "D:";
|
|
|
|
|
seventhLine += distance;
|
|
|
|
|
seventhLine += "km";
|
2025-02-12 18:15:36 +01:00
|
|
|
} else if (nextChar == '`' || nextChar == '\'') {
|
2024-05-30 22:27:07 +02:00
|
|
|
sixthLine += "> MIC-E";
|
2025-02-12 18:15:36 +01:00
|
|
|
} else if (nextChar == ';') {
|
2024-05-30 22:27:07 +02:00
|
|
|
sixthLine += "> OBJECT";
|
2024-06-24 17:02:38 +02:00
|
|
|
} else if (packet.indexOf(":T#") >= 10 && packet.indexOf(":=/") == -1) {
|
|
|
|
|
sixthLine += "> TELEMETRY";
|
2023-10-08 15:16:12 +02:00
|
|
|
} else {
|
2024-05-30 22:27:07 +02:00
|
|
|
sixthLine += "> ??????????";
|
2025-02-12 18:15:36 +01:00
|
|
|
}
|
|
|
|
|
if (nextChar != '!' && nextChar != '=' && nextChar != '@') { // Common assignment for non-GPS cases
|
|
|
|
|
seventhLine = "RSSI:";
|
|
|
|
|
seventhLine += String(rssi);
|
|
|
|
|
seventhLine += "dBm SNR: ";
|
|
|
|
|
seventhLine += String(snr);
|
|
|
|
|
seventhLine += "dBm";
|
2023-06-20 05:06:41 +02:00
|
|
|
}
|
2023-06-09 07:12:13 +02:00
|
|
|
}
|
|
|
|
|
|
2024-05-15 23:47:29 +02:00
|
|
|
void print(const String& text) {
|
2024-03-17 12:21:11 +01:00
|
|
|
if (!Config.tnc.enableSerial) {
|
|
|
|
|
Serial.print(text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-15 23:47:29 +02:00
|
|
|
void println(const String& text) {
|
2024-03-17 12:21:11 +01:00
|
|
|
if (!Config.tnc.enableSerial) {
|
|
|
|
|
Serial.println(text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-23 01:19:25 +02:00
|
|
|
void checkRebootMode() {
|
|
|
|
|
if (Config.rebootMode && Config.rebootModeTime > 0) {
|
|
|
|
|
Serial.println("(Reboot Time Set to " + String(Config.rebootModeTime) + " hours)");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void checkRebootTime() {
|
|
|
|
|
if (Config.rebootMode && Config.rebootModeTime > 0) {
|
|
|
|
|
if (millis() > Config.rebootModeTime * 60 * 60 * 1000) {
|
|
|
|
|
Serial.println("\n*** Automatic Reboot Time Restart! ****\n");
|
|
|
|
|
ESP.restart();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-24 20:24:40 +02:00
|
|
|
void checkSleepByLowBatteryVoltage(uint8_t mode) {
|
|
|
|
|
if (shouldSleepLowVoltage) {
|
2024-08-28 23:11:50 +02:00
|
|
|
if (mode == 0) { // at startup
|
2024-05-24 20:24:40 +02:00
|
|
|
delay(3000);
|
|
|
|
|
}
|
|
|
|
|
Serial.println("\n\n*** Sleeping Low Battey Voltage ***\n\n");
|
|
|
|
|
esp_sleep_enable_timer_wakeup(30 * 60 * 1000000); // sleep 30 min
|
2024-08-28 23:11:50 +02:00
|
|
|
if (mode == 1) { // low voltage detected after a while
|
2024-08-14 18:32:34 +02:00
|
|
|
displayToggle(false);
|
2024-05-24 20:24:40 +02:00
|
|
|
}
|
|
|
|
|
#ifdef VEXT_CTRL
|
|
|
|
|
#ifndef HELTEC_WSL_V3
|
|
|
|
|
digitalWrite(VEXT_CTRL, LOW);
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
2024-05-29 21:43:23 +02:00
|
|
|
LoRa_Utils::sleepRadio();
|
2024-05-29 21:46:07 +02:00
|
|
|
transmitFlag = true;
|
2024-05-29 21:43:23 +02:00
|
|
|
delay(100);
|
2024-05-24 20:24:40 +02:00
|
|
|
esp_deep_sleep_start();
|
2024-05-24 19:05:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-07 23:29:55 +02:00
|
|
|
bool checkValidCallsign(const String& callsign) {
|
2024-06-08 20:39:15 +02:00
|
|
|
if (callsign == "WLNK-1") return true;
|
2024-06-10 17:33:26 +02:00
|
|
|
|
2024-06-07 23:29:55 +02:00
|
|
|
String cleanCallsign;
|
2024-06-25 22:36:49 +02:00
|
|
|
if (callsign.indexOf("-") > 0) { // SSID Validation
|
2024-06-07 23:29:55 +02:00
|
|
|
cleanCallsign = callsign.substring(0, callsign.indexOf("-"));
|
|
|
|
|
String ssid = callsign.substring(callsign.indexOf("-") + 1);
|
2024-06-18 21:15:27 +02:00
|
|
|
if (ssid.indexOf("-") != -1 || ssid.length() > 2) return false;
|
|
|
|
|
for (int i = 0; i < ssid.length(); i++) {
|
|
|
|
|
if (!isAlphaNumeric(ssid[i])) return false;
|
2024-06-07 23:29:55 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
cleanCallsign = callsign;
|
|
|
|
|
}
|
2024-06-10 17:33:26 +02:00
|
|
|
|
2024-06-08 19:57:58 +02:00
|
|
|
if (cleanCallsign.length() < 4 || cleanCallsign.length() > 6) return false;
|
2024-06-07 23:29:55 +02:00
|
|
|
|
2024-06-10 17:33:26 +02:00
|
|
|
if (cleanCallsign.length() < 6 && isAlpha(cleanCallsign[0]) && isDigit(cleanCallsign[1]) && isAlpha(cleanCallsign[2]) && isAlpha(cleanCallsign[3]) ) {
|
|
|
|
|
cleanCallsign = " " + cleanCallsign; // A0AA --> _A0AA
|
2024-06-07 23:29:55 +02:00
|
|
|
}
|
2024-06-08 18:52:47 +02:00
|
|
|
|
2024-08-05 21:20:58 +02:00
|
|
|
if (!isDigit(cleanCallsign[2]) || !isAlpha(cleanCallsign[3])) { // __0A__ must be validated
|
|
|
|
|
if (cleanCallsign[0] != 'R' && !isDigit(cleanCallsign[1]) && !isAlpha(cleanCallsign[2])) return false; // to accepto R0A___
|
|
|
|
|
}
|
2024-06-10 17:33:26 +02:00
|
|
|
|
|
|
|
|
bool isValid = false;
|
|
|
|
|
if ((isAlphaNumeric(cleanCallsign[0]) || cleanCallsign[0] == ' ') && isAlpha(cleanCallsign[1])) {
|
|
|
|
|
isValid = true; // AA0A (+A+A) + _A0AA (+A) + 0A0A (+A+A)
|
|
|
|
|
} else if (isAlpha(cleanCallsign[0]) && isDigit(cleanCallsign[1])) {
|
|
|
|
|
isValid = true; // A00A (+A+A)
|
2024-08-05 21:20:58 +02:00
|
|
|
} else if (cleanCallsign[0] == 'R' && cleanCallsign.length() == 6 && isDigit(cleanCallsign[1]) && isAlpha(cleanCallsign[2]) && isAlpha(cleanCallsign[3]) && isAlpha(cleanCallsign[4])) {
|
|
|
|
|
isValid = true; // R0AA (+A+A)
|
2024-06-07 23:29:55 +02:00
|
|
|
}
|
2024-06-10 17:33:26 +02:00
|
|
|
if (!isValid) return false; // also 00__ avoided
|
|
|
|
|
|
2024-08-05 21:20:58 +02:00
|
|
|
if (cleanCallsign.length() > 4) { // to validate ____AA
|
2024-06-10 17:33:26 +02:00
|
|
|
for (int i = 5; i <= cleanCallsign.length(); i++) {
|
|
|
|
|
if (!isAlpha(cleanCallsign[i - 1])) return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-07 23:29:55 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-04 20:18:30 +02:00
|
|
|
}
|