Allows to configure LoRa frequency and speed on the web interface

This commit is contained in:
gorzynsk 2021-08-03 18:11:18 +02:00
parent 5dd2eec54a
commit 1a44bea515
4 changed files with 76 additions and 12 deletions

View file

@ -45,6 +45,22 @@
</div>
<article>
<form action="/save_aprs_cfg" method="post">
<div class="grid-container full">
<h5 class="u-full-width">Transmission Settings</h5>
</div>
<div class="grid-container halves">
<div>
<label for="lora_freq">Frequency [MHz]</label>
<input name="lora_freq" id="lora_freq" type="number" min="433.000" max="434.000" step="0.001" title="LoRa center frequency between 433.001 and 434.000">
</div>
<div>
<label for="lora_speed">Speed [baud]</label>
<select id="lora_speed" name="lora_speed">
<option value="300">300 baud</option>
<option value="1200">1200 baud</option>
</select>
</div>
</div>
<div class="grid-container full">
<h5 class="u-full-width">Station Settings</h5>
</div>

View file

@ -10,6 +10,12 @@ extern Preferences preferences;
// MAX 15 chars for preferenece key!!!
static const char *const PREF_WIFI_SSID = "wifi_ssid";
static const char *const PREF_WIFI_PASSWORD = "wifi_password";
// LoRa settings
static const char *const PREF_LORA_FREQ_PRESET_INIT = "lora_freq_i";
static const char *const PREF_LORA_FREQ_PRESET = "lora_freq";
static const char *const PREF_LORA_SPEED_PRESET_INIT = "lora_speed_i";
static const char *const PREF_LORA_SPEED_PRESET = "lora_speed";
// Station settings
static const char *const PREF_APRS_CALLSIGN = "aprs_callsign";
static const char *const PREF_APRS_RELAY_PATH = "aprs_relay_path";
static const char *const PREF_APRS_RELAY_PATH_INIT = "aprs_relay_init";

View file

@ -86,6 +86,10 @@
const byte TXLED = 4; //pin number for LED on TX Tracker
#endif
// Variables for LoRa settings
ulong lora_speed = 1200;
double lora_freq = 433.775;
// Variables for APRS packaging
String Tcall; //your Call Sign for normal position reports
String aprsSymbolTable = APRS_SYMBOL_TABLE;
@ -314,7 +318,7 @@ void sendpacket(){
#endif
batt_read();
prepareAPRSFrame();
loraSend(txPower, TXFREQ, outString); //send the packet, data is in TXbuff from lora_TXStart to lora_TXEnd
loraSend(txPower, lora_freq, outString); //send the packet, data is in TXbuff from lora_TXStart to lora_TXEnd
}
/**
@ -331,11 +335,12 @@ void loraSend(byte lora_LTXPower, float lora_FREQ, const String &message) {
int messageSize = min(message.length(), sizeof(lora_TXBUFF) - 1);
message.toCharArray((char*)lora_TXBUFF, messageSize + 1, 0);
#ifdef SPEED_1200
if(lora_speed==1200){
rf95.setModemConfig(BG_RF95::Bw125Cr47Sf512);
#else
}
else{
rf95.setModemConfig(BG_RF95::Bw125Cr45Sf4096);
#endif
}
rf95.setFrequency(lora_FREQ);
rf95.setTxPower(lora_LTXPower);
rf95.sendAPRS(lora_TXBUFF, messageSize);
@ -499,7 +504,8 @@ void sendTelemetryFrame() {
// + SETUP --------------------------------------------------------------+//
void setup(){
SPI.begin(SPI_sck,SPI_miso,SPI_mosi,SPI_ss); //DO2JMG Heltec Patch
Serial.begin(115200);
#ifdef BUZZER
ledcSetup(0,1E5,12);
ledcAttachPin(BUZZER,0);
@ -523,6 +529,23 @@ void setup(){
}
preferences.begin("cfg", false);
// LoRa transmission settings
if (!preferences.getBool(PREF_LORA_FREQ_PRESET_INIT)){
preferences.putBool(PREF_LORA_FREQ_PRESET_INIT, true);
preferences.putDouble(PREF_LORA_FREQ_PRESET, lora_freq);
}
lora_freq = preferences.getDouble(PREF_LORA_FREQ_PRESET);
if (!preferences.getBool(PREF_LORA_SPEED_PRESET_INIT)){
preferences.putBool(PREF_LORA_SPEED_PRESET_INIT, true);
preferences.putInt(PREF_LORA_SPEED_PRESET, lora_speed);
}
lora_speed = preferences.getInt(PREF_LORA_SPEED_PRESET);
// APRS station settings
aprsSymbolTable = preferences.getString(PREF_APRS_SYMBOL_TABLE);
if (aprsSymbolTable.isEmpty()){
preferences.putString(PREF_APRS_SYMBOL_TABLE, APRS_SYMBOL_TABLE);
@ -676,7 +699,7 @@ void setup(){
pinMode(BUTTON, INPUT_PULLUP);
#endif
digitalWrite(TXLED, LOW); // turn blue LED off
Serial.begin(115200);
Wire.begin(I2C_SDA, I2C_SCL);
#ifdef T_BEAM_V1_0
@ -751,12 +774,16 @@ void setup(){
#endif
batt_read();
writedisplaytext("LoRa-APRS","","Init:","ADC OK!","BAT: "+String(BattVolts,1),"");
#ifdef SPEED_1200
if(lora_speed==1200)
rf95.setModemConfig(BG_RF95::Bw125Cr47Sf512);
#else
else
rf95.setModemConfig(BG_RF95::Bw125Cr45Sf4096);
#endif
rf95.setFrequency(433.775);
Serial.printf("LoRa Speed:\t%d\n", lora_speed);
rf95.setFrequency(lora_freq);
Serial.printf("LoRa FREQ:\t%f\n", lora_freq);
rf95.setTxPower(txPower);
delay(250);
#ifdef KISS_PROTOCOL
@ -877,7 +904,7 @@ void loop() {
if (xQueueReceive(tncToSendQueue, &TNC2DataFrame, (1 / portTICK_PERIOD_MS)) == pdPASS) {
writedisplaytext("((KISSTX))","","","","","");
time_to_refresh = millis() + showRXTime;
loraSend(txPower, TXFREQ, *TNC2DataFrame);
loraSend(txPower, lora_freq, *TNC2DataFrame);
delete TNC2DataFrame;
}
}

View file

@ -56,6 +56,9 @@ String jsonLineFromPreferenceBool(const char *preferenceName, bool last=false){
String jsonLineFromPreferenceInt(const char *preferenceName, bool last=false){
return String("\"") + preferenceName + "\":" + (preferences.getInt(preferenceName)) + (last ? + R"()" : + R"(,)");
}
String jsonLineFromPreferenceDouble(const char *preferenceName, bool last=false){
return String("\"") + preferenceName + "\":" + String(preferences.getDouble(preferenceName),3) + (last ? + R"()" : + R"(,)");
}
String jsonLineFromString(const char *name, const char *value, bool last=false){
return String("\"") + name + "\":\"" + jsonEscape(value) + "\"" + (last ? + R"()" : + R"(,)");
}
@ -130,6 +133,8 @@ void handle_Cfg() {
String jsonData = "{";
jsonData += String("\"") + PREF_WIFI_PASSWORD + "\": \"" + jsonEscape((preferences.getString(PREF_WIFI_PASSWORD).isEmpty() ? String("") : "*")) + R"(",)";
jsonData += jsonLineFromPreferenceString(PREF_WIFI_SSID);
jsonData += jsonLineFromPreferenceDouble(PREF_LORA_FREQ_PRESET);
jsonData += jsonLineFromPreferenceInt(PREF_LORA_SPEED_PRESET);
jsonData += jsonLineFromPreferenceString(PREF_APRS_CALLSIGN);
jsonData += jsonLineFromPreferenceString(PREF_APRS_RELAY_PATH);
jsonData += jsonLineFromPreferenceString(PREF_APRS_SYMBOL_TABLE);
@ -178,6 +183,15 @@ void handle_ReceivedList() {
}
void handle_SaveAPRSCfg() {
// LoRa settings
if (server.hasArg(PREF_LORA_FREQ_PRESET)){
preferences.putDouble(PREF_LORA_FREQ_PRESET, server.arg(PREF_LORA_FREQ_PRESET).toDouble());
Serial.printf("FREQ saved:\t%f\n", server.arg(PREF_LORA_FREQ_PRESET).toDouble());
}
if (server.hasArg(PREF_LORA_SPEED_PRESET)){
preferences.putInt(PREF_LORA_SPEED_PRESET, server.arg(PREF_LORA_SPEED_PRESET).toInt());
}
// APRS station settings
if (server.hasArg(PREF_APRS_CALLSIGN) && !server.arg(PREF_APRS_CALLSIGN).isEmpty()){
preferences.putString(PREF_APRS_CALLSIGN, server.arg(PREF_APRS_CALLSIGN));
}
@ -195,7 +209,8 @@ void handle_SaveAPRSCfg() {
}
if (server.hasArg(PREF_APRS_LATITUDE_PRESET)){
preferences.putString(PREF_APRS_LATITUDE_PRESET, server.arg(PREF_APRS_LATITUDE_PRESET));
}
}
// Smart Beaconing settings
if (server.hasArg(PREF_APRS_FIXED_BEACON_INTERVAL_PRESET)){
preferences.putInt(PREF_APRS_FIXED_BEACON_INTERVAL_PRESET, server.arg(PREF_APRS_FIXED_BEACON_INTERVAL_PRESET).toInt());
}