2023-03-02 12:51:38 +01:00
|
|
|
#include <Arduino.h>
|
|
|
|
|
#include <WiFi.h>
|
2023-05-20 00:52:59 +02:00
|
|
|
#include <vector>
|
2023-06-06 17:21:59 +02:00
|
|
|
#include "configuration.h"
|
2023-06-06 17:30:32 +02:00
|
|
|
#include "aprs_is_utils.h"
|
2023-06-06 20:26:17 +02:00
|
|
|
#include "station_utils.h"
|
2023-06-12 07:31:18 +02:00
|
|
|
#include "syslog_utils.h"
|
2023-06-08 06:58:10 +02:00
|
|
|
#include "pins_config.h"
|
2023-06-06 21:53:06 +02:00
|
|
|
#include "query_utils.h"
|
2024-01-03 05:13:44 +01:00
|
|
|
#include "power_utils.h"
|
2023-06-08 06:58:10 +02:00
|
|
|
#include "lora_utils.h"
|
|
|
|
|
#include "wifi_utils.h"
|
2023-06-07 23:25:50 +02:00
|
|
|
#include "digi_utils.h"
|
2023-06-08 06:58:10 +02:00
|
|
|
#include "gps_utils.h"
|
2023-06-18 00:28:40 +02:00
|
|
|
#include "bme_utils.h"
|
2024-02-24 14:09:05 +01:00
|
|
|
#include "web_utils.h"
|
2023-06-08 06:58:10 +02:00
|
|
|
#include "display.h"
|
2023-06-04 20:54:11 +02:00
|
|
|
#include "utils.h"
|
2023-06-05 05:02:25 +02:00
|
|
|
|
2023-07-16 22:24:09 +02:00
|
|
|
|
2023-06-08 06:44:13 +02:00
|
|
|
Configuration Config;
|
2023-03-26 18:19:01 +02:00
|
|
|
WiFiClient espClient;
|
|
|
|
|
|
2024-02-25 14:53:16 +01:00
|
|
|
String versionDate = "2024.02.25";
|
2023-07-30 23:12:50 +02:00
|
|
|
int myWiFiAPIndex = 0;
|
|
|
|
|
int myWiFiAPSize = Config.wifiAPs.size();
|
|
|
|
|
WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex];
|
2023-03-26 18:19:01 +02:00
|
|
|
|
2023-07-30 23:12:50 +02:00
|
|
|
int stationMode = Config.stationMode;
|
|
|
|
|
bool statusAfterBoot = true;
|
|
|
|
|
bool beaconUpdate = true;
|
|
|
|
|
uint32_t lastBeaconTx = 0;
|
|
|
|
|
uint32_t previousWiFiMillis = 0;
|
|
|
|
|
uint32_t lastScreenOn = millis();
|
2023-06-08 05:55:31 +02:00
|
|
|
|
2023-07-30 23:12:50 +02:00
|
|
|
uint32_t lastWiFiCheck = 0;
|
|
|
|
|
bool WiFiConnect = true;
|
2024-02-24 14:09:05 +01:00
|
|
|
bool WiFiConnected = false;
|
2023-07-30 23:12:50 +02:00
|
|
|
int lastStationModeState = 1;
|
2023-07-30 17:34:20 +02:00
|
|
|
|
2024-02-24 14:09:05 +01:00
|
|
|
bool WiFiAutoAPStarted = false;
|
|
|
|
|
long WiFiAutoAPTime = false;
|
|
|
|
|
|
2024-03-06 13:01:17 +01:00
|
|
|
uint32_t bmeLastReading = -60000;
|
|
|
|
|
|
2023-07-06 06:14:26 +02:00
|
|
|
String batteryVoltage;
|
|
|
|
|
|
2023-05-20 00:52:59 +02:00
|
|
|
std::vector<String> lastHeardStation;
|
2023-05-25 16:27:46 +02:00
|
|
|
std::vector<String> lastHeardStation_temp;
|
2023-09-05 06:08:18 +02:00
|
|
|
std::vector<String> packetBuffer;
|
|
|
|
|
std::vector<String> packetBuffer_temp;
|
2023-05-10 06:59:00 +02:00
|
|
|
|
2024-01-12 03:22:58 +01:00
|
|
|
String firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, iGateBeaconPacket, iGateLoRaBeaconPacket;
|
2023-03-02 12:51:38 +01:00
|
|
|
|
|
|
|
|
void setup() {
|
2024-02-24 14:09:05 +01:00
|
|
|
Serial.begin(115200);
|
|
|
|
|
|
|
|
|
|
#if defined(TTGO_T_LORA32_V2_1) || defined(HELTEC_V2)
|
|
|
|
|
pinMode(batteryPin, INPUT);
|
|
|
|
|
#endif
|
|
|
|
|
#if defined(TTGO_T_LORA32_V2_1) || defined(HELTEC_V2) || defined(HELTEC_V3) || defined(ESP32_DIY_LoRa) || defined(ESP32_DIY_1W_LoRa)
|
|
|
|
|
pinMode(internalLedPin, OUTPUT);
|
|
|
|
|
#endif
|
|
|
|
|
if (Config.externalVoltageMeasurement) {
|
|
|
|
|
pinMode(Config.externalVoltagePin, INPUT);
|
|
|
|
|
}
|
|
|
|
|
#if defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_0_SX1268) || defined(TTGO_T_Beam_V1_2) || defined(TTGO_T_Beam_V1_2_SX1262)
|
|
|
|
|
POWER_Utils::setup();
|
|
|
|
|
#endif
|
|
|
|
|
delay(1000);
|
|
|
|
|
Utils::setupDisplay();
|
|
|
|
|
WIFI_Utils::setup();
|
|
|
|
|
LoRa_Utils::setup();
|
|
|
|
|
Utils::validateDigiFreqs();
|
|
|
|
|
iGateBeaconPacket = GPS_Utils::generateBeacon();
|
|
|
|
|
iGateLoRaBeaconPacket = GPS_Utils::generateiGateLoRaBeacon();
|
|
|
|
|
SYSLOG_Utils::setup();
|
|
|
|
|
BME_Utils::setup();
|
|
|
|
|
WEB_Utils::setup();
|
2023-06-07 23:25:50 +02:00
|
|
|
}
|
2023-03-03 00:40:59 +01:00
|
|
|
|
2023-06-07 23:25:50 +02:00
|
|
|
void loop() {
|
2024-02-24 14:09:05 +01:00
|
|
|
WEB_Utils::loop();
|
|
|
|
|
|
|
|
|
|
WIFI_Utils::checkIfAutoAPShouldPowerOff();
|
|
|
|
|
|
|
|
|
|
if (stationMode==1 || stationMode==2 ) { // iGate (1 Only Rx / 2 Rx+Tx)
|
2024-02-25 18:02:50 +01:00
|
|
|
if (!WiFiConnected) {
|
|
|
|
|
thirdLine = Utils::getLocalIP();
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-24 14:09:05 +01:00
|
|
|
WIFI_Utils::checkWiFi();
|
|
|
|
|
if (!espClient.connected()) {
|
|
|
|
|
APRS_IS_Utils::connect();
|
|
|
|
|
}
|
|
|
|
|
APRS_IS_Utils::loop();
|
|
|
|
|
} else if (stationMode==3 || stationMode==4) { // DigiRepeater (3 RxFreq=TxFreq / 4 RxFreq!=TxFreq)
|
|
|
|
|
DIGI_Utils::loop();
|
|
|
|
|
} else if (stationMode==5) { // iGate when WiFi and APRS available , DigiRepeater when not (RxFreq=TxFreq)
|
|
|
|
|
Utils::checkWiFiInterval();
|
2024-02-25 18:08:24 +01:00
|
|
|
thirdLine = Utils::getLocalIP();
|
2024-02-24 14:09:05 +01:00
|
|
|
if (WiFi.status() == WL_CONNECTED) { // iGate Mode
|
|
|
|
|
if (!espClient.connected()) {
|
|
|
|
|
APRS_IS_Utils::connect();
|
|
|
|
|
}
|
|
|
|
|
if (lastStationModeState == 1) {
|
|
|
|
|
iGateBeaconPacket = GPS_Utils::generateBeacon();
|
|
|
|
|
lastStationModeState = 0;
|
|
|
|
|
}
|
|
|
|
|
APRS_IS_Utils::loop();
|
|
|
|
|
} else { // DigiRepeater Mode
|
|
|
|
|
DIGI_Utils::loop();
|
|
|
|
|
}
|
2023-07-30 17:34:20 +02:00
|
|
|
}
|
2023-03-26 14:12:27 +02:00
|
|
|
}
|