final beta update

This commit is contained in:
richonguzman 2023-03-01 14:58:52 -03:00
parent da560ba300
commit 1e2d8410d7
2 changed files with 94 additions and 77 deletions

View File

@ -1,10 +1,13 @@
#include <Arduino.h> #include <Arduino.h>
#include <WiFi.h> #include <WiFi.h>
#include "time.h"
#include "config.h" #include "config.h"
WiFiClient espClient; WiFiClient espClient;
uint32_t lastTxTime = 0; uint32_t lastTxTime = 0;
static bool beacon_update = true; static bool beacon_update = true;
unsigned long previousWiFiMillis = 0;
void setup_wifi() { void setup_wifi() {
int status = WL_IDLE_STATUS; int status = WL_IDLE_STATUS;
@ -21,10 +24,10 @@ void setup_wifi() {
Serial.println(WiFi.localIP()); Serial.println(WiFi.localIP());
} }
void APRS_connect(){ void APRS_IS_connect(){
int count = 0; int count = 0;
String aprsauth; String aprsauth;
Serial.println("Conectando a APRS-IS"); Serial.println("Connecting to APRS-IS ...");
while (!espClient.connect(AprsServer.c_str(), AprsServerPort) && count < 20) { while (!espClient.connect(AprsServer.c_str(), AprsServerPort) && count < 20) {
Serial.println("Didn't connect with server..."); Serial.println("Didn't connect with server...");
delay(1000); delay(1000);
@ -45,84 +48,91 @@ void APRS_connect(){
} }
} }
void APRS_IS_READ(){ String GetTime() {
String aprsisData = ""; struct tm timeinfo;
String packet = ""; String currentTime, year, month, day, hour, minute, seconds;
String mensaje1 = ""; if(!getLocalTime(&timeinfo)){
String mensaje2 = ""; Serial.println("Failed to obtain time");
String emisario = ""; return "no time info... restarting";
String mensajeRespuesta; ESP.restart();
while (espClient.connected()) {
while (espClient.available()) {
uint32_t lastTx = millis() - lastTxTime;
if (lastTx >= BeaconInterval) {
beacon_update = true;
}
if (beacon_update) {
Serial.println("enviando Beacon Estacion/iGate");
espClient.write(WeatherReportBeaconPacket.c_str());
lastTxTime = millis();
beacon_update = false;
}
// ver como responder el ack !!!
aprsisData = espClient.readStringUntil('\n');
Serial.println(aprsisData);
packet.concat(aprsisData);
if (packet.indexOf("WRCLP") > 0){
if (packet.indexOf("::")>0) {
mensaje1 = packet.substring(packet.indexOf("::")+2);
mensaje2 = mensaje1.substring(mensaje1.indexOf(":")+1);
emisario = packet.substring(0,packet.indexOf(">"));
Serial.print("--> es un mensaje para WRCLP = ");
Serial.println(mensaje2);
Serial.print("--> enviado por : ");
Serial.println(emisario);
for(int i = emisario.length(); i < 9; i++) {
emisario += ' ';
}
mensajeRespuesta = "WRCLP>APLG01,TCPIP*,qAC,CHILE::" + emisario + ":" + "hola para ti tambien5" + "\n";
Serial.print(mensajeRespuesta);
espClient.write(mensajeRespuesta.c_str());
}
}
aprsisData = "";
packet = "";
mensaje1 = "";
mensaje2 = "";
emisario = "";
}
} }
year = (String)(timeinfo.tm_year + 1900);
month = (String)(timeinfo.tm_mon+1);
day = (String)(timeinfo.tm_mday);
hour = (String)(timeinfo.tm_hour);
minute = (String)(timeinfo.tm_min);
seconds = (String)(timeinfo.tm_sec);
currentTime = year + "/" + month + "/" + day + " " + hour + ":" + minute + ":" + seconds;
//Serial.println(currentTime);
return currentTime;
} }
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
setup_wifi(); setup_wifi();
btStop(); btStop();
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
GetTime();
Serial.println("Starting Weather Report APRS\n"); Serial.println("Starting Weather Report APRS\n");
APRS_connect();
} }
void loop() { void loop() {
APRS_IS_READ(); unsigned long currentWiFiMillis = millis();
if ((WiFi.status() != WL_CONNECTED) && (currentWiFiMillis - previousWiFiMillis >= WifiCheckInterval)) { // if WiFi is down, try reconnecting
Serial.print(millis());
/*uint32_t lastTx = millis() - lastTxTime; Serial.println("Reconnecting to WiFi...");
if (lastTx >= BeaconInterval) { WiFi.disconnect();
beacon_update = true; WiFi.reconnect();
previousWiFiMillis = currentWiFiMillis;
} }
if (beacon_update) { if (!espClient.connected()) {
Serial.println("enviando Beacon Estacion/iGate"); APRS_IS_connect();
espClient.write(WeatherReportBeaconPacket.c_str()); }
lastTxTime = millis();
beacon_update = false; while (espClient.connected()) {
}*/ while (espClient.available()) {
uint32_t lastTx = millis() - lastTxTime;
if (lastTx >= BeaconInterval) {
beacon_update = true;
}
if (beacon_update) {
Serial.println("---- Sending WeatherReport Beacon ----");
espClient.write(WeatherReportBeaconPacket.c_str());
lastTxTime = millis();
beacon_update = false;
}
String aprsisData, packet, subpacket1, subpacket2, questioner, answerMessage, ackNumber, ackMessage, currentDate;
aprsisData = espClient.readStringUntil('\n');
packet.concat(aprsisData);
if (!packet.startsWith("#")){
Serial.println(packet);
if (packet.indexOf("WRCLP") > 0){
if (packet.indexOf("::")>0) {
subpacket1 = packet.substring(packet.indexOf("::")+2);
subpacket2 = subpacket1.substring(subpacket1.indexOf(":")+1);
questioner = packet.substring(0,packet.indexOf(">"));
for(int i = questioner.length(); i < 9; i++) {
questioner += ' ';
}
if (subpacket2.indexOf("{")>0) { // if questioner solicitates ack
ackNumber = subpacket2.substring(subpacket2.indexOf("{")+1);
ackMessage = "WRCLP>APLG01,TCPIP*,qAC,CHILE::" + questioner + ":ack" + ackNumber + "\n";
Serial.print("---> " + ackMessage);
espClient.write(ackMessage.c_str());
delay(500);
}
currentDate = GetTime();
answerMessage = "WRCLP>APLG01,TCPIP*,qAC,CHILE::" + questioner + ":" + "hola, " + questioner + " " + currentDate + "\n";
Serial.print("-------> " + answerMessage);
espClient.write(answerMessage.c_str());
}
}
}
}
}
} }

View File

@ -6,22 +6,29 @@
#define WIFI_SSID "Richon" #define WIFI_SSID "Richon"
#define WIFI_PASSWORD "k4fPnmg5qnyf" #define WIFI_PASSWORD "k4fPnmg5qnyf"
#define BeaconInterval 900000 // 15 minutes = 900000 seg #define BeaconInterval 900000 // 15 minutes = 900000 seg
#define WifiCheckInterval 60000 // wificheck after one minute
const String WeatherReportCallsign = "WRCLP"; const String WeatherReportCallsign = "WRCLP";
const String WeatherReportPasscode = "14332"; const String WeatherReportPasscode = "14332";
const String AprsServer = "radioaficion.pro"; // write the address of the aprs server //const String SERVER = "brazil.aprs2.net"; const String AprsServer = "radioaficion.pro"; // write the address of the aprs server //const String SERVER = "brazil.aprs2.net";
const int AprsServerPort = 14580; // 14579 port is allready filtered so use 14580 const int AprsServerPort = 14580; // 14579 port is allready filtered so use 14580
const String AprsSoftwareName = "ESP32_TEST"; const String AprsSoftwareName = "ESP32_TEST";
const String AprsSoftwareVersion = "0.1.0"; const String AprsSoftwareVersion = "0.1.0";
const int ReportingDistance = 30; const int ReportingDistance = 30; // kms
const String AprsFilter = "t/poms/CD2RXU-10/50"; //cambio a : "t/poms/" + WeatherReportCallsign + "/" + String(ReportingDistance) const String AprsFilter = "t/poms/CD2RXU-10/50"; //cambio a : "t/poms/" + WeatherReportCallsign + "/" + String(ReportingDistance)
const String WeatherReportComment = "LoRa APRS Weather Report https://github.com/richonguzman/ESP32_APRS_Weather_Report"; const String WeatherReportComment = "LoRa APRS Weather Report https://github.com/richonguzman/ESP32_APRS_Weather_Report";
const String LAT = "3302.03S"; // por corregir // write your latitude const String LAT = "3302.04S"; // por corregir // write your own latitude!!!!
const String LON = "07134.42W"; //por corregir const String LON = "07134.43W"; // por corregir
String WeatherReportBeaconPacket = WeatherReportCallsign + ">APRS,TCPIP*,qAC,CHILE:=" + LAT + "/" + LON + "?" + WeatherReportComment + "\n";
const char* ntpServer = "pool.ntp.org";
const long GMT = -3; // GMT -3
const long gmtOffset_sec = GMT*60*60;
const int daylightOffset_sec = 3600;
String WeatherReportBeaconPacket = WeatherReportCallsign + ">APLG01,TCPIP*,qAC,CHILE:=" + LAT + "L" + LON + "&" + WeatherReportComment + "\n";
#endif #endif