mirror of
https://github.com/richonguzman/LoRa_APRS_iGate.git
synced 2026-03-20 12:15:21 +01:00
cambio4
This commit is contained in:
parent
ae3947b7ea
commit
eb5b3aaa25
|
|
@ -8,6 +8,7 @@ namespace LoRa_Utils {
|
|||
|
||||
void setup();
|
||||
void sendNewPacket(const String& newPacket);
|
||||
String receivePacketFromSleep();
|
||||
String receivePacket();
|
||||
void changeFreqTx();
|
||||
void changeFreqRx();
|
||||
|
|
|
|||
|
|
@ -4,8 +4,10 @@
|
|||
#include <Arduino.h>
|
||||
|
||||
namespace SLEEP_Utils {
|
||||
|
||||
void setup();
|
||||
|
||||
void setup();
|
||||
void checkWakeUpFlag();
|
||||
void startSleeping();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ namespace STATION_Utils {
|
|||
bool wasHeard(const String& station);
|
||||
void clean25SegBuffer();
|
||||
bool check25SegBuffer(const String& station, const String& textMessage);
|
||||
void processOutputPacketBufferUltraEcoMode();
|
||||
void processOutputPacketBuffer();
|
||||
void addToOutputPacketBuffer(const String& packet);
|
||||
|
||||
|
|
|
|||
|
|
@ -148,95 +148,102 @@ void setup() {
|
|||
}
|
||||
|
||||
void loop() {
|
||||
WIFI_Utils::checkAutoAPTimeout();
|
||||
if (Config.digi.ecoMode == 1) {
|
||||
SLEEP_Utils::checkWakeUpFlag();
|
||||
Utils::checkBeaconInterval();
|
||||
STATION_Utils::processOutputPacketBufferUltraEcoMode();
|
||||
SLEEP_Utils::startSleeping();
|
||||
} else {
|
||||
WIFI_Utils::checkAutoAPTimeout();
|
||||
|
||||
if (isUpdatingOTA) {
|
||||
ElegantOTA.loop();
|
||||
return; // Don't process IGate and Digi during OTA update
|
||||
}
|
||||
if (isUpdatingOTA) {
|
||||
ElegantOTA.loop();
|
||||
return; // Don't process IGate and Digi during OTA update
|
||||
}
|
||||
|
||||
if (Config.lowVoltageCutOff > 0) {
|
||||
BATTERY_Utils::checkIfShouldSleep();
|
||||
}
|
||||
|
||||
#ifdef HAS_GPS
|
||||
if (Config.beacon.gpsActive) {
|
||||
if (millis() - gpsSatelliteTime > 5000) {
|
||||
gpsInfoToggle = !gpsInfoToggle;
|
||||
gpsSatelliteTime = millis();
|
||||
}
|
||||
if (gpsInfoToggle) {
|
||||
thirdLine = "Satellite(s): ";
|
||||
String gpsData = String(gps.satellites.value());
|
||||
if (gpsData.length() < 2) gpsData = "0" + gpsData; // Ensure two-digit formatting
|
||||
thirdLine += gpsData;
|
||||
if (Config.lowVoltageCutOff > 0) {
|
||||
BATTERY_Utils::checkIfShouldSleep();
|
||||
}
|
||||
|
||||
#ifdef HAS_GPS
|
||||
if (Config.beacon.gpsActive) {
|
||||
if (millis() - gpsSatelliteTime > 5000) {
|
||||
gpsInfoToggle = !gpsInfoToggle;
|
||||
gpsSatelliteTime = millis();
|
||||
}
|
||||
if (gpsInfoToggle) {
|
||||
thirdLine = "Satellite(s): ";
|
||||
String gpsData = String(gps.satellites.value());
|
||||
if (gpsData.length() < 2) gpsData = "0" + gpsData; // Ensure two-digit formatting
|
||||
thirdLine += gpsData;
|
||||
} else {
|
||||
thirdLine = Utils::getLocalIP();
|
||||
}
|
||||
} else {
|
||||
thirdLine = Utils::getLocalIP();
|
||||
}
|
||||
} else {
|
||||
#else
|
||||
thirdLine = Utils::getLocalIP();
|
||||
}
|
||||
#else
|
||||
thirdLine = Utils::getLocalIP();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAS_A7670
|
||||
if (Config.aprs_is.active && !modemLoggedToAPRSIS) A7670_Utils::APRS_IS_connect();
|
||||
#else
|
||||
WIFI_Utils::checkWiFi();
|
||||
if (Config.aprs_is.active && (WiFi.status() == WL_CONNECTED) && !espClient.connected()) APRS_IS_Utils::connect();
|
||||
#endif
|
||||
#ifdef HAS_A7670
|
||||
if (Config.aprs_is.active && !modemLoggedToAPRSIS) A7670_Utils::APRS_IS_connect();
|
||||
#else
|
||||
WIFI_Utils::checkWiFi();
|
||||
if (Config.aprs_is.active && (WiFi.status() == WL_CONNECTED) && !espClient.connected()) APRS_IS_Utils::connect();
|
||||
#endif
|
||||
|
||||
NTP_Utils::update();
|
||||
TNC_Utils::loop();
|
||||
NTP_Utils::update();
|
||||
TNC_Utils::loop();
|
||||
|
||||
Utils::checkDisplayInterval();
|
||||
Utils::checkBeaconInterval();
|
||||
|
||||
APRS_IS_Utils::checkStatus(); // Need that to update display, maybe split this and send APRSIS status to display func?
|
||||
Utils::checkDisplayInterval();
|
||||
Utils::checkBeaconInterval();
|
||||
|
||||
APRS_IS_Utils::checkStatus(); // Need that to update display, maybe split this and send APRSIS status to display func?
|
||||
|
||||
String packet = "";
|
||||
if (Config.loramodule.rxActive) {
|
||||
packet = LoRa_Utils::receivePacket(); // We need to fetch LoRa packet above APRSIS and Digi
|
||||
}
|
||||
|
||||
if (packet != "") {
|
||||
if (Config.aprs_is.active) { // If APRSIS enabled
|
||||
APRS_IS_Utils::processLoRaPacket(packet); // Send received packet to APRSIS
|
||||
String packet = "";
|
||||
if (Config.loramodule.rxActive) {
|
||||
packet = LoRa_Utils::receivePacket(); // We need to fetch LoRa packet above APRSIS and Digi
|
||||
}
|
||||
|
||||
if (Config.loramodule.txActive && (Config.digi.mode == 2 || Config.digi.mode == 3 || backUpDigiMode)) { // If Digi enabled
|
||||
STATION_Utils::clean25SegBuffer();
|
||||
DIGI_Utils::processLoRaPacket(packet); // Send received packet to Digi
|
||||
}
|
||||
if (packet != "") {
|
||||
if (Config.aprs_is.active) { // If APRSIS enabled
|
||||
APRS_IS_Utils::processLoRaPacket(packet); // Send received packet to APRSIS
|
||||
}
|
||||
|
||||
if (Config.tnc.enableServer) { // If TNC server enabled
|
||||
TNC_Utils::sendToClients(packet); // Send received packet to TNC KISS
|
||||
}
|
||||
if (Config.tnc.enableSerial) { // If Serial KISS enabled
|
||||
TNC_Utils::sendToSerial(packet); // Send received packet to Serial KISS
|
||||
}
|
||||
}
|
||||
if (Config.loramodule.txActive && (Config.digi.mode == 2 || Config.digi.mode == 3 || backUpDigiMode)) { // If Digi enabled
|
||||
STATION_Utils::clean25SegBuffer();
|
||||
DIGI_Utils::processLoRaPacket(packet); // Send received packet to Digi
|
||||
}
|
||||
|
||||
if (Config.aprs_is.active) {
|
||||
APRS_IS_Utils::listenAPRSIS(); // listen received packet from APRSIS
|
||||
}
|
||||
|
||||
STATION_Utils::processOutputPacketBuffer();
|
||||
|
||||
#ifdef HAS_EPAPER // Only consider updating every 10 seconds (when data to show is different from before)
|
||||
if(lastEpaperTime == 0 || millis() - lastEpaperTime > 10000) {
|
||||
String posibleEpaperText = firstLine + secondLine + thirdLine + fourthLine + fifthLine + sixthLine + seventhLine;
|
||||
if (lastEpaperText != posibleEpaperText) {
|
||||
displayShow(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0);
|
||||
lastEpaperText = posibleEpaperText;
|
||||
lastEpaperTime = millis();
|
||||
if (Config.tnc.enableServer) { // If TNC server enabled
|
||||
TNC_Utils::sendToClients(packet); // Send received packet to TNC KISS
|
||||
}
|
||||
if (Config.tnc.enableSerial) { // If Serial KISS enabled
|
||||
TNC_Utils::sendToSerial(packet); // Send received packet to Serial KISS
|
||||
}
|
||||
}
|
||||
#else
|
||||
displayShow(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0);
|
||||
#endif
|
||||
|
||||
Utils::checkRebootTime();
|
||||
Utils::checkSleepByLowBatteryVoltage(1);
|
||||
if (Config.aprs_is.active) {
|
||||
APRS_IS_Utils::listenAPRSIS(); // listen received packet from APRSIS
|
||||
}
|
||||
|
||||
STATION_Utils::processOutputPacketBuffer();
|
||||
|
||||
#ifdef HAS_EPAPER // Only consider updating every 10 seconds (when data to show is different from before)
|
||||
if(lastEpaperTime == 0 || millis() - lastEpaperTime > 10000) {
|
||||
String posibleEpaperText = firstLine + secondLine + thirdLine + fourthLine + fifthLine + sixthLine + seventhLine;
|
||||
if (lastEpaperText != posibleEpaperText) {
|
||||
displayShow(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0);
|
||||
lastEpaperText = posibleEpaperText;
|
||||
lastEpaperTime = millis();
|
||||
}
|
||||
}
|
||||
#else
|
||||
displayShow(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0);
|
||||
#endif
|
||||
|
||||
Utils::checkRebootTime();
|
||||
Utils::checkSleepByLowBatteryVoltage(1);
|
||||
}
|
||||
}
|
||||
|
|
@ -148,11 +148,7 @@ namespace DIGI_Utils {
|
|||
if (!queryMessage) {
|
||||
String loraPacket = generateDigipeatedPacket(packet.substring(3), thirdPartyPacket);
|
||||
if (loraPacket != "") {
|
||||
if (Config.lowPowerMode) {
|
||||
LoRa_Utils::sendNewPacket(loraPacket);
|
||||
} else {
|
||||
STATION_Utils::addToOutputPacketBuffer(loraPacket);
|
||||
}
|
||||
STATION_Utils::addToOutputPacketBuffer(loraPacket);
|
||||
displayToggle(true);
|
||||
lastScreenOn = millis();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ namespace LoRa_Utils {
|
|||
radio.startReceive();
|
||||
}*/
|
||||
|
||||
/*String receiveFromSleep() {
|
||||
String receivePacketFromSleep() {
|
||||
String packet = "";
|
||||
int state = radio.readData(packet);
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
|
|
@ -168,13 +168,13 @@ namespace LoRa_Utils {
|
|||
packet = "";
|
||||
}
|
||||
return packet;
|
||||
}*/
|
||||
}
|
||||
|
||||
String receivePacket() {
|
||||
String packet = "";
|
||||
if (operationDone || Config.lowPowerMode) {
|
||||
if (operationDone) {
|
||||
operationDone = false;
|
||||
if (transmitFlag && !Config.lowPowerMode) {
|
||||
if (transmitFlag) {
|
||||
radio.startReceive();
|
||||
transmitFlag = false;
|
||||
} else {
|
||||
|
|
@ -190,7 +190,7 @@ namespace LoRa_Utils {
|
|||
Utils::println("<--- LoRa Packet Rx : " + packet.substring(3));
|
||||
Utils::println("(RSSI:" + String(rssi) + " / SNR:" + String(snr) + " / FreqErr:" + String(freqError) + ")");
|
||||
|
||||
if (!Config.lowPowerMode && Config.digi.ecoMode == 0) {
|
||||
if (Config.digi.ecoMode == 0) {
|
||||
if (receivedPackets.size() >= 10) {
|
||||
receivedPackets.erase(receivedPackets.begin());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
#include "configuration.h"
|
||||
#include "board_pinout.h"
|
||||
#include "sleep_utils.h"
|
||||
#include "digi_utils.h"
|
||||
#include "lora_utils.h"
|
||||
|
||||
|
||||
extern Configuration Config;
|
||||
extern uint32_t lastBeaconTx;
|
||||
|
||||
bool wakeUpFlag = false;
|
||||
|
||||
|
|
@ -15,6 +17,16 @@ namespace SLEEP_Utils {
|
|||
wakeUpFlag = true;
|
||||
}
|
||||
|
||||
void checkWakeUpFlag() {
|
||||
if (wakeUpFlag) {
|
||||
String packet = LoRa_Utils::receivePacketFromSleep();
|
||||
if (packet != "") {
|
||||
DIGI_Utils::processLoRaPacket(packet);
|
||||
}
|
||||
wakeUpFlag = false;
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
if (Config.digi.ecoMode == 1) {
|
||||
pinMode(RADIO_WAKEUP_PIN, INPUT);
|
||||
|
|
@ -29,4 +41,17 @@ namespace SLEEP_Utils {
|
|||
}
|
||||
}
|
||||
|
||||
uint32_t getSecondsToSleep() {
|
||||
uint32_t elapsedTime = (millis() - lastBeaconTx) / 1000; // in secs
|
||||
uint32_t intervalTime = Config.beacon.interval * 60; // in secs
|
||||
return (elapsedTime < intervalTime) ? (intervalTime - elapsedTime) : 0;
|
||||
}
|
||||
|
||||
void startSleeping() {
|
||||
esp_sleep_enable_timer_wakeup(getSecondsToSleep() * 1000000); // 1 min = 60sec
|
||||
delay(100);
|
||||
LoRa_Utils::wakeRadio();
|
||||
esp_light_sleep_start();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -149,6 +149,24 @@ namespace STATION_Utils {
|
|||
return true;
|
||||
}
|
||||
|
||||
void processOutputPacketBufferUltraEcoMode() {
|
||||
size_t currentIndex = 0;
|
||||
while (currentIndex < outputPacketBuffer.size()) { // this sends all packets from output buffer
|
||||
delay(3000); // and cleans buffer to avoid sending packets with time offset
|
||||
LoRa_Utils::sendNewPacket(outputPacketBuffer[currentIndex]); // next time it wakes up
|
||||
currentIndex++;
|
||||
}
|
||||
outputPacketBuffer.clear();
|
||||
//
|
||||
if (saveNewDigiEcoModeConfig) {
|
||||
Config.writeFile();
|
||||
delay(1000);
|
||||
displayToggle(false);
|
||||
ESP.restart();
|
||||
}
|
||||
//
|
||||
}
|
||||
|
||||
void processOutputPacketBuffer() {
|
||||
int timeToWait = 3 * 1000; // 3 segs between packet Tx and also Rx ???
|
||||
uint32_t lastRx = millis() - lastRxTime;
|
||||
|
|
@ -166,7 +184,7 @@ namespace STATION_Utils {
|
|||
}
|
||||
}
|
||||
if (saveNewDigiEcoModeConfig) {
|
||||
setCpuFrequencyMhz(80);
|
||||
//setCpuFrequencyMhz(80);
|
||||
Config.writeFile();
|
||||
delay(1000);
|
||||
displayToggle(false);
|
||||
|
|
|
|||
Loading…
Reference in a new issue