This commit is contained in:
richonguzman 2024-09-24 13:28:19 -03:00
parent 06794b7226
commit 329aa2715c
17 changed files with 19367 additions and 1 deletions

12200
data_embed/bootstrap.css vendored Normal file

File diff suppressed because it is too large Load Diff

BIN
data_embed/bootstrap.css.gz Normal file

Binary file not shown.

4467
data_embed/bootstrap.js vendored Normal file

File diff suppressed because it is too large Load Diff

BIN
data_embed/bootstrap.js.gz Normal file

Binary file not shown.

BIN
data_embed/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 813 B

BIN
data_embed/favicon.png.gz Normal file

Binary file not shown.

1848
data_embed/index.html Normal file

File diff suppressed because one or more lines are too long

BIN
data_embed/index.html.gz Normal file

Binary file not shown.

550
data_embed/script.js Normal file
View File

@ -0,0 +1,550 @@
// Custom scripts
let currentSettings = null;
function backupSettings() {
const data =
"data:text/json;charset=utf-8," +
encodeURIComponent(JSON.stringify(currentSettings));
const a = document.createElement("a");
a.setAttribute("href", data);
a.setAttribute("download", "TrackerConfigurationBackup.json");
a.click();
}
document.getElementById("backup").onclick = backupSettings;
document.getElementById("restore").onclick = function (e) {
e.preventDefault();
document.querySelector("input[type=file]").click();
};
document.querySelector("input[type=file]").onchange = function () {
const files = document.querySelector("input[type=file]").files;
if (!files.length) return;
const file = files.item(0);
const reader = new FileReader();
reader.readAsText(file);
reader.onload = () => {
const data = JSON.parse(reader.result);
loadSettings(data);
};
};
function fetchSettings() {
fetch("/configuration.json")
.then((response) => response.json())
.then((settings) => {
loadSettings(settings);
})
.catch((err) => {
console.error(err);
alert(`Failed to load configuration`);
});
}
const alwaysOnCheckbox = document.querySelector(
'input[name="display.alwaysOn"]'
);
const timeoutInput = document.querySelector('input[name="display.timeout"]');
alwaysOnCheckbox.addEventListener("change", function () {
timeoutInput.disabled = this.checked;
});
// timeoutInput.addEventListener("change", function () {
// alwaysOnCheckbox.disabled = this.value !== "";
// });
const logCheckbox = document.querySelector('input[name="syslog.active"]');
const serverField = document.querySelector('input[name="syslog.server"]');
const portField = document.querySelector('input[name="syslog.port"]');
logCheckbox.addEventListener("change", function () {
serverField.disabled = !this.checked;
portField.disabled = !this.checked;
});
function loadSettings(settings) {
currentSettings = settings;
// General
document.getElementById("callsign").value = settings.callsign;
document.getElementById("beacon.comment").value = settings.beacon.comment;
document.getElementById("beacon.path").value = settings.beacon.path;
document.getElementById("beacon.symbol").value = settings.beacon.symbol;
document.getElementById("beacon.overlay").value = settings.beacon.overlay;
document.getElementById("personalNote").value = settings.personalNote;
document.getElementById("action.symbol").value = settings.beacon.overlay + settings.beacon.symbol;
document.querySelector(".list-networks").innerHTML = "";
// Networks
const wifiNetworks = settings.wifi.AP || [];
const networksContainer = document.querySelector(".list-networks");
let networkCount = 0;
wifiNetworks.forEach((network) => {
const networkElement = document.createElement("div");
networkElement.classList.add("row", "network", "border-bottom", "py-2");
// Increment the name, id, and for attributes
const attributeName = `wifi.AP.${networkCount}`;
networkElement.innerHTML = `
<div class="form-floating col-5 px-1 mb-2">
<input type="text" class="form-control form-control-sm" name="${attributeName}.ssid" id="${attributeName}.ssid" value="${network.ssid}">
<label for="${attributeName}.ssid">SSID</label>
</div>
<div class="form-floating col-5 px-1 mb-2">
<input type="password" class="form-control form-control-sm" name="${attributeName}.password" id="${attributeName}.password" value="${network.password}">
<label for="${attributeName}.password">Passphrase</label>
</div>
<div class="col-2 d-flex align-items-center justify-content-end">
<div class="btn-group" role="group">
<button type="button" class="btn btn-sm btn-danger" title="Delete" onclick="return this.parentNode.parentNode.parentNode.remove();"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash3-fill" viewBox="0 0 16 16">
<path d="M11 1.5v1h3.5a.5.5 0 0 1 0 1h-.538l-.853 10.66A2 2 0 0 1 11.115 16h-6.23a2 2 0 0 1-1.994-1.84L2.038 3.5H1.5a.5.5 0 0 1 0-1H5v-1A1.5 1.5 0 0 1 6.5 0h3A1.5 1.5 0 0 1 11 1.5m-5 0v1h4v-1a.5.5 0 0 0-.5-.5h-3a.5.5 0 0 0-.5.5M4.5 5.029l.5 8.5a.5.5 0 1 0 .998-.06l-.5-8.5a.5.5 0 1 0-.998.06m6.53-.528a.5.5 0 0 0-.528.47l-.5 8.5a.5.5 0 0 0 .998.058l.5-8.5a.5.5 0 0 0-.47-.528M8 4.5a.5.5 0 0 0-.5.5v8.5a.5.5 0 0 0 1 0V5a.5.5 0 0 0-.5-.5"/>
</svg><span class="visually-hidden">Delete</span></button>
</div>
</div>
`;
networksContainer.appendChild(networkElement);
networkCount++;
});
// APRS-IS
document.getElementById("aprs_is.active").checked = settings.aprs_is.active;
document.getElementById("aprs_is.messagesToRF").checked = settings.aprs_is.messagesToRF;
document.getElementById("aprs_is.objectsToRF").checked = settings.aprs_is.objectsToRF;
document.getElementById("aprs_is.server").value = settings.aprs_is.server;
document.getElementById("aprs_is.port").value = settings.aprs_is.port;
document.getElementById("aprs_is.filter").value = settings.aprs_is.filter;
document.getElementById("aprs_is.passcode").value = settings.aprs_is.passcode;
// Beacon
document.getElementById("beacon.latitude").value = settings.beacon.latitude;
document.getElementById("beacon.longitude").value = settings.beacon.longitude;
document.getElementById("beacon.interval").value = settings.beacon.interval;
document.getElementById("other.rememberStationTime").value = settings.other.rememberStationTime;
document.getElementById("beacon.sendViaAPRSIS").checked = settings.beacon.sendViaAPRSIS;
document.getElementById("beacon.sendViaRF").checked = settings.beacon.sendViaRF;
// Digi
document.getElementById("digi.mode").value = settings.digi.mode;
// LoRa
document.getElementById("lora.txFreq").value = settings.lora.txFreq;
document.getElementById("lora.rxFreq").value = settings.lora.rxFreq;
document.getElementById("lora.txActive").checked = settings.lora.txActive;
document.getElementById("lora.rxActive").checked = settings.lora.rxActive;
document.getElementById("lora.spreadingFactor").value = settings.lora.spreadingFactor;
document.getElementById("lora.signalBandwidth").value = settings.lora.signalBandwidth;
document.getElementById("lora.codingRate4").value = settings.lora.codingRate4;
document.getElementById("lora.power").value = settings.lora.power;
// Display
document.getElementById("display.alwaysOn").checked = settings.display.alwaysOn;
document.getElementById("display.turn180").checked = settings.display.turn180;
document.getElementById("display.timeout").value = settings.display.timeout;
if (settings.display.alwaysOn) {
timeoutInput.disabled = true;
}
// BATTERY
document.getElementById("battery.sendInternalVoltage").checked = settings.battery.sendInternalVoltage;
document.getElementById("battery.monitorInternalVoltage").checked = settings.battery.monitorInternalVoltage;
document.getElementById("battery.internalSleepVoltage").value = settings.battery.internalSleepVoltage.toFixed(1);
document.getElementById("battery.sendExternalVoltage").checked = settings.battery.sendExternalVoltage;
document.getElementById("battery.externalVoltagePin").value = settings.battery.externalVoltagePin;
document.getElementById("battery.voltageDividerR1").value = settings.battery.voltageDividerR1.toFixed(1);
document.getElementById("battery.voltageDividerR2").value = settings.battery.voltageDividerR2.toFixed(1);
document.getElementById("battery.monitorExternalVoltage").checked = settings.battery.monitorExternalVoltage;
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);
// SYSLOG
document.getElementById("syslog.active").checked = settings.syslog.active;
document.getElementById("syslog.server").value = settings.syslog.server;
document.getElementById("syslog.port").value = settings.syslog.port;
if (settings.syslog.active) {
serverField.disabled = false;
portField.disabled = false;
}
// TNC
if (settings.tnc) {
document.getElementById("tnc.enableServer").checked = settings.tnc.enableServer;
document.getElementById("tnc.enableSerial").checked = settings.tnc.enableSerial;
document.getElementById("tnc.acceptOwn").checked = settings.tnc.acceptOwn;
}
// Reboot
document.getElementById("other.rebootMode").checked = settings.other.rebootMode;
document.getElementById("other.rebootModeTime").value = settings.other.rebootModeTime;
// WiFi Auto AP
document.getElementById("wifi.autoAP.password").value = settings.wifi.autoAP.password;
document.getElementById("wifi.autoAP.powerOff").value = settings.wifi.autoAP.powerOff;
// OTA
document.getElementById("ota.username").value = settings.ota.username;
document.getElementById("ota.password").value = settings.ota.password;
// Webadmin
document.getElementById("webadmin.active").checked = settings.webadmin.active;
document.getElementById("webadmin.username").value = settings.webadmin.username;
document.getElementById("webadmin.password").value = settings.webadmin.password;
// Experimental
document.getElementById("other.backupDigiMode").checked = settings.other.backupDigiMode;
document.getElementById("other.lowPowerMode").checked = settings.other.lowPowerMode;
document.getElementById("other.lowVoltageCutOff").value = settings.other.lowVoltageCutOff || 0
updateImage();
refreshSpeedStandard();
toggleFields();
}
function showToast(message) {
const el = document.querySelector('#toast');
el.querySelector('.toast-body').innerHTML = message;
(new bootstrap.Toast(el)).show();
}
document.getElementById('send-beacon').addEventListener('click', function (e) {
e.preventDefault();
fetch("/action?type=send-beacon", { method: "POST" });
showToast("Your beacon will be sent in a moment. <br> <u>This action will be ignored if you have APRSIS and LoRa TX disabled!</u>");
});
document.getElementById('reboot').addEventListener('click', function (e) {
e.preventDefault();
fetch("/action?type=reboot", { method: "POST" });
showToast("Your device will be rebooted in a while");
});
const bmeCheckbox = document.querySelector("input[name='bme.active']");
const stationModeSelect = document.querySelector("select[name='stationMode']");
function updateImage() {
const value = document.getElementById("beacon.overlay").value + document.getElementById("beacon.symbol").value;
const image = document.querySelector("img");
switch (value) {
case "L&":
image.src =
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHgAAAB4CAYAAAA5ZDbSAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAQ6SURBVHgB7d0/axRBGMfx50IMWPoKkpA02gUsLfZdqOCLOPBFWAliHbCUVNpaxQNrIY0WVjZaJlUsIsZ5uDu9bGb/zMwzs/PM/L7wIG4Ocflwl7ndvVsihBBCmTajunpk5uHG33+aOSGkvhdmLs1cW+bKzDEhle2a+UZ22Pacrx6PlMRYXc/arrkkIKvIBxfISgrBBXLmSeACOdMkcYGcWTFwgZxJMXGBPHEpcIE8USl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ltageCheckbox = document.querySelector(
'input[name="battery.sendExternalVoltage"]'
);
const externalVoltagePinInput = document.querySelector(
'input[name="battery.externalVoltagePin"]'
);
externalVoltagePinInput.disabled = !sendExternalVoltageCheckbox.checked;
voltageDividerR1.disabled = !sendExternalVoltageCheckbox.checked;
voltageDividerR2.disabled = !sendExternalVoltageCheckbox.checked;
const WebadminCheckbox = document.querySelector(
'input[name="webadmin.active"]'
);
const WebadminUsername = document.querySelector(
'input[name="webadmin.username"]'
);
const WebadminPassword = document.querySelector(
'input[name="webadmin.password"]'
);
WebadminUsername.disabled = !WebadminCheckbox.checked;
WebadminPassword.disabled = !WebadminCheckbox.checked;
}
const sendExternalVoltageCheckbox = document.querySelector(
'input[name="battery.sendExternalVoltage"]'
);
const externalVoltagePinInput = document.querySelector(
'input[name="battery.externalVoltagePin"]'
);
const voltageDividerR1 = document.querySelector(
'input[name="battery.voltageDividerR1"]'
);
const voltageDividerR2 = document.querySelector(
'input[name="battery.voltageDividerR2"]'
);
sendExternalVoltageCheckbox.addEventListener("change", function () {
externalVoltagePinInput.disabled = !this.checked;
voltageDividerR1.disabled = !this.checked;
voltageDividerR2.disabled = !this.checked;
});
const WebadminCheckbox = document.querySelector(
'input[name="webadmin.active"]'
);
const WebadminUsername = document.querySelector(
'input[name="webadmin.username"]'
);
const WebadminPassword = document.querySelector(
'input[name="webadmin.password"]'
);
WebadminCheckbox.addEventListener("change", function () {
WebadminUsername.disabled = !this.checked;
WebadminPassword.disabled = !this.checked;
});
document.querySelector(".new button").addEventListener("click", function () {
const networksContainer = document.querySelector(".list-networks");
let networkCount = document.querySelectorAll(".network").length;
const networkElement = document.createElement("div");
networkElement.classList.add("row", "network", "border-bottom", "py-2");
// Increment the name, id, and for attributes
const attributeName = `wifi.AP.${networkCount}`;
networkElement.innerHTML = `
<div class="form-floating col-6 col-md-5 px-1 mb-2">
<input type="text" class="form-control form-control-sm" name="${attributeName}.ssid" id="${attributeName}.ssid" placeholder="" >
<label for="${attributeName}.ssid">SSID</label>
</div>
<div class="form-floating col-6 col-md-5 px-1 mb-2">
<input type="password" class="form-control form-control-sm" name="${attributeName}.password" id="${attributeName}.password" placeholder="">
<label for="${attributeName}.password">Passphrase</label>
</div>
<div class="col-4 col-md-2 d-flex align-items-center justify-content-end">
<div class="btn-group" role="group">
<button type="button" class="btn btn-sm btn-danger" title="Delete" onclick="return this.parentNode.parentNode.parentNode.remove();"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash3-fill" viewBox="0 0 16 16">
<path d="M11 1.5v1h3.5a.5.5 0 0 1 0 1h-.538l-.853 10.66A2 2 0 0 1 11.115 16h-6.23a2 2 0 0 1-1.994-1.84L2.038 3.5H1.5a.5.5 0 0 1 0-1H5v-1A1.5 1.5 0 0 1 6.5 0h3A1.5 1.5 0 0 1 11 1.5m-5 0v1h4v-1a.5.5 0 0 0-.5-.5h-3a.5.5 0 0 0-.5.5M4.5 5.029l.5 8.5a.5.5 0 1 0 .998-.06l-.5-8.5a.5.5 0 1 0-.998.06m6.53-.528a.5.5 0 0 0-.528.47l-.5 8.5a.5.5 0 0 0 .998.058l.5-8.5a.5.5 0 0 0-.47-.528M8 4.5a.5.5 0 0 0-.5.5v8.5a.5.5 0 0 0 1 0V5a.5.5 0 0 0-.5-.5"/>
</svg><span class="visually-hidden">Delete</span></button>
</div>
</div>
`;
networksContainer.appendChild(networkElement);
networkCount++;
// Add the new network element to the end of the document
document.querySelector(".new").before(networkElement);
});
document
.getElementById("action.symbol")
.addEventListener("change", function () {
const value = document.getElementById("action.symbol").value;
document.getElementById("beacon.overlay").value = value[0];
document.getElementById("beacon.symbol").value = value[1];
updateImage();
});
const speedStandards = {
300: [125, 5, 12],
244: [125, 6, 12],
209: [125, 7, 12],
183: [125, 8, 12],
610: [125, 8, 10],
1200: [125, 7, 9],
};
function refreshSpeedStandard() {
const bw = Number(document.getElementById("lora.signalBandwidth").value);
const cr4 = Number(document.getElementById("lora.codingRate4").value);
const sf = Number(document.getElementById("lora.spreadingFactor").value);
let found = false;
for (const speed in speedStandards) {
const standard = speedStandards[speed];
if (standard[0] !== bw / 1000) continue;
if (standard[1] !== cr4) continue;
if (standard[2] !== sf) continue;
document.getElementById("action.speed").value = speed;
found = true;
break;
}
if (!found) {
document.getElementById("action.speed").value = "";
}
}
document
.getElementById("lora.signalBandwidth")
.addEventListener("focusout", refreshSpeedStandard);
document
.getElementById("lora.codingRate4")
.addEventListener("focusout", refreshSpeedStandard);
document
.getElementById("lora.spreadingFactor")
.addEventListener("focusout", refreshSpeedStandard);
document.getElementById("action.speed").addEventListener("change", function () {
const speed = document.getElementById("action.speed").value;
if (speed !== "") {
const value = speedStandards[Number(speed)];
const bw = value[0];
const cr4 = value[1];
const sf = value[2];
document.getElementById("lora.signalBandwidth").value = bw * 1000;
document.getElementById("lora.codingRate4").value = cr4;
document.getElementById("lora.spreadingFactor").value = sf;
}
});
const form = document.querySelector("form");
const saveModal = new bootstrap.Modal(document.getElementById("saveModal"), {
backdrop: "static",
keyboard: false,
});
const savedModal = new bootstrap.Modal(
document.getElementById("savedModal"),
{}
);
function checkConnection() {
const controller = new AbortController();
setTimeout(() => controller.abort(), 2000);
fetch("/status?_t=" + Date.now(), { signal: controller.signal })
.then(() => {
saveModal.hide();
savedModal.show();
setTimeout(function () {
savedModal.hide();
}, 3000);
fetchSettings();
})
.catch((err) => {
setTimeout(checkConnection, 0);
});
}
form.addEventListener("submit", async (event) => {
event.preventDefault();
document.getElementById("wifi.APs").value =
document.querySelectorAll(".network").length;
fetch(form.action, {
method: form.method,
body: new FormData(form),
});
saveModal.show();
setTimeout(checkConnection, 2000);
});
fetchSettings();
function loadReceivedPackets(packets) {
if (packets) {
document.querySelector('#received-packets tbody').innerHTML = '';
const container = document.querySelector("#received-packets tbody");
container.innerHTML = '';
const date = new Date();
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.packet}</td>
<td>${packet.RSSI}</td>
<td>${packet.SNR}</td>
`;
container.appendChild(element);
})
}
setTimeout(fetchReceivedPackets, 15000);
}
function fetchReceivedPackets() {
fetch("/received-packets.json")
.then((response) => response.json())
.then((packets) => {
loadReceivedPackets(packets);
})
.catch((err) => {
console.error(err);
console.error(`Failed to load received packets`);
});
}
document.querySelector('a[href="/received-packets"]').addEventListener('click', function (e) {
e.preventDefault();
document.getElementById('received-packets').classList.remove('d-none');
document.getElementById('configuration').classList.add('d-none');
document.querySelector('button[type=submit]').remove();
fetchReceivedPackets();
})

BIN
data_embed/script.js.gz Normal file

Binary file not shown.

8
data_embed/style.css Normal file
View File

@ -0,0 +1,8 @@
.alert-fixed {
position:fixed;
top: 0px;
left: 0px;
width: 100%;
z-index:9999;
border-radius:0px
}

BIN
data_embed/style.css.gz Normal file

Binary file not shown.

View File

@ -21,6 +21,15 @@ extends = env
platform = espressif32 @ 6.7.0
board_build.partitions = huge_app.csv
monitor_filters = esp32_exception_decoder
board_build.embed_files =
data_embed/index.html.gz
data_embed/style.css.gz
data_embed/script.js.gz
data_embed/bootstrap.css.gz
data_embed/bootstrap.js.gz
data_embed/favicon.png.gz
extra_scripts =
pre:tools/compress.py
[env:nrf52]
extends = env
@ -41,6 +50,8 @@ lib_deps =
adafruit/Adafruit BME280 Library @ 2.2.4
adafruit/Adafruit BMP280 Library @ 2.6.8
adafruit/Adafruit BME680 Library @ 2.0.4
mathieucarbou/ESPAsyncWebServer @ 3.2.3
mathieucarbou/AsyncTCP @ 3.2.5
[env:ttgo-t-beam-v1_2]

View File

@ -34,6 +34,7 @@ ________________________________________________________________________________
#include "msg_utils.h"
#include "gps_utils.h"
#include "bme_utils.h"
#include "web_utils.h"
#include "ble_utils.h"
#include "display.h"
#include "utils.h"
@ -119,7 +120,7 @@ void setup() {
displayShow(" WEB-CONF","", "WiFiAP:LoRaTracker-AP", "IP : 192.168.4.1","", "");
logger.log(logging::LoggerLevel::LOGGER_LEVEL_WARN, "Main", "WebConfiguration Started!");
WIFI_Utils::startAutoAP();
//WEB_Utils::setup();
WEB_Utils::setup();
while (true) { // comienza web config
// algo

210
src/web_utils.cpp Normal file
View File

@ -0,0 +1,210 @@
#include <ArduinoJson.h>
#include "configuration.h"
#include "web_utils.h"
#include "display.h"
#include "utils.h"
extern Configuration Config;
extern const char web_index_html[] asm("_binary_data_embed_index_html_gz_start");
extern const char web_index_html_end[] asm("_binary_data_embed_index_html_gz_end");
extern const size_t web_index_html_len = web_index_html_end - web_index_html;
extern const char web_style_css[] asm("_binary_data_embed_style_css_gz_start");
extern const char web_style_css_end[] asm("_binary_data_embed_style_css_gz_end");
extern const size_t web_style_css_len = web_style_css_end - web_style_css;
extern const char web_script_js[] asm("_binary_data_embed_script_js_gz_start");
extern const char web_script_js_end[] asm("_binary_data_embed_script_js_gz_end");
extern const size_t web_script_js_len = web_script_js_end - web_script_js;
extern const char web_bootstrap_css[] asm("_binary_data_embed_bootstrap_css_gz_start");
extern const char web_bootstrap_css_end[] asm("_binary_data_embed_bootstrap_css_gz_end");
extern const size_t web_bootstrap_css_len = web_bootstrap_css_end - web_bootstrap_css;
extern const char web_bootstrap_js[] asm("_binary_data_embed_bootstrap_js_gz_start");
extern const char web_bootstrap_js_end[] asm("_binary_data_embed_bootstrap_js_gz_end");
extern const size_t web_bootstrap_js_len = web_bootstrap_js_end - web_bootstrap_js;
// Declare external symbols for the embedded image data
extern const unsigned char favicon_data[] asm("_binary_data_embed_favicon_png_gz_start");
extern const unsigned char favicon_data_end[] asm("_binary_data_embed_favicon_png_gz_end");
extern const size_t favicon_data_len = favicon_data_end - favicon_data;
namespace WEB_Utils {
AsyncWebServer server(80);
void handleNotFound(AsyncWebServerRequest *request) {
AsyncWebServerResponse *response = request->beginResponse(404, "text/plain", "Not found");
response->addHeader("Cache-Control", "max-age=3600");
request->send(response);
}
void handleStatus(AsyncWebServerRequest *request) {
request->send(200, "text/plain", "OK");
}
void handleHome(AsyncWebServerRequest *request) {
AsyncWebServerResponse *response = request->beginResponse(200, "text/html", (const uint8_t*)web_index_html, web_index_html_len);
response->addHeader("Content-Encoding", "gzip");
request->send(response);
}
void handleFavicon(AsyncWebServerRequest *request) {
AsyncWebServerResponse *response = request->beginResponse(200, "image/x-icon", (const uint8_t*)favicon_data, favicon_data_len);
response->addHeader("Content-Encoding", "gzip");
request->send(response);
}
void handleReadConfiguration(AsyncWebServerRequest *request) {
File file = SPIFFS.open("/tracker_conf.json");
String fileContent;
while(file.available()){
fileContent += String((char)file.read());
}
request->send(200, "application/json", fileContent);
}
void handleReceivedPackets(AsyncWebServerRequest *request) {
StaticJsonDocument<2048> data;
String buffer;
serializeJson(data, buffer);
request->send(200, "application/json", buffer);
}
void handleWriteConfiguration(AsyncWebServerRequest *request) {
Serial.println("Got new config from www");
if (request->hasParam("display.ecoMode", true)) {
Config.display.ecoMode = true;
if (request->hasParam("display.timeout", true)) {
Config.display.timeout = request->getParam("display.timeout", true)->value().toInt();
}
} else {
Config.display.ecoMode = false;
}
Config.display.turn180 = request->hasParam("display.turn180", true);
Config.display.showSymbol = request->hasParam("display.showSymbol", true);
if (request->hasParam("winlink.password", true)) {
Config.winlink.password = request->getParam("winlink.password", true)->value();
}
/*Config.bme.active = request->hasParam("bme.active", true);
Config.bme.temperatureCorrection = request->getParam("bme.temperatureCorrection", true)->value().toFloat();
Config.bme.sendTelemetry = request->hasParam("bme.sendTelemetry", true);
Config.notification.ledTx = request->hasParam("notification.ledTx", true);
Config.notification.ledTxPin = request->getParam("notification.ledTxPin", true)->value().toInt();
Config.notification.ledMessage = request->hasParam("notification.ledMessage", true);
Config.notification.ledMessagePin = request->getParam("notification.ledMessagePin", true)->value().toInt();
Config.notification.ledFlashlight = request->hasParam("notification.ledFlashlight", true);
Config.notification.ledFlashlightPin = request->getParam("notification.ledFlashlightPin", true)->value().toInt();
Config.notification.buzzerActive = request->hasParam("notification.buzzerActive", true);
Config.notification.buzzerPinTone = request->getParam("notification.buzzerPinTone", true)->value().toInt();
Config.notification.buzzerPinVcc = request->getParam("notification.buzzerPinVcc", true)->value().toInt();
Config.notification.bootUpBeep = request->hasParam("notification.bootUpBeep", true);
Config.notification.txBeep = request->hasParam("notification.txBeep", true);
Config.notification.messageRxBeep = request->hasParam("notification.messageRxBeep", true);
Config.notification.stationBeep = request->hasParam("notification.stationBeep", true);
Config.notification.lowBatteryBeep = request->hasParam("notification.lowBatteryBeep", true);
Config.notification.shutDownBeep = request->hasParam("notification.shutDownBeep", true);
Config.ptt.active = request->hasParam("ptt.active", true);
Config.ptt.io_pin = request->getParam("ptt.io_pin", true)->value().toInt();
Config.ptt.preDelay = request->getParam("ptt.preDelay", true)->value().toInt();
Config.ptt.postDelay = request->getParam("ptt.postDelay", true)->value().toInt();
Config.ptt.reverse = request->hasParam("ptt.reverse", true);
Config.simplifiedTrackerMode = request->hasParam("other.simplifiedTrackerMode", true);
Config.sendCommentAfterXBeacons = request->getParam("other.sendCommentAfterXBeacons", true)->value().toInt();
Config.path = request->getParam("other.path", true)->value();
Config.nonSmartBeaconRate = request->getParam("other.nonSmartBeaconRate", true)->value().toInt();
Config.rememberStationTime = request->getParam("other.rememberStationTime", true)->value().toInt();
Config.maxDistanceToTracker = request->getParam("other.maxDistanceToTracker", true)->value().toInt();
Config.standingUpdateTime = request->getParam("other.standingUpdateTime", true)->value().toInt();
Config.sendAltitude = request->hasParam("other.sendAltitude", true);
Config.sendBatteryInfo = request->hasParam("other.sendBatteryInfo", true);
Config.bluetoothType = request->getParam("other.bluetoothType", true)->value().toInt();
Config.bluetoothActive = request->hasParam("other.bluetoothActive", true);
Config.disableGPS = request->hasParam("other.disableGPS", true);*/
Config.writeFile();
AsyncWebServerResponse *response = request->beginResponse(302, "text/html", "");
response->addHeader("Location", "/");
request->send(response);
displayToggle(false);
delay(500);
ESP.restart();
}
void handleAction(AsyncWebServerRequest *request) {
String type = request->getParam("type", false)->value();
if (type == "send-beacon") {
//lastBeaconTx = 0;
request->send(200, "text/plain", "Beacon will be sent in a while");
} else if (type == "reboot") {
displayToggle(false);
ESP.restart();
} else {
request->send(404, "text/plain", "Not Found");
}
}
void handleStyle(AsyncWebServerRequest *request) {
AsyncWebServerResponse *response = request->beginResponse(200, "text/css", (const uint8_t*)web_style_css, web_style_css_len);
response->addHeader("Content-Encoding", "gzip");
request->send(response);
}
void handleScript(AsyncWebServerRequest *request) {
AsyncWebServerResponse *response = request->beginResponse(200, "text/javascript", (const uint8_t*)web_script_js, web_script_js_len);
response->addHeader("Content-Encoding", "gzip");
request->send(response);
}
void handleBootstrapStyle(AsyncWebServerRequest *request) {
AsyncWebServerResponse *response = request->beginResponse(200, "text/css", (const uint8_t*)web_bootstrap_css, web_bootstrap_css_len);
response->addHeader("Content-Encoding", "gzip");
response->addHeader("Cache-Control", "max-age=3600");
request->send(response);
}
void handleBootstrapScript(AsyncWebServerRequest *request) {
AsyncWebServerResponse *response = request->beginResponse(200, "text/javascript", (const uint8_t*)web_bootstrap_js, web_bootstrap_js_len);
response->addHeader("Content-Encoding", "gzip");
response->addHeader("Cache-Control", "max-age=3600");
request->send(response);
}
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);
server.onNotFound(handleNotFound);
server.begin();
}
}

29
src/web_utils.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef WEB_UTILS_H_
#define WEB_UTILS_H_
#include <ESPAsyncWebServer.h>
#include <ESPmDNS.h>
#include <Arduino.h>
#include <SPIFFS.h>
#include <WiFi.h>
namespace WEB_Utils {
void handleNotFound(AsyncWebServerRequest *request);
void handleStatus(AsyncWebServerRequest *request);
void handleHome(AsyncWebServerRequest *request);
//void handleReadConfiguration(AsyncWebServerRequest *request);
//void handleWriteConfiguration(AsyncWebServerRequest *request);
void handleStyle(AsyncWebServerRequest *request);
void handleScript(AsyncWebServerRequest *request);
void handleBootstrapStyle(AsyncWebServerRequest *request);
void handleBootstrapScript(AsyncWebServerRequest *request);
void setup();
}
#endif

42
tools/compress.py Normal file
View File

@ -0,0 +1,42 @@
import gzip
import os
import datetime
Import("env")
files = [
'data_embed/index.html',
'data_embed/script.js',
'data_embed/style.css',
'data_embed/bootstrap.js',
'data_embed/bootstrap.css',
'data_embed/favicon.png',
]
string_to_find_str = "String"
string_to_find_ver = "versionDate"
with open('src/LoRa_APRS_Tracker.cpp', encoding='utf-8') as cpp_file:
for line in cpp_file:
if string_to_find_str in line and string_to_find_ver in line:
start = line.find('"') + 1
end = line.find('"', start)
if start > 0 and end > start:
versionDate = line[start:end]
break
for src in files:
out = src + ".gz"
with open(src, 'rb') as f:
content = f.read()
if src == 'data_embed/index.html':
env_vars = env["BOARD"] + "<br>" + ','.join(env["BUILD_FLAGS"]).replace('-Werror -Wall,', '').replace(',-DELEGANTOTA_USE_ASYNC_WEBSERVER=1', '') + "<br>" + "Version date: " + versionDate
current_date = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S') + " UTC"
build_info = f'{env_vars}<br>Build date: {current_date}'.encode()
content = content.replace(b'%BUILD_INFO%', build_info)
with open(out, 'wb') as f:
f.write(gzip.compress(content, compresslevel=9))