From 1a0fffcdfb312d79e0c5f0b4d3b0cdda21a7b280 Mon Sep 17 00:00:00 2001 From: richonguzman Date: Sun, 26 Mar 2023 17:50:32 -0300 Subject: [PATCH] 1.1 --- src/LoRa_APRS_iGate.cpp | 93 +++++++++++++++++++---------------- src/iGate_config.h | 106 ++++++++-------------------------------- src/iGate_config_OLD.h | 15 +----- 3 files changed, 73 insertions(+), 141 deletions(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 1bd507c..3a03ff4 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -12,33 +12,29 @@ #include "iGate_config_OLD.h" WiFiClient espClient; -String ConfigurationFilePath = "/igate_conf.json"; +String ConfigurationFilePath = "/igate_conf.json"; Configuration Config(ConfigurationFilePath); -uint32_t lastTxTime = 0; -static bool beacon_update = true; -unsigned long previousWiFiMillis = 0; -static uint32_t lastRxTxTime = millis(); -static bool displayEcoMode = true; +uint32_t lastTxTime = 0; +static bool beacon_update = true; +unsigned long previousWiFiMillis = 0; +static uint32_t lastRxTxTime = millis(); +//static bool displayEcoMode = true; -static int myWiFiAPIndex = 0; -int myWiFiAPSize = Config.wifiAPs.size(); -WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex]; +static int myWiFiAPIndex = 1; +int myWiFiAPSize = Config.wifiAPs.size(); +WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex]; String firstLine, secondLine, thirdLine, fourthLine; -void load_config() { - Serial.println("cargando configuracion desde SPIFFS"); -} - void setup_wifi() { int status = WL_IDLE_STATUS; - Serial.print("\nConnecting to '"); Serial.print(WIFI_SSID); Serial.println("' WiFi ..."); + Serial.print("\nConnecting to '"); Serial.print(currentWiFi->ssid); Serial.println("' WiFi ..."); WiFi.mode(WIFI_STA); WiFi.disconnect(); delay(100); - WiFi.begin(WIFI_SSID, WIFI_PASSWORD); + WiFi.begin(currentWiFi->ssid.c_str(), currentWiFi->password.c_str()); while (WiFi.status() != WL_CONNECTED) { Serial.print('.'); delay(1000); @@ -50,18 +46,16 @@ void setup_wifi() { void setup_lora() { SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS); LoRa.setPins(LORA_CS, LORA_RST, LORA_IRQ); - - long freq = 433775000; - if (!LoRa.begin(freq)) { + if (!LoRa.begin(Config.loramodule.frequency)) { Serial.println("Starting LoRa failed!"); while (true) { } } - LoRa.setSpreadingFactor(12); - LoRa.setSignalBandwidth(125000); - LoRa.setCodingRate4(5); + LoRa.setSpreadingFactor(Config.loramodule.spreading_factor); + LoRa.setSignalBandwidth(Config.loramodule.signal_bandwidth); + LoRa.setCodingRate4(Config.loramodule.coding_rate4); LoRa.enableCrc(); - LoRa.setTxPower(20); + LoRa.setTxPower(Config.loramodule.power); Serial.println("LoRa init done!\n"); } @@ -69,21 +63,21 @@ void APRS_IS_connect(){ int count = 0; String aprsauth; Serial.println("Connecting to APRS-IS ..."); - while (!espClient.connect(AprsServer.c_str(), AprsServerPort) && count < 20) { + while (!espClient.connect(Config.aprs_is.server.c_str(), Config.aprs_is.port) && count < 20) { Serial.println("Didn't connect with server..."); delay(1000); espClient.stop(); espClient.flush(); Serial.println("Run client.stop"); - Serial.println("Trying to connect with Server: " + String(AprsServer) + " AprsServerPort: " + String(AprsServerPort)); + Serial.println("Trying to connect with Server: " + String(Config.aprs_is.server) + " AprsServerPort: " + String(Config.aprs_is.port)); count++; Serial.println("Try: " + String(count)); } if (count == 20) { Serial.println("Tried: " + String(count) + " FAILED!"); } else { - Serial.println("Connected with Server: '" + String(AprsServer) + "' (port: " + String(AprsServerPort)+ ")"); - aprsauth = "user " + iGateCallsign + " pass " + iGatePasscode + " vers " + AprsSoftwareName + " " + AprsSoftwareVersion + " filter " + AprsFilter + "\n\r"; + Serial.println("Connected with Server: '" + String(Config.aprs_is.server) + "' (port: " + String(Config.aprs_is.port)+ ")"); + aprsauth = "user " + Config.callsign + " pass " + Config.aprs_is.passcode + " vers " + AprsSoftwareName + " " + AprsSoftwareVersion + " filter " + AprsFilter + "\n\r"; espClient.write(aprsauth.c_str()); delay(200); } @@ -94,7 +88,7 @@ String createAPRSPacket(String unprocessedPacket) { int two_dots_position = unprocessedPacket.indexOf(':'); callsign_and_path_tracker = unprocessedPacket.substring(3, two_dots_position); payload_tracker = unprocessedPacket.substring(two_dots_position); - processedPacket = callsign_and_path_tracker + ",qAO," + iGateCallsign + payload_tracker + "\n"; + processedPacket = callsign_and_path_tracker + ",qAO," + Config.callsign + payload_tracker; return processedPacket; } @@ -108,11 +102,11 @@ void validate_and_upload(String packet) { espClient.write(aprsPacket.c_str()); Serial.print("Message uploaded : "); Serial.println(aprsPacket); if (aprsPacket.indexOf("::") >= 10) { - show_display("LoRa iGate: " + iGateCallsign, secondLine, String(aprsPacket.substring(0,aprsPacket.indexOf(">"))) + " MESSAGE", 1000); + show_display("LoRa iGate: " + Config.callsign, secondLine, String(aprsPacket.substring(0,aprsPacket.indexOf(">"))) + " MESSAGE", 1000); } else if (aprsPacket.indexOf(":>") >= 10) { - show_display("LoRa iGate: " + iGateCallsign, secondLine, String(aprsPacket.substring(0,aprsPacket.indexOf(">"))) + " NEW STATUS", 1000); + show_display("LoRa iGate: " + Config.callsign, secondLine, String(aprsPacket.substring(0,aprsPacket.indexOf(">"))) + " NEW STATUS", 1000); } else { - show_display("LoRa iGate: " + iGateCallsign, secondLine, String(aprsPacket.substring(0,aprsPacket.indexOf(">"))) + " GPS BEACON", 1000); + show_display("LoRa iGate: " + Config.callsign, secondLine, String(aprsPacket.substring(0,aprsPacket.indexOf(">"))) + " GPS BEACON", 1000); } } else { @@ -124,12 +118,12 @@ String process_aprsisPacket(String aprsisMessage) { String firstPart, messagePart, newLoraPacket; firstPart = aprsisMessage.substring(0, aprsisMessage.indexOf("*")); messagePart = aprsisMessage.substring(aprsisMessage.indexOf("::")+2); - newLoraPacket = "}" + firstPart + "," + iGateCallsign + "*::" + messagePart + "\n"; + newLoraPacket = "}" + firstPart + "," + Config.callsign + "*::" + messagePart + "\n"; Serial.print(newLoraPacket); return newLoraPacket; } -void showConfig() { +/*void showConfig() { Serial.println(myWiFiAPSize); Serial.println(myWiFiAPIndex); if(myWiFiAPIndex >= (myWiFiAPSize-1)) { @@ -144,12 +138,24 @@ void showConfig() { Serial.println(currentWiFi->latitude); Serial.println(currentWiFi->longitude); Serial.println(Config.callsign); -} + Serial.println(Config.comment); + Serial.println(Config.aprs_is.active); + Serial.println(Config.aprs_is.passcode); + Serial.println(Config.aprs_is.server); + Serial.println(Config.aprs_is.port); + Serial.println(Config.loramodule.frequency); + Serial.println(Config.loramodule.spreading_factor); + Serial.println(Config.loramodule.signal_bandwidth); + Serial.println(Config.loramodule.coding_rate4); + Serial.println(Config.loramodule.power); + Serial.println(Config.display.always_on); + Serial.println(Config.display.timeout); + Serial.println(" "); +}*/ void setup() { Serial.begin(115200); - Serial.println("Starting iGate: " + iGateCallsign + "\n"); - load_config(); + Serial.println("Starting iGate: " + Config.callsign + "\n"); setup_display(); setup_wifi(); btStop(); @@ -157,10 +163,10 @@ void setup() { } void loop() { - showConfig(); - delay(2000); - /*String wifiState, aprsisState; - firstLine = "LoRa iGate: " + iGateCallsign; + //showConfig(); + //delay(2000); + String wifiState, aprsisState; + firstLine = "LoRa iGate: " + Config.callsign; secondLine = " "; thirdLine = " "; fourthLine = " "; @@ -185,8 +191,8 @@ void loop() { while (espClient.connected()) { uint32_t lastRxTx = millis() - lastRxTxTime; - if (displayEcoMode) { - if (lastRxTx >= EcoModeDisplayTime) { + if (Config.display.always_on) { + if (lastRxTx >= Config.display.timeout*1000) { display_toggle(false); } } @@ -201,6 +207,9 @@ void loop() { if (beacon_update) { display_toggle(true); Serial.println("---- Sending iGate Beacon ----"); + //String iGateBeaconPacket = Config.callsign + ">APRS,TCPIP*,qAC,CHILE:=" + currentWiFi->latitude + "L" + currentWiFi->longitude + "&" + Config.comment; + String iGateBeaconPacket = Config.callsign + ">APRS,TCPIP*,qAC,CHILE:=" + Latitude + "L" + Longitude + "&" + Config.comment + "\n"; + Serial.println(iGateBeaconPacket); espClient.write(iGateBeaconPacket.c_str()); lastTxTime = millis(); display_toggle(true); @@ -246,6 +255,4 @@ void loop() { } } } - - */ } \ No newline at end of file diff --git a/src/iGate_config.h b/src/iGate_config.h index a206a84..d916497 100644 --- a/src/iGate_config.h +++ b/src/iGate_config.h @@ -21,15 +21,14 @@ public: int passcode; String server; int port; - }; -class LoRa { +class LoraModule { public: long frequency; - int spreadingFactor; - long signalBandwidth; - int codingRate4; + int spreading_factor; + long signal_bandwidth; + int coding_rate4; int power; }; @@ -45,6 +44,9 @@ public: String callsign; String comment; std::vector wifiAPs; + APRS_IS aprs_is; + LoraModule loramodule; + Display display; Configuration(String &filePath) { _filePath = filePath; @@ -77,90 +79,24 @@ private: wifiAPs.push_back(wifiap); } - callsign = data["callsign"].as(); - comment = data["comment"].as(); + callsign = data["callsign"].as(); + comment = data["comment"].as(); + aprs_is.active = data["aprs_is"]["active"].as(); + aprs_is.passcode = data["aprs_is"]["passcode"].as(); + aprs_is.server = data["aprs_is"]["server"].as(); + aprs_is.port = data["aprs_is"]["port"].as(); - /*conf.aprs_is.active = data["aprs_is"]["active"]; - conf.aprs_is.passcode = data["aprs_is"]["passcode"]; - conf.aprs_is.server = data["aprs_is"]["server"]; - conf.aprs_is.port = data["aprs_is"]["port"]; - - conf.lora.port = data["lora"]["frequency"]; - conf.lora.port = data["lora"]["spreading_factor"]; - conf.lora.port = data["lora"]["signal_bandwidth"]; - conf.lora.port = data["lora"]["coding_rate4"]; - conf.lora.port = data["lora"]["power"]; - - conf.display.always_on = data["display"]["always_on"]; - conf.display.timeout = data["display"]["timeout"];*/ + loramodule.frequency = data["lora"]["frequency"].as(); + loramodule.spreading_factor = data["lora"]["spreading_factor"].as(); + loramodule.signal_bandwidth = data["lora"]["signal_bandwidth"].as(); + loramodule.coding_rate4 = data["lora"]["coding_rate4"].as(); + loramodule.power = data["lora"]["power"].as(); + display.always_on = data["display"]["always_on"].as(); + display.timeout = data["display"]["timeout"].as(); configFile.close(); } }; -#endif - -/*class Configuration { -public: - /*class WiFiAccessPoint { - public: - class WiFiAP { - WiFiAP(): SSID(), Password(), Latitude(), Longitude() { - } - std::string SSID; - std::string Password; - long Latitude; - long Longitude; - } - - WiFiAccessPoint() : active() { - } - bool active; - };*/ - - /*class APRSIS { - public: - APRSIS() : active(), passcode(), server(), port() { - } - bool active; - int passcode; - String server; - int port; - - }; - - class LoRa { - public: - LoRa() : frequency(), power(), spreadingFactor(), signalBandwidth(), codingRate4() { - } - long frequency; - int spreadingFactor; - long signalBandwidth; - int codingRate4; - int power; - }; - - class Display { - public: - Display() : always_on(), timeout() { - } - bool always_on; - int timeout; - }; - - - Configuration() : callsign(), comment() { - } - - String callsign; - String comment; - /// WIFI - std::list beacons; - /// - WiFiAccessPioint wifiap; - APRSIS aprsis; - LoRa lora; - Display display; - -};*/ \ No newline at end of file +#endif \ No newline at end of file diff --git a/src/iGate_config_OLD.h b/src/iGate_config_OLD.h index 9c4d042..685dca3 100644 --- a/src/iGate_config_OLD.h +++ b/src/iGate_config_OLD.h @@ -5,28 +5,17 @@ #define VERSION "V.0.0.1" //MEGA BETA -#define WIFI_SSID "Richon" -#define WIFI_PASSWORD "k4fPnmg5qnyf" - #define BeaconInterval 900000 // 15 minutes = 900000 seg #define WifiCheckInterval 60000 // wificheck after one minute -#define EcoModeDisplayTime 5000 // after 5 segs Display goes off - -const String iGateCallsign = "CD2RXU-11"; // use your own iGate Callsign -const String iGatePasscode = "23201"; // use your one iGate Callsign Passcode -const String AprsServer = "radioaficion.pro"; // write the address of the aprs server near you , like "brazil.aprs2.net"; -const int AprsServerPort = 14580; const String AprsSoftwareName = "ESP32_LoRa_iGate"; const String AprsSoftwareVersion = "0.0.9"; + +const String iGateCallsign = "CD2RXU-11"; // use your own iGate Callsign const int AprsReportingDistance = 20; // kms const String AprsFilter = "t/m/" + iGateCallsign + "/" + (String)AprsReportingDistance; -const String iGateComment = "LoRa_APRS_iGate https://github.com/richonguzman/LoRa_APRS_iGate"; - const String Latitude = "3302.02S"; // write your own iGate latitude and longitude const String Longitude = "07134.42W"; -String iGateBeaconPacket = iGateCallsign + ">APRS,TCPIP*,qAC,CHILE:=" + Latitude + "L" + Longitude+ "&" + iGateComment + "\n"; - #endif \ No newline at end of file