First steps to config / preferences
This commit is contained in:
9
include/config.h
Normal file
9
include/config.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
class Config {
|
||||||
|
private:
|
||||||
|
Preferences *prefs;
|
||||||
|
public:
|
||||||
|
Config();
|
||||||
|
bool loadConfig();
|
||||||
|
};
|
||||||
@@ -20,6 +20,8 @@
|
|||||||
#define FIRMWARE_TYPE STRINGIFY(PIO_ENV_BUILD)
|
#define FIRMWARE_TYPE STRINGIFY(PIO_ENV_BUILD)
|
||||||
#define IDF_VERSION STRINGIFY(ESP_IDF_VERSION_MAJOR) "." STRINGIFY(ESP_IDF_VERSION_MINOR) "." STRINGIFY(ESP_IDF_VERSION_PATCH)
|
#define IDF_VERSION STRINGIFY(ESP_IDF_VERSION_MAJOR) "." STRINGIFY(ESP_IDF_VERSION_MINOR) "." STRINGIFY(ESP_IDF_VERSION_PATCH)
|
||||||
|
|
||||||
|
#define PREF_NAME "nvs"
|
||||||
|
|
||||||
// WIFI AP
|
// WIFI AP
|
||||||
#define WIFI_CHANNEL 9
|
#define WIFI_CHANNEL 9
|
||||||
#define WIFI_MAX_STA 2
|
#define WIFI_MAX_STA 2
|
||||||
|
|||||||
12
src/config.cpp
Normal file
12
src/config.cpp
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#include <Preferences.h>
|
||||||
|
#include "main.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
Config::Config() {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Config::loadConfig() {
|
||||||
|
prefs->begin(PREF_NAME);
|
||||||
|
prefs->end();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
80
src/main.cpp
80
src/main.cpp
@@ -119,6 +119,9 @@ bool rgb_r = false;
|
|||||||
bool rgb_g = false;
|
bool rgb_g = false;
|
||||||
bool rgb_b = false;
|
bool rgb_b = false;
|
||||||
|
|
||||||
|
int cpuspeed = 240; // MHz
|
||||||
|
|
||||||
|
char globalmode = 'K'; // (K)eyboard | (A)utopilot | (L)ogbook
|
||||||
char mode = 'N'; // (N)ormal | (C)onfig
|
char mode = 'N'; // (N)ormal | (C)onfig
|
||||||
char ledmode = 'D'; // (D)ay | (N)ight
|
char ledmode = 'D'; // (D)ay | (N)ight
|
||||||
char audiomode = 'E'; // (E)nabled | (D)isabled
|
char audiomode = 'E'; // (E)nabled | (D)isabled
|
||||||
@@ -300,9 +303,14 @@ void keyTask(void *parameter) {
|
|||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void stopApTimerCallback(TimerHandle_t xTimer) {
|
||||||
|
Serial.println("reached AP switchoff time: accesspoint switched off ");
|
||||||
|
WiFi.softAPdisconnect(true);
|
||||||
|
}
|
||||||
|
|
||||||
void cpuFreqTimerCallback(TimerHandle_t xTimer) {
|
void cpuFreqTimerCallback(TimerHandle_t xTimer) {
|
||||||
Serial.println("after 3 minutes: set CPU frequency to 160MHz");
|
Serial.println("after 3 minutes: set CPU frequency to 160MHz");
|
||||||
setCpuFrequencyMhz(160);
|
setCpuFrequencyMhz(cpuspeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
@@ -385,6 +393,10 @@ void setup() {
|
|||||||
ESP_LOGI(TAG, "N2K default node is %d", nodeid);
|
ESP_LOGI(TAG, "N2K default node is %d", nodeid);
|
||||||
preferences.begin("nvs", false);
|
preferences.begin("nvs", false);
|
||||||
nodeid = preferences.getInt("LastNodeId", N2K_DEFAULT_NODEID);
|
nodeid = preferences.getInt("LastNodeId", N2K_DEFAULT_NODEID);
|
||||||
|
cpuspeed = preferences.getInt("cpuSpeed", 160);
|
||||||
|
int apstoptime = preferences.getInt("stopApTime", 0);
|
||||||
|
String apip = preferences.getString("apIp", "192.168.15.1");
|
||||||
|
String apmask = preferences.getString("apMask", "255.255.255.0");
|
||||||
preferences.end();
|
preferences.end();
|
||||||
ESP_LOGI(TAG, "N2K node id set to %d from preferences", nodeid);
|
ESP_LOGI(TAG, "N2K node id set to %d from preferences", nodeid);
|
||||||
|
|
||||||
@@ -394,11 +406,20 @@ void setup() {
|
|||||||
|
|
||||||
int channel = WIFI_CHANNEL;
|
int channel = WIFI_CHANNEL;
|
||||||
bool hidden = false;
|
bool hidden = false;
|
||||||
|
// TODO do not enable if preferences apEnable = false
|
||||||
|
// but prepare later switch on by config key
|
||||||
WiFi.softAP(wifi_ssid, wifi_pass, channel, hidden, WIFI_MAX_STA);
|
WiFi.softAP(wifi_ssid, wifi_pass, channel, hidden, WIFI_MAX_STA);
|
||||||
|
|
||||||
IPAddress ap_addr(192, 168, 15, 1);
|
// IPAddress ap_addr(192, 168, 15, 1);
|
||||||
IPAddress ap_subnet(255, 255, 255, 0);
|
IPAddress ap_addr;
|
||||||
|
ap_addr.fromString(apip);
|
||||||
|
|
||||||
|
// IPAddress ap_subnet(255, 255, 255, 0);
|
||||||
|
IPAddress ap_subnet;
|
||||||
|
ap_subnet.fromString(apmask);
|
||||||
|
|
||||||
IPAddress ap_gateway(ap_addr);
|
IPAddress ap_gateway(ap_addr);
|
||||||
|
|
||||||
WiFi.softAPConfig(ap_addr, ap_gateway, ap_subnet);
|
WiFi.softAPConfig(ap_addr, ap_gateway, ap_subnet);
|
||||||
apEnabled = true;
|
apEnabled = true;
|
||||||
|
|
||||||
@@ -462,6 +483,7 @@ void setup() {
|
|||||||
doc["salt"] = "secret";
|
doc["salt"] = "secret";
|
||||||
doc["AdminPassword"] = "********";
|
doc["AdminPassword"] = "********";
|
||||||
doc["useAdminPass"] = false;
|
doc["useAdminPass"] = false;
|
||||||
|
doc["apEnable"] = true;
|
||||||
doc["apIp"] = "192.168.15.1";
|
doc["apIp"] = "192.168.15.1";
|
||||||
doc["apMask"] = "255.255.255.0";
|
doc["apMask"] = "255.255.255.0";
|
||||||
doc["apPassword"] = "********";
|
doc["apPassword"] = "********";
|
||||||
@@ -570,13 +592,22 @@ void setup() {
|
|||||||
NMEA2000.SetN2kCANReceiveFrameBufSize(250);
|
NMEA2000.SetN2kCANReceiveFrameBufSize(250);
|
||||||
NMEA2000.SetN2kCANSendFrameBufSize(250);
|
NMEA2000.SetN2kCANSendFrameBufSize(250);
|
||||||
|
|
||||||
NMEA2000.SetProductInformation("00000001", // Manufacturer's Model serial code
|
NMEA2000.SetProductInformation(
|
||||||
74, // Manufacturer's product code
|
"00000001", // Manufacturer's Model serial code
|
||||||
"OBPkeypad6/1", // Manufacturer's Model ID
|
74, // Manufacturer's product code
|
||||||
"0.1.0 (2026-01-04)", // Manufacturer's Software version code
|
"OBPkeypad6/1", // Manufacturer's Model ID
|
||||||
"0.1", // Manufacturer's Model version
|
"0.1.0 (2026-01-04)", // Manufacturer's Software version code
|
||||||
1 // LoadEquivalency (LEN)
|
"0.1", // Manufacturer's Model version
|
||||||
);
|
1 // LoadEquivalency (LEN)
|
||||||
|
);
|
||||||
|
|
||||||
|
// TODO Read configuration information from preferences
|
||||||
|
// Manufacturer information is not changeable
|
||||||
|
NMEA2000.SetConfigurationInformation(
|
||||||
|
"Open boat projects / NMEA2000 library", // Manufacturer
|
||||||
|
"", // Info 1
|
||||||
|
"" // Info 2
|
||||||
|
);
|
||||||
|
|
||||||
uint32_t uid; // ISO 21bit identity number devived from chipid (MAC)
|
uint32_t uid; // ISO 21bit identity number devived from chipid (MAC)
|
||||||
uid = ((chipid >> 32) ^ (chipid & 0xFFFFFFFF)) & 0x1FFFFF;
|
uid = ((chipid >> 32) ^ (chipid & 0xFFFFFFFF)) & 0x1FFFFF;
|
||||||
@@ -688,14 +719,27 @@ void setup() {
|
|||||||
Serial.println("Keine Wakeup-Funktion vorhanden! Deep-sleep deaktiviert.");
|
Serial.println("Keine Wakeup-Funktion vorhanden! Deep-sleep deaktiviert.");
|
||||||
}
|
}
|
||||||
|
|
||||||
TimerHandle_t cpuFreqTimer = xTimerCreate(
|
if (cpuspeed < 240) {
|
||||||
"cpuFreqTimer",
|
TimerHandle_t cpuFreqTimer = xTimerCreate(
|
||||||
pdMS_TO_TICKS(2 * 60 * 1000),
|
"cpuFreqTimer",
|
||||||
pdFALSE, // one shot only
|
pdMS_TO_TICKS(3 * 60 * 1000),
|
||||||
nullptr,
|
pdFALSE, // one shot only
|
||||||
cpuFreqTimerCallback
|
nullptr,
|
||||||
);
|
cpuFreqTimerCallback
|
||||||
xTimerStart(cpuFreqTimer, 0);
|
);
|
||||||
|
xTimerStart(cpuFreqTimer, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apstoptime > 0) {
|
||||||
|
TimerHandle_t stopApTimer = xTimerCreate(
|
||||||
|
"stopApTimer",
|
||||||
|
pdMS_TO_TICKS(apstoptime * 1000),
|
||||||
|
pdFALSE, // one shot only
|
||||||
|
nullptr,
|
||||||
|
stopApTimerCallback
|
||||||
|
);
|
||||||
|
xTimerStart(stopApTimer, 0);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,19 @@
|
|||||||
"description": "System name, used also for the access point SSID.",
|
"description": "System name, used also for the access point SSID.",
|
||||||
"category": "System"
|
"category": "System"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "systemMode",
|
||||||
|
"label": "System mode",
|
||||||
|
"type": "list",
|
||||||
|
"default": "K",
|
||||||
|
"list": [
|
||||||
|
{"l":"Keypad","v":"K"},
|
||||||
|
{"l":"Autopilot","v":"A"},
|
||||||
|
{"l":"Logbook","v":"L"}
|
||||||
|
],
|
||||||
|
"description": "Global system mode.",
|
||||||
|
"category": "System"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "logLevel",
|
"name": "logLevel",
|
||||||
"label": "Log level",
|
"label": "Log level",
|
||||||
@@ -30,7 +43,7 @@
|
|||||||
"type": "password",
|
"type": "password",
|
||||||
"default": "esp32admin",
|
"default": "esp32admin",
|
||||||
"check": "checkAdminPass",
|
"check": "checkAdminPass",
|
||||||
"description": "Set the password for config modifications",
|
"description": "Set the password for configuration modifications and firmware upload",
|
||||||
"category": "System"
|
"category": "System"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -38,9 +51,17 @@
|
|||||||
"label": "Use Admin-Pass",
|
"label": "Use Admin-Pass",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": "true",
|
"default": "true",
|
||||||
"description": "A password for config modifications is required.",
|
"description": "A password for configuration modifications is required.",
|
||||||
"category": "System"
|
"category": "System"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "apEnable",
|
||||||
|
"label": "Enable AP",
|
||||||
|
"type": "boolean",
|
||||||
|
"default": "true",
|
||||||
|
"description": "Enable Accesspoint, switch off if device is configured to save power",
|
||||||
|
"category": "Wifi"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "apPassword",
|
"name": "apPassword",
|
||||||
"label": "Wifi password",
|
"label": "Wifi password",
|
||||||
|
|||||||
Reference in New Issue
Block a user