Merge pull request #31 from Qyon/master_sq9mdd

Fix for not properly saving gps enabled state.
master_sq9mdd
Rysiek Labus (SQ9MDD) 2021-04-25 20:25:35 +02:00 committed by GitHub
commit 0a70d9129f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 135 additions and 49 deletions

View File

@ -0,0 +1,48 @@
#include <Preferences.h>
#ifndef PREF_STORAGE
#define PREF_STORAGE
#define ENABLE_PREFERENCES
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";
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";
static const char *const PREF_APRS_SYMBOL_TABLE = "aprs_s_table";
static const char *const PREF_APRS_SYMBOL = "aprs_symbol";
static const char *const PREF_APRS_COMMENT = "aprs_comment";
static const char *const PREF_APRS_COMMENT_INIT = "aprs_comm_init";
static const char *const PREF_APRS_SHOW_ALTITUDE = "aprs_alt";
static const char *const PREF_APRS_SHOW_ALTITUDE_INIT = "aprs_alt_init";
static const char *const PREF_APRS_SHOW_BATTERY = "aprs_batt";
static const char *const PREF_APRS_SHOW_BATTERY_INIT = "aprs_batt_init";
static const char *const PREF_APRS_LATITUDE_PRESET = "aprs_lat_p";
static const char *const PREF_APRS_LATITUDE_PRESET_INIT = "aprs_lat_p_init";
static const char *const PREF_APRS_LONGITUDE_PRESET = "aprs_lon_p";
static const char *const PREF_APRS_LONGITUDE_PRESET_INIT = "aprs_lon_p_init";
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";
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";
static const char *const PREF_APRS_SHOW_CMT_INIT = "show_cmt_init";
static const char *const PREF_DEV_BT_EN = "bt_enabled";
static const char *const PREF_DEV_BT_EN_INIT = "bt_enabled_init";
static const char *const PREF_DEV_OL_EN = "oled_enabled";
static const char *const PREF_DEV_OL_EN_INIT = "ol_enabled_init";
static const char *const PREF_DEV_SHOW_RX_TIME = "sh_rxtime";
static const char *const PREF_DEV_SHOW_RX_TIME_INIT = "sh_rxtime_init";
static const char *const PREF_DEV_AUTO_SHUT = "shutdown_act";
static const char *const PREF_DEV_AUTO_SHUT_INIT = "shutdown_actini";
static const char *const PREF_DEV_AUTO_SHUT_PRESET = "shutdown_dt";
static const char *const PREF_DEV_AUTO_SHUT_PRESET_INIT = "shutdown_dtini";
#endif

View File

@ -0,0 +1,25 @@
#ifdef ENABLE_SYSLOG
#include <Syslog.h>
#include <WiFiUdp.h>
#endif
#ifndef SYSLOG_LOG
#define SYSLOG_LOG
#ifdef ENABLE_SYSLOG
extern Syslog syslog;
#define syslog_log(a, b) syslog.log(a, b)
#else
#define LOG_EMERG 0
#define LOG_ALERT 1
#define LOG_CRIT 2
#define LOG_ERR 3
#define LOG_WARNING 4
#define LOG_NOTICE 5
#define LOG_INFO 6
#define LOG_DEBUG 7
#define syslog_log(a, b) do{}while(0)
#endif
#endif

View File

@ -2,56 +2,15 @@
#include <WiFi.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <Preferences.h>
#include <Update.h>
#ifndef TASK_WEBSERVER
#define TASK_WEBSERVER
#define ENABLE_PREFERENCES
extern Preferences preferences;
#ifdef KISS_PROTOCOL
extern WiFiServer tncServer;
#endif
// MAX 15 chars for preferenece key!!!
static const char *const PREF_WIFI_SSID = "wifi_ssid";
static const char *const PREF_WIFI_PASSWORD = "wifi_password";
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";
static const char *const PREF_APRS_SYMBOL_TABLE = "aprs_s_table";
static const char *const PREF_APRS_SYMBOL = "aprs_symbol";
static const char *const PREF_APRS_COMMENT = "aprs_comment";
static const char *const PREF_APRS_COMMENT_INIT = "aprs_comm_init";
static const char *const PREF_APRS_SHOW_ALTITUDE = "aprs_alt";
static const char *const PREF_APRS_SHOW_ALTITUDE_INIT = "aprs_alt_init";
static const char *const PREF_APRS_SHOW_BATTERY = "aprs_batt";
static const char *const PREF_APRS_SHOW_BATTERY_INIT = "aprs_batt_init";
static const char *const PREF_APRS_LATITUDE_PRESET = "aprs_lat_p";
static const char *const PREF_APRS_LATITUDE_PRESET_INIT = "aprs_lat_p_init";
static const char *const PREF_APRS_LONGITUDE_PRESET = "aprs_lon_p";
static const char *const PREF_APRS_LONGITUDE_PRESET_INIT = "aprs_lon_p_init";
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";
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";
static const char *const PREF_APRS_SHOW_CMT_INIT = "show_cmt_init";
static const char *const PREF_DEV_BT_EN = "bt_enabled";
static const char *const PREF_DEV_BT_EN_INIT = "bt_enabled_init";
static const char *const PREF_DEV_OL_EN = "oled_enabled";
static const char *const PREF_DEV_OL_EN_INIT = "ol_enabled_init";
static const char *const PREF_DEV_SHOW_RX_TIME = "sh_rxtime";
static const char *const PREF_DEV_SHOW_RX_TIME_INIT = "sh_rxtime_init";
static const char *const PREF_DEV_AUTO_SHUT = "shutdown_act";
static const char *const PREF_DEV_AUTO_SHUT_INIT = "shutdown_actini";
static const char *const PREF_DEV_AUTO_SHUT_PRESET = "shutdown_dt";
static const char *const PREF_DEV_AUTO_SHUT_PRESET_INIT = "shutdown_dtini";
typedef struct {
String callsign;
} tWebServerCfg;

View File

@ -108,3 +108,16 @@ build_flags =
-D ENABLE_WIFI
-D HELTEC_V2
[env:ttgo-t-beam-v1.0-development]
platform = espressif32 @ 3.0.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"'
lib_deps =
${env.lib_deps}
arcao/Syslog

View File

@ -22,6 +22,8 @@
#include <axp20x.h>
#include "taskGPS.h"
#include "version.h"
#include "preference_storage.h"
#include "syslog_log.h"
#ifdef KISS_PROTOCOL
#include "taskTNC.h"
@ -744,15 +746,17 @@ void loop() {
if(digitalRead(BUTTON)==LOW && key_up == false && millis() >= time_delay && t_lock == false){
t_lock = true;
if(gps_state == true){
if(gps_state){
gps_state = false;
#ifdef T_BEAM_V1_0
axp.setPowerOutPut(AXP192_LDO3, AXP202_OFF); // GPS OFF
#endif
writedisplaytext("((GPSOFF))","","","","","");
next_fixed_beacon = millis() + fix_beacon_interval;
preferences.putBool(PREF_APRS_GPS_EN_INIT, false);
#ifdef ENABLE_PREFERENCES
preferences.putBool(PREF_APRS_GPS_EN, false);
#endif
}else{
gps_state = true;
@ -760,8 +764,9 @@ void loop() {
axp.setPowerOutPut(AXP192_LDO3, AXP202_ON);
#endif
writedisplaytext("((GPS ON))","","","","",""); // GPS ON
preferences.putBool(PREF_APRS_GPS_EN_INIT, true);
#ifdef ENABLE_PREFERENCES
preferences.putBool(PREF_APRS_GPS_EN, true);
#endif
}
}
@ -834,6 +839,7 @@ void loop() {
#ifdef KISS_PROTOCOL
sendToTNC(loraReceivedFrameString);
#endif
syslog_log(LOG_INFO, String("Received LoRa: '") + loraReceivedFrameString + "', RSSI:" + rf95.lastRssi() + ", SNR: " + rf95.lastSNR());
}
#endif
#ifdef T_BEAM_V1_0

View File

@ -0,0 +1,3 @@
#include "preference_storage.h"
Preferences preferences;

View File

@ -1,4 +1,6 @@
#include "taskWebServer.h"
#include "preference_storage.h"
#include "syslog_log.h"
/**
* @see board_build.embed_txtfiles in platformio.ini
*/
@ -13,11 +15,18 @@ extern const char web_js_js_end[] asm("_binary_data_embed_js_js_out_end");
String apSSID = "";
String apPassword = "xxxxxxxxxx";
WebServer server(80);
Preferences preferences;
#ifdef KISS_PROTOCOL
WiFiServer tncServer(NETWORK_TNC_PORT);
#endif
#ifdef ENABLE_SYSLOG
// A UDP instance to let us send and receive packets over UDP
WiFiUDP udpClient;
// Create a new empty syslog instance
Syslog syslog(udpClient, SYSLOG_PROTO_IETF);
#endif
void sendCacheHeader() { server.sendHeader("Cache-Control", "max-age=3600"); }
void sendGzipHeader() { server.sendHeader("Content-Encoding", "gzip"); }
@ -199,25 +208,31 @@ void handle_saveDeviceCfg(){
server.on("/save_device_cfg", handle_saveDeviceCfg);
server.on("/restore", handle_Restore);
server.on("/update", HTTP_POST, []() {
syslog_log(LOG_WARNING, String("Update finished. Status: ") + (Update.hasError() ? "Ok" : "Error"));
server.sendHeader("Connection", "close");
server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
delay(500);
ESP.restart();
}, []() {
HTTPUpload& upload = server.upload();
if (upload.status == UPLOAD_FILE_START) {
Serial.printf("Update: %s\n", upload.filename.c_str());
if (!Update.begin(UPDATE_SIZE_UNKNOWN)) { //start with max available size
syslog_log(LOG_ERR, String("Update begin error: ") + Update.errorString());
Update.printError(Serial);
}
} else if (upload.status == UPLOAD_FILE_WRITE) {
/* flashing firmware to ESP*/
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
syslog_log(LOG_ERR, String("Update error: ") + Update.errorString());
Update.printError(Serial);
}
} else if (upload.status == UPLOAD_FILE_END) {
if (Update.end(true)) { //true to set the size to the current progress
Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
syslog_log(LOG_WARNING, String("Update Success: ") + String((int)upload.totalSize));
} else {
syslog_log(LOG_ERR, String("Update error: ") + Update.errorString());
Update.printError(Serial);
}
}
@ -237,6 +252,14 @@ void handle_saveDeviceCfg(){
vTaskDelay(500/portTICK_PERIOD_MS);
}
Serial.println("Connected. IP: " + WiFi.localIP().toString());
#ifdef ENABLE_SYSLOG
syslog.server(SYSLOG_IP, 514);
syslog.deviceHostname(webServerCfg->callsign.c_str());
syslog.appName("TTGO");
syslog.defaultPriority(LOG_KERN);
syslog_log(LOG_INFO, "Connected. IP: " + WiFi.localIP().toString());
#endif
}
server.begin();

View File

@ -3,6 +3,7 @@ FILENAME_VERSION_H = 'include/version.h'
version = 'v0.3.'
import datetime
from subprocess import *
build_no = 0
try:
@ -15,7 +16,15 @@ with open(FILENAME_BUILDNO, 'w+') as f:
f.write(str(build_no))
print('Build number: {}'.format(build_no))
version_string = "{} - {}".format(version+str(build_no), datetime.datetime.now())
version_full = version + str(build_no)
try:
git_id = Popen('git rev-parse --short HEAD', stdout=PIPE, shell=True).stdout.read().strip().decode('ascii')
version_full = "%s-%s" % (version_full, git_id)
except:
pass
version_string = "{} - {}".format(version_full, datetime.datetime.now())
hf = """
#ifndef BUILD_NUMBER
#define BUILD_NUMBER "{}"
@ -26,7 +35,7 @@ hf = """
#ifndef VERSION_SHORT
#define VERSION_SHORT "{}"
#endif
""".format(build_no, version_string, version+str(build_no))
""".format(build_no, version_string, version_full)
with open(FILENAME_VERSION_H, 'w+') as f:
f.write(hf)