2023-12-19 08:09:20 -03:00
|
|
|
//#include <ElegantOTA.h>
|
2023-03-02 08:51:38 -03:00
|
|
|
#include <Arduino.h>
|
|
|
|
|
#include <LoRa.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"
|
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"
|
2023-06-12 01:31:18 -04:00
|
|
|
#include "syslog_utils.h"
|
2023-06-08 00:58:10 -04:00
|
|
|
#include "pins_config.h"
|
2023-06-06 15:53:06 -04:00
|
|
|
#include "query_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"
|
2023-06-08 00:58:10 -04:00
|
|
|
#include "display.h"
|
2023-06-04 14:54:11 -04:00
|
|
|
#include "utils.h"
|
2023-06-04 23:02:25 -04:00
|
|
|
|
2023-07-16 16:24:09 -04:00
|
|
|
|
2023-06-08 00:44:13 -04:00
|
|
|
Configuration Config;
|
2023-03-26 13:19:01 -03:00
|
|
|
WiFiClient espClient;
|
|
|
|
|
|
2023-12-19 08:09:20 -03:00
|
|
|
String versionDate = "2023.12.19";
|
2023-07-30 17:12:50 -04:00
|
|
|
int myWiFiAPIndex = 0;
|
|
|
|
|
int myWiFiAPSize = Config.wifiAPs.size();
|
|
|
|
|
WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex];
|
2023-03-26 13:19:01 -03:00
|
|
|
|
2023-07-30 17:12:50 -04: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-07 23:55:31 -04:00
|
|
|
|
2023-07-30 17:12:50 -04:00
|
|
|
uint32_t lastWiFiCheck = 0;
|
|
|
|
|
bool WiFiConnect = true;
|
|
|
|
|
int lastStationModeState = 1;
|
2023-07-30 11:34:20 -04:00
|
|
|
|
2023-07-06 00:14:26 -04:00
|
|
|
String batteryVoltage;
|
|
|
|
|
|
2023-05-19 18:52:59 -04:00
|
|
|
std::vector<String> lastHeardStation;
|
2023-05-25 10:27:46 -04:00
|
|
|
std::vector<String> lastHeardStation_temp;
|
2023-09-05 01:08:18 -03:00
|
|
|
std::vector<String> packetBuffer;
|
|
|
|
|
std::vector<String> packetBuffer_temp;
|
2023-05-10 00:59:00 -04:00
|
|
|
|
2023-06-18 10:56:53 -04:00
|
|
|
String firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, iGateBeaconPacket;
|
2023-03-02 08:51:38 -03:00
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
|
Serial.begin(115200);
|
2023-07-06 00:14:26 -04:00
|
|
|
pinMode(batteryPin, INPUT);
|
2023-06-09 20:20:39 -04:00
|
|
|
pinMode(greenLed, OUTPUT);
|
2023-09-20 21:28:17 -03:00
|
|
|
if (Config.externalVoltageMeasurement) {
|
|
|
|
|
pinMode(Config.externalVoltagePin, INPUT);
|
|
|
|
|
}
|
2023-06-04 15:05:48 -04:00
|
|
|
delay(1000);
|
2023-06-20 21:05:54 -04:00
|
|
|
Utils::setupDisplay();
|
2023-06-08 17:09:05 -04:00
|
|
|
WIFI_Utils::setup();
|
2023-06-07 17:25:50 -04:00
|
|
|
LoRa_Utils::setup();
|
2023-06-12 01:31:18 -04:00
|
|
|
Utils::validateDigiFreqs();
|
2023-06-08 17:09:05 -04:00
|
|
|
iGateBeaconPacket = GPS_Utils::generateBeacon();
|
2023-08-28 23:21:20 -04:00
|
|
|
Utils::startServer();
|
2023-06-12 01:31:18 -04:00
|
|
|
SYSLOG_Utils::setup();
|
2023-06-17 18:28:40 -04:00
|
|
|
BME_Utils::setup();
|
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() {
|
2023-06-11 21:28:12 -04:00
|
|
|
if (stationMode==1 || stationMode==2 ) { // iGate (1 Only Rx / 2 Rx+Tx)
|
2023-06-09 01:12:13 -04:00
|
|
|
WIFI_Utils::checkWiFi();
|
2023-06-07 17:25:50 -04:00
|
|
|
if (!espClient.connected()) {
|
|
|
|
|
APRS_IS_Utils::connect();
|
2023-06-04 14:54:11 -04:00
|
|
|
}
|
2023-07-30 23:53:59 -04:00
|
|
|
APRS_IS_Utils::loop();
|
2023-09-20 22:27:02 -03:00
|
|
|
} else if (stationMode==3 || stationMode==4 || stationMode==6) { // DigiRepeater (3 RxFreq=TxFreq / 4 RxFreq!=TxFreq)
|
2023-07-30 23:53:59 -04:00
|
|
|
DIGI_Utils::loop();
|
2023-07-30 18:57:31 -04:00
|
|
|
} else if (stationMode==5) { // iGate when WiFi and APRS available , DigiRepeater when not (RxFreq=TxFreq)
|
2023-07-30 18:21:06 -04:00
|
|
|
Utils::checkWiFiInterval();
|
2023-07-30 18:57:31 -04:00
|
|
|
if (WiFi.status() == WL_CONNECTED) { // iGate Mode
|
2023-07-30 17:12:50 -04:00
|
|
|
thirdLine = Utils::getLocalIP();
|
|
|
|
|
if (!espClient.connected()) {
|
|
|
|
|
APRS_IS_Utils::connect();
|
|
|
|
|
}
|
|
|
|
|
if (lastStationModeState == 1) {
|
|
|
|
|
iGateBeaconPacket = GPS_Utils::generateBeacon();
|
|
|
|
|
lastStationModeState = 0;
|
2023-08-28 23:21:20 -04:00
|
|
|
Utils::startServer();
|
2023-07-30 17:12:50 -04:00
|
|
|
}
|
2023-07-30 23:53:59 -04:00
|
|
|
APRS_IS_Utils::loop();
|
2023-07-30 18:57:31 -04:00
|
|
|
} else { // DigiRepeater Mode
|
2023-07-30 23:53:59 -04:00
|
|
|
DIGI_Utils::loop();
|
2023-07-30 11:34:20 -04:00
|
|
|
}
|
2023-03-02 20:40:59 -03:00
|
|
|
}
|
2023-12-19 08:09:20 -03:00
|
|
|
//ElegantOTA.loop();
|
2023-03-26 09:12:27 -03:00
|
|
|
}
|