feat(firmware): 更新 OCPP 配置,添加密码字段以支持基本认证
This commit is contained in:
@@ -9,5 +9,7 @@
|
|||||||
#define CFG_CP_FW_VERSION "1.0.0"
|
#define CFG_CP_FW_VERSION "1.0.0"
|
||||||
#define CFG_CP_MODAL "Helios DA One"
|
#define CFG_CP_MODAL "Helios DA One"
|
||||||
#define CFG_CP_VENDOR "RayineElec"
|
#define CFG_CP_VENDOR "RayineElec"
|
||||||
// #define CFG_AUTHORIZATIONKEY "my_secret_key"
|
// OCPP Security Profile 1: Basic Auth password (username = chargePointIdentifier)
|
||||||
#define CFG_AUTHORIZATIONKEY nullptr
|
// Set to nullptr to disable authentication
|
||||||
|
// #define CFG_OCPP_PASSWORD "my_password"
|
||||||
|
#define CFG_OCPP_PASSWORD nullptr
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ char cpSerial[13];
|
|||||||
// OCPP Configuration Variables
|
// OCPP Configuration Variables
|
||||||
char ocpp_backend[128];
|
char ocpp_backend[128];
|
||||||
char cp_identifier[64];
|
char cp_identifier[64];
|
||||||
char auth_key[64];
|
char ocpp_password[64];
|
||||||
bool shouldSaveConfig = false;
|
bool shouldSaveConfig = false;
|
||||||
|
|
||||||
// callback notifying us of the need to save config
|
// callback notifying us of the need to save config
|
||||||
@@ -169,13 +169,13 @@ void setup()
|
|||||||
Preferences preferences;
|
Preferences preferences;
|
||||||
preferences.begin("ocpp-config", false);
|
preferences.begin("ocpp-config", false);
|
||||||
String b = preferences.getString("backend", CFG_OCPP_BACKEND);
|
String b = preferences.getString("backend", CFG_OCPP_BACKEND);
|
||||||
String a = preferences.getString("auth_key", CFG_AUTHORIZATIONKEY ? CFG_AUTHORIZATIONKEY : "");
|
String p = preferences.getString("ocpp_password", CFG_OCPP_PASSWORD ? CFG_OCPP_PASSWORD : "");
|
||||||
|
|
||||||
Serial.printf("\n[OCPP] Loaded Backend URL: %s\n", b.c_str());
|
Serial.printf("\n[OCPP] Loaded Backend URL: %s\n", b.c_str());
|
||||||
Serial.printf("[OCPP] Loaded Auth Key length: %d\n", a.length());
|
Serial.printf("[OCPP] Loaded Password length: %d\n", p.length());
|
||||||
|
|
||||||
strncpy(ocpp_backend, b.c_str(), sizeof(ocpp_backend));
|
strncpy(ocpp_backend, b.c_str(), sizeof(ocpp_backend));
|
||||||
strncpy(auth_key, a.c_str(), sizeof(auth_key));
|
strncpy(ocpp_password, p.c_str(), sizeof(ocpp_password));
|
||||||
|
|
||||||
WiFiManager wm;
|
WiFiManager wm;
|
||||||
wm.setSaveConfigCallback(saveConfigCallback);
|
wm.setSaveConfigCallback(saveConfigCallback);
|
||||||
@@ -184,10 +184,10 @@ void setup()
|
|||||||
|
|
||||||
// Use autocomplete=off to prevent browsers from autofilling old URLs after a reset
|
// Use autocomplete=off to prevent browsers from autofilling old URLs after a reset
|
||||||
WiFiManagerParameter custom_ocpp_backend("backend", "OCPP Backend URL", ocpp_backend, 128, "autocomplete=\"off\"");
|
WiFiManagerParameter custom_ocpp_backend("backend", "OCPP Backend URL", ocpp_backend, 128, "autocomplete=\"off\"");
|
||||||
WiFiManagerParameter custom_auth_key("auth_key", "Auth Key (leave blank if none)", auth_key, 64, "autocomplete=\"off\"");
|
WiFiManagerParameter custom_ocpp_password("ocpp_password", "OCPP 连接密码 (Basic Auth, 没有请留空)", ocpp_password, 64, "autocomplete=\"off\" type=\"password\"");
|
||||||
|
|
||||||
wm.addParameter(&custom_ocpp_backend);
|
wm.addParameter(&custom_ocpp_backend);
|
||||||
wm.addParameter(&custom_auth_key);
|
wm.addParameter(&custom_ocpp_password);
|
||||||
|
|
||||||
const char *customHeadElement = R"rawliteral(
|
const char *customHeadElement = R"rawliteral(
|
||||||
<style>
|
<style>
|
||||||
@@ -335,10 +335,10 @@ void setup()
|
|||||||
if (shouldSaveConfig)
|
if (shouldSaveConfig)
|
||||||
{
|
{
|
||||||
strncpy(ocpp_backend, custom_ocpp_backend.getValue(), sizeof(ocpp_backend));
|
strncpy(ocpp_backend, custom_ocpp_backend.getValue(), sizeof(ocpp_backend));
|
||||||
strncpy(auth_key, custom_auth_key.getValue(), sizeof(auth_key));
|
strncpy(ocpp_password, custom_ocpp_password.getValue(), sizeof(ocpp_password));
|
||||||
|
|
||||||
preferences.putString("backend", ocpp_backend);
|
preferences.putString("backend", ocpp_backend);
|
||||||
preferences.putString("auth_key", auth_key);
|
preferences.putString("ocpp_password", ocpp_password);
|
||||||
Serial.println("Saved new OCPP config to Preferences");
|
Serial.println("Saved new OCPP config to Preferences");
|
||||||
}
|
}
|
||||||
preferences.end();
|
preferences.end();
|
||||||
@@ -354,8 +354,8 @@ void setup()
|
|||||||
s_led_state = LED_WIFI_CONNECTED;
|
s_led_state = LED_WIFI_CONNECTED;
|
||||||
|
|
||||||
mg_mgr_init(&mgr);
|
mg_mgr_init(&mgr);
|
||||||
const char *final_auth_key = (strlen(auth_key) > 0) ? auth_key : nullptr;
|
const char *final_ocpp_password = (strlen(ocpp_password) > 0) ? ocpp_password : nullptr;
|
||||||
MicroOcpp::MOcppMongooseClient *client = new MicroOcpp::MOcppMongooseClient(&mgr, ocpp_backend, cp_identifier, final_auth_key, "", MicroOcpp::makeDefaultFilesystemAdapter(MicroOcpp::FilesystemOpt::Use_Mount_FormatOnFail), MicroOcpp::ProtocolVersion(1, 6));
|
MicroOcpp::MOcppMongooseClient *client = new MicroOcpp::MOcppMongooseClient(&mgr, ocpp_backend, cp_identifier, final_ocpp_password, "", MicroOcpp::makeDefaultFilesystemAdapter(MicroOcpp::FilesystemOpt::Use_Mount_FormatOnFail), MicroOcpp::ProtocolVersion(1, 6));
|
||||||
mocpp_initialize(*client, ChargerCredentials(CFG_CP_MODAL, CFG_CP_VENDOR, CFG_CP_FW_VERSION, cpSerial, nullptr, nullptr, CFG_CB_SERIAL, nullptr, nullptr), MicroOcpp::makeDefaultFilesystemAdapter(MicroOcpp::FilesystemOpt::Use_Mount_FormatOnFail));
|
mocpp_initialize(*client, ChargerCredentials(CFG_CP_MODAL, CFG_CP_VENDOR, CFG_CP_FW_VERSION, cpSerial, nullptr, nullptr, CFG_CB_SERIAL, nullptr, nullptr), MicroOcpp::makeDefaultFilesystemAdapter(MicroOcpp::FilesystemOpt::Use_Mount_FormatOnFail));
|
||||||
|
|
||||||
// For development/recovery: Set up BOOT button (GPIO 0)
|
// For development/recovery: Set up BOOT button (GPIO 0)
|
||||||
@@ -417,7 +417,7 @@ void loop()
|
|||||||
Preferences preferences;
|
Preferences preferences;
|
||||||
preferences.begin("ocpp-config", false);
|
preferences.begin("ocpp-config", false);
|
||||||
preferences.remove("backend");
|
preferences.remove("backend");
|
||||||
preferences.remove("auth_key");
|
preferences.remove("ocpp_password");
|
||||||
preferences.clear();
|
preferences.clear();
|
||||||
preferences.end();
|
preferences.end();
|
||||||
Serial.println("NVS ocpp-config cleared.");
|
Serial.println("NVS ocpp-config cleared.");
|
||||||
|
|||||||
Reference in New Issue
Block a user