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-03-26 18:19:01 +02:00
|
|
|
|
|
|
|
|
#include "pins_config.h"
|
2023-06-06 17:21:59 +02:00
|
|
|
//
|
|
|
|
|
//#include "igate_config.h"
|
|
|
|
|
//
|
|
|
|
|
#include "configuration.h"
|
2023-03-26 14:12:27 +02:00
|
|
|
#include "display.h"
|
2023-06-04 16:10:39 +02:00
|
|
|
#include "lora_utils.h"
|
2023-06-06 17:21:59 +02:00
|
|
|
#include "wifi_utils.h"
|
2023-06-06 17:30:32 +02:00
|
|
|
#include "aprs_is_utils.h"
|
2023-06-04 20:54:11 +02:00
|
|
|
#include "utils.h"
|
2023-03-26 18:19:01 +02:00
|
|
|
|
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-06 16:43:04 +02:00
|
|
|
#define VERSION "2023.06.06"
|
2023-05-17 21:51:47 +02:00
|
|
|
|
2023-03-26 18:19:01 +02:00
|
|
|
WiFiClient espClient;
|
2023-06-06 17:21:59 +02:00
|
|
|
//AsyncWebServer server(80);
|
2023-03-26 22:50:32 +02:00
|
|
|
String ConfigurationFilePath = "/igate_conf.json";
|
2023-03-26 18:19:01 +02:00
|
|
|
Configuration Config(ConfigurationFilePath);
|
|
|
|
|
|
2023-06-04 17:23:26 +02:00
|
|
|
uint32_t lastTxTime = 0;
|
|
|
|
|
static bool beacon_update = true;
|
|
|
|
|
unsigned long previousWiFiMillis = 0;
|
|
|
|
|
static uint32_t lastRxTxTime = millis();
|
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];
|
|
|
|
|
bool statusAfterBoot = Config.statusAfterBoot;
|
2023-03-26 18:19:01 +02:00
|
|
|
|
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-05-23 06:25:47 +02:00
|
|
|
String firstLine, secondLine, thirdLine, fourthLine, iGateLatitude, iGateLongitude;
|
2023-03-26 14:12:27 +02:00
|
|
|
|
2023-06-06 17:30:32 +02:00
|
|
|
/*void APRS_IS_connect(){
|
2023-03-02 12:51:38 +01:00
|
|
|
int count = 0;
|
|
|
|
|
String aprsauth;
|
2023-03-03 00:40:59 +01:00
|
|
|
Serial.println("Connecting to APRS-IS ...");
|
2023-03-26 22:50:32 +02:00
|
|
|
while (!espClient.connect(Config.aprs_is.server.c_str(), Config.aprs_is.port) && count < 20) {
|
2023-03-03 00:40:59 +01:00
|
|
|
Serial.println("Didn't connect with server...");
|
2023-03-02 12:51:38 +01:00
|
|
|
delay(1000);
|
|
|
|
|
espClient.stop();
|
|
|
|
|
espClient.flush();
|
|
|
|
|
Serial.println("Run client.stop");
|
2023-03-26 22:50:32 +02:00
|
|
|
Serial.println("Trying to connect with Server: " + String(Config.aprs_is.server) + " AprsServerPort: " + String(Config.aprs_is.port));
|
2023-03-02 12:51:38 +01:00
|
|
|
count++;
|
|
|
|
|
Serial.println("Try: " + String(count));
|
|
|
|
|
}
|
|
|
|
|
if (count == 20) {
|
2023-03-03 00:40:59 +01:00
|
|
|
Serial.println("Tried: " + String(count) + " FAILED!");
|
2023-03-02 12:51:38 +01:00
|
|
|
} else {
|
2023-03-26 22:50:32 +02:00
|
|
|
Serial.println("Connected with Server: '" + String(Config.aprs_is.server) + "' (port: " + String(Config.aprs_is.port)+ ")");
|
2023-06-04 16:10:39 +02:00
|
|
|
aprsauth = "user " + Config.callsign + " pass " + Config.aprs_is.passcode + " vers " + Config.aprs_is.softwareName + " " + Config.aprs_is.softwareVersion + " filter t/m/" + Config.callsign + "/" + (String)Config.aprs_is.reportingDistance + "\n\r";
|
2023-03-03 00:40:59 +01:00
|
|
|
espClient.write(aprsauth.c_str());
|
|
|
|
|
delay(200);
|
2023-03-02 12:51:38 +01:00
|
|
|
}
|
2023-06-06 17:30:32 +02:00
|
|
|
}*/
|
2023-03-02 12:51:38 +01:00
|
|
|
|
2023-03-26 14:12:27 +02:00
|
|
|
String createAPRSPacket(String unprocessedPacket) {
|
2023-03-03 00:40:59 +01:00
|
|
|
String callsign_and_path_tracker, payload_tracker, processedPacket;
|
2023-05-22 23:17:56 +02:00
|
|
|
int dotsPosition = unprocessedPacket.indexOf(':');
|
|
|
|
|
callsign_and_path_tracker = unprocessedPacket.substring(3, dotsPosition);
|
|
|
|
|
payload_tracker = unprocessedPacket.substring(dotsPosition);
|
2023-06-04 17:23:26 +02:00
|
|
|
if (Config.loramodule.enableTx) {
|
|
|
|
|
processedPacket = callsign_and_path_tracker + ",qAR," + Config.callsign + payload_tracker + "\n";
|
|
|
|
|
} else {
|
|
|
|
|
processedPacket = callsign_and_path_tracker + ",qAO," + Config.callsign + payload_tracker + "\n";
|
|
|
|
|
}
|
2023-03-03 00:40:59 +01:00
|
|
|
return processedPacket;
|
2023-03-02 12:51:38 +01:00
|
|
|
}
|
|
|
|
|
|
2023-05-20 07:03:14 +02:00
|
|
|
bool checkValidHeardStation(String station) {
|
2023-05-23 18:04:22 +02:00
|
|
|
bool validStation = false;
|
2023-05-20 07:03:14 +02:00
|
|
|
for (int i=0; i<lastHeardStation.size(); i++) {
|
|
|
|
|
if (lastHeardStation[i].substring(0,lastHeardStation[i].indexOf(",")) == station) {
|
2023-05-23 18:04:22 +02:00
|
|
|
validStation = true;
|
|
|
|
|
Serial.println(" ---> Listened Station");
|
2023-05-20 07:03:14 +02:00
|
|
|
}
|
|
|
|
|
}
|
2023-05-23 18:04:22 +02:00
|
|
|
if (!validStation) {
|
|
|
|
|
Serial.println(" ---> Station not Heard for last 30 min (Not Tx)\n");
|
|
|
|
|
}
|
|
|
|
|
return validStation;
|
2023-05-20 07:03:14 +02:00
|
|
|
}
|
|
|
|
|
|
2023-05-20 03:42:59 +02:00
|
|
|
void deleteNotHeardStation() {
|
2023-05-20 07:12:24 +02:00
|
|
|
uint32_t minReportingTime = 30*60*1000; // 30 minutes // from .json and CONFIGURATION?????
|
2023-05-20 00:52:59 +02:00
|
|
|
for (int i=0; i<lastHeardStation.size(); i++) {
|
2023-05-20 03:16:47 +02:00
|
|
|
String deltaTimeString = lastHeardStation[i].substring(lastHeardStation[i].indexOf(",")+1);
|
|
|
|
|
uint32_t deltaTime = deltaTimeString.toInt();
|
|
|
|
|
if ((millis() - deltaTime) < minReportingTime) {
|
2023-05-25 16:27:46 +02:00
|
|
|
lastHeardStation_temp.push_back(lastHeardStation[i]);
|
2023-05-20 03:16:47 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lastHeardStation.clear();
|
2023-05-25 16:27:46 +02:00
|
|
|
for (int j=0; j<lastHeardStation_temp.size(); j++) {
|
|
|
|
|
lastHeardStation.push_back(lastHeardStation_temp[j]);
|
2023-05-20 03:16:47 +02:00
|
|
|
}
|
2023-05-25 16:27:46 +02:00
|
|
|
lastHeardStation_temp.clear();
|
2023-05-20 03:42:59 +02:00
|
|
|
}
|
2023-05-20 03:16:47 +02:00
|
|
|
|
2023-05-20 03:42:59 +02:00
|
|
|
void updateLastHeardStation(String station) {
|
|
|
|
|
bool stationHeard = false;
|
|
|
|
|
for (int i=0; i<lastHeardStation.size(); i++) {
|
|
|
|
|
if (lastHeardStation[i].substring(0,lastHeardStation[i].indexOf(",")) == station) {
|
|
|
|
|
lastHeardStation[i] = station + "," + String(millis());
|
|
|
|
|
stationHeard = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!stationHeard) {
|
|
|
|
|
lastHeardStation.push_back(station + "," + String(millis()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////
|
2023-05-26 19:57:10 +02:00
|
|
|
Serial.print("Stations Near (last 30 minutes): ");
|
2023-05-20 03:16:47 +02:00
|
|
|
for (int k=0; k<lastHeardStation.size(); k++) {
|
2023-05-26 19:57:10 +02:00
|
|
|
Serial.print(lastHeardStation[k].substring(0,lastHeardStation[k].indexOf(","))); Serial.print(" ");
|
2023-05-20 00:52:59 +02:00
|
|
|
}
|
2023-05-25 16:27:46 +02:00
|
|
|
Serial.println("");
|
2023-05-20 00:52:59 +02:00
|
|
|
}
|
|
|
|
|
|
2023-05-23 18:04:22 +02:00
|
|
|
String processQueryAnswer(String query, String station, String queryOrigin) {
|
2023-05-23 06:25:47 +02:00
|
|
|
String processedQuery, queryAnswer;
|
2023-05-26 19:57:10 +02:00
|
|
|
if (query=="?APRS?" || query=="?aprs?" || query=="?Aprs?" || query=="H" || query=="h" || query=="Help" || query=="help" || query=="?") {
|
2023-05-23 06:25:47 +02:00
|
|
|
processedQuery = "?APRSV ?APRSP ?APRSL ?APRSH ?WHERE callsign";
|
2023-05-26 19:57:10 +02:00
|
|
|
} else if (query=="?APRSV" || query=="?aprsv" || query=="?Aprsv") {
|
2023-06-04 16:10:39 +02:00
|
|
|
processedQuery = Config.aprs_is.softwareName + " " + Config.aprs_is.softwareVersion;
|
2023-05-26 19:57:10 +02:00
|
|
|
} else if (query=="?APRSP" || query=="?aprsp" || query=="?Aprsp") {
|
2023-05-23 06:56:39 +02:00
|
|
|
processedQuery = "iGate QTH: " + String(currentWiFi->latitude) + " " + String(currentWiFi->longitude);
|
2023-05-26 19:57:10 +02:00
|
|
|
} else if (query=="?APRSL" || query=="?aprsl" || query=="?Aprsl") {
|
2023-05-23 06:25:47 +02:00
|
|
|
for (int i=0; i<lastHeardStation.size(); i++) {
|
|
|
|
|
processedQuery += lastHeardStation[i].substring(0,lastHeardStation[i].indexOf(",")) + " ";
|
|
|
|
|
}
|
|
|
|
|
processedQuery.trim();
|
|
|
|
|
} /*else if (query.indexOf("?APRSH") == 0 || query.indexOf("?aprsv") == 0 || query.indexOf("?Aprsv") == 0) {
|
|
|
|
|
// sacar callsign despues de ?APRSH
|
|
|
|
|
Serial.println("escuchaste a X estacion? en las ultimas 24 o 8 horas?");
|
|
|
|
|
processedQuery = "APRSH";
|
|
|
|
|
} else if (query.indexOf("?WHERE") == 0) {
|
|
|
|
|
// agregar callsign para completar donde esta X callsign
|
|
|
|
|
Serial.println("estaciones escuchadas directo (ultimos 30 min)");
|
|
|
|
|
processedQuery = "WHERE";
|
|
|
|
|
}*/
|
|
|
|
|
for(int i = station.length(); i < 9; i++) {
|
|
|
|
|
station += ' ';
|
|
|
|
|
}
|
2023-05-23 18:04:22 +02:00
|
|
|
if (queryOrigin == "APRSIS") {
|
2023-05-26 22:33:01 +02:00
|
|
|
queryAnswer = Config.callsign + ">APLR10,TCPIP,qAC::" + station + ":" + processedQuery + "\n";
|
2023-05-23 18:04:22 +02:00
|
|
|
} else if (queryOrigin == "LoRa") {
|
2023-05-26 22:33:01 +02:00
|
|
|
queryAnswer = Config.callsign + ">APLR10,RFONLY::" + station + ":" + processedQuery;
|
2023-05-23 18:04:22 +02:00
|
|
|
}
|
2023-05-23 06:25:47 +02:00
|
|
|
return queryAnswer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void checkReceivedPacket(String packet) {
|
|
|
|
|
bool queryMessage = false;
|
2023-05-25 16:27:46 +02:00
|
|
|
String aprsPacket, Sender, AddresseeAndMessage, Addressee, ackMessage, receivedMessage;
|
2023-05-23 18:04:22 +02:00
|
|
|
Serial.print("Received Lora Packet : " + String(packet));
|
2023-05-10 06:59:00 +02:00
|
|
|
if ((packet.substring(0, 3) == "\x3c\xff\x01") && (packet.indexOf("TCPIP") == -1) && (packet.indexOf("NOGATE") == -1) && (packet.indexOf("RFONLY") == -1)) {
|
2023-05-23 18:04:22 +02:00
|
|
|
Serial.print(" ---> APRS LoRa Packet!");
|
2023-05-23 06:25:47 +02:00
|
|
|
Sender = packet.substring(3,packet.indexOf(">"));
|
2023-06-04 17:23:26 +02:00
|
|
|
if (Sender != Config.callsign) { // avoid listening yourself by digirepeating
|
|
|
|
|
if (Config.loramodule.enableTx) {
|
|
|
|
|
if (packet.indexOf("::") > 10) { // its a Message!
|
|
|
|
|
AddresseeAndMessage = packet.substring(packet.indexOf("::")+2);
|
|
|
|
|
Addressee = AddresseeAndMessage.substring(0,AddresseeAndMessage.indexOf(":"));
|
|
|
|
|
Addressee.trim();
|
|
|
|
|
if (Addressee == Config.callsign) { // its for me!
|
|
|
|
|
if (AddresseeAndMessage.indexOf("{")>0) { // ack?
|
|
|
|
|
ackMessage = "ack" + AddresseeAndMessage.substring(AddresseeAndMessage.indexOf("{")+1);
|
|
|
|
|
ackMessage.trim();
|
|
|
|
|
delay(4000);
|
|
|
|
|
Serial.println(ackMessage);
|
|
|
|
|
for(int i = Sender.length(); i < 9; i++) {
|
|
|
|
|
Sender += ' ';
|
|
|
|
|
}
|
|
|
|
|
LoRaUtils::sendNewPacket("APRS", Config.callsign + ">APLR10,RFONLY::" + Sender + ":" + ackMessage);
|
|
|
|
|
receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":")+1, AddresseeAndMessage.indexOf("{"));
|
|
|
|
|
} else {
|
|
|
|
|
receivedMessage = AddresseeAndMessage.substring(AddresseeAndMessage.indexOf(":")+1);
|
2023-05-23 18:04:22 +02:00
|
|
|
}
|
2023-06-04 17:23:26 +02:00
|
|
|
if (receivedMessage.indexOf("?") == 0) {
|
|
|
|
|
queryMessage = true;
|
|
|
|
|
String queryAnswer = processQueryAnswer(receivedMessage, Sender, "LoRa");
|
|
|
|
|
delay(2000);
|
|
|
|
|
if (!Config.display.alwaysOn) {
|
|
|
|
|
display_toggle(true);
|
|
|
|
|
}
|
|
|
|
|
lastRxTxTime = millis();
|
|
|
|
|
LoRaUtils::sendNewPacket("APRS", queryAnswer);
|
2023-06-04 20:54:11 +02:00
|
|
|
show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE --> QUERY", 1000);
|
2023-06-04 17:23:26 +02:00
|
|
|
}
|
2023-05-23 06:25:47 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!queryMessage) {
|
|
|
|
|
aprsPacket = createAPRSPacket(packet);
|
2023-06-04 16:10:39 +02:00
|
|
|
if (!Config.display.alwaysOn) {
|
2023-05-23 06:46:47 +02:00
|
|
|
display_toggle(true);
|
2023-05-23 06:25:47 +02:00
|
|
|
}
|
|
|
|
|
lastRxTxTime = millis();
|
|
|
|
|
espClient.write(aprsPacket.c_str());
|
2023-05-23 18:04:22 +02:00
|
|
|
Serial.println(" ---> Uploaded to APRS-IS");
|
2023-05-23 06:25:47 +02:00
|
|
|
deleteNotHeardStation();
|
|
|
|
|
updateLastHeardStation(Sender);
|
|
|
|
|
if (aprsPacket.indexOf("::") >= 10) {
|
2023-06-04 20:54:11 +02:00
|
|
|
show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE --> MESSAGE", 1000);
|
2023-05-23 06:25:47 +02:00
|
|
|
} else if (aprsPacket.indexOf(":>") >= 10) {
|
2023-06-04 20:54:11 +02:00
|
|
|
show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE --> NEW STATUS", 1000);
|
2023-05-24 15:54:48 +02:00
|
|
|
} else if (aprsPacket.indexOf(":!") >= 10) {
|
2023-06-04 20:54:11 +02:00
|
|
|
show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE --> GPS BEACON", 1000);
|
2023-05-23 06:25:47 +02:00
|
|
|
} else {
|
2023-06-04 20:54:11 +02:00
|
|
|
show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE --> ??????????", 1000);
|
2023-05-23 06:25:47 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-02 12:51:38 +01:00
|
|
|
} else {
|
2023-05-23 18:04:22 +02:00
|
|
|
Serial.println(" ---> Not APRS Packet (Ignore)\n");
|
2023-03-02 12:51:38 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 14:57:17 +02:00
|
|
|
String processAPRSISPacket(String aprsisMessage) {
|
2023-03-03 03:56:32 +01:00
|
|
|
String firstPart, messagePart, newLoraPacket;
|
2023-05-10 06:59:00 +02:00
|
|
|
aprsisMessage.trim();
|
|
|
|
|
firstPart = aprsisMessage.substring(0, aprsisMessage.indexOf(","));
|
2023-03-03 03:56:32 +01:00
|
|
|
messagePart = aprsisMessage.substring(aprsisMessage.indexOf("::")+2);
|
2023-05-23 06:25:47 +02:00
|
|
|
newLoraPacket = firstPart + ",TCPIP," + Config.callsign + "::" + messagePart;
|
2023-05-23 18:04:22 +02:00
|
|
|
Serial.print("Received from APRS-IS : " + aprsisMessage);
|
2023-03-03 03:56:32 +01:00
|
|
|
return newLoraPacket;
|
2023-03-03 02:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
2023-03-27 05:32:27 +02:00
|
|
|
String double2string(double n, int ndec) {
|
|
|
|
|
String r = "";
|
|
|
|
|
int v = n;
|
|
|
|
|
r += v;
|
|
|
|
|
r += '.';
|
|
|
|
|
int i;
|
|
|
|
|
for (i=0;i<ndec;i++) {
|
|
|
|
|
n -= v;
|
|
|
|
|
n = 10 * abs(n);
|
|
|
|
|
v = n;
|
|
|
|
|
r += v;
|
|
|
|
|
}
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String create_lat_aprs(double lat) {
|
|
|
|
|
String degrees = double2string(lat,6);
|
|
|
|
|
String north_south, latitude, convDeg3;
|
|
|
|
|
float convDeg, convDeg2;
|
|
|
|
|
|
2023-04-27 19:00:20 +02:00
|
|
|
if (abs(degrees.toFloat()) < 10) {
|
|
|
|
|
latitude += "0";
|
|
|
|
|
}
|
|
|
|
|
Serial.println(latitude);
|
2023-03-27 05:32:27 +02:00
|
|
|
if (degrees.indexOf("-") == 0) {
|
|
|
|
|
north_south = "S";
|
2023-04-27 19:00:20 +02:00
|
|
|
latitude += degrees.substring(1,degrees.indexOf("."));
|
2023-03-27 05:32:27 +02:00
|
|
|
} else {
|
|
|
|
|
north_south = "N";
|
2023-04-27 19:00:20 +02:00
|
|
|
latitude += degrees.substring(0,degrees.indexOf("."));
|
2023-04-27 17:53:46 +02:00
|
|
|
}
|
2023-03-27 05:32:27 +02:00
|
|
|
convDeg = abs(degrees.toFloat()) - abs(int(degrees.toFloat()));
|
|
|
|
|
convDeg2 = (convDeg * 60)/100;
|
|
|
|
|
convDeg3 = String(convDeg2,6);
|
|
|
|
|
latitude += convDeg3.substring(convDeg3.indexOf(".")+1,convDeg3.indexOf(".")+3) + "." + convDeg3.substring(convDeg3.indexOf(".")+3,convDeg3.indexOf(".")+5);
|
|
|
|
|
latitude += north_south;
|
|
|
|
|
return latitude;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String create_lng_aprs(double lng) {
|
|
|
|
|
String degrees = double2string(lng,6);
|
|
|
|
|
String east_west, longitude, convDeg3;
|
|
|
|
|
float convDeg, convDeg2;
|
|
|
|
|
|
|
|
|
|
if (abs(degrees.toFloat()) < 100) {
|
|
|
|
|
longitude += "0";
|
|
|
|
|
}
|
2023-04-27 19:00:20 +02:00
|
|
|
if (abs(degrees.toFloat()) < 10) {
|
|
|
|
|
longitude += "0";
|
|
|
|
|
}
|
2023-03-27 05:32:27 +02:00
|
|
|
if (degrees.indexOf("-") == 0) {
|
|
|
|
|
east_west = "W";
|
|
|
|
|
longitude += degrees.substring(1,degrees.indexOf("."));
|
2023-03-26 18:19:01 +02:00
|
|
|
} else {
|
2023-03-27 05:32:27 +02:00
|
|
|
east_west = "E";
|
|
|
|
|
longitude += degrees.substring(0,degrees.indexOf("."));
|
2023-03-26 18:19:01 +02:00
|
|
|
}
|
2023-03-27 05:32:27 +02:00
|
|
|
convDeg = abs(degrees.toFloat()) - abs(int(degrees.toFloat()));
|
|
|
|
|
convDeg2 = (convDeg * 60)/100;
|
|
|
|
|
convDeg3 = String(convDeg2,6);
|
|
|
|
|
longitude += convDeg3.substring(convDeg3.indexOf(".")+1,convDeg3.indexOf(".")+3) + "." + convDeg3.substring(convDeg3.indexOf(".")+3,convDeg3.indexOf(".")+5);
|
|
|
|
|
longitude += east_west;
|
|
|
|
|
return longitude;
|
|
|
|
|
}
|
2023-03-26 18:19:01 +02:00
|
|
|
|
2023-03-02 12:51:38 +01:00
|
|
|
void setup() {
|
|
|
|
|
Serial.begin(115200);
|
2023-06-04 21:05:48 +02:00
|
|
|
delay(1000);
|
2023-03-26 14:12:27 +02:00
|
|
|
setup_display();
|
2023-06-04 21:05:48 +02:00
|
|
|
Serial.println("\nStarting iGate: " + Config.callsign + " Version: " + String(VERSION));
|
|
|
|
|
show_display(" LoRa APRS iGate", " Richonguzman", " -- CD2RXU --", " " VERSION, 4000);
|
2023-06-06 17:21:59 +02:00
|
|
|
WIFI_Utils::setup();
|
2023-03-02 12:51:38 +01:00
|
|
|
btStop();
|
2023-06-05 05:02:25 +02:00
|
|
|
|
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-06 17:21:59 +02:00
|
|
|
Serial.println("HTTP server started");*/
|
2023-06-05 05:02:25 +02:00
|
|
|
|
2023-06-04 16:10:39 +02:00
|
|
|
LoRaUtils::setup();
|
2023-05-23 06:25:47 +02:00
|
|
|
iGateLatitude = create_lat_aprs(currentWiFi->latitude);
|
|
|
|
|
iGateLongitude = create_lng_aprs(currentWiFi->longitude);
|
2023-03-02 12:51:38 +01:00
|
|
|
}
|
|
|
|
|
|
2023-03-26 14:12:27 +02:00
|
|
|
void loop() {
|
2023-05-23 06:25:47 +02:00
|
|
|
String wifiState, aprsisState;
|
2023-03-26 22:50:32 +02:00
|
|
|
firstLine = "LoRa iGate: " + Config.callsign;
|
2023-05-25 16:27:46 +02:00
|
|
|
secondLine = "";
|
|
|
|
|
thirdLine = "";
|
|
|
|
|
fourthLine = "";
|
2023-03-03 00:40:59 +01:00
|
|
|
unsigned long currentWiFiMillis = millis();
|
|
|
|
|
|
2023-06-06 17:21:59 +02:00
|
|
|
if ((WiFi.status() != WL_CONNECTED) && (currentWiFiMillis - previousWiFiMillis >= currentWiFi->checkInterval*1000)) {
|
2023-03-03 00:40:59 +01:00
|
|
|
Serial.print(millis());
|
|
|
|
|
Serial.println("Reconnecting to WiFi...");
|
|
|
|
|
WiFi.disconnect();
|
|
|
|
|
WiFi.reconnect();
|
|
|
|
|
previousWiFiMillis = currentWiFiMillis;
|
|
|
|
|
}
|
2023-03-27 05:32:27 +02:00
|
|
|
|
2023-03-03 00:40:59 +01:00
|
|
|
if (!espClient.connected()) {
|
2023-06-06 17:30:32 +02:00
|
|
|
APRS_IS_Utils::connect();
|
2023-03-02 12:51:38 +01:00
|
|
|
}
|
2023-03-27 05:32:27 +02:00
|
|
|
|
2023-03-27 19:20:15 +02:00
|
|
|
if (WiFi.status() == WL_CONNECTED) {
|
|
|
|
|
wifiState = "OK";
|
|
|
|
|
} else {
|
|
|
|
|
wifiState = "--";
|
2023-06-04 16:10:39 +02:00
|
|
|
if (!Config.display.alwaysOn) {
|
2023-03-27 19:20:15 +02:00
|
|
|
display_toggle(true);
|
|
|
|
|
}
|
|
|
|
|
lastRxTxTime = millis();
|
|
|
|
|
}
|
|
|
|
|
if (espClient.connected()) {
|
|
|
|
|
aprsisState = "OK";
|
|
|
|
|
} else {
|
|
|
|
|
aprsisState = "--";
|
2023-06-04 16:10:39 +02:00
|
|
|
if (!Config.display.alwaysOn) {
|
2023-03-27 19:20:15 +02:00
|
|
|
display_toggle(true);
|
|
|
|
|
}
|
|
|
|
|
lastRxTxTime = millis();
|
|
|
|
|
}
|
2023-03-26 14:12:27 +02:00
|
|
|
secondLine = "WiFi: " + wifiState + "/ APRS-IS: " + aprsisState;
|
|
|
|
|
|
|
|
|
|
show_display(firstLine, secondLine, thirdLine, fourthLine, 0);
|
2023-03-03 00:40:59 +01:00
|
|
|
|
|
|
|
|
while (espClient.connected()) {
|
2023-03-26 14:12:27 +02:00
|
|
|
uint32_t lastRxTx = millis() - lastRxTxTime;
|
2023-06-04 16:10:39 +02:00
|
|
|
if (!Config.display.alwaysOn) {
|
2023-03-26 22:50:32 +02:00
|
|
|
if (lastRxTx >= Config.display.timeout*1000) {
|
2023-03-26 14:12:27 +02:00
|
|
|
display_toggle(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-25 16:27:46 +02:00
|
|
|
thirdLine = "";
|
|
|
|
|
fourthLine = "";
|
2023-03-03 00:40:59 +01:00
|
|
|
|
2023-06-04 20:54:11 +02:00
|
|
|
if (!Config.display.keepLastPacketOnScreen) {
|
|
|
|
|
show_display(firstLine, secondLine, thirdLine, fourthLine, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-03 01:40:39 +01:00
|
|
|
uint32_t lastTx = millis() - lastTxTime;
|
2023-06-04 16:10:39 +02:00
|
|
|
if (lastTx >= Config.beaconInterval*60*1000) {
|
2023-03-03 01:40:39 +01:00
|
|
|
beacon_update = true;
|
|
|
|
|
}
|
2023-03-26 14:12:27 +02:00
|
|
|
if (beacon_update) {
|
|
|
|
|
display_toggle(true);
|
2023-03-03 02:31:22 +01:00
|
|
|
Serial.println("---- Sending iGate Beacon ----");
|
2023-06-04 17:23:26 +02:00
|
|
|
String iGateBeaconPacket = Config.callsign + ">APLR10,";
|
|
|
|
|
if (Config.loramodule.enableTx) {
|
|
|
|
|
iGateBeaconPacket += "qAC:=" + iGateLatitude + "L" + iGateLongitude + "a" + Config.comment;
|
|
|
|
|
} else {
|
|
|
|
|
iGateBeaconPacket += "qAC:=" + iGateLatitude + "L" + iGateLongitude + "&" + Config.comment;
|
|
|
|
|
}
|
2023-03-26 23:37:42 +02:00
|
|
|
//Serial.println(iGateBeaconPacket);
|
2023-06-04 17:23:26 +02:00
|
|
|
espClient.write((iGateBeaconPacket + "\n").c_str());
|
2023-03-03 01:40:39 +01:00
|
|
|
lastTxTime = millis();
|
2023-03-26 14:12:27 +02:00
|
|
|
lastRxTxTime = millis();
|
2023-05-23 18:10:49 +02:00
|
|
|
show_display(firstLine, secondLine, thirdLine, "SENDING iGate BEACON", 1000);
|
2023-06-04 20:54:11 +02:00
|
|
|
show_display(firstLine, secondLine, thirdLine, fourthLine, 0);
|
2023-03-03 01:40:39 +01:00
|
|
|
beacon_update = false;
|
|
|
|
|
}
|
2023-03-03 00:40:59 +01:00
|
|
|
|
2023-03-03 01:40:39 +01:00
|
|
|
String loraPacket = "";
|
|
|
|
|
int packetSize = LoRa.parsePacket();
|
|
|
|
|
if (packetSize) {
|
|
|
|
|
while (LoRa.available()) {
|
|
|
|
|
int inChar = LoRa.read();
|
|
|
|
|
loraPacket += (char)inChar;
|
2023-03-03 00:40:59 +01:00
|
|
|
}
|
2023-05-23 06:25:47 +02:00
|
|
|
checkReceivedPacket(loraPacket);
|
2023-03-02 12:51:38 +01:00
|
|
|
}
|
2023-03-03 01:40:39 +01:00
|
|
|
|
|
|
|
|
if (espClient.available()) {
|
2023-05-25 16:27:46 +02:00
|
|
|
String aprsisData, aprsisPacket, newLoraPacket, Sender, AddresseeAndMessage, Addressee, receivedMessage;
|
2023-05-20 07:03:14 +02:00
|
|
|
bool validHeardStation = false;
|
2023-05-10 06:59:00 +02:00
|
|
|
aprsisData = espClient.readStringUntil('\r'); // or '\n'
|
2023-03-03 01:40:39 +01:00
|
|
|
aprsisPacket.concat(aprsisData);
|
|
|
|
|
if (!aprsisPacket.startsWith("#")){
|
2023-03-03 21:07:52 +01:00
|
|
|
if (aprsisPacket.indexOf("::")>0) {
|
2023-05-23 18:04:22 +02:00
|
|
|
Sender = aprsisPacket.substring(0,aprsisPacket.indexOf(">"));
|
|
|
|
|
AddresseeAndMessage = aprsisPacket.substring(aprsisPacket.indexOf("::")+2);
|
|
|
|
|
Addressee = AddresseeAndMessage.substring(0, AddresseeAndMessage.indexOf(":"));
|
2023-05-20 07:03:14 +02:00
|
|
|
Addressee.trim();
|
2023-05-23 18:04:22 +02:00
|
|
|
if (Addressee == Config.callsign) { // its for me!
|
|
|
|
|
if (AddresseeAndMessage.indexOf("{")>0) { // ack?
|
2023-05-25 16:27:46 +02:00
|
|
|
String ackMessage = "ack" + AddresseeAndMessage.substring(AddresseeAndMessage.indexOf("{")+1);
|
2023-05-23 18:04:22 +02:00
|
|
|
ackMessage.trim();
|
|
|
|
|
delay(4000);
|
|
|
|
|
Serial.println(ackMessage);
|
|
|
|
|
for(int i = Sender.length(); i < 9; i++) {
|
|
|
|
|
Sender += ' ';
|
|
|
|
|
}
|
2023-05-26 22:33:01 +02:00
|
|
|
String ackPacket = Config.callsign + ">APLR10,TCPIP,qAC::" + Sender + ":" + ackMessage + "\n";
|
2023-05-23 18:04:22 +02:00
|
|
|
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);
|
2023-05-25 16:27:46 +02:00
|
|
|
String queryAnswer = processQueryAnswer(receivedMessage, Sender, "APRSIS");
|
2023-05-23 18:04:22 +02:00
|
|
|
Serial.println("---> QUERY Answer : " + queryAnswer.substring(0,queryAnswer.indexOf("\n")));
|
2023-06-04 16:10:39 +02:00
|
|
|
if (!Config.display.alwaysOn) {
|
2023-05-23 18:04:22 +02:00
|
|
|
display_toggle(true);
|
|
|
|
|
}
|
|
|
|
|
lastRxTxTime = millis();
|
|
|
|
|
delay(500);
|
|
|
|
|
espClient.write(queryAnswer.c_str());
|
2023-06-04 20:54:11 +02:00
|
|
|
show_display(firstLine, secondLine, "Callsign = " + Sender, "TYPE --> QUERY", 1000);
|
2023-05-23 18:04:22 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
newLoraPacket = processAPRSISPacket(aprsisPacket);
|
|
|
|
|
deleteNotHeardStation();
|
|
|
|
|
validHeardStation = checkValidHeardStation(Addressee);
|
|
|
|
|
if (validHeardStation) {
|
2023-06-04 16:10:39 +02:00
|
|
|
LoRaUtils::sendNewPacket("APRS", newLoraPacket);
|
2023-05-23 18:04:22 +02:00
|
|
|
display_toggle(true);
|
|
|
|
|
lastRxTxTime = millis();
|
2023-06-04 20:54:11 +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-03-03 21:07:52 +01:00
|
|
|
}
|
2023-03-03 01:40:39 +01:00
|
|
|
}
|
2023-03-03 02:31:22 +01:00
|
|
|
}
|
2023-06-04 17:23:26 +02:00
|
|
|
if (statusAfterBoot) {
|
2023-06-04 20:54:11 +02:00
|
|
|
utils::processStatus();
|
2023-05-26 22:33:01 +02:00
|
|
|
}
|
2023-03-03 00:40:59 +01:00
|
|
|
}
|
2023-03-26 14:12:27 +02:00
|
|
|
}
|