From 1a44bea515bafed1f17d38dff4e23bb759ef4868 Mon Sep 17 00:00:00 2001 From: gorzynsk Date: Tue, 3 Aug 2021 18:11:18 +0200 Subject: [PATCH] Allows to configure LoRa frequency and speed on the web interface --- data_embed/index.html | 16 ++++++++++++ include/preference_storage.h | 6 +++++ src/TTGO_T-Beam_LoRa_APRS.ino | 49 +++++++++++++++++++++++++++-------- src/taskWebServer.cpp | 17 +++++++++++- 4 files changed, 76 insertions(+), 12 deletions(-) diff --git a/data_embed/index.html b/data_embed/index.html index 3cdd548..46833e0 100644 --- a/data_embed/index.html +++ b/data_embed/index.html @@ -45,6 +45,22 @@
+
+
Transmission Settings
+
+
+
+ + +
+
+ + +
+
Station Settings
diff --git a/include/preference_storage.h b/include/preference_storage.h index 6499c4c..0ce5548 100644 --- a/include/preference_storage.h +++ b/include/preference_storage.h @@ -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"; diff --git a/src/TTGO_T-Beam_LoRa_APRS.ino b/src/TTGO_T-Beam_LoRa_APRS.ino index e6cef63..dff2100 100644 --- a/src/TTGO_T-Beam_LoRa_APRS.ino +++ b/src/TTGO_T-Beam_LoRa_APRS.ino @@ -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; } } diff --git a/src/taskWebServer.cpp b/src/taskWebServer.cpp index dc312bc..58c03f2 100644 --- a/src/taskWebServer.cpp +++ b/src/taskWebServer.cpp @@ -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()); }