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 IDF_VERSION STRINGIFY(ESP_IDF_VERSION_MAJOR) "." STRINGIFY(ESP_IDF_VERSION_MINOR) "." STRINGIFY(ESP_IDF_VERSION_PATCH)
|
||||
|
||||
#define PREF_NAME "nvs"
|
||||
|
||||
// WIFI AP
|
||||
#define WIFI_CHANNEL 9
|
||||
#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;
|
||||
}
|
||||
54
src/main.cpp
54
src/main.cpp
@@ -119,6 +119,9 @@ bool rgb_r = false;
|
||||
bool rgb_g = 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 ledmode = 'D'; // (D)ay | (N)ight
|
||||
char audiomode = 'E'; // (E)nabled | (D)isabled
|
||||
@@ -300,9 +303,14 @@ void keyTask(void *parameter) {
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void stopApTimerCallback(TimerHandle_t xTimer) {
|
||||
Serial.println("reached AP switchoff time: accesspoint switched off ");
|
||||
WiFi.softAPdisconnect(true);
|
||||
}
|
||||
|
||||
void cpuFreqTimerCallback(TimerHandle_t xTimer) {
|
||||
Serial.println("after 3 minutes: set CPU frequency to 160MHz");
|
||||
setCpuFrequencyMhz(160);
|
||||
setCpuFrequencyMhz(cpuspeed);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
@@ -385,6 +393,10 @@ void setup() {
|
||||
ESP_LOGI(TAG, "N2K default node is %d", nodeid);
|
||||
preferences.begin("nvs", false);
|
||||
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();
|
||||
ESP_LOGI(TAG, "N2K node id set to %d from preferences", nodeid);
|
||||
|
||||
@@ -394,11 +406,20 @@ void setup() {
|
||||
|
||||
int channel = WIFI_CHANNEL;
|
||||
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);
|
||||
|
||||
IPAddress ap_addr(192, 168, 15, 1);
|
||||
IPAddress ap_subnet(255, 255, 255, 0);
|
||||
// IPAddress ap_addr(192, 168, 15, 1);
|
||||
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);
|
||||
|
||||
WiFi.softAPConfig(ap_addr, ap_gateway, ap_subnet);
|
||||
apEnabled = true;
|
||||
|
||||
@@ -462,6 +483,7 @@ void setup() {
|
||||
doc["salt"] = "secret";
|
||||
doc["AdminPassword"] = "********";
|
||||
doc["useAdminPass"] = false;
|
||||
doc["apEnable"] = true;
|
||||
doc["apIp"] = "192.168.15.1";
|
||||
doc["apMask"] = "255.255.255.0";
|
||||
doc["apPassword"] = "********";
|
||||
@@ -570,7 +592,8 @@ void setup() {
|
||||
NMEA2000.SetN2kCANReceiveFrameBufSize(250);
|
||||
NMEA2000.SetN2kCANSendFrameBufSize(250);
|
||||
|
||||
NMEA2000.SetProductInformation("00000001", // Manufacturer's Model serial code
|
||||
NMEA2000.SetProductInformation(
|
||||
"00000001", // Manufacturer's Model serial code
|
||||
74, // Manufacturer's product code
|
||||
"OBPkeypad6/1", // Manufacturer's Model ID
|
||||
"0.1.0 (2026-01-04)", // Manufacturer's Software version code
|
||||
@@ -578,6 +601,14 @@ void setup() {
|
||||
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)
|
||||
uid = ((chipid >> 32) ^ (chipid & 0xFFFFFFFF)) & 0x1FFFFF;
|
||||
// TODO Device unique id stored in preferences
|
||||
@@ -688,14 +719,27 @@ void setup() {
|
||||
Serial.println("Keine Wakeup-Funktion vorhanden! Deep-sleep deaktiviert.");
|
||||
}
|
||||
|
||||
if (cpuspeed < 240) {
|
||||
TimerHandle_t cpuFreqTimer = xTimerCreate(
|
||||
"cpuFreqTimer",
|
||||
pdMS_TO_TICKS(2 * 60 * 1000),
|
||||
pdMS_TO_TICKS(3 * 60 * 1000),
|
||||
pdFALSE, // one shot only
|
||||
nullptr,
|
||||
cpuFreqTimerCallback
|
||||
);
|
||||
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.",
|
||||
"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",
|
||||
"label": "Log level",
|
||||
@@ -30,7 +43,7 @@
|
||||
"type": "password",
|
||||
"default": "esp32admin",
|
||||
"check": "checkAdminPass",
|
||||
"description": "Set the password for config modifications",
|
||||
"description": "Set the password for configuration modifications and firmware upload",
|
||||
"category": "System"
|
||||
},
|
||||
{
|
||||
@@ -38,9 +51,17 @@
|
||||
"label": "Use Admin-Pass",
|
||||
"type": "boolean",
|
||||
"default": "true",
|
||||
"description": "A password for config modifications is required.",
|
||||
"description": "A password for configuration modifications is required.",
|
||||
"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",
|
||||
"label": "Wifi password",
|
||||
|
||||
Reference in New Issue
Block a user