2023-02-20 01:15:28 +01:00
|
|
|
#include <Arduino.h>
|
2023-02-10 11:56:22 +01:00
|
|
|
#include <WiFi.h>
|
2023-02-22 11:30:45 +01:00
|
|
|
#include "config.h"
|
2023-02-10 11:56:22 +01:00
|
|
|
|
|
|
|
|
WiFiClient espClient;
|
2023-02-10 20:18:50 +01:00
|
|
|
uint32_t lastTxTime = 0;
|
2023-02-22 11:57:38 +01:00
|
|
|
static bool beacon_update = true;
|
2023-02-10 20:18:50 +01:00
|
|
|
|
2023-02-10 11:56:22 +01:00
|
|
|
void setup_wifi() {
|
2023-02-11 21:05:49 +01:00
|
|
|
int status = WL_IDLE_STATUS;
|
2023-02-10 11:56:22 +01:00
|
|
|
WiFi.mode(WIFI_STA);
|
|
|
|
|
WiFi.disconnect();
|
|
|
|
|
delay(100);
|
|
|
|
|
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
|
|
|
|
Serial.print("\nConnecting to '"); Serial.print(WIFI_SSID); Serial.println("' WiFi ...");
|
|
|
|
|
while (WiFi.status() != WL_CONNECTED) {
|
|
|
|
|
Serial.print('.');
|
|
|
|
|
delay(1000);
|
|
|
|
|
}
|
|
|
|
|
Serial.print("Connected as ");
|
|
|
|
|
Serial.println(WiFi.localIP());
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 01:15:28 +01:00
|
|
|
void APRS_connect(){
|
2023-02-17 17:26:35 +01:00
|
|
|
int count = 0;
|
|
|
|
|
String aprsauth;
|
|
|
|
|
Serial.println("Conectando a APRS-IS");
|
2023-02-22 11:57:38 +01:00
|
|
|
while (!espClient.connect(AprsServer.c_str(), AprsServerPort) && count < 20) {
|
|
|
|
|
Serial.println("Didn't connect with server...");
|
2023-02-17 17:26:35 +01:00
|
|
|
delay(1000);
|
|
|
|
|
espClient.stop();
|
|
|
|
|
espClient.flush();
|
|
|
|
|
Serial.println("Run client.stop");
|
2023-02-22 11:57:38 +01:00
|
|
|
Serial.println("Trying to connect with Server: " + String(AprsServer) + " AprsServerPort: " + String(AprsServerPort));
|
2023-02-17 17:26:35 +01:00
|
|
|
count++;
|
|
|
|
|
Serial.println("Try: " + String(count));
|
|
|
|
|
}
|
|
|
|
|
if (count == 20) {
|
2023-02-22 11:57:38 +01:00
|
|
|
Serial.println("Tried: " + String(count) + " FAILED!");
|
2023-02-17 17:26:35 +01:00
|
|
|
} else {
|
2023-02-22 11:57:38 +01:00
|
|
|
Serial.println("Connected with Server: " + String(AprsServer) + " Port: " + String(AprsServerPort));
|
|
|
|
|
aprsauth = "user " + WeatherReportCallsign + " pass " + WeatherReportPasscode + " vers " + AprsSoftwareName + " " + AprsSoftwareVersion + " filter " + AprsFilter + "\n\r";
|
2023-02-20 01:15:28 +01:00
|
|
|
espClient.write(aprsauth.c_str());
|
|
|
|
|
delay(200);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void APRS_IS_READ(){
|
|
|
|
|
String aprsisData;
|
|
|
|
|
while (espClient.connected()) {
|
2023-02-20 12:29:24 +01:00
|
|
|
while (espClient.available() > 0) {
|
|
|
|
|
char c = espClient.read();
|
|
|
|
|
if (c == '\n') {
|
|
|
|
|
Serial.print(aprsisData);
|
|
|
|
|
aprsisData = "";
|
|
|
|
|
}
|
|
|
|
|
aprsisData += c;
|
2023-02-17 17:26:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-10 12:39:12 +01:00
|
|
|
void setup() {
|
|
|
|
|
Serial.begin(115200);
|
|
|
|
|
setup_wifi();
|
|
|
|
|
btStop();
|
2023-02-22 11:57:38 +01:00
|
|
|
Serial.println("Starting Weather Report APRS\n");
|
2023-02-20 12:29:24 +01:00
|
|
|
APRS_connect();
|
2023-02-10 12:39:12 +01:00
|
|
|
}
|
|
|
|
|
|
2023-02-10 11:56:22 +01:00
|
|
|
void loop() {
|
2023-02-20 12:29:24 +01:00
|
|
|
APRS_IS_READ();
|
2023-02-17 17:26:35 +01:00
|
|
|
|
2023-02-22 11:57:38 +01:00
|
|
|
uint32_t lastTx = millis() - lastTxTime;
|
2023-02-11 21:05:49 +01:00
|
|
|
if (lastTx >= BeaconInterval) {
|
2023-02-11 20:47:08 +01:00
|
|
|
beacon_update = true;
|
2023-02-11 22:18:34 +01:00
|
|
|
}
|
2023-02-11 20:47:08 +01:00
|
|
|
|
|
|
|
|
if (beacon_update) {
|
2023-02-10 20:18:50 +01:00
|
|
|
Serial.println("enviando Beacon Estacion/iGate");
|
2023-02-22 11:57:38 +01:00
|
|
|
espClient.write(WeatherReportBeaconPacket.c_str());
|
2023-02-10 20:18:50 +01:00
|
|
|
lastTxTime = millis();
|
2023-02-11 20:47:08 +01:00
|
|
|
beacon_update = false;
|
2023-02-22 11:57:38 +01:00
|
|
|
}
|
2023-02-10 11:56:22 +01:00
|
|
|
}
|