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-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"
|
|
|
|
|
#include "display.h"
|
2023-06-04 20:54:11 +02:00
|
|
|
#include "utils.h"
|
2023-06-06 17:21:59 +02:00
|
|
|
/*#include <AsyncTCP.h>
|
2023-06-05 05:02:25 +02:00
|
|
|
#include <ESPAsyncWebServer.h>
|
2023-06-06 17:21:59 +02:00
|
|
|
#include <AsyncElegantOTA.h>*/
|
2023-06-05 05:02:25 +02:00
|
|
|
|
2023-06-08 06:44:13 +02:00
|
|
|
#define VERSION "2023.06.08"
|
2023-05-17 21:51:47 +02:00
|
|
|
|
2023-06-08 06:44:13 +02:00
|
|
|
Configuration Config;
|
2023-03-26 18:19:01 +02:00
|
|
|
WiFiClient espClient;
|
2023-06-06 17:21:59 +02:00
|
|
|
//AsyncWebServer server(80);
|
2023-03-26 18:19:01 +02:00
|
|
|
|
2023-06-06 17:21:59 +02:00
|
|
|
int myWiFiAPIndex = 0;
|
2023-06-04 17:23:26 +02:00
|
|
|
int myWiFiAPSize = Config.wifiAPs.size();
|
|
|
|
|
WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex];
|
2023-06-09 06:23:11 +02:00
|
|
|
bool statusAfterBoot = true;
|
2023-06-07 23:25:50 +02:00
|
|
|
int stationMode = Config.stationMode;
|
2023-03-26 18:19:01 +02:00
|
|
|
|
2023-06-08 05:55:31 +02:00
|
|
|
bool beacon_update = true;
|
|
|
|
|
uint32_t lastBeaconTx = 0;
|
|
|
|
|
unsigned long previousWiFiMillis = 0;
|
|
|
|
|
uint32_t lastScreenOn = millis();
|
|
|
|
|
|
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-06 18:37:22 +02:00
|
|
|
String firstLine, secondLine, thirdLine, fourthLine, iGateBeaconPacket;
|
2023-03-02 12:51:38 +01:00
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
|
Serial.begin(115200);
|
2023-06-04 21:05:48 +02:00
|
|
|
delay(1000);
|
2023-06-08 05:55:31 +02:00
|
|
|
utils::setupDiplay();
|
2023-06-04 21:05:48 +02:00
|
|
|
Serial.println("\nStarting iGate: " + Config.callsign + " Version: " + String(VERSION));
|
2023-06-07 23:25:50 +02:00
|
|
|
show_display(" LoRa APRS iGate", " Richonguzman", " -- CD2RXU --", " " VERSION, 4000);
|
2023-06-08 23:09:05 +02:00
|
|
|
WIFI_Utils::setup();
|
2023-06-07 23:25:50 +02:00
|
|
|
LoRa_Utils::setup();
|
2023-06-08 23:09:05 +02:00
|
|
|
utils::validateDigiFreqs();
|
|
|
|
|
iGateBeaconPacket = GPS_Utils::generateBeacon();
|
|
|
|
|
|
2023-06-06 17:21:59 +02:00
|
|
|
/*server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
|
2023-06-05 05:02:25 +02:00
|
|
|
request->send(200, "text/plain", "Hi! I am ESP32.");
|
|
|
|
|
});
|
|
|
|
|
AsyncElegantOTA.begin(&server); // Start ElegantOTA
|
|
|
|
|
server.begin();
|
2023-06-07 23:25:50 +02:00
|
|
|
Serial.println("HTTP server started");*/
|
|
|
|
|
}
|
2023-03-03 00:40:59 +01:00
|
|
|
|
2023-06-07 23:25:50 +02:00
|
|
|
void loop() {
|
2023-06-08 03:04:20 +02:00
|
|
|
if (stationMode==3 || stationMode==4) { // DigiRepeater (3 RxFreq=TxFreq / 4 RxFreq!=TxFreq)
|
2023-06-08 05:55:31 +02:00
|
|
|
utils::checkDisplayInterval();
|
|
|
|
|
utils::checkBeaconInterval();
|
2023-06-07 23:25:50 +02:00
|
|
|
show_display(firstLine, secondLine, thirdLine, fourthLine, 0);
|
2023-06-08 03:25:31 +02:00
|
|
|
DIGI_Utils::processPacket(LoRa_Utils::receivePacket());
|
2023-06-08 03:04:20 +02:00
|
|
|
} else if (stationMode==1 || stationMode==2 ) { // iGate (1 Only Rx / 2 Rx+Tx)
|
2023-06-07 23:25:50 +02:00
|
|
|
unsigned long currentWiFiMillis = millis();
|
2023-06-09 01:31:27 +02:00
|
|
|
if ((WiFi.status() != WL_CONNECTED) && (currentWiFiMillis - previousWiFiMillis >= 30*1000)) {
|
2023-06-07 23:25:50 +02:00
|
|
|
Serial.print(millis());
|
|
|
|
|
Serial.println("Reconnecting to WiFi...");
|
|
|
|
|
WiFi.disconnect();
|
|
|
|
|
WiFi.reconnect();
|
|
|
|
|
previousWiFiMillis = currentWiFiMillis;
|
2023-03-26 14:12:27 +02:00
|
|
|
}
|
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-07 23:25:50 +02:00
|
|
|
secondLine = APRS_IS_Utils::checkStatus();
|
|
|
|
|
show_display(firstLine, secondLine, thirdLine, fourthLine, 0);
|
|
|
|
|
|
|
|
|
|
while (espClient.connected()) {
|
2023-06-08 05:55:31 +02:00
|
|
|
utils::checkDisplayInterval();
|
|
|
|
|
utils::checkBeaconInterval();
|
|
|
|
|
APRS_IS_Utils::processLoRaPacket(LoRa_Utils::receivePacket());
|
2023-06-07 23:25:50 +02:00
|
|
|
if (espClient.available()) {
|
|
|
|
|
String aprsisData, aprsisPacket, Sender, AddresseeAndMessage, Addressee, receivedMessage;
|
|
|
|
|
bool validHeardStation = false;
|
|
|
|
|
aprsisData = espClient.readStringUntil('\r'); // or '\n'
|
|
|
|
|
aprsisPacket.concat(aprsisData);
|
|
|
|
|
if (!aprsisPacket.startsWith("#")){
|
|
|
|
|
if (aprsisPacket.indexOf("::")>0) {
|
|
|
|
|
Sender = aprsisPacket.substring(0,aprsisPacket.indexOf(">"));
|
|
|
|
|
AddresseeAndMessage = aprsisPacket.substring(aprsisPacket.indexOf("::")+2);
|
|
|
|
|
Addressee = AddresseeAndMessage.substring(0, AddresseeAndMessage.indexOf(":"));
|
|
|
|
|
Addressee.trim();
|
|
|
|
|
if (Addressee == Config.callsign) { // its for me!
|
|
|
|
|
if (AddresseeAndMessage.indexOf("{")>0) { // ack?
|
|
|
|
|
String ackMessage = "ack" + AddresseeAndMessage.substring(AddresseeAndMessage.indexOf("{")+1);
|
|
|
|
|
ackMessage.trim();
|
|
|
|
|
delay(4000);
|
|
|
|
|
Serial.println(ackMessage);
|
|
|
|
|
for(int i = Sender.length(); i < 9; i++) {
|
|
|
|
|
Sender += ' ';
|
|
|
|
|
}
|
|
|
|
|
String ackPacket = Config.callsign + ">APLRG1,TCPIP,qAC::" + Sender + ":" + ackMessage + "\n";
|
|
|
|
|
espClient.write(ackPacket.c_str());
|
|
|
|
|
receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":")+1, AddresseeAndMessage.indexOf("{"));
|
|
|
|
|
} else {
|
|
|
|
|
receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":")+1);
|
|
|
|
|
}
|
|
|
|
|
if (receivedMessage.indexOf("?") == 0) {
|
|
|
|
|
Serial.println("Received Query APRS-IS : " + aprsisPacket);
|
|
|
|
|
String queryAnswer = QUERY_Utils::process(receivedMessage, Sender, "APRSIS");
|
|
|
|
|
Serial.println("---> QUERY Answer : " + queryAnswer.substring(0,queryAnswer.indexOf("\n")));
|
|
|
|
|
if (!Config.display.alwaysOn) {
|
|
|
|
|
display_toggle(true);
|
|
|
|
|
}
|
2023-06-08 05:55:31 +02:00
|
|
|
lastScreenOn = millis();
|
2023-06-07 23:25:50 +02:00
|
|
|
delay(500);
|
|
|
|
|
espClient.write(queryAnswer.c_str());
|
|
|
|
|
show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE --> QUERY", 1000);
|
2023-05-23 18:04:22 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
2023-06-07 23:25:50 +02:00
|
|
|
Serial.print("Received from APRS-IS : " + aprsisPacket);
|
|
|
|
|
if (stationMode == 1) {
|
|
|
|
|
Serial.println(" ---> Cant Tx without Ham Lincence");
|
|
|
|
|
} else if (stationMode > 1) {
|
|
|
|
|
if (STATION_Utils::wasHeard(Addressee)) {
|
|
|
|
|
LoRa_Utils::sendNewPacket("APRS", LoRa_Utils::generatePacket(aprsisPacket));
|
|
|
|
|
display_toggle(true);
|
2023-06-08 05:55:31 +02:00
|
|
|
lastScreenOn = millis();
|
2023-06-07 23:25:50 +02:00
|
|
|
receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":")+1);
|
|
|
|
|
show_display(firstLine, secondLine, Sender + " -> " + Addressee, receivedMessage, 1000);
|
|
|
|
|
}
|
2023-05-23 18:04:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
2023-06-07 23:25:50 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-03 02:31:22 +01:00
|
|
|
}
|
2023-03-03 00:40:59 +01:00
|
|
|
}
|
2023-03-26 14:12:27 +02:00
|
|
|
}
|