Compare commits

...

36 Commits
V2.0 ... V2.1

Author SHA1 Message Date
richonguzman
5ceff0064f small update to avoid sending gps = 0 2024-10-21 11:16:31 -03:00
richonguzman
8beb7c0465 readme update 2024-10-21 09:09:47 -03:00
richonguzman
112e38312d codingRate4 = 4 does not exists 2024-10-21 09:08:53 -03:00
richonguzman
5a1c6e7ed9 testing GPS 2024-10-21 08:28:35 -03:00
richonguzman
0defd5b289 added HWT with GPS 2024-10-14 17:48:14 -03:00
richonguzman
cdac54c34e cleaning code 2024-10-14 17:44:01 -03:00
richonguzman
71e98487f6 readme and index update 2024-10-14 17:23:42 -03:00
richonguzman
510b5bdc59 index reads better 2024-10-14 17:15:56 -03:00
richonguzman
00db358cc3 GPS for iGate 2024-10-14 17:04:28 -03:00
richonguzman
c0641986aa RxPacket freeze fix 2024-10-14 12:49:01 -03:00
richonguzman
55378bb9f3 readme Update for NTP update 2024-10-14 11:56:48 -03:00
richonguzman
79cf50a630 NTP time added 2024-10-14 11:44:22 -03:00
richonguzman
03ccd2b12e r up 2024-10-11 07:16:44 -03:00
richonguzman
d5ffd26c3c double validation for DigiEcoMode start stop 2024-10-10 18:45:12 -03:00
richonguzman
2f0f991785 readme2 2024-10-09 11:46:45 -03:00
richonguzman
975b140c73 readme1 2024-10-09 11:45:01 -03:00
richonguzman
f2abe34af1 readme Update Digi Eco Mode 2024-10-08 12:25:09 -03:00
richonguzman
a786d83b9e Queries for DigiEcoMode 2024-10-08 12:19:22 -03:00
richonguzman
bf0a0d6e4c EcoMode Digi 2024-10-08 11:04:36 -03:00
richonguzman
d08e5b1b27 ready for testing LowPowerDigi 2024-10-08 01:22:10 -03:00
richonguzman
f387e03b53 testing LowPowerDigi 2024-10-08 01:03:58 -03:00
richonguzman
16215f9e56 minor update for Internal Battery Sleep 2024-10-07 11:10:19 -03:00
richonguzman
ce01d0aa4d minor white spaces kill 2024-10-07 09:39:31 -03:00
richonguzman
b0a05f89f6 readme update 2024-10-06 23:35:51 -03:00
richonguzman
58d8736969 test for Killed Wifi Active 2024-10-06 23:23:22 -03:00
richonguzman
df9060d906 testing not active 2024-10-06 23:02:10 -03:00
richonguzman
2bd6844d89 WiFiAP Active switch added 2024-10-06 22:59:58 -03:00
richonguzman
0a79b6459b added initial corrections to WiFiAP 2024-10-06 22:30:44 -03:00
richonguzman
d5eb32a38b cross digi rules added 2024-10-06 11:37:25 -03:00
richonguzman
d6c5741fde cross digi added 2024-10-06 11:36:37 -03:00
richonguzman
1063a82294 se viene thirdParty 2024-10-05 20:25:29 -03:00
richonguzman
6913b6b89f ahora a probar thirdParty 2024-10-05 20:23:58 -03:00
richonguzman
42c990f5cf !thirdParty con o sin path 2024-10-05 20:21:36 -03:00
richonguzman
a17900e4d0 bme into wxsensor 2024-10-05 08:48:08 -03:00
richonguzman
3fd819bd4e not encoded telemetry as default 2024-09-25 11:23:38 -03:00
richonguzman
640166a50b update for wiki 2024-09-23 17:41:05 -03:00
33 changed files with 674 additions and 288 deletions

View File

@@ -7,6 +7,8 @@ This firmware is for using ESP32 based boards with LoRa Modules and GPS to live
__(This iGate Firmware works with all LoRa Tracker Firmwares (specially this <a href="https://github.com/richonguzman/LoRa_APRS_Tracker" target="_blank">LoRa APRS Tracker Firmware</a>))__
<br />
____________________________________________________
## You can support this project to continue to grow:
[<img src="https://github.com/richonguzman/LoRa_APRS_Tracker/blob/main/images/github-sponsors.png">](https://github.com/sponsors/richonguzman) [<img src="https://github.com/richonguzman/LoRa_APRS_Tracker/blob/main/images/paypalme.png">](http://paypal.me/richonguzman)
@@ -14,7 +16,8 @@ __(This iGate Firmware works with all LoRa Tracker Firmwares (specially this <a
<br />
# WEB FLASHER/INSTALLER is <a href="https://richonguzman.github.io/lora-igate-web-flasher/installer.html" target="_blank">here</a>
<br />
____________________________________________________
# WIKI
@@ -47,6 +50,10 @@ __(This iGate Firmware works with all LoRa Tracker Firmwares (specially this <a
## Timeline (Versions):
- 2024.10.21 Boards with GPS can now send Real-GPS Beacon (also posible: GPS ambiguity of ~ 1 km).
- 2024.10.14 Received Packets in WebUI show real Local Time (NTP with GMT offset).
- 2024.10.08 New EcoMode for Remote Digirepeaters without WiFi/WiFiAP, Screen, Leds (Example: LILYGO LoRa32 uses only 24mA, with WifiAP and all was 150mA). APRS Message/Queries can start/stop this mode too.
- 2024.10.06 Cross Frequency Digirepeater Rules added.
- 2024.09.23 Libraries Update for SDK3
- 2024.09.23 Added Enconded Telemetry for Battery (+ External Voltage) in Station GPS Beacon Packet.
- 2024.08.23 Wemos S2 Mini DIY LoRa added.
@@ -111,4 +118,4 @@ __(This iGate Firmware works with all LoRa Tracker Firmwares (specially this <a
__________________________________________
# Hope You Enjoy this, 73 !! CA2RXU , Valparaiso, Chile
# Hope You Enjoy this, 73! CA2RXU, Valparaiso, Chile

View File

@@ -3,7 +3,7 @@
"wifi": {
"autoAP": {
"password": "1234567890",
"powerOff": 10
"timeout": 10
},
"AP": []
},
@@ -28,7 +28,8 @@
"objectsToRF": false
},
"digi": {
"mode": 0
"mode": 0,
"ecoMode": false
},
"lora": {
"txFreq": 433775000,
@@ -48,7 +49,7 @@
"battery": {
"sendInternalVoltage": false,
"monitorInternalVoltage": false,
"internalSleepVoltage": 3.0,
"internalSleepVoltage": 2.9,
"sendExternalVoltage": false,
"externalVoltagePin": 34,
"monitorExternalVoltage": false,
@@ -57,7 +58,7 @@
"voltageDividerR2": 27.0,
"sendVoltageAsTelemetry": true
},
"bme": {
"wxsensor": {
"active": false,
"heightCorrection": 0,
"temperatureCorrection": 0.0
@@ -80,6 +81,9 @@
"username": "admin",
"password": ""
},
"ntp": {
"gmtCorrection": 0
},
"other": {
"rememberStationTime": 30,
"lowPowerMode": false,

View File

@@ -62,11 +62,11 @@
<div class="container d-none" id="received-packets">
<div class="row my-5 d-flex align-items-top">
<div class="col-12">
<h3>Last 20 received packets list</h3>
<h3>Last 10 received packets list</h3>
<table class="table mt-4">
<thead>
<tr>
<th scope="col">Time*</th>
<th scope="col">Time</th>
<th scope="col">Frame</th>
<th scope="col">RSSI</th>
<th scope="col">SNR</th>
@@ -77,7 +77,7 @@
</tbody>
</table>
<span>List refresh automatically every 15 seconds.</span><br>
<small>* - For now time is measured from board boot up.</small>
<small>(Local Time is NPT-Time adjusted with your GMT Offset)</small>
</div>
</div>
<hr />
@@ -532,7 +532,7 @@
class="form-control"
required=""
step="1"
min="1"
min="15"
/>
<span class="input-group-text"
>minutes
@@ -540,6 +540,36 @@
</div>
</div>
</div>
<div class="col-12 mt-3">
<div class="form-check form-switch">
<input
type="checkbox"
name="beacon.gpsActive"
id="beacon.gpsActive"
class="form-check-input"
/>
<label
for="beacon.gpsActive"
class="form-label"
>Send Real-GPS Beacon <small>(Only for Boards with GPS Modules)</small>
</label>
</div>
</div>
<div class="col-12">
<div class="form-check form-switch">
<input
type="checkbox"
name="beacon.gpsAmbiguity"
id="beacon.gpsAmbiguity"
class="form-check-input"
/>
<label
for="beacon.gpsAmbiguity"
class="form-label"
>Send Real-GPS Beacon with Ambiguity <small>(~ 1 Km of Random Error)</small>
</label>
</div>
</div>
</div>
</div>
<hr />
@@ -585,6 +615,21 @@
</option>
</select>
</div>
<div class="col-12 mt-5">
<div class="form-check form-switch">
<input
type="checkbox"
name="digi.ecoMode"
id="digi.ecoMode"
class="form-check-input"
/>
<label
for="digi.ecoMode"
class="form-label"
>Eco Mode<small> This will disable WiFi, Display, Leds and lower CPU Speed for Low Power Digirepeater. (<strong>Caution:</strong> Active means No WebUI Configuration, so <strong>ONLY</strong> activate this for Remote Digirepeater)</small></label
>
</div>
</div>
</div>
</div>
</div>
@@ -791,7 +836,6 @@
id="lora.codingRate4"
required=""
>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
@@ -1012,7 +1056,7 @@
placeholder="3.0"
class="form-control"
step="0.1"
min="3.0"
min="2.9"
max="3.7"
/>
<span class="input-group-text"
@@ -1135,7 +1179,7 @@
d="M3.05 3.05a7 7 0 0 0 0 9.9.5.5 0 0 1-.707.707 8 8 0 0 1 0-11.314.5.5 0 0 1 .707.707m2.122 2.122a4 4 0 0 0 0 5.656.5.5 0 1 1-.708.708 5 5 0 0 1 0-7.072.5.5 0 0 1 .708.708m5.656-.708a.5.5 0 0 1 .708 0 5 5 0 0 1 0 7.072.5.5 0 1 1-.708-.708 4 4 0 0 0 0-5.656.5.5 0 0 1 0-.708m2.122-2.12a.5.5 0 0 1 .707 0 8 8 0 0 1 0 11.313.5.5 0 0 1-.707-.707 7 7 0 0 0 0-9.9.5.5 0 0 1 0-.707zM6 8a2 2 0 1 1 2.5 1.937V15.5a.5.5 0 0 1-1 0V9.937A2 2 0 0 1 6 8"
/>
</svg>
Telemetry
WX Telemetry
</h5>
<small>Define Wx telemetry</small>
</div>
@@ -1145,12 +1189,12 @@
<div class="form-check form-switch">
<input
type="checkbox"
name="bme.active"
id="bme.active"
name="wxsensor.active"
id="wxsensor.active"
class="form-check-input"
/>
<label
for="bme.active"
for="wxsensor.active"
class="form-label"
><b>Activate Wx Telemetry</b>
<small
@@ -1162,14 +1206,14 @@
</div>
<div class="row mt-3">
<div class="col-6">
<label for="bme.heightCorrection" class="form-label"
<label for="wxsensor.heightCorrection" class="form-label"
>Height Correction (Above Sea-Level)</label
>
<div class="input-group">
<input
type="number"
name="bme.heightCorrection"
id="bme.heightCorrection"
name="wxsensor.heightCorrection"
id="wxsensor.heightCorrection"
placeholder="0"
class="form-control"
step="1"
@@ -1181,14 +1225,14 @@
</div>
</div>
<div class="col-6">
<label for="bme.temperatureCorrection" class="form-label"
<label for="wxsensor.temperatureCorrection" class="form-label"
>Temperature Correction</label
>
<div class="input-group">
<input
type="number"
name="bme.temperatureCorrection"
id="bme.temperatureCorrection"
name="wxsensor.temperatureCorrection"
id="wxsensor.temperatureCorrection"
placeholder="0.0"
class="form-control"
step="0.1"
@@ -1453,10 +1497,10 @@
d="M8.5 5.5a.5.5 0 1 1-1 0 .5.5 0 0 1 1 0"
/>
</svg>
Auto AP
WiFi Auto AP
</h5>
<small
>Add your password and power off timeout to
>Add your password and WiFi AP timeout to
auto access point. Auto AP will start if
there is no WiFi connection. Timeout will
count from startup or last client
@@ -1481,24 +1525,24 @@
</div>
<div class="col-12 mt-3">
<label
for="wifi.autoAP.powerOff"
for="wifi.autoAP.timeout"
class="form-label"
>Power off timeout
>WiFi AP timeout to search again for available WiFi's
<small>(in minutes)</small></label
>
<input
type="number"
name="wifi.autoAP.powerOff"
id="wifi.autoAP.powerOff"
name="wifi.autoAP.timeout"
id="wifi.autoAP.timeout"
class="form-control"
placeholder="15"
placeholder="10"
required=""
step="1"
min="0"
/>
<div class="form-text">
Set to <strong>0</strong> if you don't
want this option.
want WiFi AP to stop.
</div>
</div>
</div>
@@ -1624,6 +1668,55 @@
</div>
<hr />
<div class="row my-5 d-flex align-items-top">
<div class="col-lg-3 col-sm-12">
<h5>
<svg
xmlns="http://www.w3.org/2000/svg"
width="20"
height="20"
fill="currentColor"
class="bi bi-cloud-upload-fill"
viewBox="0 0 16 16"
>
<path
fill-rule="evenodd"
d="M8 0a5.53 5.53 0 0 0-3.594 1.342c-.766.66-1.321 1.52-1.464 2.383C1.266 4.095 0 5.555 0 7.318 0 9.366 1.708 11 3.781 11H7.5V5.707L5.354 7.854a.5.5 0 1 1-.708-.708l3-3a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1-.708.708L8.5 5.707V11h4.188C14.502 11 16 9.57 16 7.773c0-1.636-1.242-2.969-2.834-3.194C12.923 1.999 10.69 0 8 0m-.5 14.5V11h1v3.5a.5.5 0 0 1-1 0"
/>
</svg>
NTP
</h5>
<small
>Set your GMT Time Zone.
</small>
</div>
<div class="col-lg-9 col-sm-12">
<div class="col-12">
<label
for="ntp.gmtCorrection"
class="form-label"
>GMT Time Correction for accurate Local Time</label
>
<div class="input-group">
<input
type="number"
name="ntp.gmtCorrection"
id="ntp.gmtCorrection"
placeholder="0"
class="form-control"
step="1"
min="-23"
max="23"
/>
<span class="input-group-text"
>hours</span
>
</div>
</div>
</div>
</div>
<hr />
<div class="row my-5 d-flex align-items-top">
<div class="col-lg-3 col-sm-12">
<h5>

View File

@@ -134,8 +134,12 @@ function loadSettings(settings) {
document.getElementById("beacon.sendViaAPRSIS").checked = settings.beacon.sendViaAPRSIS;
document.getElementById("beacon.sendViaRF").checked = settings.beacon.sendViaRF;
document.getElementById("beacon.gpsActive").checked = settings.beacon.gpsActive;
document.getElementById("beacon.gpsAmbiguity").checked = settings.beacon.gpsAmbiguity;
// Digi
document.getElementById("digi.mode").value = settings.digi.mode;
document.getElementById("digi.ecoMode").checked = settings.digi.ecoMode;
// LoRa
document.getElementById("lora.txFreq").value = settings.lora.txFreq;
@@ -168,10 +172,10 @@ function loadSettings(settings) {
document.getElementById("battery.externalSleepVoltage").value = settings.battery.externalSleepVoltage.toFixed(1);
document.getElementById("battery.sendVoltageAsTelemetry").checked = settings.battery.sendVoltageAsTelemetry;
// TELEMETRY BME/WX
document.getElementById("bme.active").checked = settings.bme.active;
document.getElementById("bme.heightCorrection").value = settings.bme.heightCorrection;
document.getElementById("bme.temperatureCorrection").value = settings.bme.temperatureCorrection.toFixed(1);
// TELEMETRY WX SENSOR
document.getElementById("wxsensor.active").checked = settings.wxsensor.active;
document.getElementById("wxsensor.heightCorrection").value = settings.wxsensor.heightCorrection;
document.getElementById("wxsensor.temperatureCorrection").value = settings.wxsensor.temperatureCorrection.toFixed(1);
// SYSLOG
document.getElementById("syslog.active").checked = settings.syslog.active;
@@ -196,7 +200,7 @@ function loadSettings(settings) {
// WiFi Auto AP
document.getElementById("wifi.autoAP.password").value = settings.wifi.autoAP.password;
document.getElementById("wifi.autoAP.powerOff").value = settings.wifi.autoAP.powerOff;
document.getElementById("wifi.autoAP.timeout").value = settings.wifi.autoAP.timeout;
// OTA
document.getElementById("ota.username").value = settings.ota.username;
@@ -207,6 +211,9 @@ function loadSettings(settings) {
document.getElementById("webadmin.username").value = settings.webadmin.username;
document.getElementById("webadmin.password").value = settings.webadmin.password;
// NTP
document.getElementById("ntp.gmtCorrection").value = settings.ntp.gmtCorrection;
// Experimental
document.getElementById("other.backupDigiMode").checked = settings.other.backupDigiMode;
@@ -242,7 +249,7 @@ document.getElementById('reboot').addEventListener('click', function (e) {
showToast("Your device will be rebooted in a while");
});
const bmeCheckbox = document.querySelector("input[name='bme.active']");
const wxsensorCheckbox = document.querySelector("input[name='wxsensor.active']");
const stationModeSelect = document.querySelector("select[name='stationMode']");
@@ -506,13 +513,9 @@ function loadReceivedPackets(packets) {
packets.forEach((packet) => {
const element = document.createElement("tr");
date.setTime(packet.millis);
const p = date.toUTCString().split(' ')
element.innerHTML = `
<td>${p[p.length-2]}</td>
<td>${packet.rxTime}</td>
<td>${packet.packet}</td>
<td>${packet.RSSI}</td>
<td>${packet.SNR}</td>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 110 KiB

After

Width:  |  Height:  |  Size: 198 KiB

View File

@@ -40,6 +40,7 @@ lib_deps =
ayushsharma82/ElegantOTA @ 3.1.5
mathieucarbou/ESPAsyncWebServer @ 3.2.3
mathieucarbou/AsyncTCP @ 3.2.5
arduino-libraries/NTPClient @ 3.2.1
[env:ttgo-lora32-v21]
board = ttgo-lora32-v21
@@ -211,6 +212,7 @@ build_flags =
-DTTGO_T_Beam_V1_2
-DHAS_SX1278
-DHAS_AXP2101
-DHAS_GPS
-DELEGANTOTA_USE_ASYNC_WEBSERVER=1
lib_deps =
${common.lib_deps}
@@ -225,6 +227,7 @@ build_flags =
-DTTGO_T_Beam_V1_2_915
-DHAS_SX1276
-DHAS_AXP2101
-DHAS_GPS
-DELEGANTOTA_USE_ASYNC_WEBSERVER=1
lib_deps =
${common.lib_deps}
@@ -239,6 +242,7 @@ build_flags =
-DTTGO_T_Beam_V1_0
-DHAS_SX1278
-DHAS_AXP192
-DHAS_GPS
-DELEGANTOTA_USE_ASYNC_WEBSERVER=1
lib_deps =
${common.lib_deps}
@@ -253,6 +257,7 @@ build_flags =
-DTTGO_T_Beam_V1_0_915
-DHAS_SX1276
-DHAS_AXP192
-DHAS_GPS
-DELEGANTOTA_USE_ASYNC_WEBSERVER=1
lib_deps =
${common.lib_deps}
@@ -267,6 +272,7 @@ build_flags =
-DTTGO_T_Beam_V1_0_SX1268
-DHAS_SX1268
-DHAS_AXP192
-DHAS_GPS
-DELEGANTOTA_USE_ASYNC_WEBSERVER=1
lib_deps =
${common.lib_deps}
@@ -281,6 +287,7 @@ build_flags =
-DTTGO_T_Beam_V1_2_SX1262
-DHAS_SX1262
-DHAS_AXP2101
-DHAS_GPS
-DELEGANTOTA_USE_ASYNC_WEBSERVER=1
lib_deps =
${common.lib_deps}
@@ -326,6 +333,8 @@ build_flags =
-Werror -Wall
-DHELTEC_WIRELESS_TRACKER
-DHAS_SX1262
-DHAS_GPS
-DGPS_BAUDRATE=115200
-DHAS_TFT
-D USER_SETUP_LOADED
-D TFT_WIDTH=80

View File

@@ -13,6 +13,7 @@
______________________________________________________________________________________________________________*/
#include <ElegantOTA.h>
#include <TinyGPS++.h>
#include <Arduino.h>
#include <WiFi.h>
#include <vector>
@@ -29,28 +30,33 @@ ________________________________________________________________________________
#include "wifi_utils.h"
#include "digi_utils.h"
#include "gps_utils.h"
#include "bme_utils.h"
#include "web_utils.h"
#include "tnc_utils.h"
#include "ntp_utils.h"
#include "wx_utils.h"
#include "display.h"
#include "utils.h"
#ifdef HAS_A7670
#include "A7670_utils.h"
#endif
String versionDate = "2024.09.23";
Configuration Config;
WiFiClient espClient;
String versionDate = "2024.10.21";
Configuration Config;
WiFiClient espClient;
#ifdef HAS_GPS
HardwareSerial gpsSerial(1);
TinyGPSPlus gps;
#endif
uint8_t myWiFiAPIndex = 0;
int myWiFiAPSize = Config.wifiAPs.size();
WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex];
uint8_t myWiFiAPIndex = 0;
int myWiFiAPSize = Config.wifiAPs.size();
WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex];
bool isUpdatingOTA = false;
uint32_t lastBatteryCheck = 0;
bool isUpdatingOTA = false;
uint32_t lastBatteryCheck = 0;
bool backUpDigiMode = false;
bool modemLoggedToAPRSIS = false;
bool backUpDigiMode = false;
bool modemLoggedToAPRSIS = false;
std::vector<ReceivedPacket> receivedPackets;
@@ -64,11 +70,11 @@ void setup() {
Utils::setupDisplay();
LoRa_Utils::setup();
Utils::validateFreqs();
GPS_Utils::generateBeacons();
GPS_Utils::setup();
#ifdef STARTUP_DELAY // (TEST) just to wait for WiFi init of Routers
displayShow("", " STARTUP DELAY ...", "", "", 0);
delay(STARTUP_DELAY * 60 * 1000);
displayShow("", " STARTUP DELAY ...", "", "", 0);
delay(STARTUP_DELAY * 60 * 1000);
#endif
#ifdef HELTEC_HTCT62
@@ -111,9 +117,11 @@ void setup() {
Config.loramodule.rxActive = false;
}
#endif
DIGI_Utils::checkEcoMode();
WIFI_Utils::setup();
NTP_Utils::setup();
SYSLOG_Utils::setup();
BME_Utils::setup();
WX_Utils::setup();
WEB_Utils::setup();
TNC_Utils::setup();
#ifdef HAS_A7670
@@ -123,7 +131,7 @@ void setup() {
}
void loop() {
WIFI_Utils::checkIfAutoAPShouldPowerOff();
WIFI_Utils::checkAutoAPTimeout();
if (isUpdatingOTA) {
ElegantOTA.loop();
@@ -136,7 +144,7 @@ void loop() {
thirdLine = Utils::getLocalIP();
WIFI_Utils::checkWiFi(); // Always use WiFi, not related to IGate/Digi mode
WIFI_Utils::checkWiFi();
#ifdef HAS_A7670
if (Config.aprs_is.active && !modemLoggedToAPRSIS) A7670_Utils::APRS_IS_connect();
@@ -144,6 +152,7 @@ void loop() {
if (Config.aprs_is.active && (WiFi.status() == WL_CONNECTED) && !espClient.connected()) APRS_IS_Utils::connect();
#endif
NTP_Utils::update();
TNC_Utils::loop();
Utils::checkDisplayInterval();

View File

@@ -71,7 +71,7 @@ namespace APRS_IS_Utils {
if (WiFi.status() == WL_CONNECTED) {
wifiState = "OK";
} else {
if (backUpDigiMode) {
if (backUpDigiMode || Config.digi.ecoMode) {
wifiState = "--";
} else {
wifiState = "AP";
@@ -138,7 +138,8 @@ namespace APRS_IS_Utils {
//Serial.println(ackMessage);
String addToBuffer = Config.callsign;
addToBuffer += ">APLRG1,RFONLY";
addToBuffer += ">APLRG1";
if (!thirdParty) addToBuffer += ",RFONLY";
if (Config.beacon.path != "") {
addToBuffer += ",";
addToBuffer += Config.beacon.path;

View File

@@ -222,7 +222,6 @@ namespace BATTERY_Utils {
}
}
String generateEncodedTelemetryBytes(float value, bool firstBytes, byte voltageType) { // 0 = internal battery(0-4,2V) , 1 = external battery(0-15V)
String encodedBytes;
int tempValue;
@@ -251,7 +250,6 @@ namespace BATTERY_Utils {
return encodedBytes;
}
String generateEncodedTelemetry() {
String telemetry = "|";
telemetry += generateEncodedTelemetryBytes(telemetryCounter, true, 0);

View File

@@ -14,8 +14,8 @@ namespace BATTERY_Utils {
void checkIfShouldSleep(); // ????
void startupBatteryHealth();
String generateEncodedTelemetryBytes(float value, bool firstBytes, byte voltageType);
String generateEncodedTelemetry();
String generateEncodedTelemetryBytes(float value, bool firstBytes, byte voltageType);
String generateEncodedTelemetry();
}

View File

@@ -1,23 +0,0 @@
#ifndef BME_UTILS_H_
#define BME_UTILS_H_
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <Adafruit_BMP280.h>
#include <Adafruit_BME680.h>
#include "Adafruit_Si7021.h"
#include <Arduino.h>
namespace BME_Utils {
void getWxModuleAddres();
void setup();
String generateTempString(const float bmeTemp);
String generateHumString(const float bmeHum);
String generatePresString(const float bmePress);
String readDataSensor();
}
#endif

View File

@@ -10,7 +10,7 @@
// LORA MODULES
#if defined(TTGO_T_LORA32_V2_1) || defined(HELTEC_V2) || defined(ESP32_DIY_LoRa) || defined(TTGO_T_Beam_V1_2) || defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_LORA32_V2_1_915) || defined(ESP32_DIY_LoRa_915) || defined(TTGO_T_Beam_V1_2_915) || defined(TTGO_T_Beam_V1_0_915)
#define RADIO_SCLK_PIN 5 // GPIO5 - SX1278 SCK
#define RADIO_SCLK_PIN 5 // GPIO5 - SX1278 SCK
#define RADIO_MISO_PIN 19 // GPIO19 - SX1278 MISO
#define RADIO_MOSI_PIN 27 // GPIO27 - SX1278 MOSI
#define RADIO_CS_PIN 18 // GPIO18 - SX1278 CS ---> NSS
@@ -19,13 +19,13 @@
#endif
#if defined(HELTEC_V3) || defined(HELTEC_WSL_V3) || defined(HELTEC_WSL_V3_DISPLAY) || defined(HELTEC_WIRELESS_TRACKER) || defined(HELTEC_WS) || defined(HELTEC_WP)
#define RADIO_SCLK_PIN 9 // SX1262 SCK
#define RADIO_MISO_PIN 11 // SX1262 MISO
#define RADIO_MOSI_PIN 10 // SX1262 MOSI
#define RADIO_CS_PIN 8 // SX1262 NSS
#define RADIO_RST_PIN 12 // SX1262 RST
#define RADIO_DIO1_PIN 14 // SX1262 DIO1
#define RADIO_BUSY_PIN 13 // SX1262 BUSY
#define RADIO_SCLK_PIN 9 // SX1262 SCK
#define RADIO_MISO_PIN 11 // SX1262 MISO
#define RADIO_MOSI_PIN 10 // SX1262 MOSI
#define RADIO_CS_PIN 8 // SX1262 NSS
#define RADIO_RST_PIN 12 // SX1262 RST
#define RADIO_DIO1_PIN 14 // SX1262 DIO1
#define RADIO_BUSY_PIN 13 // SX1262 BUSY
#endif
#if defined(ESP32_DIY_1W_LoRa) || defined(ESP32_DIY_1W_LoRa_915) || defined(ESP32_DIY_1W_LoRa_LLCC68) // Ebyte E22 400M30S (SX1268) or E22 900M30S (SX1262) or E220 LLCC68
@@ -256,6 +256,16 @@
#define RADIO_BUSY_PIN 8
#endif
#if defined(TTGO_T_Beam_V1_2) || defined(TTGO_T_Beam_V1_2_915) || defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_0_915) || defined(TTGO_T_Beam_V1_0_SX1268) || defined(TTGO_T_Beam_V1_2_SX1262)
#define GPS_RX 12
#define GPS_TX 34
#endif
#if defined( HELTEC_WIRELESS_TRACKER)
#define GPS_RX 34
#define GPS_TX 33
#endif
/* (Same pins for LILYGO LoRa32 and ESP32 Wroom Dev )
SX1278-------------------> ESP32 ttgo-lora32-v21 and ESP32 WROOM Dev
GND GND

View File

@@ -18,7 +18,7 @@ void Configuration::writeFile() {
}
data["wifi"]["autoAP"]["password"] = wifiAutoAP.password;
data["wifi"]["autoAP"]["powerOff"] = wifiAutoAP.powerOff;
data["wifi"]["autoAP"]["timeout"] = wifiAutoAP.timeout;
data["callsign"] = callsign;
@@ -40,7 +40,11 @@ void Configuration::writeFile() {
data["beacon"]["sendViaRF"] = beacon.sendViaRF;
data["beacon"]["path"] = beacon.path;
data["beacon"]["gpsActive"] = beacon.gpsActive;
data["beacon"]["gpsAmbiguity"] = beacon.gpsAmbiguity;
data["digi"]["mode"] = digi.mode;
data["digi"]["ecoMode"] = digi.ecoMode;
data["lora"]["rxFreq"] = loramodule.rxFreq;
data["lora"]["txFreq"] = loramodule.txFreq;
@@ -68,9 +72,9 @@ void Configuration::writeFile() {
data["battery"]["sendVoltageAsTelemetry"] = battery.sendVoltageAsTelemetry;
data["bme"]["active"] = bme.active;
data["bme"]["heightCorrection"] = bme.heightCorrection;
data["bme"]["temperatureCorrection"] = bme.temperatureCorrection;
data["wxsensor"]["active"] = wxsensor.active;
data["wxsensor"]["heightCorrection"] = wxsensor.heightCorrection;
data["wxsensor"]["temperatureCorrection"] = wxsensor.temperatureCorrection;
data["syslog"]["active"] = syslog.active;
data["syslog"]["server"] = syslog.server;
@@ -99,6 +103,8 @@ void Configuration::writeFile() {
data["webadmin"]["username"] = webadmin.username;
data["webadmin"]["password"] = webadmin.password;
data["ntp"]["gmtCorrection"] = ntp.gmtCorrection;
serializeJson(data, configFile);
configFile.close();
@@ -129,7 +135,7 @@ bool Configuration::readFile() {
}
wifiAutoAP.password = data["wifi"]["autoAP"]["password"] | "1234567890";
wifiAutoAP.powerOff = data["wifi"]["autoAP"]["powerOff"] | 10;
wifiAutoAP.timeout = data["wifi"]["autoAP"]["timeout"] | 10;
callsign = data["callsign"] | "NOCALL-10";
rememberStationTime = data["other"]["rememberStationTime"] | 30;
@@ -143,6 +149,9 @@ bool Configuration::readFile() {
beacon.path = data["beacon"]["path"] | "WIDE1-1";
beacon.sendViaAPRSIS = data["beacon"]["sendViaAPRSIS"] | false;
beacon.sendViaRF = data["beacon"]["sendViaRF"] | false;
beacon.gpsActive = data["beacon"]["gpsActive"] | false;
beacon.gpsAmbiguity = data["beacon"]["gpsAmbiguity"] | false;
aprs_is.active = data["aprs_is"]["active"] | false;
aprs_is.passcode = data["aprs_is"]["passcode"] | "XYZWV";
@@ -153,6 +162,7 @@ bool Configuration::readFile() {
aprs_is.objectsToRF = data["aprs_is"]["objectsToRF"] | false;
digi.mode = data["digi"]["mode"] | 0;
digi.ecoMode = data["digi"]["ecoMode"] | false;
loramodule.txFreq = data["lora"]["txFreq"] | 433775000;
loramodule.rxFreq = data["lora"]["rxFreq"] | 433775000;
@@ -169,7 +179,7 @@ bool Configuration::readFile() {
battery.sendInternalVoltage = data["battery"]["sendInternalVoltage"] | false;
battery.monitorInternalVoltage = data["battery"]["monitorInternalVoltage"] | false;
battery.internalSleepVoltage = data["battery"]["internalSleepVoltage"] | 3.0;
battery.internalSleepVoltage = data["battery"]["internalSleepVoltage"] | 2.9;
battery.sendExternalVoltage = data["battery"]["sendExternalVoltage"] | false;
battery.externalVoltagePin = data["battery"]["externalVoltagePin"] | 34;
@@ -178,11 +188,11 @@ bool Configuration::readFile() {
battery.voltageDividerR1 = data["battery"]["voltageDividerR1"] | 100.0;
battery.voltageDividerR2 = data["battery"]["voltageDividerR2"] | 27.0;
battery.sendVoltageAsTelemetry = data["battery"]["sendVoltageAsTelemetry"] | true;
battery.sendVoltageAsTelemetry = data["battery"]["sendVoltageAsTelemetry"] | false;
bme.active = data["bme"]["active"] | false;
bme.heightCorrection = data["bme"]["heightCorrection"] | 0;
bme.temperatureCorrection = data["bme"]["temperatureCorrection"] | 0.0;
wxsensor.active = data["wxsensor"]["active"] | false;
wxsensor.heightCorrection = data["wxsensor"]["heightCorrection"] | 0;
wxsensor.temperatureCorrection = data["wxsensor"]["temperatureCorrection"] | 0.0;
syslog.active = data["syslog"]["active"] | false;
syslog.server = data["syslog"]["server"] | "192.168.0.100";
@@ -199,6 +209,8 @@ bool Configuration::readFile() {
webadmin.username = data["webadmin"]["username"] | "admin";
webadmin.password = data["webadmin"]["password"] | "";
ntp.gmtCorrection = data["ntp"]["gmtCorrection"] | 0;
lowPowerMode = data["other"]["lowPowerMode"] | false;
lowVoltageCutOff = data["other"]["lowVoltageCutOff"] | 0;
@@ -234,7 +246,7 @@ void Configuration::init() {
wifiAPs.push_back(wifiap);
wifiAutoAP.password = "1234567890";
wifiAutoAP.powerOff = 15;
wifiAutoAP.timeout = 10;
callsign = "N0CALL-10";
@@ -247,8 +259,12 @@ void Configuration::init() {
beacon.sendViaAPRSIS = true;
beacon.sendViaRF = false;
beacon.path = "WIDE1-1";
beacon.gpsActive = false;
beacon.gpsAmbiguity = false;
digi.mode = 0;
digi.mode = 0;
digi.ecoMode = false;
tnc.enableServer = false;
tnc.enableSerial = false;
@@ -279,9 +295,9 @@ void Configuration::init() {
syslog.server = "192.168.0.100";
syslog.port = 514;
bme.active = false;
bme.heightCorrection = 0;
bme.temperatureCorrection = 0.0;
wxsensor.active = false;
wxsensor.heightCorrection = 0;
wxsensor.temperatureCorrection = 0.0;
ota.username = "";
ota.password = "";
@@ -290,7 +306,7 @@ void Configuration::init() {
battery.sendInternalVoltage = false;
battery.monitorInternalVoltage = false;
battery.internalSleepVoltage = 3.0;
battery.internalSleepVoltage = 2.9;
battery.sendExternalVoltage = false;
battery.externalVoltagePin = 34;
@@ -315,6 +331,8 @@ void Configuration::init() {
webadmin.username = "admin";
webadmin.password = "";
ntp.gmtCorrection = 0;
Serial.println("All is Written!");
}

View File

@@ -14,7 +14,7 @@ public:
class WiFi_Auto_AP {
public:
String password;
int powerOff;
int timeout;
};
class BEACON {
@@ -28,6 +28,8 @@ public:
String path;
bool sendViaRF;
bool sendViaAPRSIS;
bool gpsActive;
bool gpsAmbiguity;
};
class APRS_IS {
@@ -44,6 +46,7 @@ public:
class DIGI {
public:
int mode;
bool ecoMode;
};
@@ -80,7 +83,7 @@ public:
bool sendVoltageAsTelemetry;
};
class BME {
class WXSENSOR {
public:
bool active;
int heightCorrection;
@@ -114,6 +117,13 @@ public:
String password;
};
class NTP {
public:
int gmtCorrection;
};
class Configuration {
public:
String callsign;
@@ -132,11 +142,12 @@ public:
LoraModule loramodule;
Display display;
BATTERY battery;
BME bme;
WXSENSOR wxsensor;
SYSLOG syslog;
TNC tnc;
OTA ota;
WEBADMIN webadmin;
NTP ntp;
void init();
void writeFile();

View File

@@ -25,31 +25,52 @@ extern bool backUpDigiMode;
namespace DIGI_Utils {
String buildPacket(const String& path, const String& packet, bool thirdParty) {
String packetToRepeat = packet.substring(0, packet.indexOf(",") + 1);
String tempPath = path;
String buildPacket(const String& path, const String& packet, bool thirdParty, bool crossFreq) {
if (!crossFreq) {
String packetToRepeat = packet.substring(0, packet.indexOf(",") + 1);
String tempPath = path;
if (path.indexOf("WIDE1-1") != -1 && (Config.digi.mode == 2 || Config.digi.mode == 3)) {
tempPath.replace("WIDE1-1", Config.callsign + "*");
} else if (path.indexOf("WIDE2-") != -1 && Config.digi.mode == 3) {
if (path.indexOf("*") != 1) {
tempPath.remove(path.indexOf("*"), 1);
if (path.indexOf("WIDE1-1") != -1 && (Config.digi.mode == 2 || Config.digi.mode == 3)) {
tempPath.replace("WIDE1-1", Config.callsign + "*");
} else if (path.indexOf("WIDE2-") != -1 && Config.digi.mode == 3) {
if (path.indexOf(",WIDE1*") != -1) {
tempPath.remove(path.indexOf(",WIDE1*"), 7);
}
if (path.indexOf("*") != -1) {
tempPath.remove(path.indexOf("*"), 1);
}
if (path.indexOf("WIDE2-1") != -1) {
tempPath.replace("WIDE2-1", Config.callsign + "*");
} else if (path.indexOf("WIDE2-2") != -1) {
tempPath.replace("WIDE2-2", Config.callsign + "*,WIDE2-1");
} else {
return "";
}
}
if (path.indexOf("WIDE2-1") != -1) {
tempPath.replace("WIDE2-1", Config.callsign + "*");
} else if (path.indexOf("WIDE2-2") != -1) {
tempPath.replace("WIDE2-2", Config.callsign + "*,WIDE2-1");
packetToRepeat += tempPath;
if (thirdParty) {
packetToRepeat += APRS_IS_Utils::checkForStartingBytes(packet.substring(packet.indexOf(":}")));
} else {
return "";
packetToRepeat += APRS_IS_Utils::checkForStartingBytes(packet.substring(packet.indexOf(":")));
}
return packetToRepeat;
} else { // CrossFreq Digirepeater
String suffix = thirdParty ? ":}" : ":";
String packetToRepeat = packet.substring(0, packet.indexOf(suffix));
String terms[] = {",WIDE1*", ",WIDE2*", "*"};
for (String term : terms) {
int index = packetToRepeat.indexOf(term);
if (index != -1) {
packetToRepeat.remove(index, term.length());
}
}
packetToRepeat += ",";
packetToRepeat += Config.callsign;
packetToRepeat += "*";
packetToRepeat += APRS_IS_Utils::checkForStartingBytes(packet.substring(packet.indexOf(suffix)));
return packetToRepeat;
}
packetToRepeat += tempPath;
if (thirdParty) {
packetToRepeat += APRS_IS_Utils::checkForStartingBytes(packet.substring(packet.indexOf(":}")));
} else {
packetToRepeat += APRS_IS_Utils::checkForStartingBytes(packet.substring(packet.indexOf(":")));
}
return packetToRepeat;
}
String generateDigiRepeatedPacket(const String& packet, bool thirdParty){
@@ -62,24 +83,34 @@ namespace DIGI_Utils {
}
if (temp.indexOf(",") > 2) { // checks for path
const String& path = temp.substring(temp.indexOf(",") + 1); // after tocall
if ((Config.digi.mode == 2 || backUpDigiMode) && path.indexOf("WIDE1-1") != - 1) {
return buildPacket(path, packet, thirdParty);
if (Config.digi.mode == 2 || backUpDigiMode) {
if (path.indexOf("WIDE1-1") != - 1) {
return buildPacket(path, packet, thirdParty, false);
} else if (path.indexOf("WIDE1-1") == -1 && (abs(Config.loramodule.txFreq - Config.loramodule.rxFreq) >= 125000)) { // CrossFreq Digi
return buildPacket(path, packet, thirdParty, true);
} else {
return "";
}
} else if (Config.digi.mode == 3) {
int wide1Index = path.indexOf("WIDE1-1");
int wide2Index = path.indexOf("WIDE2-");
if (path.indexOf("WIDE1-1") != -1 || path.indexOf("WIDE2-") != -1) {
int wide1Index = path.indexOf("WIDE1-1");
int wide2Index = path.indexOf("WIDE2-");
if (wide1Index != -1 && wide2Index != -1 && wide1Index < wide2Index) { // WIDE1-1 && WIDE2-n
return buildPacket(path, packet, thirdParty);
} else if (wide1Index != -1 && wide2Index == -1) { // only WIDE1-1
return buildPacket(path, packet, thirdParty);
} else if (wide1Index == -1 && wide2Index != -1) { // only WIDE2-n
return buildPacket(path, packet, thirdParty);
// WIDE1-1 && WIDE2-n / only WIDE1-1 / only WIDE2-n
if ((wide1Index != -1 && wide2Index != -1 && wide1Index < wide2Index) || (wide1Index != -1 && wide2Index == -1) || (wide1Index == -1 && wide2Index != -1)) {
return buildPacket(path, packet, thirdParty, false);
}
return "";
} else if (path.indexOf("WIDE1-1") == -1 && path.indexOf("WIDE2-") == -1 && (abs(Config.loramodule.txFreq - Config.loramodule.rxFreq) >= 125000)) { // CrossFreq Digi
return buildPacket(path, packet, thirdParty, true);
} else {
return "";
}
} else {
return "";
}
} else if (temp.indexOf(",") == -1 && (Config.digi.mode == 2 || backUpDigiMode || Config.digi.mode == 3) && (abs(Config.loramodule.txFreq - Config.loramodule.rxFreq) >= 125000)) {
return buildPacket("", packet, thirdParty, true);
} else {
return "";
}
@@ -133,4 +164,12 @@ namespace DIGI_Utils {
}
}
void checkEcoMode() {
if (Config.digi.ecoMode) {
Config.display.alwaysOn = false;
Config.display.timeout = 0;
setCpuFrequencyMhz(10);
}
}
}

View File

@@ -6,9 +6,10 @@
namespace DIGI_Utils {
String buildPacket(const String& path, const String& packet, bool thirdParty);
String buildPacket(const String& path, const String& packet, bool thirdParty, bool crossFreq);
String generateDigiRepeatedPacket(const String& packet, bool thirdParty);
void processLoRaPacket(const String& packet);
void checkEcoMode();
}

View File

@@ -1,13 +1,22 @@
#include <TinyGPS++.h>
#include <WiFi.h>
#include "configuration.h"
#include "boards_pinout.h"
#include "gps_utils.h"
#include "display.h"
#include "utils.h"
extern Configuration Config;
extern WiFiClient espClient;
String distance, iGateBeaconPacket, iGateLoRaBeaconPacket;
#ifdef GPS_BAUDRATE
#define GPS_BAUD GPS_BAUDRATE
#else
#define GPS_BAUD 9600
#endif
extern Configuration Config;
extern WiFiClient espClient;
extern HardwareSerial gpsSerial;
extern TinyGPSPlus gps;
String distance, iGateBeaconPacket, iGateLoRaBeaconPacket;
namespace GPS_Utils {
@@ -24,20 +33,32 @@ namespace GPS_Utils {
return(s);
}
float roundToTwoDecimals(float degrees) {
return round(degrees * 100) / 100;
}
String encodeGPS(float latitude, float longitude, const String& overlay, const String& symbol) {
String encodedData = overlay;
uint32_t aprs_lat, aprs_lon;
aprs_lat = 900000000 - latitude * 10000000;
float processedLatitude = latitude;
float processedLongitude = longitude;
if (Config.beacon.gpsActive && Config.beacon.gpsAmbiguity) {
processedLatitude = roundToTwoDecimals(latitude);
processedLongitude = roundToTwoDecimals(longitude);
}
aprs_lat = 900000000 - processedLatitude * 10000000;
aprs_lat = aprs_lat / 26 - aprs_lat / 2710 + aprs_lat / 15384615;
aprs_lon = 900000000 + longitude * 10000000 / 2;
aprs_lon = 900000000 + processedLongitude * 10000000 / 2;
aprs_lon = aprs_lon / 26 - aprs_lon / 2710 + aprs_lon / 15384615;
String Ns, Ew, helper;
if(latitude < 0) { Ns = "S"; } else { Ns = "N"; }
if(latitude < 0) { latitude= -latitude; }
if(processedLatitude < 0) { Ns = "S"; } else { Ns = "N"; }
if(processedLatitude < 0) { processedLatitude = -processedLatitude; }
if(longitude < 0) { Ew = "W"; } else { Ew = "E"; }
if(longitude < 0) { longitude= -longitude; }
if(processedLongitude < 0) { Ew = "W"; } else { Ew = "E"; }
if(processedLongitude < 0) { processedLongitude = -processedLongitude; }
char helper_base91[] = {"0000\0"};
int i;
@@ -55,6 +76,19 @@ namespace GPS_Utils {
return encodedData;
}
void generateBeaconFirstPart() {
String beaconPacket = Config.callsign;
beaconPacket += ">APLRG1";
if (Config.beacon.path.indexOf("WIDE") == 0) {
beaconPacket += ",";
beaconPacket += Config.beacon.path;
}
iGateBeaconPacket = beaconPacket;
iGateBeaconPacket += ",qAC:!";
iGateLoRaBeaconPacket = beaconPacket;
iGateLoRaBeaconPacket += ":!";
}
void generateBeacons() {
if (Config.callsign.indexOf("NOCALL-10") != 0 && !Utils::checkValidCallsign(Config.callsign)) {
displayShow("***** ERROR ******", "CALLSIGN = NOT VALID!", "", "Only Rx Mode Active", 3000);
@@ -64,19 +98,8 @@ namespace GPS_Utils {
Config.beacon.sendViaRF = false;
Config.digi.mode = 0;
Config.backupDigiMode = false;
}
String beaconPacket = Config.callsign;
beaconPacket += ">APLRG1";
if (Config.beacon.path.indexOf("WIDE") == 0) {
beaconPacket += ",";
beaconPacket += Config.beacon.path;
}
iGateBeaconPacket = beaconPacket;
iGateBeaconPacket += ",qAC:!";
iGateLoRaBeaconPacket = beaconPacket;
iGateLoRaBeaconPacket += ":!";
generateBeaconFirstPart();
String encodedGPS = encodeGPS(Config.beacon.latitude, Config.beacon.longitude, Config.beacon.overlay, Config.beacon.symbol);
iGateBeaconPacket += encodedGPS;
iGateLoRaBeaconPacket += encodedGPS;
@@ -184,4 +207,19 @@ namespace GPS_Utils {
}
}
void setup() {
#ifdef HAS_GPS
if (Config.beacon.gpsActive) {
gpsSerial.begin(GPS_BAUD, SERIAL_8N1, GPS_TX, GPS_RX);
}
#endif
generateBeacons();
}
void getData() {
while (gpsSerial.available() > 0) {
gps.encode(gpsSerial.read());
}
}
}

View File

@@ -5,16 +5,19 @@
namespace GPS_Utils {
String getiGateLoRaBeaconPacket();
char *ax25_base91enc(char *s, uint8_t n, uint32_t v);
String encodeGPS(float latitude, float longitude, const String& overlay, const String& symbol);
void generateBeaconFirstPart();
void generateBeacons();
double calculateDistanceCourse(double latitude, double longitude);
String decodeEncodedGPS(const String& packet);
String getReceivedGPS(const String& packet);
String getDistanceAndComment(const String& packet);
void setup();
void getData();
}
#endif

View File

@@ -4,6 +4,7 @@
#include "aprs_is_utils.h"
#include "boards_pinout.h"
#include "syslog_utils.h"
#include "ntp_utils.h"
#include "display.h"
#include "utils.h"
@@ -116,9 +117,9 @@ namespace LoRa_Utils {
if (Config.loramodule.txFreq != Config.loramodule.rxFreq) {
changeFreqTx();
}
#ifdef INTERNAL_LED_PIN
digitalWrite(INTERNAL_LED_PIN, HIGH);
if (!Config.digi.ecoMode) digitalWrite(INTERNAL_LED_PIN, HIGH);
#endif
int state = radio.transmit("\x3c\xff\x01" + newPacket);
transmitFlag = true;
@@ -133,7 +134,7 @@ namespace LoRa_Utils {
Utils::println(String(state));
}
#ifdef INTERNAL_LED_PIN
digitalWrite(INTERNAL_LED_PIN, LOW);
if (!Config.digi.ecoMode) digitalWrite(INTERNAL_LED_PIN, LOW);
#endif
if (Config.loramodule.txFreq != Config.loramodule.rxFreq) {
changeFreqRx();
@@ -175,15 +176,15 @@ 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) {
if (!Config.lowPowerMode && !Config.digi.ecoMode) {
if (receivedPackets.size() >= 10) {
receivedPackets.erase(receivedPackets.begin());
}
ReceivedPacket receivedPacket;
receivedPacket.millis = millis();
receivedPacket.rxTime = NTP_Utils::getFormatedTime();
receivedPacket.packet = packet.substring(3);
receivedPacket.RSSI = rssi;
receivedPacket.SNR = snr;
if (receivedPackets.size() >= 20) {
receivedPackets.erase(receivedPackets.begin());
}
receivedPackets.push_back(receivedPacket);
}

34
src/ntp_utils.cpp Normal file
View File

@@ -0,0 +1,34 @@
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <WiFi.h>
#include "configuration.h"
#include "ntp_utils.h"
#include "time.h"
extern Configuration Config;
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", 0, 15 * 60 * 1000); // Update interval 15 min
namespace NTP_Utils {
void setup() {
if (WiFi.status() == WL_CONNECTED && !Config.digi.ecoMode && Config.callsign != "NOCALL-10") {
int gmt = Config.ntp.gmtCorrection * 3600;
timeClient.setTimeOffset(gmt);
timeClient.begin();
}
}
void update() {
if (WiFi.status() == WL_CONNECTED && !Config.digi.ecoMode && Config.callsign != "NOCALL-10") timeClient.update();
}
String getFormatedTime() {
if (!Config.digi.ecoMode) return timeClient.getFormattedTime();
return "DigiEcoMode Active";
}
}

14
src/ntp_utils.h Normal file
View File

@@ -0,0 +1,14 @@
#ifndef NTP_UTILS_H_
#define NTP_UTILS_H_
#include <Arduino.h>
namespace NTP_Utils {
void setup();
void update();
String getFormatedTime();
}
#endif

View File

@@ -47,6 +47,36 @@ namespace POWER_Utils {
#endif
}
void activateGPS() {
#ifdef HAS_AXP192
PMU.setLDO3Voltage(3300);
PMU.enableLDO3();
#endif
#ifdef HAS_AXP2101
PMU.setALDO3Voltage(3300);
PMU.enableALDO3();
#endif
#ifdef HELTEC_WIRELESS_TRACKER
digitalWrite(VEXT_CTRL, HIGH);
#endif
//gpsIsActive = true;
}
void deactivateGPS() {
#ifdef HAS_AXP192
PMU.disableLDO3();
#endif
#ifdef HAS_AXP2101
PMU.disableALDO3();
#endif
#ifdef HELTEC_WIRELESS_TRACKER
digitalWrite(VEXT_CTRL, LOW);
#endif
//gpsIsActive = false;
}
void activateLoRa() {
#ifdef HAS_AXP192
PMU.setLDO2Voltage(3300);
@@ -159,6 +189,10 @@ namespace POWER_Utils {
#endif
#endif
#ifdef HAS_GPS
if (Config.beacon.gpsActive) activateGPS();
#endif
#ifdef ADC_CTRL
pinMode(ADC_CTRL, OUTPUT);
#endif

View File

@@ -14,6 +14,8 @@ namespace POWER_Utils {
double getBatteryVoltage();
bool isBatteryConnected();
void activateMeasurement();
void activateGPS();
void deactivateGPS();
void activateLoRa();
void deactivateLoRa();
bool begin(TwoWire &port);

View File

@@ -3,6 +3,7 @@
#include "query_utils.h"
#include "lora_utils.h"
extern Configuration Config;
extern std::vector<LastHeardStation> lastHeardStations;
extern String versionDate;
@@ -50,6 +51,16 @@ namespace QUERY_Utils {
// agregar callsign para completar donde esta X callsign --> posicion
Serial.println("estaciones escuchadas directo (ultimos 30 min)");
answer.concat("?WHERE on development 73!");
} else if (queryQuestion.indexOf("?APRSEEM") == 0 && Config.digi.ecoMode == true) { // Exit DigiRepeater EcoMode
answer = "DigiEcoMode:Stop";
Config.digi.ecoMode = false;
Config.display.alwaysOn = true;
Config.display.timeout = 10;
} else if (queryQuestion.indexOf("?APRSSEM") == 0 && Config.digi.ecoMode == false) { // Start DigiRepeater EcoMode
answer = "DigiEcoMode:Start";
Config.digi.ecoMode = true;
} else if (queryQuestion.indexOf("?APRSEMS") == 0) { // DigiRepeater EcoMode Status
answer = (Config.digi.ecoMode) ? "DigiEcoMode:ON" : "DigiEcoMode:OFF";
}
String queryAnswer = Config.callsign;

View File

@@ -3,6 +3,7 @@
#include "aprs_is_utils.h"
#include "configuration.h"
#include "lora_utils.h"
#include "display.h"
#include "utils.h"
#include <vector>
@@ -100,11 +101,16 @@ namespace STATION_Utils {
}
void processOutputPacketBuffer() {
int timeToWait = 3 * 1000; // 3 segs between packet Tx and also Rx ???
uint32_t lastRx = millis() - lastRxTime;
uint32_t lastTx = millis() - lastTxTime;
int timeToWait = 3 * 1000; // 3 segs between packet Tx and also Rx ???
uint32_t lastRx = millis() - lastRxTime;
uint32_t lastTx = millis() - lastTxTime;
bool saveNewDigiEcoModeConfig = false;
if (outputPacketBuffer.size() > 0 && lastTx > timeToWait && lastRx > timeToWait) {
LoRa_Utils::sendNewPacket(outputPacketBuffer[0]);
if (outputPacketBuffer[0].indexOf("DigiEcoMode:Start") != -1 || outputPacketBuffer[0].indexOf("DigiEcoMode:Stop") != -1) {
saveNewDigiEcoModeConfig = true;
shouldSleepLowVoltage = true; // to make sure all packets in outputPacketBuffer are sended before restart.
}
outputPacketBuffer.erase(outputPacketBuffer.begin());
lastTxTime = millis();
}
@@ -115,6 +121,11 @@ namespace STATION_Utils {
delay(4000);
}
}
if (saveNewDigiEcoModeConfig) {
Config.writeFile();
displayToggle(false);
ESP.restart();
}
}
void addToOutputPacketBuffer(const String& packet) {

View File

@@ -22,7 +22,7 @@ String inputSerialBuffer = "";
namespace TNC_Utils {
void setup() {
if (Config.tnc.enableServer) {
if (Config.tnc.enableServer && !Config.digi.ecoMode) {
tncServer.stop();
tncServer.begin();
}
@@ -133,12 +133,14 @@ namespace TNC_Utils {
}
void loop() {
if (Config.tnc.enableServer) {
checkNewClients();
readFromClients();
}
if (Config.tnc.enableSerial) {
readFromSerial();
if (!Config.digi.ecoMode) {
if (Config.tnc.enableServer) {
checkNewClients();
readFromClients();
}
if (Config.tnc.enableSerial) {
readFromSerial();
}
}
}
}

View File

@@ -1,3 +1,4 @@
#include <TinyGPS++.h>
#include <WiFi.h>
#include "configuration.h"
#include "station_utils.h"
@@ -9,12 +10,14 @@
#include "lora_utils.h"
#include "wifi_utils.h"
#include "gps_utils.h"
#include "bme_utils.h"
#include "wx_utils.h"
#include "display.h"
#include "utils.h"
extern Configuration Config;
extern WiFiClient espClient;
extern TinyGPSPlus gps;
extern String versionDate;
extern String firstLine;
extern String secondLine;
@@ -42,6 +45,8 @@ bool sendStartTelemetry = true;
bool beaconUpdate = true;
uint32_t lastBeaconTx = 0;
uint32_t lastScreenOn = millis();
String beaconPacket;
String secondaryBeaconPacket;
namespace Utils {
@@ -70,7 +75,9 @@ namespace Utils {
}
String getLocalIP() {
if (!WiFiConnected) {
if (Config.digi.ecoMode) {
return "** WiFi AP Killed **";
} else if (!WiFiConnected) {
return "IP : 192.168.4.1";
} else if (backUpDigiMode) {
return "- BACKUP DIGI MODE -";
@@ -85,6 +92,7 @@ namespace Utils {
digitalWrite(INTERNAL_LED_PIN,HIGH);
#endif
Serial.println("\nStarting Station: " + Config.callsign + " Version: " + versionDate);
Serial.println((Config.digi.ecoMode) ? "(DigiEcoMode: ON)" : "(DigiEcoMode: OFF)");
displayShow(" LoRa APRS", "", "", " ( iGATE & DIGI )", "", "" , " CA2RXU " + versionDate, 4000);
#ifdef INTERNAL_LED_PIN
digitalWrite(INTERNAL_LED_PIN,LOW);
@@ -103,7 +111,6 @@ namespace Utils {
fourthLine.concat(String(lastHeardStations.size()));
}
void sendInitialTelemetryPackets() {
String sender = Config.callsign;
for (int i = sender.length(); i < 9; i++) {
@@ -172,19 +179,25 @@ namespace Utils {
sendStartTelemetry = false;
}
void checkBeaconInterval() {
uint32_t lastTx = millis() - lastBeaconTx;
if (lastBeaconTx == 0 || lastTx >= Config.beacon.interval * 60 * 1000) {
beaconUpdate = true;
}
#ifdef HAS_GPS
if (Config.beacon.gpsActive && gps.location.lat() == 0.0 && gps.location.lng() == 0.0 && Config.beacon.latitude == 0.0 && Config.beacon.longitude == 0.0) {
GPS_Utils::getData();
beaconUpdate = false;
}
#endif
if (beaconUpdate) {
if (!Config.display.alwaysOn && Config.display.timeout != 0) {
displayToggle(true);
}
if (sendStartTelemetry && Config.battery.sendVoltageAsTelemetry && !Config.bme.active && (Config.battery.sendInternalVoltage || Config.battery.sendExternalVoltage)) {
if (sendStartTelemetry && Config.battery.sendVoltageAsTelemetry && !Config.wxsensor.active && (Config.battery.sendInternalVoltage || Config.battery.sendExternalVoltage)) {
sendInitialTelemetryPackets();
}
@@ -192,13 +205,25 @@ namespace Utils {
activeStations();
String beaconPacket = iGateBeaconPacket;
String secondaryBeaconPacket = iGateLoRaBeaconPacket;
if (Config.bme.active && wxModuleType != 0) {
String sensorData = BME_Utils::readDataSensor();
beaconPacket = iGateBeaconPacket;
secondaryBeaconPacket = iGateLoRaBeaconPacket;
#ifdef HAS_GPS
if (Config.beacon.gpsActive && !Config.digi.ecoMode) {
GPS_Utils::getData();
if (gps.location.isUpdated() && gps.location.lat() != 0.0 && gps.location.lng() != 0.0) {
GPS_Utils::generateBeaconFirstPart();
String encodedGPS = GPS_Utils::encodeGPS(gps.location.lat(), gps.location.lng(), Config.beacon.overlay, Config.beacon.symbol);
beaconPacket = iGateBeaconPacket + encodedGPS;
secondaryBeaconPacket = iGateLoRaBeaconPacket + encodedGPS;
}
}
#endif
if (Config.wxsensor.active && wxModuleType != 0) {
String sensorData = WX_Utils::readDataSensor();
beaconPacket += sensorData;
secondaryBeaconPacket += sensorData;
} else if (Config.bme.active && wxModuleType == 0) {
} else if (Config.wxsensor.active && wxModuleType == 0) {
beaconPacket += ".../...g...t...";
secondaryBeaconPacket += ".../...g...t...";
}
@@ -253,7 +278,7 @@ namespace Utils {
}
#endif
if (Config.battery.sendVoltageAsTelemetry && !Config.bme.active && (Config.battery.sendInternalVoltage || Config.battery.sendExternalVoltage)){
if (Config.battery.sendVoltageAsTelemetry && !Config.wxsensor.active && (Config.battery.sendInternalVoltage || Config.battery.sendExternalVoltage)){
String encodedTelemetry = BATTERY_Utils::generateEncodedTelemetry();
beaconPacket += encodedTelemetry;
secondaryBeaconPacket += encodedTelemetry;

View File

@@ -5,7 +5,7 @@
class ReceivedPacket {
public:
long millis;
String rxTime;
String packet;
int RSSI;
float SNR;

View File

@@ -81,10 +81,10 @@ namespace WEB_Utils {
StaticJsonDocument<1536> data;
for (int i = 0; i < receivedPackets.size(); i++) {
data[i]["millis"] = receivedPackets[i].millis;
data[i]["packet"] = receivedPackets[i].packet;
data[i]["RSSI"] = receivedPackets[i].RSSI;
data[i]["SNR"] = receivedPackets[i].SNR;
data[i]["rxTime"] = receivedPackets[i].rxTime;
data[i]["packet"] = receivedPackets[i].packet;
data[i]["RSSI"] = receivedPackets[i].RSSI;
data[i]["SNR"] = receivedPackets[i].SNR;
}
String buffer;
@@ -110,10 +110,10 @@ namespace WEB_Utils {
}
Config.callsign = request->getParam("callsign", true)->value();
Config.wifiAutoAP.password = request->getParam("wifi.autoAP.password", true)->value();
Config.wifiAutoAP.powerOff = request->getParam("wifi.autoAP.powerOff", true)->value().toInt();
Config.wifiAutoAP.password = request->getParam("wifi.autoAP.password", true)->value();
Config.wifiAutoAP.timeout = request->getParam("wifi.autoAP.timeout", true)->value().toInt();
Config.aprs_is.active = request->hasParam("aprs_is.active", true);
Config.aprs_is.passcode = request->getParam("aprs_is.passcode", true)->value();
@@ -134,8 +134,12 @@ namespace WEB_Utils {
Config.beacon.symbol = request->getParam("beacon.symbol", true)->value();
Config.beacon.path = request->getParam("beacon.path", true)->value();
Config.beacon.gpsActive = request->hasParam("beacon.gpsActive", true);
Config.beacon.gpsAmbiguity = request->hasParam("beacon.gpsAmbiguity", true);
Config.digi.mode = request->getParam("digi.mode", true)->value().toInt();
Config.digi.mode = request->getParam("digi.mode", true)->value().toInt();
Config.digi.ecoMode = request->hasParam("digi.ecoMode", true);
Config.loramodule.txFreq = request->getParam("lora.txFreq", true)->value().toInt();
@@ -148,11 +152,11 @@ namespace WEB_Utils {
Config.loramodule.rxActive = request->hasParam("lora.rxActive", true);
Config.display.alwaysOn = request->hasParam("display.alwaysOn", true);
Config.display.alwaysOn = request->hasParam("display.alwaysOn", true);
if (!Config.display.alwaysOn) {
Config.display.timeout = request->getParam("display.timeout", true)->value().toInt();
}
Config.display.turn180 = request->hasParam("display.turn180", true);
Config.display.turn180 = request->hasParam("display.turn180", true);
Config.battery.sendInternalVoltage = request->hasParam("battery.sendInternalVoltage", true);
@@ -162,18 +166,18 @@ namespace WEB_Utils {
Config.battery.sendExternalVoltage = request->hasParam("battery.sendExternalVoltage", true);
if (Config.battery.sendExternalVoltage) {
Config.battery.externalVoltagePin = request->getParam("battery.externalVoltagePin", true)->value().toInt();
Config.battery.voltageDividerR1 = request->getParam("battery.voltageDividerR1", true)->value().toFloat();
Config.battery.voltageDividerR2 = request->getParam("battery.voltageDividerR2", true)->value().toFloat();
Config.battery.voltageDividerR1 = request->getParam("battery.voltageDividerR1", true)->value().toFloat();
Config.battery.voltageDividerR2 = request->getParam("battery.voltageDividerR2", true)->value().toFloat();
}
Config.battery.monitorExternalVoltage = request->hasParam("battery.monitorExternalVoltage", true);
Config.battery.externalSleepVoltage = request->getParam("battery.externalSleepVoltage", true)->value().toFloat();
Config.battery.sendVoltageAsTelemetry = request->hasParam("battery.sendVoltageAsTelemetry", true);
Config.bme.active = request->hasParam("bme.active", true);
Config.bme.heightCorrection = request->getParam("bme.heightCorrection", true)->value().toInt();
Config.bme.temperatureCorrection = request->getParam("bme.temperatureCorrection", true)->value().toFloat();
if (Config.bme.active) {
Config.wxsensor.active = request->hasParam("wxsensor.active", true);
Config.wxsensor.heightCorrection = request->getParam("wxsensor.heightCorrection", true)->value().toInt();
Config.wxsensor.temperatureCorrection = request->getParam("wxsensor.temperatureCorrection", true)->value().toFloat();
if (Config.wxsensor.active) {
Config.beacon.symbol = "_";
}
@@ -207,6 +211,8 @@ namespace WEB_Utils {
Config.webadmin.password = request->getParam("webadmin.password", true)->value();
}
Config.ntp.gmtCorrection = request->getParam("ntp.gmtCorrection", true)->value().toInt();
Config.writeFile();
AsyncWebServerResponse *response = request->beginResponse(302, "text/html", "");
@@ -258,23 +264,25 @@ namespace WEB_Utils {
}
void setup() {
server.on("/", HTTP_GET, handleHome);
server.on("/status", HTTP_GET, handleStatus);
server.on("/received-packets.json", HTTP_GET, handleReceivedPackets);
server.on("/configuration.json", HTTP_GET, handleReadConfiguration);
server.on("/configuration.json", HTTP_POST, handleWriteConfiguration);
server.on("/action", HTTP_POST, handleAction);
server.on("/style.css", HTTP_GET, handleStyle);
server.on("/script.js", HTTP_GET, handleScript);
server.on("/bootstrap.css", HTTP_GET, handleBootstrapStyle);
server.on("/bootstrap.js", HTTP_GET, handleBootstrapScript);
server.on("/favicon.png", HTTP_GET, handleFavicon);
if (!Config.digi.ecoMode) {
server.on("/", HTTP_GET, handleHome);
server.on("/status", HTTP_GET, handleStatus);
server.on("/received-packets.json", HTTP_GET, handleReceivedPackets);
server.on("/configuration.json", HTTP_GET, handleReadConfiguration);
server.on("/configuration.json", HTTP_POST, handleWriteConfiguration);
server.on("/action", HTTP_POST, handleAction);
server.on("/style.css", HTTP_GET, handleStyle);
server.on("/script.js", HTTP_GET, handleScript);
server.on("/bootstrap.css", HTTP_GET, handleBootstrapStyle);
server.on("/bootstrap.js", HTTP_GET, handleBootstrapScript);
server.on("/favicon.png", HTTP_GET, handleFavicon);
OTA_Utils::setup(&server); // Include OTA Updater for WebServer
OTA_Utils::setup(&server); // Include OTA Updater for WebServer
server.onNotFound(handleNotFound);
server.onNotFound(handleNotFound);
server.begin();
server.begin();
}
}
}

View File

@@ -23,33 +23,35 @@ uint32_t lastBackupDigiTime = millis();
namespace WIFI_Utils {
void checkWiFi() {
if (backUpDigiMode) {
uint32_t WiFiCheck = millis() - lastBackupDigiTime;
if (WiFi.status() != WL_CONNECTED && WiFiCheck >= 15 * 60 * 1000) {
Serial.println("*** Stoping BackUp Digi Mode ***");
backUpDigiMode = false;
wifiCounter = 0;
} else if (WiFi.status() == WL_CONNECTED) {
Serial.println("*** WiFi Reconnect Success (Stoping Backup Digi Mode) ***");
backUpDigiMode = false;
wifiCounter = 0;
if (!Config.digi.ecoMode) {
if (backUpDigiMode) {
uint32_t WiFiCheck = millis() - lastBackupDigiTime;
if (WiFi.status() != WL_CONNECTED && WiFiCheck >= 15 * 60 * 1000) {
Serial.println("*** Stoping BackUp Digi Mode ***");
backUpDigiMode = false;
wifiCounter = 0;
} else if (WiFi.status() == WL_CONNECTED) {
Serial.println("*** WiFi Reconnect Success (Stoping Backup Digi Mode) ***");
backUpDigiMode = false;
wifiCounter = 0;
}
}
}
if (!backUpDigiMode && (WiFi.status() != WL_CONNECTED) && ((millis() - previousWiFiMillis) >= 30 * 1000) && !WiFiAutoAPStarted) {
Serial.print(millis());
Serial.println("Reconnecting to WiFi...");
WiFi.disconnect();
WIFI_Utils::startWiFi();//WiFi.reconnect();
previousWiFiMillis = millis();
if (!backUpDigiMode && (WiFi.status() != WL_CONNECTED) && ((millis() - previousWiFiMillis) >= 30 * 1000) && !WiFiAutoAPStarted) {
Serial.print(millis());
Serial.println("Reconnecting to WiFi...");
WiFi.disconnect();
WIFI_Utils::startWiFi();//WiFi.reconnect();
previousWiFiMillis = millis();
if (Config.backupDigiMode) {
wifiCounter++;
}
if (wifiCounter >= 2) {
Serial.println("*** Starting BackUp Digi Mode ***");
backUpDigiMode = true;
lastBackupDigiTime = millis();
if (Config.backupDigiMode) {
wifiCounter++;
}
if (wifiCounter >= 2) {
Serial.println("*** Starting BackUp Digi Mode ***");
backUpDigiMode = true;
lastBackupDigiTime = millis();
}
}
}
}
@@ -58,7 +60,7 @@ namespace WIFI_Utils {
WiFi.mode(WIFI_MODE_NULL);
WiFi.mode(WIFI_AP);
WiFi.softAP(Config.callsign + " AP", Config.wifiAutoAP.password);
WiFi.softAP(Config.callsign + "-AP", Config.wifiAutoAP.password);
WiFiAutoAPTime = millis();
WiFiAutoAPStarted = true;
@@ -131,14 +133,14 @@ namespace WIFI_Utils {
}
}
void checkIfAutoAPShouldPowerOff() {
if (WiFiAutoAPStarted && Config.wifiAutoAP.powerOff > 0) {
void checkAutoAPTimeout() {
if (WiFiAutoAPStarted && Config.wifiAutoAP.timeout > 0) {
if (WiFi.softAPgetStationNum() > 0) {
WiFiAutoAPTime = 0;
} else {
if (WiFiAutoAPTime == 0) {
WiFiAutoAPTime = millis();
} else if ((millis() - WiFiAutoAPTime) > Config.wifiAutoAP.powerOff * 60 * 1000) {
} else if ((millis() - WiFiAutoAPTime) > Config.wifiAutoAP.timeout * 60 * 1000) {
Serial.println("Stopping auto AP");
WiFiAutoAPStarted = false;
@@ -151,7 +153,7 @@ namespace WIFI_Utils {
}
void setup() {
startWiFi();
if (!Config.digi.ecoMode) startWiFi();
btStop();
}

View File

@@ -9,7 +9,7 @@ namespace WIFI_Utils {
void checkWiFi();
void startAutoAP();
void startWiFi();
void checkIfAutoAPShouldPowerOff();
void checkAutoAPTimeout();
void setup();
}

View File

@@ -1,10 +1,10 @@
#include "bme_utils.h"
#include "configuration.h"
#include "gps_utils.h"
#include "wx_utils.h"
#include "display.h"
#define SEALEVELPRESSURE_HPA (1013.25)
#define CORRECTION_FACTOR (8.2296) // for meters
#define SEALEVELPRESSURE_HPA (1013.25)
#define CORRECTION_FACTOR (8.2296) // for meters
extern Configuration Config;
extern String fifthLine;
@@ -27,7 +27,7 @@ Adafruit_Si7021 sensor = Adafruit_Si7021();
namespace BME_Utils {
namespace WX_Utils {
void getWxModuleAddres() {
uint8_t err, addr;
@@ -53,7 +53,7 @@ namespace BME_Utils {
}
void setup() {
if (Config.bme.active) {
if (Config.wxsensor.active) {
getWxModuleAddres();
if (wxModuleAddress != 0x00) {
bool wxModuleFound = false;
@@ -129,8 +129,8 @@ namespace BME_Utils {
}
}
String generateTempString(const float bmeTemp) {
String strTemp = String((int)bmeTemp);
String generateTempString(const float sensorTemp) {
String strTemp = String((int)sensorTemp);
switch (strTemp.length()) {
case 1:
return "00" + strTemp;
@@ -143,15 +143,15 @@ namespace BME_Utils {
}
}
String generateHumString(const float bmeHum) {
String strHum = String((int)bmeHum);
String generateHumString(const float sensorHum) {
String strHum = String((int)sensorHum);
switch (strHum.length()) {
case 1:
return "0" + strHum;
case 2:
return strHum;
case 3:
if ((int)bmeHum == 100) {
if ((int)sensorHum == 100) {
return "00";
} else {
return "-99";
@@ -161,9 +161,9 @@ namespace BME_Utils {
}
}
String generatePresString(const float bmePress) {
String strPress = String((int)bmePress);
String decPress = String(int((bmePress - int(bmePress)) * 10));
String generatePresString(const float sensorPres) {
String strPress = String((int)sensorPres);
String decPress = String(int((sensorPres - int(sensorPres)) * 10));
switch (strPress.length()) {
case 1:
return "000" + strPress + decPress;
@@ -213,14 +213,12 @@ namespace BME_Utils {
break;
}
String wx;
if (isnan(newTemp) || isnan(newHum) || isnan(newPress)) {
Serial.println("BME/BMP/Si7021 Module data failed");
wx = ".../...g...t...";
fifthLine = "";
return wx;
return ".../...g...t...";
} else {
String tempStr = generateTempString(((newTemp + Config.bme.temperatureCorrection) * 1.8) + 32);
String tempStr = generateTempString(((newTemp + Config.wxsensor.temperatureCorrection) * 1.8) + 32);
String humStr;
if (wxModuleType == 1 || wxModuleType == 3 || wxModuleType == 4) {
@@ -233,30 +231,30 @@ namespace BME_Utils {
if (wxModuleAddress == 4) {
presStr = ".....";
} else {
presStr = generatePresString(newPress + (Config.bme.heightCorrection/CORRECTION_FACTOR));
presStr = generatePresString(newPress + (Config.wxsensor.heightCorrection/CORRECTION_FACTOR));
}
fifthLine = "BME-> ";
fifthLine += String(int(newTemp + Config.bme.temperatureCorrection));
fifthLine += String(int(newTemp + Config.wxsensor.temperatureCorrection));
fifthLine += "C ";
fifthLine += humStr;
fifthLine += "% ";
fifthLine += presStr.substring(0,4);
fifthLine += "hPa";
wx = ".../...g...t";
wx += tempStr;
wx += "h";
wx += humStr;
wx += "b";
wx += presStr;
String wxPayload = ".../...g...t";
wxPayload += tempStr;
wxPayload += "h";
wxPayload += humStr;
wxPayload += "b";
wxPayload += presStr;
if (wxModuleType == 3) {
wx += "Gas: ";
wx += String(newGas);
wx += "Kohms";
wxPayload += "Gas: ";
wxPayload += String(newGas);
wxPayload += "Kohms";
}
return wx;
return wxPayload;
}
}

23
src/wx_utils.h Normal file
View File

@@ -0,0 +1,23 @@
#ifndef WX_UTILS_H_
#define WX_UTILS_H_
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <Adafruit_BMP280.h>
#include <Adafruit_BME680.h>
#include "Adafruit_Si7021.h"
#include <Arduino.h>
namespace WX_Utils {
void getWxModuleAddres();
void setup();
String generateTempString(const float sensorTemp);
String generateHumString(const float sensorHum);
String generatePresString(const float sensorPres);
String readDataSensor();
}
#endif