This commit is contained in:
richonguzman 2023-07-30 17:12:50 -04:00
parent ddee75e95b
commit 5ee4418d5b
4 changed files with 65 additions and 31 deletions

View file

@ -5,7 +5,7 @@
"wifi": {
"AP": [
{ "ssid": "Richon",
"password": "k4fPnmg5qny",
"password": "k4fPnmg5qnyf",
"latitude": -33.0337313,
"longitude": -71.5737261
},
@ -22,7 +22,7 @@
"longitude": -71.1202063
},
"aprs_is": {
"passcode": "23201",
"passcode": "23202",
"server": "euro.aprs2.net",
"port": 14580,
"reportingDistance": 30

View file

@ -20,20 +20,21 @@
Configuration Config;
WiFiClient espClient;
String versionDate = "2023.07.30";
int myWiFiAPIndex = 0;
int myWiFiAPSize = Config.wifiAPs.size();
WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex];
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;
uint32_t lastBeaconTx = 0;
uint32_t previousWiFiMillis = 0;
uint32_t lastScreenOn = millis();
int stationMode = Config.stationMode;
bool statusAfterBoot = true;
bool beaconUpdate = true;
uint32_t lastBeaconTx = 0;
uint32_t previousWiFiMillis = 0;
uint32_t lastScreenOn = millis();
uint32_t lastWiFiCheck = 0;
bool WiFiConnect = true;
uint32_t lastWiFiCheck = 0;
bool WiFiConnect = true;
int lastStationModeState = 1;
String batteryVoltage;
@ -82,7 +83,7 @@ void loop() {
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) {
if (WiFi.status() != WL_CONNECTED && WiFiCheck >= Config.lastWiFiCheck*4*1000) {
WiFiConnect = true;
}
if (WiFiConnect) {
@ -91,17 +92,33 @@ void loop() {
lastWiFiCheck = millis();
WiFiConnect = false;
}
if (WiFi.status() == WL_CONNECTED) { // Modo iGate
Serial.println("conectado a Wifi: " + currentWiFi->ssid);
// probar si pierde wifi que pasa...
// cuanto tiene wifi , tratar de conectarse a APRS IS
// si lo logra --> igate
// si no --------> digirepeater
thirdLine = Utils::getLocalIP();
if (!espClient.connected()) {
APRS_IS_Utils::connect();
}
if (lastStationModeState == 1) {
iGateBeaconPacket = GPS_Utils::generateBeacon();
lastStationModeState = 0;
}
APRS_IS_Utils::checkStatus();
show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0);
while (espClient.connected()) {
Utils::checkDisplayInterval();
Utils::checkBeaconInterval();
APRS_IS_Utils::processLoRaPacket(LoRa_Utils::receivePacket());
if (espClient.available()) {
String aprsisPacket;
aprsisPacket.concat(espClient.readStringUntil('\r'));
APRS_IS_Utils::processAPRSISPacket(aprsisPacket);
}
}
} else { // Modo DigiRepeater
if (lastStationModeState == 0) {
iGateBeaconPacket = GPS_Utils::generateBeacon();
lastStationModeState = 1;
thirdLine = "<< DigiRepeater >>";
}
Utils::checkDisplayInterval();
Utils::checkBeaconInterval();
show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0);

View file

@ -1,9 +1,11 @@
#include <TinyGPS++.h>
#include <WiFi.h>
#include "configuration.h"
#include "gps_utils.h"
extern Configuration Config;
extern WiFi_AP *currentWiFi;
extern WiFiClient espClient;
extern int stationMode;
String distance;
@ -78,7 +80,7 @@ String processLongitudeAPRS(double lon) {
String generateBeacon() {
String stationLatitude, stationLongitude, beaconPacket;
if (stationMode==1 || stationMode==2) {
if (stationMode==1 || stationMode==2 || (stationMode==5 && WiFi.status() == WL_CONNECTED && espClient.connected())) {
stationLatitude = processLatitudeAPRS(currentWiFi->latitude);
stationLongitude = processLongitudeAPRS(currentWiFi->longitude);
beaconPacket = Config.callsign + ">APLRG1,qAC:=" + stationLatitude + "L" + stationLongitude;

View file

@ -6,6 +6,7 @@
#include "configuration.h"
#include "station_utils.h"
#include "battery_utils.h"
#include "aprs_is_utils.h"
#include "syslog_utils.h"
#include "pins_config.h"
#include "wifi_utils.h"
@ -75,9 +76,9 @@ void setupDisplay() {
show_display(" LoRa APRS", " ( iGate )", "", " Richonguzman", " -- CD2RXU --", "", " " + versionDate, 4000);
digitalWrite(greenLed,LOW);
firstLine = Config.callsign;
if (stationMode==3 || stationMode==4) {
/*if (stationMode==3 || stationMode==4) {
thirdLine = "<< DigiRepeater >>";
}
}*/
seventhLine = " listening...";
}
@ -92,7 +93,7 @@ void activeStations() {
void checkBeaconInterval() {
uint32_t lastTx = millis() - lastBeaconTx;
String beaconPacket;
if (lastTx >= Config.beaconInterval*60*1000) {
if (lastTx >= Config.beaconInterval*12*1000) { // 60!!!
beaconUpdate = true;
}
if (beaconUpdate) {
@ -130,6 +131,7 @@ void checkBeaconInterval() {
secondLine = "Rx:" + String(Rx.substring(0,3)) + "." + String(Rx.substring(3,6));
}
secondLine += " Tx:" + String(Tx.substring(0,3)) + "." + String(Tx.substring(3,6));
thirdLine = "<< DigiRepeater >>";
fifthLine = "";
sixthLine = "";
show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "SENDING iGate BEACON", 0);
@ -145,10 +147,25 @@ void checkBeaconInterval() {
LoRa_Utils::changeFreqRx();
}
} else if (stationMode==5) {
if (WiFi.status() != WL_CONNECTED) {
if (WiFi.status() == WL_CONNECTED && espClient.connected()) {
APRS_IS_Utils::checkStatus();
thirdLine = getLocalIP();
if (!Config.bme.active) {
fifthLine = "";
}
sixthLine = "";
show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "SENDING iGate BEACON", 1000);
if (Config.sendBatteryVoltage) {
sixthLine = " (Batt=" + String(BATTERY_Utils::checkVoltages(),2) + "V)";
}
seventhLine = " listening...";
espClient.write((beaconPacket + "\n").c_str());
show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0);
} else {
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));
thirdLine = "<< DigiRepeater >>";
fifthLine = "";
sixthLine = "";
show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "SENDING iGate BEACON", 0);
@ -157,8 +174,6 @@ void checkBeaconInterval() {
}
seventhLine = " listening...";
LoRa_Utils::sendNewPacket("APRS", beaconPacket);
} else {
Serial.println("enviando beacon por APRS WIFI");
}
}
lastBeaconTx = millis();