diff --git a/data/igate_conf.json b/data/igate_conf.json index 070f994..2a28328 100644 --- a/data/igate_conf.json +++ b/data/igate_conf.json @@ -1,14 +1,14 @@ { - "callsign": "NOCALL-10", - "stationMode": 1, - "iGateComment": "LoRa_APRS_iGate", - "wifi": { - "AP": [ - { "ssid": "WIFI_1", - "password": "password_1", - "latitude": 0.0000000, - "longitude": 0.0000000 - }, + "callsign": "CD2RXU-11", + "stationMode": 5, + "iGateComment": "LoRa_APRS_iGate", + "wifi": { + "AP": [ + { "ssid": "Richon", + "password": "k4fPnmg5qny", + "latitude": -33.0337313, + "longitude": -71.5737261 + }, { "ssid": "WIFI_2", "password": "password_2", "latitude": 0.0000000, @@ -18,11 +18,11 @@ }, "digi": { "comment": "LoRa_APRS_Digirepeater", - "latitude": 0.0000000, - "longitude": 0.0000000 + "latitude": -32.9543284, + "longitude": -71.1202063 }, "aprs_is": { - "passcode": "VWXYZ", + "passcode": "23201", "server": "euro.aprs2.net", "port": 14580, "reportingDistance": 30 @@ -49,7 +49,8 @@ "other": { "beaconInterval": 15, "rememberStationTime": 30, - "sendBatteryVoltage": false + "sendBatteryVoltage": false, + "lastWiFiCheck": 15 }, "bme": { "active": false diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 09cbf86..164bd40 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -20,18 +20,21 @@ Configuration Config; WiFiClient espClient; -String versionDate = "2023.07.17"; +String versionDate = "2023.07.30"; int myWiFiAPIndex = 0; int myWiFiAPSize = Config.wifiAPs.size(); WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex]; int stationMode = Config.stationMode; bool statusAfterBoot = true; -bool beaconUpdate = true; +bool beaconUpdate = true; uint32_t lastBeaconTx = 0; uint32_t previousWiFiMillis = 0; uint32_t lastScreenOn = millis(); +uint32_t lastWiFiCheck = 0; +bool WiFiConnect = true; + String batteryVoltage; std::vector lastHeardStation; @@ -77,5 +80,38 @@ void loop() { Utils::checkBeaconInterval(); show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0); DIGI_Utils::processPacket(LoRa_Utils::receivePacket()); + } else if (stationMode==5) { + uint32_t WiFiCheck = millis() - lastWiFiCheck; + if (WiFi.status() != WL_CONNECTED && WiFiCheck >= Config.lastWiFiCheck*33*1000) { + WiFiConnect = true; + } + if (WiFiConnect) { + Serial.println("\n\n###############\ncomenzando nueva revision\n###############"); + WIFI_Utils::startWiFi2(); + lastWiFiCheck = millis(); + WiFiConnect = false; + } + + if (WiFi.status() == WL_CONNECTED) { // Modo iGate + Serial.println("conectado"); + } else { // Modo DigiRepeater + Utils::checkDisplayInterval(); + Utils::checkBeaconInterval(); + show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0); + DIGI_Utils::processPacket(LoRa_Utils::receivePacket()); + } + + /* si wifi + si aprs --> igate + else --> digi/exit + else--> be digi + */ + + /*if (!espClient.connected()) { + APRS_IS_Utils::connect(); + + // if aprsis ok --> be igate + // else --> be digirepeater + }*/ } } \ No newline at end of file diff --git a/src/configuration.cpp b/src/configuration.cpp index 2d90496..d6fe8b2 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -37,6 +37,7 @@ void Configuration::readFile(fs::FS &fs, const char *fileName) { beaconInterval = data["other"]["beaconInterval"].as(); rememberStationTime = data["other"]["rememberStationTime"].as(); sendBatteryVoltage = data["other"]["sendBatteryVoltage"].as(); + lastWiFiCheck = data["other"]["lastWiFiCheck"].as(); digi.comment = data["digi"]["comment"].as(); digi.latitude = data["digi"]["latitude"].as(); diff --git a/src/configuration.h b/src/configuration.h index 6d439de..f0779c8 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -67,6 +67,7 @@ public: int beaconInterval; int rememberStationTime; bool sendBatteryVoltage; + int lastWiFiCheck; std::vector wifiAPs; DIGI digi; APRS_IS aprs_is; diff --git a/src/digi_utils.cpp b/src/digi_utils.cpp index a705f32..baf78f7 100644 --- a/src/digi_utils.cpp +++ b/src/digi_utils.cpp @@ -20,7 +20,7 @@ void processPacket(String packet) { String sender = packet.substring(3,packet.indexOf(">")); STATION_Utils::updateLastHeard(sender); Utils::typeOfPacket(packet, "Digi"); - if ((stationMode==3) && (packet.indexOf("WIDE1-1") > 10)) { + if ((stationMode==3 || stationMode==5) && (packet.indexOf("WIDE1-1") > 10)) { loraPacket = packet.substring(3); loraPacket.replace("WIDE1-1", Config.callsign + "*"); delay(500); diff --git a/src/utils.cpp b/src/utils.cpp index 0f1cab1..f6f1c59 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -137,21 +137,36 @@ void checkBeaconInterval() { sixthLine = " (Batt=" + String(BATTERY_Utils::checkVoltages(),2) + "V)"; } seventhLine = " listening..."; - if (stationMode == 4) { + if (stationMode==4) { LoRa_Utils::changeFreqTx(); } LoRa_Utils::sendNewPacket("APRS", beaconPacket); - if (stationMode == 4) { + if (stationMode==4) { LoRa_Utils::changeFreqRx(); - } + } + } else if (stationMode==5) { + if (WiFi.status() != WL_CONNECTED) { + String Tx = String(Config.loramodule.digirepeaterTxFreq); + secondLine = "Rx:" + String(Tx.substring(0,3)) + "." + String(Tx.substring(3,6)); + secondLine += " Tx:" + String(Tx.substring(0,3)) + "." + String(Tx.substring(3,6)); + fifthLine = ""; + sixthLine = ""; + show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "SENDING iGate BEACON", 0); + if (Config.sendBatteryVoltage) { + sixthLine = " (Batt=" + String(BATTERY_Utils::checkVoltages(),2) + "V)"; + } + seventhLine = " listening..."; + LoRa_Utils::sendNewPacket("APRS", beaconPacket); + } else { + Serial.println("enviando beacon por APRS WIFI"); + } } lastBeaconTx = millis(); lastScreenOn = millis(); beaconUpdate = false; - } if (statusAfterBoot) { - processStatus(); + //processStatus(); } } diff --git a/src/wifi_utils.cpp b/src/wifi_utils.cpp index 30b224a..90bc783 100644 --- a/src/wifi_utils.cpp +++ b/src/wifi_utils.cpp @@ -30,7 +30,7 @@ void startWiFi() { delay(500); unsigned long start = millis(); show_display("", "", "Connecting to Wifi:", "", currentWiFi->ssid + " ...", 0); - Serial.print("\nConnecting to '"); Serial.print(currentWiFi->ssid); Serial.println("' WiFi ..."); + 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) { delay(500); @@ -59,6 +59,48 @@ void startWiFi() { show_display("", "", " Connected!!", "" , " loading ...", 1000); } +void startWiFi2() { + int wifiCounter = 0; + int status = WL_IDLE_STATUS; + 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; + 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()); + } + } + if (WiFi.status() == WL_CONNECTED) { + digitalWrite(greenLed,LOW); + Serial.print("Connected as "); + Serial.println(WiFi.localIP()); + show_display("", "", " Connected!!", "" , " loading ...", 1000); + } else { + show_display("", "", " WiFi Not Connected!", " DigiRepeater MODE" , " loading ...", 2000); + } +} + void setup() { if (stationMode == 1 || stationMode == 2) { if (stationMode==1) { @@ -76,10 +118,12 @@ void setup() { } WiFi.mode(WIFI_OFF); btStop(); + } else if (stationMode == 5) { + Serial.println("stationMode ---> iGate when Wifi/APRS available (DigiRepeater when not)"); } else { - Serial.println("stationMode ---> NOT VALID, check '/data/igate_conf.json'"); - show_display("------- ERROR -------", "stationMode Not Valid", "change it on : /data/", "igate_conf.json", 0); - while (1); + Serial.println("stationMode ---> NOT VALID, check '/data/igate_conf.json'"); + show_display("------- ERROR -------", "stationMode Not Valid", "change it on : /data/", "igate_conf.json", 0); + while (1); } } diff --git a/src/wifi_utils.h b/src/wifi_utils.h index cb4375b..2a4a5de 100644 --- a/src/wifi_utils.h +++ b/src/wifi_utils.h @@ -7,6 +7,7 @@ namespace WIFI_Utils { void checkWiFi(); void startWiFi(); +void startWiFi2(); void setup(); }