Add Smart beaconing Thanks SQ9MDD, gorzynsk

pull/1/head
US1GHQ 2021-07-12 11:21:15 +03:00
parent 1da4355ad0
commit 8c376fe01c
5 changed files with 98 additions and 25 deletions

View File

@ -43,6 +43,9 @@
<article>
<form action="/save_aprs_cfg" method="post">
<div class="grid-container quarters">
<div class="grid-container full">
<h5 class="u-full-width">Station Settings</h5>
</div>
<div>
<label for="aprs_callsign">Callsign and SSID</label>
<input class="u-full-width" type="text" minlength="3" name="aprs_callsign" placeholder="NOCALL-1" id="aprs_callsign" title="your callsign with SSID">
@ -74,6 +77,9 @@
<div>
<label for="aprs_batt">Show Battery</label>
<input name="aprs_batt" id="aprs_batt" type="checkbox" value="1" title=" show battery voltage after personal comment">
</div>
<div class="grid-container full">
<h5 class="u-full-width">Fixed Beaconing Settings</h5>
</div>
</div>
<div class="grid-container quarters">
@ -82,7 +88,7 @@
<input name="aprs_fixed_beac" id="aprs_fixed_beac" type="checkbox" value="1" title="enable fixed beacon when GPS is disabled or no fix">
</div>
<div>
<label for="aprs_fb_interv">Fixed Beacon Interval (s)</label>
<label for="aprs_fb_interv">Fixed Beacon Interval [s]</label>
<input name="aprs_fb_interv" id="aprs_fb_interv" type="number" min="120" title="time between sending a beacon if Fixed Beacon option is selected ">
</div>
<div>
@ -93,6 +99,27 @@
<label for="aprs_lon_p">Longitude Preset</label>
<input class="u-full-width" type="text" minlength="0" name="aprs_lon_p" id="aprs_lon_p" title="longtitude for fixed bicon, APRS format for example 02050.59E">
</div>
</div>
<div class="grid-container full">
<h5 class="u-full-width">Smart Beaconing Settings</h5>
</div>
<div class="grid-container quarters">
<div>
<label for="sb_min_interv">Min interval [s]</label>
<input name="sb_min_interv" id="sb_min_interv" type="number" min="60" title="Minimal time for Smart Beaconing">
</div>
<div>
<label for="sb_max_interv">Max interval [s]</label>
<input name="sb_max_interv" id="sb_max_interv" type="number" min="120" title="Maximal time for Smart Beaconing">
</div>
<div>
<label for="sb_min_speed">Min speed [km/h]</label>
<input name="sb_min_speed" id="sb_min_speed" type="number" min="0" title="Minimal speed for Smart Beaconing">
</div>
<div>
<label for="sb_max_speed">Max speed [km/h]</label>
<input name="sb_max_speed" id="sb_max_speed" type="number" min="1" title="Maximal speed for Smart Beaconing">
</div>
</div>
<div class="grid-container quarters">
<div>

View File

@ -29,6 +29,16 @@ static const char *const PREF_APRS_FIXED_BEACON_PRESET = "aprs_fixed_beac";
static const char *const PREF_APRS_FIXED_BEACON_PRESET_INIT = "aprs_fix_b_init";
static const char *const PREF_APRS_FIXED_BEACON_INTERVAL_PRESET = "aprs_fb_interv";
static const char *const PREF_APRS_FIXED_BEACON_INTERVAL_PRESET_INIT = "aprs_fb_in_init";
// SMART BEACONING
static const char *const PREF_APRS_SB_MIN_INTERVAL_PRESET = "sb_min_interv";
static const char *const PREF_APRS_SB_MIN_INTERVAL_PRESET_INIT = "sb_min_interv_i";
static const char *const PREF_APRS_SB_MAX_INTERVAL_PRESET = "sb_max_interv";
static const char *const PREF_APRS_SB_MAX_INTERVAL_PRESET_INIT = "sb_max_interv_i";
static const char *const PREF_APRS_SB_MIN_SPEED_PRESET = "sb_min_speed";
static const char *const PREF_APRS_SB_MIN_SPEED_PRESET_INIT = "sb_min_speed_i";
static const char *const PREF_APRS_SB_MAX_SPEED_PRESET = "sb_max_speed";
static const char *const PREF_APRS_SB_MAX_SPEED_PRESET_INIT = "sb_max_speed_i";
static const char *const PREF_APRS_GPS_EN = "gps_enabled";
static const char *const PREF_APRS_GPS_EN_INIT = "gps_state_init";
static const char *const PREF_APRS_SHOW_CMT = "show_cmt";

View File

@ -129,17 +129,3 @@ build_flags =
-D ENABLE_BLUETOOTH
-D ESP32_DEV_V1
[env:ttgo-t-beam-v1.0-development]
platform = espressif32 @ 3.3.0
board = ttgo-t-beam
build_flags =
${env.build_flags}
-D T_BEAM_V1_0
-D ENABLE_WIFI
-D ENABLE_BLUETOOTH
-D ENABLE_SYSLOG
-D 'SYSLOG_IP="192.168.0.102"'
-D DEVELOPMENT_DEBUG
lib_deps =
${env.lib_deps}
arcao/Syslog

View File

@ -172,11 +172,18 @@ float BattVolts;
float InpVolts;
// variables for smart beaconing
float average_speed[5] = {0,0,0,0,0}, average_speed_final=0, max_speed=30, min_speed=0;
ulong sb_min_interval = 60000L;
ulong sb_max_interval = 360000L;
float sb_min_speed = 0;
float sb_max_speed = 30;
float average_speed[5] = {0,0,0,0,0}, average_speed_final=0;
float old_course = 0, new_course = 0;
int point_avg_speed = 0, point_avg_course = 0;
ulong min_time_to_nextTX=60000L; // minimum time period between TX = 60000ms = 60secs = 1min
ulong max_time_to_nextTX= MAX_TIME_TO_NEXT_TX;
ulong min_time_to_nextTX=SB_min_interval; // minimum time period between TX = 60000ms = 60secs = 1min
ulong max_time_to_nextTX= SB_max_interval;
ulong nextTX=60000L; // preset time period between TX = 60000ms = 60secs = 1min
ulong time_to_refresh = 0;
ulong next_fixed_beacon = 0;
@ -622,7 +629,34 @@ void setup(){
preferences.putInt(PREF_APRS_FIXED_BEACON_INTERVAL_PRESET, fix_beacon_interval/1000);
}
fix_beacon_interval = preferences.getInt(PREF_APRS_FIXED_BEACON_INTERVAL_PRESET) * 1000;
// + SMART BEACONING
if (!preferences.getBool(PREF_APRS_SB_MIN_INTERVAL_PRESET_INIT)){
preferences.putBool(PREF_APRS_SB_MIN_INTERVAL_PRESET_INIT, true);
preferences.putInt(PREF_APRS_SB_MIN_INTERVAL_PRESET, sb_min_interval/1000);
}
sb_min_interval = preferences.getInt(PREF_APRS_SB_MIN_INTERVAL_PRESET) * 1000;
if (!preferences.getBool(PREF_APRS_SB_MAX_INTERVAL_PRESET_INIT)){
preferences.putBool(PREF_APRS_SB_MAX_INTERVAL_PRESET_INIT, true);
preferences.putInt(PREF_APRS_SB_MAX_INTERVAL_PRESET, sb_max_interval/1000);
}
sb_max_interval = preferences.getInt(PREF_APRS_SB_MAX_INTERVAL_PRESET) * 1000;
if (!preferences.getBool(PREF_APRS_SB_MIN_SPEED_PRESET_INIT)){
preferences.putBool(PREF_APRS_SB_MIN_SPEED_PRESET_INIT, true);
preferences.putInt(PREF_APRS_SB_MIN_SPEED_PRESET, sb_min_speed);
}
sb_min_speed = preferences.getInt(PREF_APRS_SB_MIN_SPEED_PRESET);
if (!preferences.getBool(PREF_APRS_SB_MAX_SPEED_PRESET_INIT)){
preferences.putBool(PREF_APRS_SB_MAX_SPEED_PRESET_INIT, true);
preferences.putInt(PREF_APRS_SB_MAX_SPEED_PRESET, sb_max_speed);
}
sb_max_speed = preferences.getInt(PREF_APRS_SB_MAX_SPEED_PRESET);
//
if (!preferences.getBool(PREF_DEV_SHOW_RX_TIME_INIT)){
preferences.putBool(PREF_DEV_SHOW_RX_TIME_INIT, true);
preferences.putInt(PREF_DEV_SHOW_RX_TIME, showRXTime/1000);
@ -753,8 +787,8 @@ void setup(){
for(;;); // Don't proceed, loop forever
}
if (max_time_to_nextTX < nextTX){
max_time_to_nextTX=nextTX;
if (sb_max_interval < nextTX){
sb_max_interval=nextTX;
}
writedisplaytext("LoRa-APRS","","Init:","RF95 OK!","","");
writedisplaytext(" "+Tcall,"","Init:","Waiting for GPS","","");
@ -950,9 +984,9 @@ void loop() {
point_avg_speed=0;
}
average_speed_final = (average_speed[0]+average_speed[1]+average_speed[2]+average_speed[3]+average_speed[4])/5;
nextTX = (max_time_to_nextTX-min_time_to_nextTX)/(max_speed-min_speed)*(max_speed-average_speed_final)+min_time_to_nextTX;
if (nextTX < min_time_to_nextTX) {nextTX=min_time_to_nextTX;}
if (nextTX > max_time_to_nextTX) {nextTX=max_time_to_nextTX;}
nextTX = (sb_max_interval-sb_min_interval)/(sb_max_speed-sb_min_speed)*(sb_max_speed-average_speed_final)+sb_min_interval;
if (nextTX < sb_min_interval) {nextTX=sb_min_interval;}
if (nextTX > sb_max_interval) {nextTX=sb_max_interval;}
average_course[point_avg_course] = gps.course.deg(); // calculate smart beaconing course
++point_avg_course;
if (point_avg_course>(ANGLE_AVGS-1)) {
@ -970,7 +1004,7 @@ void loop() {
if ((old_course < ANGLE) && (new_course > (360-ANGLE))) {
if (abs(new_course-old_course-360)>=ANGLE) {
nextTX = 0;
// lastTX = min_time_to_nextTX
// lastTX = sb_min_interval
}
} else {
if ((old_course > (360-ANGLE)) && (new_course < ANGLE)) {
@ -985,7 +1019,7 @@ void loop() {
}
old_course = new_course;
}
if ((millis()<max_time_to_nextTX)&&(lastTX == 0)) {
if ((millis()<sb_max_interval)&&(lastTX == 0)) {
nextTX = 0;
}
if ( (lastTX+nextTX) <= millis() ) {

View File

@ -138,6 +138,10 @@ void handle_Cfg() {
jsonData += jsonLineFromPreferenceString(PREF_APRS_LATITUDE_PRESET);
jsonData += jsonLineFromPreferenceString(PREF_APRS_LONGITUDE_PRESET);
jsonData += jsonLineFromPreferenceInt(PREF_APRS_FIXED_BEACON_INTERVAL_PRESET);
jsonData += jsonLineFromPreferenceInt(PREF_APRS_SB_MIN_INTERVAL_PRESET);
jsonData += jsonLineFromPreferenceInt(PREF_APRS_SB_MAX_INTERVAL_PRESET);
jsonData += jsonLineFromPreferenceInt(PREF_APRS_SB_MIN_SPEED_PRESET);
jsonData += jsonLineFromPreferenceInt(PREF_APRS_SB_MAX_SPEED_PRESET);
jsonData += jsonLineFromPreferenceBool(PREF_APRS_SHOW_BATTERY);
jsonData += jsonLineFromPreferenceBool(PREF_APRS_FIXED_BEACON_PRESET);
jsonData += jsonLineFromPreferenceBool(PREF_APRS_SHOW_ALTITUDE);
@ -195,6 +199,18 @@ void handle_SaveAPRSCfg() {
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());
}
if (server.hasArg(PREF_APRS_SB_MIN_INTERVAL_PRESET)){
preferences.putInt(PREF_APRS_SB_MIN_INTERVAL_PRESET, server.arg(PREF_APRS_SB_MIN_INTERVAL_PRESET).toInt());
}
if (server.hasArg(PREF_APRS_SB_MAX_INTERVAL_PRESET)){
preferences.putInt(PREF_APRS_SB_MAX_INTERVAL_PRESET, server.arg(PREF_APRS_SB_MAX_INTERVAL_PRESET).toInt());
}
if (server.hasArg(PREF_APRS_SB_MIN_SPEED_PRESET)){
preferences.putInt(PREF_APRS_SB_MIN_SPEED_PRESET, server.arg(PREF_APRS_SB_MIN_SPEED_PRESET).toInt());
}
if (server.hasArg(PREF_APRS_SB_MAX_SPEED_PRESET)){
preferences.putInt(PREF_APRS_SB_MAX_SPEED_PRESET, server.arg(PREF_APRS_SB_MAX_SPEED_PRESET).toInt());
}
if (server.hasArg(PREF_APRS_LONGITUDE_PRESET)){
preferences.putString(PREF_APRS_LONGITUDE_PRESET, server.arg(PREF_APRS_LONGITUDE_PRESET));
}