mirror of
https://github.com/richonguzman/LoRa_APRS_iGate.git
synced 2026-01-23 09:10:15 +01:00
beaconPacket update
This commit is contained in:
parent
1ffe42f45d
commit
bbff189e10
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"callsign": "CD2RXU-10",
|
||||
"comment": "LoRa_APRS_iGate https://github.com/richonguzman/LoRa_APRS_iGate",
|
||||
"comment": "LoRa_APRS_iGate",
|
||||
"wifi": {
|
||||
"AP": [
|
||||
{ "SSID": "Richon",
|
||||
|
|
|
|||
|
|
@ -2,16 +2,13 @@
|
|||
#include <LoRa.h>
|
||||
#include <WiFi.h>
|
||||
#include <vector>
|
||||
|
||||
#include "pins_config.h"
|
||||
//
|
||||
//#include "igate_config.h"
|
||||
//
|
||||
#include "configuration.h"
|
||||
#include "display.h"
|
||||
#include "lora_utils.h"
|
||||
#include "wifi_utils.h"
|
||||
#include "aprs_is_utils.h"
|
||||
#include "gps_utils.h"
|
||||
#include "utils.h"
|
||||
|
||||
/*#include <AsyncTCP.h>
|
||||
|
|
@ -38,31 +35,7 @@ bool statusAfterBoot = Config.statusAfterBoot;
|
|||
std::vector<String> lastHeardStation;
|
||||
std::vector<String> lastHeardStation_temp;
|
||||
|
||||
String firstLine, secondLine, thirdLine, fourthLine, iGateLatitude, iGateLongitude;
|
||||
|
||||
/*void APRS_IS_connect(){
|
||||
int count = 0;
|
||||
String aprsauth;
|
||||
Serial.println("Connecting to APRS-IS ...");
|
||||
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(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(Config.aprs_is.server) + "' (port: " + String(Config.aprs_is.port)+ ")");
|
||||
aprsauth = "user " + Config.callsign + " pass " + Config.aprs_is.passcode + " vers " + Config.aprs_is.softwareName + " " + Config.aprs_is.softwareVersion + " filter t/m/" + Config.callsign + "/" + (String)Config.aprs_is.reportingDistance + "\n\r";
|
||||
espClient.write(aprsauth.c_str());
|
||||
delay(200);
|
||||
}
|
||||
}*/
|
||||
String firstLine, secondLine, thirdLine, fourthLine, iGateBeaconPacket; //iGateLatitude, iGateLongitude;
|
||||
|
||||
String createAPRSPacket(String unprocessedPacket) {
|
||||
String callsign_and_path_tracker, payload_tracker, processedPacket;
|
||||
|
|
@ -237,71 +210,6 @@ String processAPRSISPacket(String aprsisMessage) {
|
|||
return newLoraPacket;
|
||||
}
|
||||
|
||||
String double2string(double n, int ndec) {
|
||||
String r = "";
|
||||
int v = n;
|
||||
r += v;
|
||||
r += '.';
|
||||
int i;
|
||||
for (i=0;i<ndec;i++) {
|
||||
n -= v;
|
||||
n = 10 * abs(n);
|
||||
v = n;
|
||||
r += v;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
String create_lat_aprs(double lat) {
|
||||
String degrees = double2string(lat,6);
|
||||
String north_south, latitude, convDeg3;
|
||||
float convDeg, convDeg2;
|
||||
|
||||
if (abs(degrees.toFloat()) < 10) {
|
||||
latitude += "0";
|
||||
}
|
||||
Serial.println(latitude);
|
||||
if (degrees.indexOf("-") == 0) {
|
||||
north_south = "S";
|
||||
latitude += degrees.substring(1,degrees.indexOf("."));
|
||||
} else {
|
||||
north_south = "N";
|
||||
latitude += degrees.substring(0,degrees.indexOf("."));
|
||||
}
|
||||
convDeg = abs(degrees.toFloat()) - abs(int(degrees.toFloat()));
|
||||
convDeg2 = (convDeg * 60)/100;
|
||||
convDeg3 = String(convDeg2,6);
|
||||
latitude += convDeg3.substring(convDeg3.indexOf(".")+1,convDeg3.indexOf(".")+3) + "." + convDeg3.substring(convDeg3.indexOf(".")+3,convDeg3.indexOf(".")+5);
|
||||
latitude += north_south;
|
||||
return latitude;
|
||||
}
|
||||
|
||||
String create_lng_aprs(double lng) {
|
||||
String degrees = double2string(lng,6);
|
||||
String east_west, longitude, convDeg3;
|
||||
float convDeg, convDeg2;
|
||||
|
||||
if (abs(degrees.toFloat()) < 100) {
|
||||
longitude += "0";
|
||||
}
|
||||
if (abs(degrees.toFloat()) < 10) {
|
||||
longitude += "0";
|
||||
}
|
||||
if (degrees.indexOf("-") == 0) {
|
||||
east_west = "W";
|
||||
longitude += degrees.substring(1,degrees.indexOf("."));
|
||||
} else {
|
||||
east_west = "E";
|
||||
longitude += degrees.substring(0,degrees.indexOf("."));
|
||||
}
|
||||
convDeg = abs(degrees.toFloat()) - abs(int(degrees.toFloat()));
|
||||
convDeg2 = (convDeg * 60)/100;
|
||||
convDeg3 = String(convDeg2,6);
|
||||
longitude += convDeg3.substring(convDeg3.indexOf(".")+1,convDeg3.indexOf(".")+3) + "." + convDeg3.substring(convDeg3.indexOf(".")+3,convDeg3.indexOf(".")+5);
|
||||
longitude += east_west;
|
||||
return longitude;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
|
|
@ -320,8 +228,9 @@ void setup() {
|
|||
Serial.println("HTTP server started");*/
|
||||
|
||||
LoRaUtils::setup();
|
||||
iGateLatitude = create_lat_aprs(currentWiFi->latitude);
|
||||
iGateLongitude = create_lng_aprs(currentWiFi->longitude);
|
||||
iGateBeaconPacket = GPS_Utils::generateBeacon();
|
||||
//iGateLatitude = GPS_Utils::processLatitudeAPRS();
|
||||
//iGateLongitude = GPS_Utils::processLongitudeAPRS();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
|
@ -387,12 +296,13 @@ void loop() {
|
|||
if (beacon_update) {
|
||||
display_toggle(true);
|
||||
Serial.println("---- Sending iGate Beacon ----");
|
||||
String iGateBeaconPacket = Config.callsign + ">APLR10,";
|
||||
/*String iGateBeaconPacket = Config.callsign + ">APLR10,qAC:=";
|
||||
if (Config.loramodule.enableTx) {
|
||||
iGateBeaconPacket += "qAC:=" + iGateLatitude + "L" + iGateLongitude + "a" + Config.comment;
|
||||
iGateBeaconPacket += iGateLatitude + "L" + iGateLongitude + "a";
|
||||
} else {
|
||||
iGateBeaconPacket += "qAC:=" + iGateLatitude + "L" + iGateLongitude + "&" + Config.comment;
|
||||
iGateBeaconPacket += iGateLatitude + "L" + iGateLongitude + "&";
|
||||
}
|
||||
iGateBeaconPacket += Config.comment;*/
|
||||
//Serial.println(iGateBeaconPacket);
|
||||
espClient.write((iGateBeaconPacket + "\n").c_str());
|
||||
lastTxTime = millis();
|
||||
|
|
|
|||
89
src/gps_utils.cpp
Normal file
89
src/gps_utils.cpp
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
#include "gps_utils.h"
|
||||
#include "configuration.h"
|
||||
|
||||
extern Configuration Config;
|
||||
extern WiFi_AP *currentWiFi;
|
||||
extern int myWiFiAPIndex;
|
||||
extern int myWiFiAPSize;
|
||||
|
||||
namespace GPS_Utils {
|
||||
|
||||
String double2string(double n, int ndec) {
|
||||
String r = "";
|
||||
int v = n;
|
||||
r += v;
|
||||
r += '.';
|
||||
int i;
|
||||
for (i=0;i<ndec;i++) {
|
||||
n -= v;
|
||||
n = 10 * abs(n);
|
||||
v = n;
|
||||
r += v;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
String processLatitudeAPRS() {
|
||||
String degrees = double2string(currentWiFi->latitude,6);
|
||||
String north_south, latitude, convDeg3;
|
||||
float convDeg, convDeg2;
|
||||
|
||||
if (abs(degrees.toFloat()) < 10) {
|
||||
latitude += "0";
|
||||
}
|
||||
Serial.println(latitude);
|
||||
if (degrees.indexOf("-") == 0) {
|
||||
north_south = "S";
|
||||
latitude += degrees.substring(1,degrees.indexOf("."));
|
||||
} else {
|
||||
north_south = "N";
|
||||
latitude += degrees.substring(0,degrees.indexOf("."));
|
||||
}
|
||||
convDeg = abs(degrees.toFloat()) - abs(int(degrees.toFloat()));
|
||||
convDeg2 = (convDeg * 60)/100;
|
||||
convDeg3 = String(convDeg2,6);
|
||||
latitude += convDeg3.substring(convDeg3.indexOf(".")+1,convDeg3.indexOf(".")+3) + "." + convDeg3.substring(convDeg3.indexOf(".")+3,convDeg3.indexOf(".")+5);
|
||||
latitude += north_south;
|
||||
return latitude;
|
||||
}
|
||||
|
||||
String processLongitudeAPRS() {
|
||||
String degrees = double2string(currentWiFi->longitude,6);
|
||||
String east_west, longitude, convDeg3;
|
||||
float convDeg, convDeg2;
|
||||
|
||||
if (abs(degrees.toFloat()) < 100) {
|
||||
longitude += "0";
|
||||
}
|
||||
if (abs(degrees.toFloat()) < 10) {
|
||||
longitude += "0";
|
||||
}
|
||||
if (degrees.indexOf("-") == 0) {
|
||||
east_west = "W";
|
||||
longitude += degrees.substring(1,degrees.indexOf("."));
|
||||
} else {
|
||||
east_west = "E";
|
||||
longitude += degrees.substring(0,degrees.indexOf("."));
|
||||
}
|
||||
convDeg = abs(degrees.toFloat()) - abs(int(degrees.toFloat()));
|
||||
convDeg2 = (convDeg * 60)/100;
|
||||
convDeg3 = String(convDeg2,6);
|
||||
longitude += convDeg3.substring(convDeg3.indexOf(".")+1,convDeg3.indexOf(".")+3) + "." + convDeg3.substring(convDeg3.indexOf(".")+3,convDeg3.indexOf(".")+5);
|
||||
longitude += east_west;
|
||||
return longitude;
|
||||
}
|
||||
|
||||
String generateBeacon() {
|
||||
String iGateLat = processLatitudeAPRS();
|
||||
String iGateLon = processLongitudeAPRS();
|
||||
String beaconPacket = Config.callsign + ">APLR10,qAC:=";
|
||||
if (Config.loramodule.enableTx) {
|
||||
beaconPacket += iGateLat + "L" + iGateLon + "a";
|
||||
} else {
|
||||
beaconPacket += iGateLat + "L" + iGateLon + "&";
|
||||
}
|
||||
beaconPacket += Config.comment;
|
||||
return beaconPacket;
|
||||
}
|
||||
|
||||
}
|
||||
15
src/gps_utils.h
Normal file
15
src/gps_utils.h
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#ifndef GPS_UTILS_H_
|
||||
#define GPS_UTILS_H_
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
namespace GPS_Utils {
|
||||
|
||||
String double2string(double n, int ndec);
|
||||
String processLatitudeAPRS();
|
||||
String processLongitudeAPRS();
|
||||
String generateBeacon();
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,116 +0,0 @@
|
|||
#ifndef IGATE_CONFIG_H_
|
||||
#define IGATE_CONFIG_H_
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <SPIFFS.h>
|
||||
#include <FS.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <vector>
|
||||
|
||||
class WiFi_AP {
|
||||
public:
|
||||
String ssid;
|
||||
String password;
|
||||
double latitude;
|
||||
double longitude;
|
||||
};
|
||||
|
||||
class APRS_IS {
|
||||
public:
|
||||
int passcode;
|
||||
String server;
|
||||
int port;
|
||||
String softwareName;
|
||||
String softwareVersion;
|
||||
int reportingDistance;
|
||||
};
|
||||
|
||||
class LoraModule {
|
||||
public:
|
||||
bool enableTx;
|
||||
long frequency;
|
||||
int spreadingFactor;
|
||||
long signalBandwidth;
|
||||
int codingRate4;
|
||||
int power;
|
||||
};
|
||||
|
||||
class Display {
|
||||
public:
|
||||
bool alwaysOn;
|
||||
bool keepLastPacketOnScreen;
|
||||
int timeout;
|
||||
};
|
||||
|
||||
class Configuration {
|
||||
public:
|
||||
|
||||
String callsign;
|
||||
String comment;
|
||||
int beaconInterval;
|
||||
bool statusAfterBoot;
|
||||
String defaultStatus;
|
||||
std::vector<WiFi_AP> wifiAPs;
|
||||
APRS_IS aprs_is;
|
||||
LoraModule loramodule;
|
||||
Display display;
|
||||
|
||||
Configuration(String &filePath) {
|
||||
_filePath = filePath;
|
||||
if (!SPIFFS.begin(false)) {
|
||||
Serial.println("SPIFFS Mount Failed");
|
||||
return;
|
||||
}
|
||||
readFile(SPIFFS, _filePath.c_str());
|
||||
}
|
||||
|
||||
private:
|
||||
String _filePath;
|
||||
|
||||
void readFile(fs::FS &fs, const char *fileName) {
|
||||
StaticJsonDocument<1536> data;
|
||||
File configFile = fs.open(fileName, "r");
|
||||
DeserializationError error = deserializeJson(data, configFile);
|
||||
if (error) {
|
||||
Serial.println("Failed to read file, using default configuration");
|
||||
}
|
||||
|
||||
JsonArray WiFiArray = data["wifi"]["AP"];
|
||||
for (int i = 0; i < WiFiArray.size(); i++) {
|
||||
WiFi_AP wifiap;
|
||||
wifiap.ssid = WiFiArray[i]["SSID"].as<String>();
|
||||
wifiap.password = WiFiArray[i]["Password"].as<String>();
|
||||
wifiap.latitude = WiFiArray[i]["Latitude"].as<double>();
|
||||
wifiap.longitude = WiFiArray[i]["Longitude"].as<double>();
|
||||
|
||||
wifiAPs.push_back(wifiap);
|
||||
}
|
||||
|
||||
callsign = data["callsign"].as<String>();
|
||||
comment = data["comment"].as<String>();
|
||||
beaconInterval = data["other"]["beaconInterval"].as<int>();
|
||||
statusAfterBoot = data["other"]["statusAfterBoot"].as<bool>();
|
||||
defaultStatus = data["other"]["defaultStatus"].as<String>();
|
||||
|
||||
aprs_is.passcode = data["aprs_is"]["passcode"].as<int>();
|
||||
aprs_is.server = data["aprs_is"]["server"].as<String>();
|
||||
aprs_is.port = data["aprs_is"]["port"].as<int>();
|
||||
aprs_is.softwareName = data["aprs_is"]["softwareName"].as<String>();
|
||||
aprs_is.softwareVersion = data["aprs_is"]["softwareVersion"].as<String>();
|
||||
aprs_is.reportingDistance = data["aprs_is"]["reportingDistance"].as<int>();
|
||||
|
||||
loramodule.enableTx = data["lora"]["enableTx"].as<bool>();
|
||||
loramodule.frequency = data["lora"]["frequency"].as<long>();
|
||||
loramodule.spreadingFactor = data["lora"]["spreadingFactor"].as<int>();
|
||||
loramodule.signalBandwidth = data["lora"]["signalBandwidth"].as<long>();
|
||||
loramodule.codingRate4 = data["lora"]["codingRate4"].as<int>();
|
||||
loramodule.power = data["lora"]["power"].as<int>();
|
||||
|
||||
display.alwaysOn = data["display"]["alwaysOn"].as<bool>();
|
||||
display.keepLastPacketOnScreen = data["display"]["keepLastPacketOnScreen"].as<bool>();
|
||||
display.timeout = data["display"]["timeout"].as<int>();
|
||||
|
||||
configFile.close();
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
#include <LoRa.h>
|
||||
//#include "igate_config.h"
|
||||
#include "configuration.h"
|
||||
#include "display.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
#include <WiFi.h>
|
||||
#include <Arduino.h>
|
||||
//#include <igate_config.h>
|
||||
#include "configuration.h"
|
||||
#include "utils.h"
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue