diff --git a/platformio.ini b/platformio.ini index 27fa94a..88763f7 100644 --- a/platformio.ini +++ b/platformio.ini @@ -39,4 +39,12 @@ build_flags = -Werror -Wall -DHELTEC_V2 -DELEGANTOTA_USE_ASYNC_WEBSERVER=1 [env:heltec_wifi_kit_32_V3] board = heltec_wifi_kit_32_V3 build_flags = -Werror -Wall -DHELTEC_V3 -DELEGANTOTA_USE_ASYNC_WEBSERVER=1 -board_build.mcu = esp32s3 \ No newline at end of file +board_build.mcu = esp32s3 + +[env:ESP32_DIY_LoRa] +board = esp32dev +build_flags = -Werror -Wall -DESP32_DIY_LoRa + +[env:ESP32_DIY_1W_LoRa] +board = esp32dev +build_flags = -Werror -Wall -DESP32_DIY_1W_LoRa \ No newline at end of file diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 68c2005..b692250 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -49,7 +49,7 @@ void setup() { #ifndef HELTEC_V3 pinMode(batteryPin, INPUT); #endif - pinMode(greenLed, OUTPUT); + pinMode(internalLedPin, OUTPUT); if (Config.externalVoltageMeasurement) { pinMode(Config.externalVoltagePin, INPUT); } diff --git a/src/aprs_is_utils.h b/src/aprs_is_utils.h index e219b50..489ac29 100644 --- a/src/aprs_is_utils.h +++ b/src/aprs_is_utils.h @@ -7,12 +7,12 @@ namespace APRS_IS_Utils { -void connect(); -void checkStatus(); -String createPacket(String unprocessedPacket); -void processLoRaPacket(String packet); -void processAPRSISPacket(String packet); -void loop(); + void connect(); + void checkStatus(); + String createPacket(String unprocessedPacket); + void processLoRaPacket(String packet); + void processAPRSISPacket(String packet); + void loop(); } diff --git a/src/battery_utils.h b/src/battery_utils.h index fe07a08..175268f 100644 --- a/src/battery_utils.h +++ b/src/battery_utils.h @@ -5,8 +5,8 @@ namespace BATTERY_Utils { -float checkBattery(); -float checkExternalVoltage(); + float checkBattery(); + float checkExternalVoltage(); } diff --git a/src/digi_utils.h b/src/digi_utils.h index 5f4415f..c7a02a4 100644 --- a/src/digi_utils.h +++ b/src/digi_utils.h @@ -5,8 +5,8 @@ namespace DIGI_Utils { -void processPacket(String packet); -void loop(); + void processPacket(String packet); + void loop(); } diff --git a/src/gps_utils.cpp b/src/gps_utils.cpp index 61d91fa..33544c0 100644 --- a/src/gps_utils.cpp +++ b/src/gps_utils.cpp @@ -11,175 +11,175 @@ String distance; namespace GPS_Utils { -String double2string(double n, int ndec) { - String r = ""; - if (n>-1 && n<0) { - r = "-"; - } - int v = n; - r += v; - r += '.'; - for (int i=0;i-1 && n<0) { + r = "-"; + } + int v = n; + r += v; + r += '.'; + for (int i=0;ilatitude); - stationLongitude = processLongitudeAPRS(currentWiFi->longitude); - beaconPacket = Config.callsign + ">APLRG1,WIDE1-1"; - if (stationMode!=6) { - beaconPacket += ",qAC"; - } - beaconPacket += ":=" + stationLatitude + "L" + stationLongitude; - if (stationMode==1) { - beaconPacket += "&"; + Serial.println(latitude); + if (degrees.indexOf("-") == 0) { + north_south = "S"; + latitude += degrees.substring(1,degrees.indexOf(".")); } else { - beaconPacket += "a"; + north_south = "N"; + latitude += degrees.substring(0,degrees.indexOf(".")); } - beaconPacket += Config.iGateComment; - } else { //stationMode 3, 4 and 5 - if (stationMode==5) { + 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 processLongitudeAPRS(double lon) { + String degrees = double2string(lon,6); + String east_west, longitude, convDeg3; + float convDeg, convDeg2; + + if (abs(degrees.toFloat()) < 100) { + longitude += "0"; + } + if (abs(degrees.toFloat()) < 10) { + longitude += "0"; + } + if (degrees.indexOf("-") == 0) { + east_west = "W"; + longitude += degrees.substring(1,degrees.indexOf(".")); + } else { + east_west = "E"; + longitude += degrees.substring(0,degrees.indexOf(".")); + } + 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; + } + + String generateBeacon() { + String stationLatitude, stationLongitude, beaconPacket; + if (stationMode==1 || stationMode==2 || (stationMode==5 && WiFi.status()==WL_CONNECTED && espClient.connected()) || stationMode==6) { stationLatitude = processLatitudeAPRS(currentWiFi->latitude); stationLongitude = processLongitudeAPRS(currentWiFi->longitude); - } else { - stationLatitude = processLatitudeAPRS(Config.digi.latitude); - stationLongitude = processLongitudeAPRS(Config.digi.longitude); + beaconPacket = Config.callsign + ">APLRG1,WIDE1-1"; + if (stationMode!=6) { + beaconPacket += ",qAC"; + } + beaconPacket += ":=" + stationLatitude + "L" + stationLongitude; + if (stationMode==1) { + beaconPacket += "&"; + } else { + beaconPacket += "a"; + } + beaconPacket += Config.iGateComment; + } else { //stationMode 3, 4 and 5 + if (stationMode==5) { + stationLatitude = processLatitudeAPRS(currentWiFi->latitude); + stationLongitude = processLongitudeAPRS(currentWiFi->longitude); + } else { + stationLatitude = processLatitudeAPRS(Config.digi.latitude); + stationLongitude = processLongitudeAPRS(Config.digi.longitude); + } + beaconPacket = Config.callsign + ">APLRG1,WIDE1-1:=" + stationLatitude + "L" + stationLongitude + "#" + Config.digi.comment; } - beaconPacket = Config.callsign + ">APLRG1,WIDE1-1:=" + stationLatitude + "L" + stationLongitude + "#" + Config.digi.comment; + return beaconPacket; } - return beaconPacket; -} -double calculateDistanceTo(double latitude, double longitude) { - return TinyGPSPlus::distanceBetween(currentWiFi->latitude,currentWiFi->longitude, latitude, longitude) / 1000.0; -} + double calculateDistanceTo(double latitude, double longitude) { + return TinyGPSPlus::distanceBetween(currentWiFi->latitude,currentWiFi->longitude, latitude, longitude) / 1000.0; + } -String decodeEncodedGPS(String packet) { - String GPSPacket = packet.substring(packet.indexOf(":!")+3); - String encodedLatitude = GPSPacket.substring(0,4); - String encodedLongtitude = GPSPacket.substring(4,8); + String decodeEncodedGPS(String packet) { + String GPSPacket = packet.substring(packet.indexOf(":!")+3); + String encodedLatitude = GPSPacket.substring(0,4); + String encodedLongtitude = GPSPacket.substring(4,8); - int Y1 = int(encodedLatitude[0]); - int Y2 = int(encodedLatitude[1]); - int Y3 = int(encodedLatitude[2]); - int Y4 = int(encodedLatitude[3]); - float decodedLatitude = 90.0 - ((((Y1-33) * pow(91,3)) + ((Y2-33) * pow(91,2)) + ((Y3-33) * 91) + Y4-33) / 380926.0); + int Y1 = int(encodedLatitude[0]); + int Y2 = int(encodedLatitude[1]); + int Y3 = int(encodedLatitude[2]); + int Y4 = int(encodedLatitude[3]); + float decodedLatitude = 90.0 - ((((Y1-33) * pow(91,3)) + ((Y2-33) * pow(91,2)) + ((Y3-33) * 91) + Y4-33) / 380926.0); + + int X1 = int(encodedLongtitude[0]); + int X2 = int(encodedLongtitude[1]); + int X3 = int(encodedLongtitude[2]); + int X4 = int(encodedLongtitude[3]); + float decodedLongitude = -180.0 + ((((X1-33) * pow(91,3)) + ((X2-33) * pow(91,2)) + ((X3-33) * 91) + X4-33) / 190463.0); + distance = String(calculateDistanceTo(decodedLatitude, decodedLongitude),1); + return String(decodedLatitude,5) + "N / " + String(decodedLongitude,5) + "E / " + distance + "km"; + } + + String getReceivedGPS(String packet) { + String infoGPS; + if (packet.indexOf(":!") > 10) { + infoGPS = packet.substring(packet.indexOf(":!")+2); + } else if (packet.indexOf(":=") > 10) { + infoGPS = packet.substring(packet.indexOf(":=")+2); + } + String Latitude = infoGPS.substring(0,8); + String Longitude = infoGPS.substring(9,18); + + float convertedLatitude, convertedLongitude; + String firstLatPart = Latitude.substring(0,2); + String secondLatPart = Latitude.substring(2,4); + String thirdLatPart = Latitude.substring(Latitude.indexOf(".")+1,Latitude.indexOf(".")+3); + String firstLngPart = Longitude.substring(0,3); + String secondLngPart = Longitude.substring(3,5); + String thirdLngPart = Longitude.substring(Longitude.indexOf(".")+1,Longitude.indexOf(".")+3); + convertedLatitude = firstLatPart.toFloat() + (secondLatPart.toFloat()/60) + (thirdLatPart.toFloat()/(60*100)); + convertedLongitude = firstLngPart.toFloat() + (secondLngPart.toFloat()/60) + (thirdLngPart.toFloat()/(60*100)); - int X1 = int(encodedLongtitude[0]); - int X2 = int(encodedLongtitude[1]); - int X3 = int(encodedLongtitude[2]); - int X4 = int(encodedLongtitude[3]); - float decodedLongitude = -180.0 + ((((X1-33) * pow(91,3)) + ((X2-33) * pow(91,2)) + ((X3-33) * 91) + X4-33) / 190463.0); - distance = String(calculateDistanceTo(decodedLatitude, decodedLongitude),1); - return String(decodedLatitude,5) + "N / " + String(decodedLongitude,5) + "E / " + distance + "km"; -} - -String getReceivedGPS(String packet) { - String infoGPS; - if (packet.indexOf(":!") > 10) { - infoGPS = packet.substring(packet.indexOf(":!")+2); - } else if (packet.indexOf(":=") > 10) { - infoGPS = packet.substring(packet.indexOf(":=")+2); - } - String Latitude = infoGPS.substring(0,8); - String Longitude = infoGPS.substring(9,18); - - float convertedLatitude, convertedLongitude; - String firstLatPart = Latitude.substring(0,2); - String secondLatPart = Latitude.substring(2,4); - String thirdLatPart = Latitude.substring(Latitude.indexOf(".")+1,Latitude.indexOf(".")+3); - String firstLngPart = Longitude.substring(0,3); - String secondLngPart = Longitude.substring(3,5); - String thirdLngPart = Longitude.substring(Longitude.indexOf(".")+1,Longitude.indexOf(".")+3); - convertedLatitude = firstLatPart.toFloat() + (secondLatPart.toFloat()/60) + (thirdLatPart.toFloat()/(60*100)); - convertedLongitude = firstLngPart.toFloat() + (secondLngPart.toFloat()/60) + (thirdLngPart.toFloat()/(60*100)); - - String LatSign = String(Latitude[7]); - String LngSign = String(Longitude[8]); - if (LatSign == "S") { - convertedLatitude = -convertedLatitude; - } - if (LngSign == "W") { - convertedLongitude = -convertedLongitude; - } - distance = String(calculateDistanceTo(convertedLatitude, convertedLongitude),1); - return String(convertedLatitude,5) + "N / " + String(convertedLongitude,5) + "E / " + distance + "km"; -} - -String getDistance(String packet) { - int encodedBytePosition = 0; - if (packet.indexOf(":!") > 10) { - encodedBytePosition = packet.indexOf(":!") + 14; - } - if (packet.indexOf(":=") > 10) { - encodedBytePosition = packet.indexOf(":=") + 14; - } - if (encodedBytePosition != 0) { - if (String(packet[encodedBytePosition]) == "G" || String(packet[encodedBytePosition]) == "Q" || String(packet[encodedBytePosition]) == "[" || String(packet[encodedBytePosition]) == "H") { - return decodeEncodedGPS(packet); - } else { - return getReceivedGPS(packet); + String LatSign = String(Latitude[7]); + String LngSign = String(Longitude[8]); + if (LatSign == "S") { + convertedLatitude = -convertedLatitude; + } + if (LngSign == "W") { + convertedLongitude = -convertedLongitude; + } + distance = String(calculateDistanceTo(convertedLatitude, convertedLongitude),1); + return String(convertedLatitude,5) + "N / " + String(convertedLongitude,5) + "E / " + distance + "km"; + } + + String getDistance(String packet) { + int encodedBytePosition = 0; + if (packet.indexOf(":!") > 10) { + encodedBytePosition = packet.indexOf(":!") + 14; + } + if (packet.indexOf(":=") > 10) { + encodedBytePosition = packet.indexOf(":=") + 14; + } + if (encodedBytePosition != 0) { + if (String(packet[encodedBytePosition]) == "G" || String(packet[encodedBytePosition]) == "Q" || String(packet[encodedBytePosition]) == "[" || String(packet[encodedBytePosition]) == "H") { + return decodeEncodedGPS(packet); + } else { + return getReceivedGPS(packet); + } + } else { + return " _ / _ / _ "; } - } else { - return " _ / _ / _ "; } -} } \ No newline at end of file diff --git a/src/gps_utils.h b/src/gps_utils.h index 8dd7390..ea24a3e 100644 --- a/src/gps_utils.h +++ b/src/gps_utils.h @@ -5,14 +5,14 @@ namespace GPS_Utils { -String double2string(double n, int ndec); -String processLatitudeAPRS(); -String processLongitudeAPRS(); -String generateBeacon(); -double calculateDistanceCourse(double latitude, double longitude); -String decodeEncodedGPS(String packet); -String getReceivedGPS(String packet); -String getDistance(String packet); + String double2string(double n, int ndec); + String processLatitudeAPRS(); + String processLongitudeAPRS(); + String generateBeacon(); + double calculateDistanceCourse(double latitude, double longitude); + String decodeEncodedGPS(String packet); + String getReceivedGPS(String packet); + String getDistance(String packet); } diff --git a/src/lora_utils.cpp b/src/lora_utils.cpp index b70bce6..15d8ad3 100644 --- a/src/lora_utils.cpp +++ b/src/lora_utils.cpp @@ -78,7 +78,7 @@ namespace LoRa_Utils { } void sendNewPacket(const String &typeOfMessage, const String &newPacket) { - digitalWrite(greenLed,HIGH); + digitalWrite(internalLedPin,HIGH); #if defined(TTGO_T_LORA_V2_1) || defined(HELTEC_V2) LoRa.beginPacket(); LoRa.write('<'); @@ -104,7 +104,7 @@ namespace LoRa_Utils { Serial.println(state); } #endif - digitalWrite(greenLed,LOW); + digitalWrite(internalLedPin,LOW); SYSLOG_Utils::log("LoRa Tx", newPacket,0,0,0); Serial.print("---> LoRa Packet Tx : "); Serial.println(newPacket); diff --git a/src/lora_utils.h b/src/lora_utils.h index b404b3b..ff0a312 100644 --- a/src/lora_utils.h +++ b/src/lora_utils.h @@ -5,12 +5,12 @@ namespace LoRa_Utils { -void setup(); -void sendNewPacket(const String &typeOfMessage, const String &newPacket); -String generatePacket(String aprsisPacket); -String receivePacket(); -void changeFreqTx(); -void changeFreqRx(); + void setup(); + void sendNewPacket(const String &typeOfMessage, const String &newPacket); + String generatePacket(String aprsisPacket); + String receivePacket(); + void changeFreqTx(); + void changeFreqRx(); } diff --git a/src/pins_config.h b/src/pins_config.h index 777916d..278295f 100644 --- a/src/pins_config.h +++ b/src/pins_config.h @@ -9,7 +9,7 @@ #undef LORA_RST // LORA MODULES -#if defined(TTGO_T_LORA_V2_1) || defined(HELTEC_V2) +#if defined(TTGO_T_LORA_V2_1) || defined(HELTEC_V2) || defined(ESP32_DIY_LoRa) #define LORA_SCK 5 // GPIO5 - SX1276 SCK #define LORA_MISO 19 // GPIO19 - SX1276 MISO #define LORA_MOSI 27 // GPIO27 - SX1276 MOSI @@ -29,7 +29,7 @@ #endif // OLED -#ifdef TTGO_T_LORA_V2_1 +#if defined(TTGO_T_LORA_V2_1) || defined(ESP32_DIY_LoRa) #define OLED_SDA 21 #define OLED_SCL 22 #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) @@ -49,12 +49,16 @@ // Led and other stuff #if defined(TTGO_T_LORA_V2_1) || defined(HELTEC_V2) -#define greenLed 25 // Green Led +#define internalLedPin 25 // Green Led #define batteryPin 35 #endif #ifdef HELTEC_V3 -#define greenLed 35 +#define internalLedPin 35 #endif +#ifdef ESP32_DIY_LoRa +#define internalLedPin 2 +#endif + /* (Same pins for LILYGO LoRa32 and ESP32 Wroom Dev ) SX1278-------------------> ESP32 ttgo-lora32-v21 and ESP32 WROOM Dev diff --git a/src/query_utils.cpp b/src/query_utils.cpp index 4785be2..4d689ec 100644 --- a/src/query_utils.cpp +++ b/src/query_utils.cpp @@ -10,40 +10,40 @@ extern int stationMode; namespace QUERY_Utils { -String process(String query, String station, String queryOrigin) { - String answer; - if (query=="?APRS?" || query=="?aprs?" || query=="?Aprs?" || query=="H" || query=="h" || query=="HELP" || query=="Help" || query=="help" || query=="?") { - answer = "?APRSV ?APRSP ?APRSL ?APRSH ?WHERE callsign"; - } else if (query=="?APRSV" || query=="?aprsv" || query=="?Aprsv") { - answer = "CA2RXU_LoRa_iGate 1.2 v" + versionDate + " sM" + String(stationMode); - } else if (query=="?APRSP" || query=="?aprsp" || query=="?Aprsp") { - answer = "iGate QTH: " + String(currentWiFi->latitude,2) + " " + String(currentWiFi->longitude,2); - } else if (query=="?APRSL" || query=="?aprsl" || query=="?Aprsl") { - if (lastHeardStation.size() == 0) { - answer = "No Station Listened in the last " + String(Config.rememberStationTime) + "min."; - } else { - for (int i=0; ilatitude,2) + " " + String(currentWiFi->longitude,2); + } else if (query=="?APRSL" || query=="?aprsl" || query=="?Aprsl") { + if (lastHeardStation.size() == 0) { + answer = "No Station Listened in the last " + String(Config.rememberStationTime) + "min."; + } else { + for (int i=0; i posicion + Serial.println("estaciones escuchadas directo (ultimos 30 min)"); + answer = "?WHERE on development 73!"; + } + for(int i = station.length(); i < 9; i++) { + station += ' '; + } + if (queryOrigin == "APRSIS") { + return Config.callsign + ">APLRG1,TCPIP,qAC::" + station + ":" + answer + "\n"; + } else { //} if (queryOrigin == "LoRa") { + return Config.callsign + ">APLRG1,RFONLY,WIDE1-1::" + station + ":" + answer; } - } else if (query.indexOf("?APRSH") == 0 || query.indexOf("?aprsh") == 0 || query.indexOf("?Aprsh") == 0) { - // sacar callsign despues de ?APRSH - Serial.println("escuchaste a X estacion? en las ultimas 24 o 8 horas?"); - answer = "APRSH on development 73!"; - } else if (query.indexOf("?WHERE") == 0) { - // agregar callsign para completar donde esta X callsign --> posicion - Serial.println("estaciones escuchadas directo (ultimos 30 min)"); - answer = "?WHERE on development 73!"; } - for(int i = station.length(); i < 9; i++) { - station += ' '; - } - if (queryOrigin == "APRSIS") { - return Config.callsign + ">APLRG1,TCPIP,qAC::" + station + ":" + answer + "\n"; - } else { //} if (queryOrigin == "LoRa") { - return Config.callsign + ">APLRG1,RFONLY,WIDE1-1::" + station + ":" + answer; - } -} } \ No newline at end of file diff --git a/src/query_utils.h b/src/query_utils.h index c2c96be..f5586e1 100644 --- a/src/query_utils.h +++ b/src/query_utils.h @@ -5,7 +5,7 @@ namespace QUERY_Utils { -String process(String query, String station, String queryOrigin); + String process(String query, String station, String queryOrigin); } diff --git a/src/station_utils.cpp b/src/station_utils.cpp index e7b7ead..872eba4 100644 --- a/src/station_utils.cpp +++ b/src/station_utils.cpp @@ -12,94 +12,93 @@ extern String fourthLine; namespace STATION_Utils { -void deleteNotHeard() { - for (int i=0; i Listened Station"); + return true; + } + } + Serial.println(" ---> Station not Heard for last 30 min (Not Tx)\n"); + return false; + } + + void checkBuffer() { + for (int i=0; i") == -1) && (packet.indexOf(":`") == -1)) { + String sender = packet.substring(3,packet.indexOf(">")); + String tempAddressee = packet.substring(packet.indexOf("::") + 2); + String addressee = tempAddressee.substring(0,tempAddressee.indexOf(":")); + addressee.trim(); + String message = tempAddressee.substring(tempAddressee.indexOf(":")+1); + //Serial.println(String(millis()) + "," + sender + "," + addressee + "," + message); + packetBuffer.push_back(String(millis()) + "," + sender + "," + addressee + "," + message); + checkBuffer(); } } - lastHeardStation.clear(); - for (int j=0; j Listened Station"); - return true; - } - } - Serial.println(" ---> Station not Heard for last 30 min (Not Tx)\n"); - return false; -} - -void checkBuffer() { - for (int i=0; i") == -1) && (packet.indexOf(":`") == -1)) { - String sender = packet.substring(3,packet.indexOf(">")); - String tempAddressee = packet.substring(packet.indexOf("::") + 2); - String addressee = tempAddressee.substring(0,tempAddressee.indexOf(":")); - addressee.trim(); - String message = tempAddressee.substring(tempAddressee.indexOf(":")+1); - //Serial.println(String(millis()) + "," + sender + "," + addressee + "," + message); - packetBuffer.push_back(String(millis()) + "," + sender + "," + addressee + "," + message); - checkBuffer(); - } -} - } \ No newline at end of file diff --git a/src/station_utils.h b/src/station_utils.h index cfe857a..3b8e825 100644 --- a/src/station_utils.h +++ b/src/station_utils.h @@ -5,11 +5,11 @@ namespace STATION_Utils { -void deleteNotHeard(); -void updateLastHeard(String station); -bool wasHeard(String station); -void checkBuffer(); -void updatePacketBuffer(String packet); + void deleteNotHeard(); + void updateLastHeard(String station); + bool wasHeard(String station); + void checkBuffer(); + void updatePacketBuffer(String packet); } diff --git a/src/syslog_utils.cpp b/src/syslog_utils.cpp index f6715dc..0a4f405 100644 --- a/src/syslog_utils.cpp +++ b/src/syslog_utils.cpp @@ -11,63 +11,63 @@ WiFiUDP udpClient; namespace SYSLOG_Utils { -void log(String type, String packet, int rssi, float snr, int freqError) { - String syslogPacket = "ESP32 LoRa [APRS] - " + Config.callsign + " - "; - if (Config.syslog.active && (stationMode==1 || stationMode==2 || (stationMode==5 && WiFi.status()==WL_CONNECTED))) { - if (type == "APRSIS Tx") { - if (packet.indexOf(":>") > 10) { - syslogPacket += type + " - StartUp STATUS - " + packet.substring(packet.indexOf(":>")+2); - } - } else if (type == "LoRa Rx") { - if (packet.indexOf("::") > 10) { - syslogPacket += type + " - MESSAGE - " + packet.substring(3,packet.indexOf(">")) + " ---> " + packet.substring(packet.indexOf("::")+2); - syslogPacket += " / " + String(rssi) + "dBm / " + String(snr) + "dB / " + String(freqError) + "Hz"; - } else if (packet.indexOf(":!") > 10 || packet.indexOf(":=") > 10) { - syslogPacket += type + " - GPS - " + packet.substring(3,packet.indexOf(">")) + " / "; - if (packet.indexOf("WIDE1-1") > 10) { - syslogPacket += packet.substring(packet.indexOf(">")+1,packet.indexOf(",")) + " / WIDE1-1 / "; - } else { - syslogPacket += packet.substring(packet.indexOf(">")+1,packet.indexOf(":")) + " / _ / "; + void log(String type, String packet, int rssi, float snr, int freqError) { + String syslogPacket = "ESP32 LoRa [APRS] - " + Config.callsign + " - "; + if (Config.syslog.active && (stationMode==1 || stationMode==2 || (stationMode==5 && WiFi.status()==WL_CONNECTED))) { + if (type == "APRSIS Tx") { + if (packet.indexOf(":>") > 10) { + syslogPacket += type + " - StartUp STATUS - " + packet.substring(packet.indexOf(":>")+2); + } + } else if (type == "LoRa Rx") { + if (packet.indexOf("::") > 10) { + syslogPacket += type + " - MESSAGE - " + packet.substring(3,packet.indexOf(">")) + " ---> " + packet.substring(packet.indexOf("::")+2); + syslogPacket += " / " + String(rssi) + "dBm / " + String(snr) + "dB / " + String(freqError) + "Hz"; + } else if (packet.indexOf(":!") > 10 || packet.indexOf(":=") > 10) { + syslogPacket += type + " - GPS - " + packet.substring(3,packet.indexOf(">")) + " / "; + if (packet.indexOf("WIDE1-1") > 10) { + syslogPacket += packet.substring(packet.indexOf(">")+1,packet.indexOf(",")) + " / WIDE1-1 / "; + } else { + syslogPacket += packet.substring(packet.indexOf(">")+1,packet.indexOf(":")) + " / _ / "; + } + syslogPacket += String(rssi) + "dBm / " + String(snr) + "dB / " + String(freqError) + "Hz / " + GPS_Utils::getDistance(packet); + } else if (packet.indexOf(":>") > 10) { + syslogPacket += type + " - STATUS - " + packet.substring(3,packet.indexOf(">")) + " ---> " + packet.substring(packet.indexOf(":>")+2); + syslogPacket += " / " + String(rssi) + "dBm / " + String(snr) + "dB / " + String(freqError) + "Hz"; + } else if (packet.indexOf(":`") > 10) { + syslogPacket += type + " - MIC-E - " + packet.substring(3,packet.indexOf(">")) + " ---> " + packet.substring(packet.indexOf(":`")+2); + syslogPacket += " / " + String(rssi) + "dBm / " + String(snr) + "dB / " + String(freqError) + "Hz"; + } else if (packet.indexOf(":T#") >= 10 && packet.indexOf(":=/") == -1) { + syslogPacket += type + " - TELEMETRY - " + packet.substring(3,packet.indexOf(">")) + " ---> " + packet.substring(packet.indexOf(":T#")+3); + syslogPacket += " / " + String(rssi) + "dBm / " + String(snr) + "dB / " + String(freqError) + "Hz"; + } else if (packet.indexOf(":;") > 10) { + syslogPacket += type + " - OBJECT - " + packet.substring(3,packet.indexOf(">")) + " ---> " + packet.substring(packet.indexOf(":;")+2); + syslogPacket += " / " + String(rssi) + "dBm / " + String(snr) + "dB / " + String(freqError) + "Hz"; + } else { + syslogPacket += type + " - " + packet; + syslogPacket += " / " + String(rssi) + "dBm / " + String(snr) + "dB / " + String(freqError) + "Hz"; + } + } else if (type == "LoRa Tx") { + if (packet.indexOf("RFONLY") > 10) { + syslogPacket += type + " - RFONLY - " + packet.substring(packet.indexOf("::")+2); + } else if (packet.indexOf("::") > 10) { + syslogPacket += type + " - MESSAGE - " + packet.substring(0,packet.indexOf(">")) + " ---> " + packet.substring(packet.indexOf("::")+2); + } else { + syslogPacket += type + " - " + packet; } - syslogPacket += String(rssi) + "dBm / " + String(snr) + "dB / " + String(freqError) + "Hz / " + GPS_Utils::getDistance(packet); - } else if (packet.indexOf(":>") > 10) { - syslogPacket += type + " - STATUS - " + packet.substring(3,packet.indexOf(">")) + " ---> " + packet.substring(packet.indexOf(":>")+2); - syslogPacket += " / " + String(rssi) + "dBm / " + String(snr) + "dB / " + String(freqError) + "Hz"; - } else if (packet.indexOf(":`") > 10) { - syslogPacket += type + " - MIC-E - " + packet.substring(3,packet.indexOf(">")) + " ---> " + packet.substring(packet.indexOf(":`")+2); - syslogPacket += " / " + String(rssi) + "dBm / " + String(snr) + "dB / " + String(freqError) + "Hz"; - } else if (packet.indexOf(":T#") >= 10 && packet.indexOf(":=/") == -1) { - syslogPacket += type + " - TELEMETRY - " + packet.substring(3,packet.indexOf(">")) + " ---> " + packet.substring(packet.indexOf(":T#")+3); - syslogPacket += " / " + String(rssi) + "dBm / " + String(snr) + "dB / " + String(freqError) + "Hz"; - } else if (packet.indexOf(":;") > 10) { - syslogPacket += type + " - OBJECT - " + packet.substring(3,packet.indexOf(">")) + " ---> " + packet.substring(packet.indexOf(":;")+2); - syslogPacket += " / " + String(rssi) + "dBm / " + String(snr) + "dB / " + String(freqError) + "Hz"; } else { - syslogPacket += type + " - " + packet; - syslogPacket += " / " + String(rssi) + "dBm / " + String(snr) + "dB / " + String(freqError) + "Hz"; + syslogPacket = "ERROR - Error in Syslog Packet"; } - } else if (type == "LoRa Tx") { - if (packet.indexOf("RFONLY") > 10) { - syslogPacket += type + " - RFONLY - " + packet.substring(packet.indexOf("::")+2); - } else if (packet.indexOf("::") > 10) { - syslogPacket += type + " - MESSAGE - " + packet.substring(0,packet.indexOf(">")) + " ---> " + packet.substring(packet.indexOf("::")+2); - } else { - syslogPacket += type + " - " + packet; - } - } else { - syslogPacket = "ERROR - Error in Syslog Packet"; + udpClient.beginPacket(Config.syslog.server.c_str(), Config.syslog.port); + udpClient.write((const uint8_t*)syslogPacket.c_str(), syslogPacket.length()); + udpClient.endPacket(); } - udpClient.beginPacket(Config.syslog.server.c_str(), Config.syslog.port); - udpClient.write((const uint8_t*)syslogPacket.c_str(), syslogPacket.length()); - udpClient.endPacket(); } -} -void setup() { - if (Config.syslog.active && (stationMode==1 || stationMode==2 || (stationMode==5 && WiFi.status()==WL_CONNECTED))) { - udpClient.begin(WiFi.localIP(), 0); - Serial.println("init : Syslog Server ... done! (at " + Config.syslog.server + ")"); + void setup() { + if (Config.syslog.active && (stationMode==1 || stationMode==2 || (stationMode==5 && WiFi.status()==WL_CONNECTED))) { + udpClient.begin(WiFi.localIP(), 0); + Serial.println("init : Syslog Server ... done! (at " + Config.syslog.server + ")"); + } } -} } \ No newline at end of file diff --git a/src/syslog_utils.h b/src/syslog_utils.h index 91fafa8..185982b 100644 --- a/src/syslog_utils.h +++ b/src/syslog_utils.h @@ -5,8 +5,8 @@ namespace SYSLOG_Utils { -void log(String type ,String packet, int rssi, float snr, int freqError); -void setup(); + void log(String type ,String packet, int rssi, float snr, int freqError); + void setup(); } diff --git a/src/utils.cpp b/src/utils.cpp index 1deea7c..121112a 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -81,10 +81,10 @@ namespace Utils { void setupDisplay() { setup_display(); - digitalWrite(greenLed,HIGH); + digitalWrite(internalLedPin,HIGH); Serial.println("\nStarting iGate: " + Config.callsign + " Version: " + versionDate); show_display(" LoRa APRS", "", " ( iGATE )", "", "", "Richonguzman / CA2RXU", " " + versionDate, 4000); - digitalWrite(greenLed,LOW); + digitalWrite(internalLedPin,LOW); firstLine = Config.callsign; seventhLine = " listening..."; } diff --git a/src/wifi_utils.cpp b/src/wifi_utils.cpp index 9ec139f..5cf9c18 100644 --- a/src/wifi_utils.cpp +++ b/src/wifi_utils.cpp @@ -13,79 +13,79 @@ extern uint32_t previousWiFiMillis; namespace WIFI_Utils { -void checkWiFi() { - if ((WiFi.status() != WL_CONNECTED) && ((millis() - previousWiFiMillis) >= 30*1000)) { - Serial.print(millis()); - Serial.println("Reconnecting to WiFi..."); - WiFi.disconnect(); - WiFi.reconnect(); - previousWiFiMillis = millis(); - } -} - -void startWiFi() { - int wifiCounter = 0; - if (stationMode!=6) { - WiFi.mode(WIFI_STA); - WiFi.disconnect(); - delay(500); - } - unsigned long start = millis(); - show_display("", "", "Connecting to Wifi:", "", currentWiFi->ssid + " ...", 0); - Serial.print("\nConnecting to WiFi '"); Serial.print(currentWiFi->ssid); Serial.println("' ..."); - WiFi.begin(currentWiFi->ssid.c_str(), currentWiFi->password.c_str()); - while (WiFi.status() != WL_CONNECTED && wifiCounter<2) { - delay(500); - digitalWrite(greenLed,HIGH); - Serial.print('.'); - delay(500); - digitalWrite(greenLed,LOW); - if ((millis() - start) > 10000){ - delay(1000); - if(myWiFiAPIndex >= (myWiFiAPSize-1)) { - myWiFiAPIndex = 0; - if (stationMode==5 || stationMode==6) { - wifiCounter++; - } - } else { - myWiFiAPIndex++; - } - currentWiFi = &Config.wifiAPs[myWiFiAPIndex]; - start = millis(); - Serial.print("\nConnecting to WiFi '"); Serial.print(currentWiFi->ssid); Serial.println("' ..."); - show_display("", "", "Connecting to Wifi:", "", currentWiFi->ssid + " ...", 0); + void checkWiFi() { + if ((WiFi.status() != WL_CONNECTED) && ((millis() - previousWiFiMillis) >= 30*1000)) { + Serial.print(millis()); + Serial.println("Reconnecting to WiFi..."); WiFi.disconnect(); - WiFi.begin(currentWiFi->ssid.c_str(), currentWiFi->password.c_str()); + WiFi.reconnect(); + previousWiFiMillis = millis(); } } - digitalWrite(greenLed,LOW); - if (WiFi.status() == WL_CONNECTED) { - Serial.print("Connected as "); - Serial.println(WiFi.localIP()); - show_display("", "", " Connected!!", "" , " loading ...", 1000); - } else if (WiFi.status() != WL_CONNECTED && stationMode==5) { - Serial.println("\nNot connected to WiFi! (DigiRepeater Mode)"); - show_display("", "", " WiFi Not Connected!", " DigiRepeater MODE" , " loading ...", 2000); - } -} -void setup() { + void startWiFi() { + int wifiCounter = 0; + if (stationMode!=6) { + WiFi.mode(WIFI_STA); + WiFi.disconnect(); + delay(500); + } + unsigned long start = millis(); + show_display("", "", "Connecting to Wifi:", "", currentWiFi->ssid + " ...", 0); + Serial.print("\nConnecting to WiFi '"); Serial.print(currentWiFi->ssid); Serial.println("' ..."); + WiFi.begin(currentWiFi->ssid.c_str(), currentWiFi->password.c_str()); + while (WiFi.status() != WL_CONNECTED && wifiCounter<2) { + delay(500); + digitalWrite(internalLedPin,HIGH); + Serial.print('.'); + delay(500); + digitalWrite(internalLedPin,LOW); + if ((millis() - start) > 10000){ + delay(1000); + if(myWiFiAPIndex >= (myWiFiAPSize-1)) { + myWiFiAPIndex = 0; + if (stationMode==5 || stationMode==6) { + wifiCounter++; + } + } else { + myWiFiAPIndex++; + } + currentWiFi = &Config.wifiAPs[myWiFiAPIndex]; + start = millis(); + Serial.print("\nConnecting to WiFi '"); Serial.print(currentWiFi->ssid); Serial.println("' ..."); + show_display("", "", "Connecting to Wifi:", "", currentWiFi->ssid + " ...", 0); + WiFi.disconnect(); + WiFi.begin(currentWiFi->ssid.c_str(), currentWiFi->password.c_str()); + } + } + digitalWrite(internalLedPin,LOW); + if (WiFi.status() == WL_CONNECTED) { + Serial.print("Connected as "); + Serial.println(WiFi.localIP()); + show_display("", "", " Connected!!", "" , " loading ...", 1000); + } else if (WiFi.status() != WL_CONNECTED && stationMode==5) { + Serial.println("\nNot connected to WiFi! (DigiRepeater Mode)"); + show_display("", "", " WiFi Not Connected!", " DigiRepeater MODE" , " loading ...", 2000); + } + } + + void setup() { if (stationMode==1 || stationMode==2) { - if (stationMode==1) { - Serial.println("stationMode ---> iGate (only Rx)"); - } else { - Serial.println("stationMode ---> iGate (Rx + Tx)"); - } - startWiFi(); - btStop(); + if (stationMode==1) { + Serial.println("stationMode ---> iGate (only Rx)"); + } else { + Serial.println("stationMode ---> iGate (Rx + Tx)"); + } + startWiFi(); + btStop(); } else if (stationMode==3 || stationMode==4) { - if (stationMode==3) { - Serial.println("stationMode ---> DigiRepeater (Rx freq == Tx freq)"); - } else { - Serial.println("stationMode ---> DigiRepeater (Rx freq != Tx freq)"); - } - WiFi.mode(WIFI_OFF); - btStop(); + if (stationMode==3) { + Serial.println("stationMode ---> DigiRepeater (Rx freq == Tx freq)"); + } else { + Serial.println("stationMode ---> DigiRepeater (Rx freq != Tx freq)"); + } + WiFi.mode(WIFI_OFF); + btStop(); } else if (stationMode==5) { Serial.println("stationMode ---> iGate when Wifi/APRS available (DigiRepeater when not)"); } else if (stationMode==6) { @@ -97,6 +97,6 @@ void setup() { show_display("------- ERROR -------", "stationMode Not Valid", "change it on : /data/", "igate_conf.json", 0); while (1); } -} + } } \ No newline at end of file diff --git a/src/wifi_utils.h b/src/wifi_utils.h index cb4375b..fc4c5e9 100644 --- a/src/wifi_utils.h +++ b/src/wifi_utils.h @@ -5,9 +5,9 @@ namespace WIFI_Utils { -void checkWiFi(); -void startWiFi(); -void setup(); + void checkWiFi(); + void startWiFi(); + void setup(); }