mayor code cleaning

This commit is contained in:
richonguzman 2024-05-13 23:30:15 -04:00
parent 794cc0640f
commit 0be60b76b0
16 changed files with 40 additions and 66 deletions

View File

@ -345,9 +345,7 @@
WiFi Access WiFi Access
</h5> </h5>
<small <small
>Add all Wi-Fi Networks intended to be used, >Add all Wi-Fi Networks intended to be used.</small
and their respective coordinates to
georeference the iGate location.</small
> >
</div> </div>
<div class="col-lg-9 col-sm-12"> <div class="col-lg-9 col-sm-12">

View File

@ -13,6 +13,7 @@ default_envs = ttgo-lora32-v21
[env] [env]
platform = espressif32 @ 6.3.1 platform = espressif32 @ 6.3.1
board_build.partitions = min_spiffs.csv
framework = arduino framework = arduino
monitor_speed = 115200 monitor_speed = 115200
board_build.embed_files = board_build.embed_files =

View File

@ -37,41 +37,31 @@ ________________________________________________________________________________
#include "A7670_utils.h" #include "A7670_utils.h"
#endif #endif
String versionDate = "2024.05.14";
Configuration Config; Configuration Config;
WiFiClient espClient; WiFiClient espClient;
String versionDate = "2024.05.13";
uint8_t myWiFiAPIndex = 0; uint8_t myWiFiAPIndex = 0;
int myWiFiAPSize = Config.wifiAPs.size(); int myWiFiAPSize = Config.wifiAPs.size();
WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex]; WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex];
bool isUpdatingOTA = false; bool isUpdatingOTA = false;
bool statusAfterBoot = true;
bool beaconUpdate = true;
uint32_t lastBeaconTx = 0;
uint32_t previousWiFiMillis = 0; uint32_t previousWiFiMillis = 0;
uint32_t lastScreenOn = millis(); uint32_t lastScreenOn = millis();
uint32_t lastWiFiCheck = 0; uint32_t lastWiFiCheck = 0;
bool WiFiConnect = true; bool WiFiConnect = true;
bool WiFiConnected = false; bool WiFiConnected = false;
bool WiFiAutoAPStarted = false; bool WiFiAutoAPStarted = false;
long WiFiAutoAPTime = false; long WiFiAutoAPTime = false;
uint32_t lastBatteryCheck = 0; uint32_t lastBatteryCheck = 0;
String batteryVoltage; String batteryVoltage;
uint32_t lastTxTime = millis();
uint32_t lastRxTime = millis();
std::vector<ReceivedPacket> receivedPackets; std::vector<ReceivedPacket> receivedPackets;
bool modemLoggedToAPRSIS = false; bool modemLoggedToAPRSIS = false;
String firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, iGateBeaconPacket, iGateLoRaBeaconPacket; String firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine;
//#define STARTUP_DELAY 5 //min //#define STARTUP_DELAY 5 //min
@ -82,8 +72,7 @@ void setup() {
Config.check(); Config.check();
LoRa_Utils::setup(); LoRa_Utils::setup();
Utils::validateFreqs(); Utils::validateFreqs();
iGateBeaconPacket = GPS_Utils::generateBeacon(); GPS_Utils::generateBeacons();
iGateLoRaBeaconPacket = GPS_Utils::generateiGateLoRaBeacon();
#ifdef STARTUP_DELAY // (TEST) just to wait for WiFi init of Routers #ifdef STARTUP_DELAY // (TEST) just to wait for WiFi init of Routers
show_display("", " STARTUP DELAY ...", "", "", 0); show_display("", " STARTUP DELAY ...", "", "", 0);

View File

@ -19,12 +19,10 @@ extern String fourthLine;
extern String fifthLine; extern String fifthLine;
extern String sixthLine; extern String sixthLine;
extern String seventhLine; extern String seventhLine;
extern std::vector<String> outputPacketBuffer;
extern uint32_t lastRxTime;
extern bool modemLoggedToAPRSIS; extern bool modemLoggedToAPRSIS;
uint32_t lastRxTime = millis();
#ifdef ESP32_DIY_LoRa_A7670 #ifdef ESP32_DIY_LoRa_A7670
extern bool stationBeacon; extern bool stationBeacon;
#endif #endif

View File

@ -6,14 +6,15 @@
#define SEALEVELPRESSURE_HPA (1013.25) #define SEALEVELPRESSURE_HPA (1013.25)
#define CORRECTION_FACTOR (8.2296) // for meters #define CORRECTION_FACTOR (8.2296) // for meters
extern Configuration Config; extern Configuration Config;
extern String fifthLine; extern String fifthLine;
float newHum, newTemp, newPress, newGas;
int wxModuleType = 0; int wxModuleType = 0;
uint8_t wxModuleAddress = 0x00; uint8_t wxModuleAddress = 0x00;
float newHum, newTemp, newPress, newGas;
Adafruit_BME280 bme280; Adafruit_BME280 bme280;
Adafruit_BME680 bme680; Adafruit_BME680 bme680;
#ifdef HELTEC_V3_GPS #ifdef HELTEC_V3_GPS
@ -23,7 +24,6 @@ Adafruit_BMP280 bmp280;
#endif #endif
namespace BME_Utils { namespace BME_Utils {
void getWxModuleAddres() { void getWxModuleAddres() {

View File

@ -3,6 +3,7 @@
#include "configuration.h" #include "configuration.h"
#include "display.h" #include "display.h"
void Configuration::check() { void Configuration::check() {
if (reload) { if (reload) {
show_display("------- UPDATE ------", "config is old", "device will update", "and then reboot", 1000); show_display("------- UPDATE ------", "config is old", "device will update", "and then reboot", 1000);

View File

@ -20,8 +20,6 @@ extern String fifthLine;
extern String sixthLine; extern String sixthLine;
extern String seventhLine; extern String seventhLine;
extern std::vector<String> outputPacketBuffer;
namespace DIGI_Utils { namespace DIGI_Utils {

View File

@ -5,7 +5,7 @@
extern Configuration Config; extern Configuration Config;
extern WiFiClient espClient; extern WiFiClient espClient;
String distance; String distance, iGateBeaconPacket, iGateLoRaBeaconPacket;
namespace GPS_Utils { namespace GPS_Utils {
@ -47,17 +47,14 @@ namespace GPS_Utils {
return encodedData; return encodedData;
} }
String generateBeacon() { void generateBeacons() {
String beaconPacket = Config.callsign + ">APLRG1," + Config.beacon.path; String beaconPacket = Config.callsign + ">APLRG1";
if (Config.beacon.path != "") {
if (Config.aprs_is.active && Config.digi.mode == 0) { // If APRSIS enabled and Digi disabled beaconPacket += "," + Config.beacon.path;
beaconPacket += ",qAC"; }
} String encodedGPS = encodeGPS(Config.beacon.latitude, Config.beacon.longitude, Config.beacon.overlay, Config.beacon.symbol);
return beaconPacket + ":!" + encodeGPS(Config.beacon.latitude, Config.beacon.longitude, Config.beacon.overlay, Config.beacon.symbol);; iGateBeaconPacket = beaconPacket + ",qAC:!" + encodedGPS;
} iGateLoRaBeaconPacket = beaconPacket + ":!" + encodedGPS;
String generateiGateLoRaBeacon() {
return Config.callsign + ">APLRG1," + Config.beacon.path + ":!" + encodeGPS(Config.beacon.latitude, Config.beacon.longitude, Config.beacon.overlay, Config.beacon.symbol);
} }
double calculateDistanceTo(double latitude, double longitude) { double calculateDistanceTo(double latitude, double longitude) {

View File

@ -8,8 +8,7 @@ namespace GPS_Utils {
char *ax25_base91enc(char *s, uint8_t n, uint32_t v); char *ax25_base91enc(char *s, uint8_t n, uint32_t v);
String encodeGPS(float latitude, float longitude, String overlay, String symbol); String encodeGPS(float latitude, float longitude, String overlay, String symbol);
String generateBeacon(); void generateBeacons();
String generateiGateLoRaBeacon();
double calculateDistanceCourse(double latitude, double longitude); double calculateDistanceCourse(double latitude, double longitude);
String decodeEncodedGPS(String packet); String decodeEncodedGPS(String packet);
String getReceivedGPS(String packet); String getReceivedGPS(String packet);

View File

@ -10,7 +10,6 @@
extern Configuration Config; extern Configuration Config;
extern uint32_t lastRxTime; extern uint32_t lastRxTime;
extern std::vector<ReceivedPacket> receivedPackets; extern std::vector<ReceivedPacket> receivedPackets;
bool transmissionFlag = true; bool transmissionFlag = true;

View File

@ -20,10 +20,6 @@ extern Configuration Config;
namespace POWER_Utils { namespace POWER_Utils {
bool BatteryIsConnected = false;
String batteryVoltage = "";
String batteryChargeDischargeCurrent = "";
void activateMeasurement() { void activateMeasurement() {
#if defined(HAS_AXP192) || defined(HAS_AXP2101) #if defined(HAS_AXP192) || defined(HAS_AXP2101)
PMU.disableTSPinMeasure(); PMU.disableTSPinMeasure();
@ -138,7 +134,7 @@ namespace POWER_Utils {
} }
#ifdef VEXT_CTRL #ifdef VEXT_CTRL
pinMode(VEXT_CTRL,OUTPUT); // this is for GPS and TFT screen on Wireless_Tracker and only for Oled in Heltec V3 pinMode(VEXT_CTRL,OUTPUT); // GPS + TFT on HELTEC Wireless_Tracker and only for Oled in HELTEC V3
digitalWrite(VEXT_CTRL, HIGH); digitalWrite(VEXT_CTRL, HIGH);
#endif #endif

View File

@ -5,11 +5,11 @@
#include "utils.h" #include "utils.h"
#include <vector> #include <vector>
extern Configuration Config; extern Configuration Config;
extern uint32_t lastTxTime; extern uint32_t lastRxTime;
extern uint32_t lastRxTime; extern String fourthLine;
extern String fourthLine;
uint32_t lastTxTime = millis();
std::vector<String> lastHeardStation; std::vector<String> lastHeardStation;
std::vector<String> outputPacketBuffer; std::vector<String> outputPacketBuffer;
std::vector<String> packet25SegBuffer; std::vector<String> packet25SegBuffer;
@ -70,7 +70,6 @@ namespace STATION_Utils {
String deltaTimeString = packet25SegBuffer[0].substring(0, packet25SegBuffer[0].indexOf(",")); String deltaTimeString = packet25SegBuffer[0].substring(0, packet25SegBuffer[0].indexOf(","));
uint32_t deltaTime = deltaTimeString.toInt(); uint32_t deltaTime = deltaTimeString.toInt();
if ((millis() - deltaTime) > 25 * 1000) { if ((millis() - deltaTime) > 25 * 1000) {
//Serial.print("Borrando : "); Serial.println(packet25SegBuffer[0]);
packet25SegBuffer.erase(packet25SegBuffer.begin()); packet25SegBuffer.erase(packet25SegBuffer.begin());
} }
} }

View File

@ -6,7 +6,6 @@
#include "utils.h" #include "utils.h"
extern Configuration Config; extern Configuration Config;
extern std::vector<String> outputPacketBuffer;
#define MAX_CLIENTS 4 #define MAX_CLIENTS 4
#define INPUT_BUFFER_SIZE (2 + MAX_CLIENTS) #define INPUT_BUFFER_SIZE (2 + MAX_CLIENTS)

View File

@ -12,10 +12,9 @@
#include "display.h" #include "display.h"
#include "utils.h" #include "utils.h"
extern WiFiClient espClient;
extern Configuration Config; extern Configuration Config;
extern WiFiClient espClient;
extern String versionDate; extern String versionDate;
extern bool statusAfterBoot;
extern String firstLine; extern String firstLine;
extern String secondLine; extern String secondLine;
extern String thirdLine; extern String thirdLine;
@ -23,9 +22,7 @@ extern String fourthLine;
extern String fifthLine; extern String fifthLine;
extern String sixthLine; extern String sixthLine;
extern String seventhLine; extern String seventhLine;
extern uint32_t lastBeaconTx;
extern uint32_t lastScreenOn; extern uint32_t lastScreenOn;
extern bool beaconUpdate;
extern String iGateBeaconPacket; extern String iGateBeaconPacket;
extern String iGateLoRaBeaconPacket; extern String iGateLoRaBeaconPacket;
extern std::vector<String> lastHeardStation; extern std::vector<String> lastHeardStation;
@ -38,6 +35,10 @@ extern bool WiFiConnect;
extern bool WiFiConnected; extern bool WiFiConnected;
extern int wxModuleType; extern int wxModuleType;
bool statusAfterBoot = true;
bool beaconUpdate = true;
uint32_t lastBeaconTx = 0;
namespace Utils { namespace Utils {
@ -169,14 +170,14 @@ namespace Utils {
void checkWiFiInterval() { void checkWiFiInterval() {
uint32_t WiFiCheck = millis() - lastWiFiCheck; uint32_t WiFiCheck = millis() - lastWiFiCheck;
if (WiFi.status() != WL_CONNECTED && WiFiCheck >= 15*60*1000) { if (WiFi.status() != WL_CONNECTED && WiFiCheck >= 15 * 60 * 1000) {
WiFiConnect = true; WiFiConnect = true;
} }
if (WiFiConnect) { if (WiFiConnect) {
Serial.println("\nConnecting to WiFi ..."); Serial.println("\nConnecting to WiFi ...");
WIFI_Utils::startWiFi(); WIFI_Utils::startWiFi();
lastWiFiCheck = millis(); lastWiFiCheck = millis();
WiFiConnect = false; WiFiConnect = false;
} }
} }

View File

@ -5,7 +5,6 @@
#include "utils.h" #include "utils.h"
extern Configuration Config; extern Configuration Config;
extern uint32_t lastBeaconTx; extern uint32_t lastBeaconTx;
extern std::vector<ReceivedPacket> receivedPackets; extern std::vector<ReceivedPacket> receivedPackets;

View File

@ -18,7 +18,7 @@ extern bool WiFiAutoAPStarted;
namespace WIFI_Utils { namespace WIFI_Utils {
void checkWiFi() { void checkWiFi() {
if ((WiFi.status() != WL_CONNECTED) && ((millis() - previousWiFiMillis) >= 30*1000) && !WiFiAutoAPStarted) { if ((WiFi.status() != WL_CONNECTED) && ((millis() - previousWiFiMillis) >= 30 * 1000) && !WiFiAutoAPStarted) {
Serial.print(millis()); Serial.print(millis());
Serial.println("Reconnecting to WiFi..."); Serial.println("Reconnecting to WiFi...");
WiFi.disconnect(); WiFi.disconnect();