2023-03-02 12:51:38 +01:00
|
|
|
#include <Arduino.h>
|
|
|
|
|
#include <LoRa.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"
|
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"
|
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;
|
|
|
|
|
|
2023-07-30 23:12:50 +02:00
|
|
|
String versionDate = "2023.07.30";
|
|
|
|
|
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;
|
|
|
|
|
int lastStationModeState = 1;
|
2023-07-30 17:34:20 +02:00
|
|
|
|
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-05-10 06:59:00 +02:00
|
|
|
|
2023-06-18 16:56:53 +02:00
|
|
|
String firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, iGateBeaconPacket;
|
2023-03-02 12:51:38 +01:00
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
|
Serial.begin(115200);
|
2023-07-06 06:14:26 +02:00
|
|
|
pinMode(batteryPin, INPUT);
|
2023-06-10 02:20:39 +02:00
|
|
|
pinMode(greenLed, OUTPUT);
|
2023-06-04 21:05:48 +02:00
|
|
|
delay(1000);
|
2023-06-21 03:05:54 +02:00
|
|
|
Utils::setupDisplay();
|
2023-06-08 23:09:05 +02:00
|
|
|
WIFI_Utils::setup();
|
2023-06-07 23:25:50 +02:00
|
|
|
LoRa_Utils::setup();
|
2023-06-12 07:31:18 +02:00
|
|
|
Utils::validateDigiFreqs();
|
2023-06-08 23:09:05 +02:00
|
|
|
iGateBeaconPacket = GPS_Utils::generateBeacon();
|
2023-06-12 07:31:18 +02:00
|
|
|
Utils::startOTAServer();
|
|
|
|
|
SYSLOG_Utils::setup();
|
2023-06-18 00:28:40 +02:00
|
|
|
BME_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() {
|
2023-06-12 03:28:12 +02:00
|
|
|
if (stationMode==1 || stationMode==2 ) { // iGate (1 Only Rx / 2 Rx+Tx)
|
2023-06-09 07:12:13 +02:00
|
|
|
WIFI_Utils::checkWiFi();
|
2023-06-07 23:25:50 +02:00
|
|
|
if (!espClient.connected()) {
|
|
|
|
|
APRS_IS_Utils::connect();
|
2023-06-04 20:54:11 +02:00
|
|
|
}
|
2023-06-17 01:08:25 +02:00
|
|
|
APRS_IS_Utils::checkStatus();
|
2023-06-18 16:56:53 +02:00
|
|
|
show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0);
|
2023-06-07 23:25:50 +02:00
|
|
|
while (espClient.connected()) {
|
2023-06-12 07:31:18 +02:00
|
|
|
Utils::checkDisplayInterval();
|
|
|
|
|
Utils::checkBeaconInterval();
|
2023-06-08 05:55:31 +02:00
|
|
|
APRS_IS_Utils::processLoRaPacket(LoRa_Utils::receivePacket());
|
2023-06-07 23:25:50 +02:00
|
|
|
if (espClient.available()) {
|
2023-06-09 14:34:34 +02:00
|
|
|
String aprsisPacket;
|
2023-06-09 07:17:45 +02:00
|
|
|
aprsisPacket.concat(espClient.readStringUntil('\r'));
|
2023-06-09 07:12:13 +02:00
|
|
|
APRS_IS_Utils::processAPRSISPacket(aprsisPacket);
|
2023-06-07 23:25:50 +02:00
|
|
|
}
|
2023-03-03 02:31:22 +01:00
|
|
|
}
|
2023-06-12 03:28:12 +02:00
|
|
|
} else if (stationMode==3 || stationMode==4) { // DigiRepeater (3 RxFreq=TxFreq / 4 RxFreq!=TxFreq)
|
2023-06-12 07:31:18 +02:00
|
|
|
Utils::checkDisplayInterval();
|
|
|
|
|
Utils::checkBeaconInterval();
|
2023-06-19 06:52:40 +02:00
|
|
|
show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0);
|
2023-06-12 03:28:12 +02:00
|
|
|
DIGI_Utils::processPacket(LoRa_Utils::receivePacket());
|
2023-07-30 17:34:20 +02:00
|
|
|
} else if (stationMode==5) {
|
|
|
|
|
uint32_t WiFiCheck = millis() - lastWiFiCheck;
|
2023-07-30 23:12:50 +02:00
|
|
|
if (WiFi.status() != WL_CONNECTED && WiFiCheck >= Config.lastWiFiCheck*4*1000) {
|
2023-07-30 17:34:20 +02:00
|
|
|
WiFiConnect = true;
|
|
|
|
|
}
|
|
|
|
|
if (WiFiConnect) {
|
2023-07-30 17:40:31 +02:00
|
|
|
Serial.println("\n\n###############\nRevision WiFi\n###############");
|
2023-07-30 17:34:20 +02:00
|
|
|
WIFI_Utils::startWiFi2();
|
|
|
|
|
lastWiFiCheck = millis();
|
|
|
|
|
WiFiConnect = false;
|
|
|
|
|
}
|
|
|
|
|
if (WiFi.status() == WL_CONNECTED) { // Modo iGate
|
2023-07-30 23:12:50 +02:00
|
|
|
thirdLine = Utils::getLocalIP();
|
|
|
|
|
if (!espClient.connected()) {
|
|
|
|
|
APRS_IS_Utils::connect();
|
|
|
|
|
}
|
|
|
|
|
if (lastStationModeState == 1) {
|
|
|
|
|
iGateBeaconPacket = GPS_Utils::generateBeacon();
|
|
|
|
|
lastStationModeState = 0;
|
|
|
|
|
}
|
|
|
|
|
APRS_IS_Utils::checkStatus();
|
|
|
|
|
show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0);
|
|
|
|
|
while (espClient.connected()) {
|
|
|
|
|
Utils::checkDisplayInterval();
|
|
|
|
|
Utils::checkBeaconInterval();
|
|
|
|
|
APRS_IS_Utils::processLoRaPacket(LoRa_Utils::receivePacket());
|
|
|
|
|
if (espClient.available()) {
|
|
|
|
|
String aprsisPacket;
|
|
|
|
|
aprsisPacket.concat(espClient.readStringUntil('\r'));
|
|
|
|
|
APRS_IS_Utils::processAPRSISPacket(aprsisPacket);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-30 17:34:20 +02:00
|
|
|
} else { // Modo DigiRepeater
|
2023-07-30 23:12:50 +02:00
|
|
|
if (lastStationModeState == 0) {
|
|
|
|
|
iGateBeaconPacket = GPS_Utils::generateBeacon();
|
|
|
|
|
lastStationModeState = 1;
|
|
|
|
|
thirdLine = "<< DigiRepeater >>";
|
|
|
|
|
}
|
2023-07-30 17:34:20 +02:00
|
|
|
Utils::checkDisplayInterval();
|
|
|
|
|
Utils::checkBeaconInterval();
|
|
|
|
|
show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0);
|
|
|
|
|
DIGI_Utils::processPacket(LoRa_Utils::receivePacket());
|
|
|
|
|
}
|
2023-03-03 00:40:59 +01:00
|
|
|
}
|
2023-03-26 14:12:27 +02:00
|
|
|
}
|