mirror of
https://github.com/Genaker/LoraSA.git
synced 2026-06-22 19:14:48 +02:00
Merge pull request #58 from Genaker/feature/config_web_interface
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>ESP Wi-Fi Manager</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="icon" href="data:,">
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="topnav">
|
||||
<h1>LORA SA ESP32 CONFIG</h1>
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="card-grid">
|
||||
<div class="card">
|
||||
<form action="/" method="POST">
|
||||
<p>
|
||||
<label for="ssid">SSID</label>
|
||||
<input type="text" id="ssid" name="ssid"><br>
|
||||
<label for="pass">Password</label>
|
||||
<input type="text" id="pass" name="pass"><br>
|
||||
<label for="ip">IP Address</label>
|
||||
<input type="text" id="ip" name="ip" value="192.168.1.200"><br>
|
||||
<label for="gateway">Gateway Address</label>
|
||||
<input type="text" id="gateway" name="gateway" value="192.168.1.1"><br>
|
||||
<label for="fstart">FREQ START</label>
|
||||
<input type="number" id="fstart" name="fstart" value="800"><br>
|
||||
<label for="fend">FREQ END</label>
|
||||
<input type="number" id="fend" name="fend" value="960"><br>
|
||||
<label for="samples">SCAN SAMPLES</label>
|
||||
<input type="number" id="samples" name="samples" value="10"><br>
|
||||
<input type="submit" value="Submit">
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
html {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
display: inline-block;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 1.8rem;
|
||||
color: white;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 1.4rem;
|
||||
}
|
||||
|
||||
.topnav {
|
||||
overflow: hidden;
|
||||
background-color: #0A1128;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.content {
|
||||
padding: 5%;
|
||||
}
|
||||
|
||||
.card-grid {
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
display: grid;
|
||||
grid-gap: 2rem;
|
||||
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
||||
}
|
||||
|
||||
.card {
|
||||
background-color: white;
|
||||
box-shadow: 2px 2px 12px 1px rgba(140, 140, 140, .5);
|
||||
}
|
||||
|
||||
.card-title {
|
||||
font-size: 1.2rem;
|
||||
font-weight: bold;
|
||||
color: #034078
|
||||
}
|
||||
|
||||
input[type=submit] {
|
||||
border: none;
|
||||
color: #FEFCFB;
|
||||
background-color: #034078;
|
||||
padding: 15px 15px;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
display: inline-block;
|
||||
font-size: 16px;
|
||||
width: 100px;
|
||||
margin-right: 10px;
|
||||
border-radius: 4px;
|
||||
transition-duration: 0.4s;
|
||||
}
|
||||
|
||||
input[type=submit]:hover {
|
||||
background-color: #1282A2;
|
||||
}
|
||||
|
||||
input[type=text],
|
||||
input[type=number],
|
||||
select {
|
||||
width: 50%;
|
||||
padding: 12px 20px;
|
||||
margin: 18px;
|
||||
display: inline-block;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 4px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
label {
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
.value {
|
||||
font-size: 1.2rem;
|
||||
color: #1282A2;
|
||||
}
|
||||
|
||||
.state {
|
||||
font-size: 1.2rem;
|
||||
color: #1282A2;
|
||||
}
|
||||
|
||||
button {
|
||||
border: none;
|
||||
color: #FEFCFB;
|
||||
padding: 15px 32px;
|
||||
text-align: center;
|
||||
font-size: 16px;
|
||||
width: 100px;
|
||||
border-radius: 4px;
|
||||
transition-duration: 0.4s;
|
||||
}
|
||||
|
||||
.button-on {
|
||||
background-color: #034078;
|
||||
}
|
||||
|
||||
.button-on:hover {
|
||||
background-color: #1282A2;
|
||||
}
|
||||
|
||||
.button-off {
|
||||
background-color: #858585;
|
||||
}
|
||||
|
||||
.button-off:hover {
|
||||
background-color: #252524;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
#include "FS.h"
|
||||
#include <LittleFS.h>
|
||||
|
||||
// Initialize LittleFS
|
||||
void initLittleFS()
|
||||
{
|
||||
if (!LittleFS.begin(true))
|
||||
{
|
||||
Serial.println("An error has occurred while mounting LittleFS");
|
||||
}
|
||||
Serial.println("LittleFS mounted successfully");
|
||||
}
|
||||
|
||||
String readFile(fs::FS &fs, const char *path)
|
||||
{
|
||||
Serial.printf("Reading file: %s\r\n", path);
|
||||
|
||||
File file = fs.open(path);
|
||||
if (!file || file.isDirectory())
|
||||
{
|
||||
Serial.println("- failed to open file for reading");
|
||||
return String("");
|
||||
}
|
||||
String content;
|
||||
Serial.println("- read from file:");
|
||||
while (file.available())
|
||||
{
|
||||
content = file.readStringUntil('\n');
|
||||
}
|
||||
file.close();
|
||||
return content;
|
||||
}
|
||||
|
||||
void writeFile(fs::FS &fs, const char *path, const char *message)
|
||||
{
|
||||
Serial.printf("Writing file: %s\r\n", path);
|
||||
Serial.printf("Content: %s\r\n", message);
|
||||
|
||||
File file = fs.open(path, FILE_WRITE);
|
||||
if (!file)
|
||||
{
|
||||
Serial.println("- failed to open file for writing");
|
||||
return;
|
||||
}
|
||||
if (file.print(message))
|
||||
{
|
||||
Serial.println("- file written");
|
||||
delay(500);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("- write failed");
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
@@ -35,6 +35,10 @@ SX1280 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUS
|
||||
// Default SPI on pins from pins_arduino.h
|
||||
SX1262 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN);
|
||||
#endif // end USING_SX1262
|
||||
#ifdef USING_LR1121
|
||||
// Default SPI on pins from pins_arduino.h
|
||||
LR1121 radio = new Module(RADIO_CS_PIN, RADIO_DIO9_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN);
|
||||
#endif // end USING_LR1121
|
||||
#ifdef USING_SX1276
|
||||
// Default SPI on pins from pins_arduino.h
|
||||
SX1276 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN);
|
||||
|
||||
@@ -0,0 +1,205 @@
|
||||
#include <AsyncTCP.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <LittleFS.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
// Create AsyncWebServer object on port 80
|
||||
AsyncWebServer server(80);
|
||||
|
||||
// Search for parameter in HTTP POST request
|
||||
const String SSID = "ssid";
|
||||
const String PASS = "pass";
|
||||
const String IP = "ip";
|
||||
const String GATEWAY = "gateway";
|
||||
const String FSTART = "fstart";
|
||||
const String FEND = "fend";
|
||||
|
||||
// File paths to save input values permanently
|
||||
// const char *ssidPath = "/ssid.txt";
|
||||
|
||||
// Variables to save values from HTML form
|
||||
String ssid = "LoraSA", pass = "1234567890", ip = "192.168.1.100",
|
||||
gateway = "192.168.1.1", fstart = "", fend = "", smpls = "";
|
||||
|
||||
IPAddress localIP;
|
||||
// Set your Gateway IP address
|
||||
IPAddress localGateway;
|
||||
IPAddress subnet(255, 255, 0, 0);
|
||||
|
||||
// Timer variables
|
||||
unsigned long previousMillis = 0;
|
||||
const long interval = 10000; // interval to wait for Wi-Fi connection (milliseconds)
|
||||
|
||||
// Initialize WiFi
|
||||
bool initWiFi()
|
||||
{
|
||||
Serial.println("SSID:" + ssid);
|
||||
Serial.println("PSWD:" + pass);
|
||||
Serial.println("IP:" + ip);
|
||||
Serial.println("SUB:" + subnet);
|
||||
Serial.println("GATAWAY:" + gateway);
|
||||
if (ssid == "" || ip == "")
|
||||
{
|
||||
Serial.println("Undefined SSID or IP address.");
|
||||
return false;
|
||||
}
|
||||
|
||||
WiFi.mode(WIFI_STA);
|
||||
localIP.fromString(ip.c_str());
|
||||
localGateway.fromString(gateway.c_str());
|
||||
|
||||
if (!WiFi.config(localIP, localGateway, subnet))
|
||||
{
|
||||
Serial.println("STA Failed to configure");
|
||||
return false;
|
||||
}
|
||||
WiFi.begin(ssid.c_str(), pass.c_str());
|
||||
Serial.println("Connecting to WiFi...");
|
||||
|
||||
unsigned long currentMillis = millis();
|
||||
previousMillis = currentMillis;
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
currentMillis = millis();
|
||||
if (currentMillis - previousMillis >= interval)
|
||||
{
|
||||
Serial.println("Failed to connect.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Serial.println(WiFi.localIP());
|
||||
return true;
|
||||
}
|
||||
|
||||
void writeParameterToFile(String value, String file)
|
||||
{
|
||||
// Write file to save value
|
||||
writeFile(LittleFS, file.c_str(), value.c_str());
|
||||
}
|
||||
|
||||
void writeParameterToParameterFile(String param, String value)
|
||||
{
|
||||
String file = String("/" + param + ".txt");
|
||||
// Write file to save value
|
||||
writeParameterToFile(value, file.c_str());
|
||||
}
|
||||
|
||||
String readParameterFromParameterFile(String param)
|
||||
{
|
||||
String file = String("/" + param + ".txt");
|
||||
return readFile(LittleFS, file.c_str());
|
||||
}
|
||||
|
||||
void serverServer()
|
||||
{
|
||||
// Route for root / web page
|
||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
|
||||
{ request->send(LittleFS, "/index.html", "text/html"); });
|
||||
|
||||
server.serveStatic("/", LittleFS, "/");
|
||||
|
||||
server.on("/", HTTP_POST,
|
||||
[](AsyncWebServerRequest *request)
|
||||
{
|
||||
int params = request->params();
|
||||
for (int i = 0; i < params; i++)
|
||||
{
|
||||
Serial.println("Parameter " + String(i) + ": " +
|
||||
request->getParam(i)->value());
|
||||
}
|
||||
Serial.println(request->params());
|
||||
|
||||
String p;
|
||||
if (request->hasParam(IP, true))
|
||||
{
|
||||
p = request->getParam(IP, true)->value();
|
||||
writeParameterToParameterFile(IP, p);
|
||||
}
|
||||
|
||||
if (request->hasParam(IP, true))
|
||||
{
|
||||
p = request->getParam(IP, true)->value();
|
||||
writeParameterToParameterFile(IP, p);
|
||||
}
|
||||
|
||||
if (request->hasParam(IP, true))
|
||||
{
|
||||
p = request->getParam(IP, true)->value();
|
||||
writeParameterToParameterFile(IP, p);
|
||||
}
|
||||
|
||||
if (request->hasParam(GATEWAY, true))
|
||||
{
|
||||
p = request->getParam(GATEWAY, true)->value();
|
||||
writeParameterToParameterFile(GATEWAY, p);
|
||||
}
|
||||
|
||||
if (request->hasParam(FSTART, true))
|
||||
{
|
||||
p = request->getParam(FSTART, true)->value();
|
||||
writeParameterToParameterFile(FSTART, p);
|
||||
}
|
||||
|
||||
if (request->hasParam(FEND, true))
|
||||
{
|
||||
p = request->getParam(FEND, true)->value();
|
||||
writeParameterToParameterFile(FEND, p);
|
||||
}
|
||||
|
||||
if (request->hasParam("samples", true))
|
||||
{
|
||||
p = request->getParam("samples", true)->value();
|
||||
writeParameterToParameterFile("samples", p);
|
||||
}
|
||||
|
||||
request->send(200, "text/plain",
|
||||
"Done. ESP will restart, connect to your router and "
|
||||
"go to IP address: " +
|
||||
ip);
|
||||
delay(3000);
|
||||
ESP.restart();
|
||||
});
|
||||
|
||||
/* // Route to set GPIO state to HIGH
|
||||
server.on("/on", HTTP_GET,
|
||||
[](AsyncWebServerRequest *request)
|
||||
{
|
||||
digitalWrite(ledPin, HIGH);
|
||||
request->send(LittleFS, "/index.html", "text/html", false,
|
||||
processor);
|
||||
});
|
||||
|
||||
// Route to set GPIO state to LOW
|
||||
server.on("/off", HTTP_GET,
|
||||
[](AsyncWebServerRequest *request)
|
||||
{
|
||||
digitalWrite(ledPin, LOW);
|
||||
request->send(LittleFS, "/index.html", "text/html", false,
|
||||
processor);
|
||||
});*/
|
||||
server.begin();
|
||||
}
|
||||
|
||||
void serverStart()
|
||||
{
|
||||
if (initWiFi())
|
||||
{
|
||||
Serial.println("Setting Secure WIFI (Access Point)");
|
||||
serverServer();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Connect to Wi-Fi network with default SSID and password
|
||||
Serial.println("Setting AP (Access Point)");
|
||||
// NULL sets an open Access Point
|
||||
WiFi.softAP("LoraSA", NULL);
|
||||
|
||||
IPAddress IP = WiFi.softAPIP();
|
||||
Serial.print("AP IP address: ");
|
||||
Serial.println(IP);
|
||||
|
||||
serverServer();
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -27,7 +27,9 @@ constexpr float HI_RSSI_THRESHOLD = -44.0;
|
||||
constexpr float LO_RSSI_THRESHOLD = HI_RSSI_THRESHOLD - 66;
|
||||
|
||||
// number of samples for RSSI method
|
||||
#define SAMPLES_RSSI 12 // 21 //
|
||||
#ifndef SAMPLES_RSSI
|
||||
#define SAMPLES_RSSI 13 // 21 //
|
||||
#endif
|
||||
#ifdef USING_SX1280PA
|
||||
#define SAMPLES_RSSI 20
|
||||
#endif
|
||||
|
||||
@@ -26,12 +26,15 @@ framework = arduino
|
||||
upload_speed = 921600
|
||||
monitor_speed = 115200
|
||||
board_build.f_cpu = 240000000
|
||||
board_build.filesystem = littlefs
|
||||
lib_deps =
|
||||
ropg/Heltec_ESP32_LoRa_v3@^0.9.1
|
||||
bblanchon/ArduinoJson@^7.2.0
|
||||
ESP Async WebServer
|
||||
build_flags =
|
||||
-DHELTEC_POWER_BUTTON
|
||||
-DHELTEC
|
||||
|
||||
|
||||
[env:heltec_wifi_lora_32_V3_433]
|
||||
platform = espressif32
|
||||
@@ -73,6 +76,36 @@ build_flags =
|
||||
-DARDUINO_LILYGO_T3_S3_V1_X
|
||||
-DARDUINO_USB_MODE=1
|
||||
|
||||
[env:lilygo-T3S3-v1-2-lr1121]
|
||||
platform = espressif32
|
||||
board = t3_s3_v1_x
|
||||
framework = arduino
|
||||
upload_speed = 921600
|
||||
monitor_speed = 115200
|
||||
board_build.f_cpu = 240000000
|
||||
board_build.filesystem = littlefs
|
||||
lib_deps =
|
||||
ropg/Heltec_ESP32_LoRa_v3@^0.9.1
|
||||
RadioLib
|
||||
U8g2
|
||||
XPowersLib
|
||||
bblanchon/ArduinoJson@^7.2.0
|
||||
ESP Async WebServer
|
||||
build_flags =
|
||||
-DLILYGO
|
||||
-DT3_S3_V1_2_LR1121
|
||||
-DT3_V1_3_SX1262
|
||||
-DARDUINO_LILYGO_T3S3_LR1121
|
||||
-DESP32
|
||||
-DSAMPLES_RSSI=5
|
||||
-DUSING_LR1121
|
||||
-DFREQ_BEGIN=2400
|
||||
-DFREQ_END=2500
|
||||
-DARDUINO_ARCH_ESP32
|
||||
-DARDUINO_USB_CDC_ON_BOOT=1
|
||||
-DARDUINO_LILYGO_T3_S3_V1_X
|
||||
-DARDUINO_USB_MODE=1
|
||||
|
||||
|
||||
[env:lilygo-T3S3-v1-2-sx1280]
|
||||
platform = espressif32
|
||||
|
||||
+130
-33
@@ -27,9 +27,18 @@
|
||||
#ifdef HELTEC
|
||||
#include <ArduinoJson.h>
|
||||
#endif
|
||||
#include "FS.h"
|
||||
#include <AsyncTCP.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <File.h>
|
||||
#include <LittleFS.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
|
||||
#include "WIFI_SERVER.h"
|
||||
|
||||
#define FORMAT_LITTLEFS_IF_FAILED true
|
||||
|
||||
// #define OSD_ENABLED true
|
||||
// #define WIFI_SCANNING_ENABLED true
|
||||
// #define BT_SCANNING_ENABLED true
|
||||
@@ -40,10 +49,12 @@
|
||||
// public and so will be exposed to the user. This allows direct manipulation of the
|
||||
// library internals.
|
||||
#define RADIOLIB_GODMODE (1)
|
||||
#define RADIOLIB_CHECK_PARAMS (0)
|
||||
|
||||
#include <charts.h>
|
||||
#include <events.h>
|
||||
#include <scan.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef LILYGO
|
||||
#include <heltec_unofficial.h>
|
||||
@@ -134,9 +145,9 @@ int SCAN_RANGES[] = {};
|
||||
|
||||
// MHZ per page
|
||||
// to put everything into one page set RANGE_PER_PAGE = FREQ_END - 800
|
||||
uint64_t RANGE_PER_PAGE = FREQ_END - FREQ_BEGIN; // FREQ_END - FREQ_BEGIN
|
||||
uint64_t RANGE_PER_PAGE; // FREQ_END - CONF_FREQ_BEGIN
|
||||
|
||||
// To Enable Multi Screen scan
|
||||
uint64_t CONF_FREQ_END, CONF_FREQ_BEGIN; // To Enable Multi Screen scan
|
||||
// uint64_t RANGE_PER_PAGE = 50;
|
||||
// Default Range on Menu Button Switch
|
||||
|
||||
@@ -168,16 +179,8 @@ constexpr int WINDOW_SIZE = 15;
|
||||
// if more than 100 it can freeze
|
||||
#define SAMPLES 35 //(scan time = 1294)
|
||||
|
||||
#define RANGE (int)(FREQ_END - FREQ_BEGIN)
|
||||
|
||||
#define SINGLE_STEP (float)(RANGE / (STEPS * SCAN_RBW_FACTOR))
|
||||
|
||||
uint64_t range = (int)(FREQ_END - FREQ_BEGIN);
|
||||
|
||||
uint64_t iterations = RANGE / RANGE_PER_PAGE;
|
||||
|
||||
// uint64_t range_frequency = FREQ_END - FREQ_BEGIN;
|
||||
uint64_t median_frequency = (FREQ_BEGIN + FREQ_END) / 2;
|
||||
uint64_t RANGE, range, iterations, median_frequency;
|
||||
float SINGLE_STEP;
|
||||
|
||||
// #define DISABLE_PLOT_CHART false // unused
|
||||
|
||||
@@ -224,11 +227,12 @@ uint64_t ranges_count = 0;
|
||||
int rssi = 0;
|
||||
int state = 0;
|
||||
|
||||
int CONF_SAMPLES;
|
||||
#ifdef METHOD_SPECTRAL
|
||||
constexpr int samples = SAMPLES;
|
||||
int samples = SAMPLES;
|
||||
#endif
|
||||
#ifdef METHOD_RSSI
|
||||
constexpr int samples = SAMPLES_RSSI;
|
||||
int samples = SAMPLES_RSSI;
|
||||
#endif
|
||||
|
||||
uint8_t result_index = 0;
|
||||
@@ -301,8 +305,8 @@ void osdProcess()
|
||||
// memset(max_step_range, 33, 30);
|
||||
max_bin = 32;
|
||||
|
||||
osd.displayString(12, 1, String(FREQ_BEGIN));
|
||||
osd.displayString(12, OSD_WIDTH - 8, String(FREQ_END));
|
||||
osd.displayString(12, 1, String(CONF_FREQ_BEGIN));
|
||||
osd.displayString(12, OSD_WIDTH - 8, String(CONF_FREQ_END));
|
||||
// Finding biggest in result
|
||||
// Skiping 0 and 32 31 to avoid overflow
|
||||
for (int i = 1; i < MAX_POWER_LEVELS - 3; i++)
|
||||
@@ -339,7 +343,7 @@ void osdProcess()
|
||||
#ifdef OSD_SIDE_BAR
|
||||
{
|
||||
osd.displayString(col, OSD_WIDTH - 7,
|
||||
String(FREQ_BEGIN + (col * osd_mhz_in_bin)) + "-" +
|
||||
String(CONF_FREQ_BEGIN + (col * osd_mhz_in_bin)) + "-" +
|
||||
String(max_step_range) + " ");
|
||||
}
|
||||
#endif
|
||||
@@ -367,13 +371,20 @@ struct RadioScan : Scan
|
||||
|
||||
float RadioScan::getRSSI()
|
||||
{
|
||||
#ifdef USING_SX1280PA
|
||||
#if defined(USING_SX1280PA)
|
||||
// radio.startReceive();
|
||||
// get instantaneous RSSI value
|
||||
// When PR will be merged we can use radi.getRSSI(false);
|
||||
uint8_t data[3] = {0, 0, 0}; // RssiInst, Status, RFU
|
||||
radio.mod->SPIreadStream(RADIOLIB_SX128X_CMD_GET_RSSI_INST, data, 3);
|
||||
return ((float)data[0] / (-2.0));
|
||||
|
||||
#elif defined(USING_LR1121)
|
||||
// Try getRssiInst
|
||||
float rssi;
|
||||
radio.getRssiInst(&rssi);
|
||||
// pass the replies
|
||||
return rssi;
|
||||
#else
|
||||
return radio.getRSSI(false);
|
||||
#endif
|
||||
@@ -392,10 +403,10 @@ void init_radio()
|
||||
{
|
||||
// initialize SX1262 FSK modem at the initial frequency
|
||||
both.println("Init radio");
|
||||
#ifdef USING_SX1280PA
|
||||
state = radio.beginGFSK(FREQ_BEGIN);
|
||||
#if defined(USING_SX1280PA) || defined(USING_LR1121)
|
||||
state = radio.beginGFSK(CONF_FREQ_BEGIN);
|
||||
#else
|
||||
state = radio.beginFSK(FREQ_BEGIN);
|
||||
state = radio.beginFSK(CONF_FREQ_BEGIN);
|
||||
#endif
|
||||
if (state == RADIOLIB_ERR_NONE)
|
||||
{
|
||||
@@ -447,7 +458,7 @@ void init_radio()
|
||||
// calibrate only once ,,, at startup
|
||||
// TODO: check documentation (9.2.1) if we must calibrate in certain ranges
|
||||
#ifdef USING_SX1280PA
|
||||
state = radio.setFrequency(FREQ_BEGIN);
|
||||
state = radio.setFrequency(CONF_FREQ_BEGIN);
|
||||
if (state != RADIOLIB_ERR_NONE)
|
||||
{
|
||||
Serial.println("Error:setFrequency:" + String(state));
|
||||
@@ -459,9 +470,9 @@ void init_radio()
|
||||
}
|
||||
#elif USING_SX1276
|
||||
// Sets carrier frequency. Allowed values range from 137.0 MHz to 1020.0 MHz.
|
||||
radio.setFrequency(FREQ_BEGIN);
|
||||
radio.setFrequency(CONF_FREQ_BEGIN);
|
||||
#else
|
||||
radio.setFrequency(FREQ_BEGIN, true);
|
||||
radio.setFrequency(CONF_FREQ_BEGIN, true);
|
||||
#endif
|
||||
|
||||
delay(50);
|
||||
@@ -546,8 +557,56 @@ void logToSerialTask(void *parameter)
|
||||
|
||||
void drone_sound_alarm(void *arg, Event &e);
|
||||
|
||||
void readConfigFile()
|
||||
{
|
||||
// writeFile(LittleFS, "/text.txt", "{WIFI:{name:\"sdfsdf\", Password:\"sdfsdf\"}");
|
||||
ssid = readParameterFromParameterFile(SSID);
|
||||
Serial.println("SSID: " + ssid);
|
||||
|
||||
pass = readParameterFromParameterFile(PASS);
|
||||
Serial.println("PASS: " + pass);
|
||||
|
||||
ip = readParameterFromParameterFile(IP);
|
||||
Serial.println("PASS: " + ip);
|
||||
|
||||
gateway = readParameterFromParameterFile(GATEWAY);
|
||||
Serial.println("GATEWAY: " + gateway);
|
||||
|
||||
fstart = readParameterFromParameterFile(FSTART);
|
||||
Serial.println("FSTART: " + fstart);
|
||||
|
||||
fend = readParameterFromParameterFile(FEND);
|
||||
Serial.println("FEND: " + fend);
|
||||
|
||||
smpls = readParameterFromParameterFile("samples");
|
||||
Serial.println("SAMPLES: " + smpls);
|
||||
|
||||
CONF_SAMPLES = (smpls == "") ? samples : atoi(smpls.c_str());
|
||||
samples = CONF_SAMPLES;
|
||||
CONF_FREQ_BEGIN = (fstart == "") ? FREQ_BEGIN : atoi(fstart.c_str());
|
||||
CONF_FREQ_END = (fend == "") ? FREQ_END : atoi(fend.c_str());
|
||||
|
||||
both.println("C FREQ BEGIN:" + String(CONF_FREQ_BEGIN));
|
||||
both.println("C FREQ END:" + String(CONF_FREQ_END));
|
||||
both.println("C SAMPLES:" + String(CONF_SAMPLES));
|
||||
|
||||
RANGE_PER_PAGE = CONF_FREQ_END - CONF_FREQ_BEGIN; // FREQ_END - CONF_FREQ_BEGIN
|
||||
|
||||
RANGE = (int)(CONF_FREQ_END - CONF_FREQ_BEGIN);
|
||||
|
||||
SINGLE_STEP = (float)(RANGE / (STEPS * SCAN_RBW_FACTOR));
|
||||
|
||||
range = (int)(CONF_FREQ_END - CONF_FREQ_BEGIN);
|
||||
|
||||
iterations = RANGE / RANGE_PER_PAGE;
|
||||
|
||||
// uint64_t range_frequency = FREQ_END - CONF_FREQ_BEGIN;
|
||||
median_frequency = (CONF_FREQ_BEGIN + CONF_FREQ_END) / 2;
|
||||
}
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
|
||||
#ifdef LILYGO
|
||||
setupBoards(); // true for disable U8g2 display library
|
||||
delay(500);
|
||||
@@ -580,6 +639,7 @@ void setup(void)
|
||||
pinMode(BUZZER_PIN, OUTPUT);
|
||||
pinMode(REB_PIN, OUTPUT);
|
||||
heltec_setup();
|
||||
|
||||
#ifdef JOYSTICK_ENABLED
|
||||
calibrate_joy();
|
||||
pinMode(JOY_BTN_PIN, INPUT_PULLUP);
|
||||
@@ -599,10 +659,46 @@ void setup(void)
|
||||
}
|
||||
}
|
||||
|
||||
display.clear();
|
||||
|
||||
both.println("CLICK for WIFI settings.");
|
||||
|
||||
for (int i = 0; i < 200; i++)
|
||||
{
|
||||
both.print(".");
|
||||
|
||||
button.update();
|
||||
delay(10);
|
||||
if (button.pressedNow())
|
||||
{
|
||||
both.println("-----------");
|
||||
both.println("Starting WIFI-SERVER...");
|
||||
// Error here: E (15752) ledc: ledc_get_duty(745): LEDC is not initialized
|
||||
tone(BUZZER_PIN, 205, 100);
|
||||
delay(50);
|
||||
tone(BUZZER_PIN, 205, 500);
|
||||
tone(BUZZER_PIN, 205, 100);
|
||||
delay(50);
|
||||
|
||||
serverStart();
|
||||
both.println("Ready to Connect: 192.168.4.1");
|
||||
delay(600);
|
||||
break;
|
||||
}
|
||||
}
|
||||
both.print("\n");
|
||||
|
||||
both.println("Init File System");
|
||||
initLittleFS();
|
||||
|
||||
readConfigFile();
|
||||
|
||||
init_radio();
|
||||
|
||||
#ifndef LILYGO
|
||||
vbat = heltec_vbat();
|
||||
both.printf("V battery: %.2fV (%d%%)\n", vbat, heltec_battery_percent(vbat));
|
||||
delay(1000);
|
||||
#endif // end not LILYGO
|
||||
#ifdef WIFI_SCANNING_ENABLED
|
||||
WiFi.mode(WIFI_STA);
|
||||
@@ -705,8 +801,9 @@ void setup(void)
|
||||
r.trigger_level = TRIGGER_LEVEL;
|
||||
stacked.reset(0, 0, display.width(), display.height());
|
||||
|
||||
bar = new DecoratedBarChart(display, 0, 0, display.width(), 0, FREQ_BEGIN, FREQ_END,
|
||||
LO_RSSI_THRESHOLD, HI_RSSI_THRESHOLD, r.trigger_level);
|
||||
bar = new DecoratedBarChart(display, 0, 0, display.width(), 0, CONF_FREQ_BEGIN,
|
||||
CONF_FREQ_END, LO_RSSI_THRESHOLD, HI_RSSI_THRESHOLD,
|
||||
r.trigger_level);
|
||||
|
||||
size_t b = stacked.addChart(bar);
|
||||
|
||||
@@ -720,9 +817,9 @@ void setup(void)
|
||||
|
||||
delete[] multiples;
|
||||
|
||||
waterChart =
|
||||
new WaterfallChart(display, 0, WATERFALL_START, display.width(), 0, FREQ_BEGIN,
|
||||
FREQ_END, r.trigger_level, WATERFALL_SENSITIVITY, model);
|
||||
waterChart = new WaterfallChart(display, 0, WATERFALL_START, display.width(), 0,
|
||||
CONF_FREQ_BEGIN, CONF_FREQ_END, r.trigger_level,
|
||||
WATERFALL_SENSITIVITY, model);
|
||||
|
||||
size_t c = stacked.addChart(waterChart);
|
||||
stacked.setHeight(c, stacked.height - WATERFALL_START - statusBar->height);
|
||||
@@ -953,13 +1050,13 @@ void loop(void)
|
||||
}
|
||||
|
||||
// do the scan
|
||||
range = FREQ_END - FREQ_BEGIN;
|
||||
range = CONF_FREQ_END - CONF_FREQ_BEGIN;
|
||||
if (RANGE_PER_PAGE > range)
|
||||
{
|
||||
RANGE_PER_PAGE = range;
|
||||
}
|
||||
|
||||
r.fr_begin = FREQ_BEGIN;
|
||||
r.fr_begin = CONF_FREQ_BEGIN;
|
||||
r.fr_end = r.fr_begin;
|
||||
|
||||
// 50 is a single-screen range
|
||||
@@ -1092,7 +1189,7 @@ void loop(void)
|
||||
// Spectrum analyzer using getRSSI
|
||||
{
|
||||
LOG("METHOD RSSI");
|
||||
uint16_t max_rssi = r.rssiMethod(SAMPLES_RSSI, result,
|
||||
uint16_t max_rssi = r.rssiMethod(CONF_SAMPLES, result,
|
||||
RADIOLIB_SX126X_SPECTRAL_SCAN_RES_SIZE);
|
||||
|
||||
if (max_x_rssi[display_x] > max_rssi)
|
||||
@@ -1104,7 +1201,7 @@ void loop(void)
|
||||
|
||||
// if this code is not executed LORA radio doesn't work
|
||||
// basically SX1262 requires delay
|
||||
// osd.displayString(12, 1, String(FREQ_BEGIN));
|
||||
// osd.displayString(12, 1, String(CONF_FREQ_BEGIN));
|
||||
// osd.displayString(12, 30 - 8, String(FREQ_END));
|
||||
// delay(2);
|
||||
|
||||
|
||||
+7
-4
@@ -16,6 +16,8 @@
|
||||
|
||||
// temporary dirty import ... to be solved durring upcoming refactoring
|
||||
extern unsigned int RANGE_PER_PAGE;
|
||||
extern uint64_t CONF_FREQ_BEGIN;
|
||||
extern uint64_t CONF_FREQ_END;
|
||||
extern unsigned int median_frequency;
|
||||
extern unsigned int drone_detected_frequency_start;
|
||||
extern unsigned int drone_detected_frequency_end;
|
||||
@@ -95,7 +97,8 @@ void StatusBar::draw()
|
||||
// Frequency start
|
||||
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display.drawString(pos_x, text_y,
|
||||
(r.fr_begin == 0) ? String(FREQ_BEGIN) : String(r.fr_begin));
|
||||
(r.fr_begin == 0) ? String(CONF_FREQ_BEGIN)
|
||||
: String(r.fr_begin));
|
||||
|
||||
// Frequency detected
|
||||
display.setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
@@ -106,7 +109,7 @@ void StatusBar::draw()
|
||||
// Frequency end
|
||||
display.setTextAlignment(TEXT_ALIGN_RIGHT);
|
||||
display.drawString(pos_x + width, text_y,
|
||||
(r.fr_end == 0) ? String(FREQ_END) : String(r.fr_end));
|
||||
(r.fr_end == 0) ? String(CONF_FREQ_END) : String(r.fr_end));
|
||||
}
|
||||
|
||||
// Status text block
|
||||
@@ -170,11 +173,11 @@ void StatusBar::draw()
|
||||
display.drawString(pos_x, text_y, String(loop_time));
|
||||
#else
|
||||
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display.drawString(pos_x, text_y, String(FREQ_BEGIN));
|
||||
display.drawString(pos_x, text_y, String(CONF_FREQ_BEGIN));
|
||||
|
||||
#endif
|
||||
display.setTextAlignment(TEXT_ALIGN_RIGHT);
|
||||
display.drawString(pos_x + width, text_y, String(FREQ_END));
|
||||
display.drawString(pos_x + width, text_y, String(CONF_FREQ_END));
|
||||
}
|
||||
else if (ranges_count > 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user