2024-05-11 12:02:08 -04:00
|
|
|
/*______________________________________________________________________________________________________________
|
|
|
|
|
|
|
|
|
|
██╗ ██████╗ ██████╗ █████╗ █████╗ ██████╗ ██████╗ ███████╗ ██╗ ██████╗ █████╗ ████████╗███████╗
|
|
|
|
|
██║ ██╔═══██╗██╔══██╗██╔══██╗ ██╔══██╗██╔══██╗██╔══██╗██╔════╝ ██║██╔════╝ ██╔══██╗╚══██╔══╝██╔════╝
|
|
|
|
|
██║ ██║ ██║██████╔╝███████║ ███████║██████╔╝██████╔╝███████╗ ██║██║ ███╗███████║ ██║ █████╗
|
|
|
|
|
██║ ██║ ██║██╔══██╗██╔══██║ ██╔══██║██╔═══╝ ██╔══██╗╚════██║ ██║██║ ██║██╔══██║ ██║ ██╔══╝
|
|
|
|
|
███████╗╚██████╔╝██║ ██║██║ ██║ ██║ ██║██║ ██║ ██║███████║ ██║╚██████╔╝██║ ██║ ██║ ███████╗
|
|
|
|
|
╚══════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝
|
|
|
|
|
|
|
|
|
|
Ricardo Guzman - CA2RXU
|
|
|
|
|
https://github.com/richonguzman/LoRa_APRS_Tracker
|
2024-05-20 11:18:01 -04:00
|
|
|
(donations : http://paypal.me/richonguzman)
|
2024-05-11 12:02:08 -04:00
|
|
|
______________________________________________________________________________________________________________*/
|
|
|
|
|
|
2024-04-20 10:06:22 -04:00
|
|
|
#include <ElegantOTA.h>
|
2023-03-02 08:51:38 -03:00
|
|
|
#include <Arduino.h>
|
|
|
|
|
#include <WiFi.h>
|
2023-05-19 18:52:59 -04:00
|
|
|
#include <vector>
|
2023-06-06 11:21:59 -04:00
|
|
|
#include "configuration.h"
|
2024-04-20 10:06:22 -04:00
|
|
|
#include "battery_utils.h"
|
2023-06-06 11:30:32 -04:00
|
|
|
#include "aprs_is_utils.h"
|
2023-06-06 14:26:17 -04:00
|
|
|
#include "station_utils.h"
|
2024-05-18 11:27:14 -04:00
|
|
|
#include "boards_pinout.h"
|
2023-06-12 01:31:18 -04:00
|
|
|
#include "syslog_utils.h"
|
2023-06-06 15:53:06 -04:00
|
|
|
#include "query_utils.h"
|
2024-01-03 01:13:44 -03:00
|
|
|
#include "power_utils.h"
|
2023-06-08 00:58:10 -04:00
|
|
|
#include "lora_utils.h"
|
|
|
|
|
#include "wifi_utils.h"
|
2023-06-07 17:25:50 -04:00
|
|
|
#include "digi_utils.h"
|
2023-06-08 00:58:10 -04:00
|
|
|
#include "gps_utils.h"
|
2023-06-17 18:28:40 -04:00
|
|
|
#include "bme_utils.h"
|
2024-02-24 14:09:05 +01:00
|
|
|
#include "web_utils.h"
|
2024-03-09 16:25:23 +01:00
|
|
|
#include "tnc_utils.h"
|
2023-06-08 00:58:10 -04:00
|
|
|
#include "display.h"
|
2023-06-04 14:54:11 -04:00
|
|
|
#include "utils.h"
|
2024-06-18 19:55:33 -04:00
|
|
|
#ifdef HAS_A7670
|
2024-05-11 12:59:25 -04:00
|
|
|
#include "A7670_utils.h"
|
2024-04-23 12:30:57 -04:00
|
|
|
#endif
|
2024-04-20 10:06:22 -04:00
|
|
|
|
2024-06-28 16:05:04 -04:00
|
|
|
String versionDate = "2024.06.28";
|
2023-06-08 00:44:13 -04:00
|
|
|
Configuration Config;
|
2023-03-26 13:19:01 -03:00
|
|
|
WiFiClient espClient;
|
|
|
|
|
|
2024-05-22 15:29:00 -04:00
|
|
|
uint8_t myWiFiAPIndex = 0;
|
|
|
|
|
int myWiFiAPSize = Config.wifiAPs.size();
|
|
|
|
|
WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex];
|
|
|
|
|
|
2024-04-20 09:27:20 -04:00
|
|
|
bool isUpdatingOTA = false;
|
|
|
|
|
uint32_t lastBatteryCheck = 0;
|
2024-05-24 14:42:39 -04:00
|
|
|
|
2024-05-22 15:29:00 -04:00
|
|
|
bool backUpDigiMode = false;
|
2024-04-23 12:30:57 -04:00
|
|
|
bool modemLoggedToAPRSIS = false;
|
|
|
|
|
|
2024-05-22 16:19:45 -04:00
|
|
|
std::vector<ReceivedPacket> receivedPackets;
|
|
|
|
|
|
2024-05-13 23:30:15 -04:00
|
|
|
String firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine;
|
2023-03-02 08:51:38 -03:00
|
|
|
|
2024-05-13 08:45:19 -04:00
|
|
|
//#define STARTUP_DELAY 5 //min
|
|
|
|
|
|
2023-03-02 08:51:38 -03:00
|
|
|
void setup() {
|
2024-02-24 14:09:05 +01:00
|
|
|
Serial.begin(115200);
|
|
|
|
|
POWER_Utils::setup();
|
|
|
|
|
Utils::setupDisplay();
|
2024-03-07 17:46:38 +01:00
|
|
|
Config.check();
|
2024-02-24 14:09:05 +01:00
|
|
|
LoRa_Utils::setup();
|
2024-03-07 17:46:38 +01:00
|
|
|
Utils::validateFreqs();
|
2024-05-13 23:30:15 -04:00
|
|
|
GPS_Utils::generateBeacons();
|
2024-03-07 17:46:38 +01:00
|
|
|
|
2024-05-13 08:45:19 -04:00
|
|
|
#ifdef STARTUP_DELAY // (TEST) just to wait for WiFi init of Routers
|
2024-05-13 08:50:34 -04:00
|
|
|
show_display("", " STARTUP DELAY ...", "", "", 0);
|
2024-05-13 08:45:19 -04:00
|
|
|
delay(STARTUP_DELAY * 60 * 1000);
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-05-11 12:59:25 -04:00
|
|
|
#ifdef HELTEC_HTCT62
|
|
|
|
|
if (Config.lowPowerMode) {
|
|
|
|
|
gpio_wakeup_enable(GPIO_NUM_3, GPIO_INTR_HIGH_LEVEL);
|
|
|
|
|
esp_deep_sleep_enable_gpio_wakeup(GPIO_NUM_3, ESP_GPIO_WAKEUP_GPIO_HIGH);
|
|
|
|
|
long lastBeacon = 0;
|
|
|
|
|
LoRa_Utils::startReceive();
|
|
|
|
|
while (true) {
|
|
|
|
|
auto wakeup_reason = esp_sleep_get_wakeup_cause();
|
|
|
|
|
if (wakeup_reason == 7) { // packet received
|
|
|
|
|
Serial.println("Received packet");
|
|
|
|
|
String packet = LoRa_Utils::receivePacket();
|
|
|
|
|
Serial.println(packet);
|
2024-05-14 09:23:22 -04:00
|
|
|
if (Config.digi.mode == 2) DIGI_Utils::processLoRaPacket(packet);
|
2024-03-28 18:00:46 +01:00
|
|
|
|
2024-05-11 12:59:25 -04:00
|
|
|
if (packet.indexOf(Config.callsign + ":?APRSELP{") != -1) { // Send `?APRSELP` to exit low power
|
|
|
|
|
Serial.println("Got ?APRSELP message, exiting from low power mode");
|
|
|
|
|
break;
|
|
|
|
|
};
|
2024-03-28 18:00:46 +01:00
|
|
|
}
|
2024-05-11 12:59:25 -04:00
|
|
|
long time = esp_timer_get_time() / 1000000;
|
|
|
|
|
if (lastBeacon == 0 || time - lastBeacon >= Config.beacon.interval * 60) {
|
|
|
|
|
Serial.println("Sending beacon");
|
|
|
|
|
String comment = Config.beacon.comment;
|
2024-05-24 14:27:39 -04:00
|
|
|
if (Config.battery.sendInternalVoltage) comment += " Batt=" + String(BATTERY_Utils::checkInternalVoltage(),2) + "V";
|
|
|
|
|
if (Config.battery.sendExternalVoltage) comment += " Ext=" + String(BATTERY_Utils::checkExternalVoltage(),2) + "V";
|
2024-05-14 09:23:22 -04:00
|
|
|
STATION_Utils::addToOutputPacketBuffer(GPS_Utils::getiGateLoRaBeaconPacket() + comment);
|
2024-05-11 12:59:25 -04:00
|
|
|
lastBeacon = time;
|
2024-04-04 17:55:20 +02:00
|
|
|
}
|
|
|
|
|
|
2024-05-11 12:59:25 -04:00
|
|
|
LoRa_Utils::startReceive();
|
|
|
|
|
Serial.println("Sleeping");
|
|
|
|
|
long sleep = (Config.beacon.interval * 60) - (time - lastBeacon);
|
|
|
|
|
Serial.flush();
|
|
|
|
|
esp_sleep_enable_timer_wakeup(sleep * 1000000);
|
|
|
|
|
esp_light_sleep_start();
|
|
|
|
|
Serial.println("Waked up");
|
|
|
|
|
}
|
|
|
|
|
Config.loramodule.rxActive = false;
|
2024-03-28 18:00:46 +01:00
|
|
|
}
|
2024-05-11 12:59:25 -04:00
|
|
|
#endif
|
2024-03-28 18:00:46 +01:00
|
|
|
WIFI_Utils::setup();
|
2024-02-24 14:09:05 +01:00
|
|
|
SYSLOG_Utils::setup();
|
|
|
|
|
BME_Utils::setup();
|
|
|
|
|
WEB_Utils::setup();
|
2024-03-09 16:25:23 +01:00
|
|
|
TNC_Utils::setup();
|
2024-06-18 19:55:33 -04:00
|
|
|
#ifdef HAS_A7670
|
2024-05-11 12:59:25 -04:00
|
|
|
A7670_Utils::setup();
|
|
|
|
|
#endif
|
2024-05-22 19:19:25 -04:00
|
|
|
Utils::checkRebootMode();
|
2023-06-07 17:25:50 -04:00
|
|
|
}
|
2023-03-02 20:40:59 -03:00
|
|
|
|
2023-06-07 17:25:50 -04:00
|
|
|
void loop() {
|
2024-02-24 14:09:05 +01:00
|
|
|
WIFI_Utils::checkIfAutoAPShouldPowerOff();
|
|
|
|
|
|
2024-03-07 17:46:38 +01:00
|
|
|
if (isUpdatingOTA) {
|
|
|
|
|
ElegantOTA.loop();
|
|
|
|
|
return; // Don't process IGate and Digi during OTA update
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-28 18:28:31 +01:00
|
|
|
if (Config.lowVoltageCutOff > 0) {
|
|
|
|
|
BATTERY_Utils::checkIfShouldSleep();
|
|
|
|
|
}
|
2024-03-21 17:31:54 +01:00
|
|
|
|
2024-03-07 17:46:38 +01:00
|
|
|
thirdLine = Utils::getLocalIP();
|
|
|
|
|
|
|
|
|
|
WIFI_Utils::checkWiFi(); // Always use WiFi, not related to IGate/Digi mode
|
|
|
|
|
|
2024-06-18 19:55:33 -04:00
|
|
|
#ifdef HAS_A7670
|
2024-05-12 22:02:12 -04:00
|
|
|
if (Config.aprs_is.active && !modemLoggedToAPRSIS) A7670_Utils::APRS_IS_connect();
|
2024-04-23 12:30:57 -04:00
|
|
|
#else
|
2024-05-22 15:29:00 -04:00
|
|
|
if (Config.aprs_is.active && (WiFi.status() == WL_CONNECTED) && !espClient.connected()) APRS_IS_Utils::connect();
|
2024-04-23 12:30:57 -04:00
|
|
|
#endif
|
2024-03-07 17:46:38 +01:00
|
|
|
|
2024-03-09 16:25:23 +01:00
|
|
|
TNC_Utils::loop();
|
|
|
|
|
|
2024-03-07 17:46:38 +01:00
|
|
|
Utils::checkDisplayInterval();
|
|
|
|
|
Utils::checkBeaconInterval();
|
2024-04-09 12:51:51 -04:00
|
|
|
|
|
|
|
|
APRS_IS_Utils::checkStatus(); // Need that to update display, maybe split this and send APRSIS status to display func?
|
|
|
|
|
|
|
|
|
|
String packet = "";
|
2024-03-07 17:46:38 +01:00
|
|
|
if (Config.loramodule.rxActive) {
|
|
|
|
|
packet = LoRa_Utils::receivePacket(); // We need to fetch LoRa packet above APRSIS and Digi
|
2024-06-03 00:02:43 -04:00
|
|
|
}
|
2024-03-07 17:46:38 +01:00
|
|
|
|
2024-03-09 16:25:23 +01:00
|
|
|
if (packet != "") {
|
|
|
|
|
if (Config.aprs_is.active) { // If APRSIS enabled
|
2024-03-27 11:26:02 -03:00
|
|
|
APRS_IS_Utils::processLoRaPacket(packet); // Send received packet to APRSIS
|
2024-03-09 16:25:23 +01:00
|
|
|
}
|
|
|
|
|
|
2024-05-22 15:29:00 -04:00
|
|
|
if (Config.digi.mode == 2 || backUpDigiMode) { // If Digi enabled
|
2024-06-18 16:45:01 -04:00
|
|
|
STATION_Utils::clean25SegBuffer();
|
|
|
|
|
DIGI_Utils::processLoRaPacket(packet); // Send received packet to Digi
|
2024-03-09 16:25:23 +01:00
|
|
|
}
|
2024-03-07 17:46:38 +01:00
|
|
|
|
2024-03-17 12:21:11 +01:00
|
|
|
if (Config.tnc.enableServer) { // If TNC server enabled
|
|
|
|
|
TNC_Utils::sendToClients(packet); // Send received packet to TNC KISS
|
|
|
|
|
}
|
|
|
|
|
if (Config.tnc.enableSerial) { // If Serial KISS enabled
|
|
|
|
|
TNC_Utils::sendToSerial(packet); // Send received packet to Serial KISS
|
|
|
|
|
}
|
2024-03-07 17:46:38 +01:00
|
|
|
}
|
|
|
|
|
|
2024-03-27 11:26:02 -03:00
|
|
|
if (Config.aprs_is.active) { // If APRSIS enabled
|
|
|
|
|
APRS_IS_Utils::listenAPRSIS(); // listen received packet from APRSIS
|
|
|
|
|
}
|
2024-06-18 16:45:01 -04:00
|
|
|
|
|
|
|
|
STATION_Utils::processOutputPacketBuffer();
|
2024-04-20 09:27:20 -04:00
|
|
|
|
2024-03-07 17:46:38 +01:00
|
|
|
show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0);
|
2024-05-22 19:19:25 -04:00
|
|
|
Utils::checkRebootTime();
|
2024-05-24 14:24:40 -04:00
|
|
|
Utils::checkSleepByLowBatteryVoltage(1);
|
2023-03-26 09:12:27 -03:00
|
|
|
}
|