🎨 Replace Arduino String with std::string
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <utils/json_utils.h>
|
||||
#include <utils/ip_utils.h>
|
||||
#include <template/state_result.h>
|
||||
#include <string>
|
||||
|
||||
#include <DNSServer.h>
|
||||
#include <IPAddress.h>
|
||||
@@ -58,8 +59,8 @@ enum APNetworkStatus { ACTIVE = 0, INACTIVE, LINGERING };
|
||||
class APSettings {
|
||||
public:
|
||||
uint8_t provisionMode;
|
||||
String ssid;
|
||||
String password;
|
||||
std::string ssid;
|
||||
std::string password;
|
||||
uint8_t channel;
|
||||
bool ssidHidden;
|
||||
uint8_t maxClients;
|
||||
@@ -76,8 +77,8 @@ class APSettings {
|
||||
|
||||
static void read(APSettings &settings, JsonVariant &root) {
|
||||
root["provision_mode"] = settings.provisionMode;
|
||||
root["ssid"] = settings.ssid;
|
||||
root["password"] = settings.password;
|
||||
root["ssid"] = settings.ssid.c_str();
|
||||
root["password"] = settings.password.c_str();
|
||||
root["channel"] = settings.channel;
|
||||
root["ssid_hidden"] = settings.ssidHidden;
|
||||
root["max_clients"] = settings.maxClients;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <utils/json_utils.h>
|
||||
#include <template/state_result.h>
|
||||
#include <filesystem.h>
|
||||
#include <string>
|
||||
|
||||
#ifndef FACTORY_MDNS_HOSTNAME
|
||||
#define FACTORY_MDNS_HOSTNAME "esp32"
|
||||
@@ -14,31 +15,31 @@
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
String key;
|
||||
String value;
|
||||
std::string key;
|
||||
std::string value;
|
||||
|
||||
void serialize(JsonVariant &json) const {
|
||||
json["key"] = key;
|
||||
json["value"] = value;
|
||||
json["key"] = key.c_str();
|
||||
json["value"] = value.c_str();
|
||||
}
|
||||
|
||||
bool deserialize(const JsonVariant &json) {
|
||||
key = json["key"].as<String>();
|
||||
value = json["value"].as<String>();
|
||||
key = json["key"].as<std::string>();
|
||||
value = json["value"].as<std::string>();
|
||||
|
||||
return key.length() > 0;
|
||||
}
|
||||
} mdns_txt_record_t;
|
||||
|
||||
typedef struct {
|
||||
String service;
|
||||
String protocol;
|
||||
std::string service;
|
||||
std::string protocol;
|
||||
uint16_t port;
|
||||
std::vector<mdns_txt_record_t> txtRecords;
|
||||
|
||||
void serialize(JsonVariant &json) const {
|
||||
json["service"] = service;
|
||||
json["protocol"] = protocol;
|
||||
json["service"] = service.c_str();
|
||||
json["protocol"] = protocol.c_str();
|
||||
json["port"] = port;
|
||||
|
||||
if (txtRecords.size() > 0) {
|
||||
@@ -51,8 +52,8 @@ typedef struct {
|
||||
}
|
||||
|
||||
bool deserialize(const JsonVariant &json) {
|
||||
service = json["service"].as<String>();
|
||||
protocol = json["protocol"].as<String>();
|
||||
service = json["service"].as<std::string>();
|
||||
protocol = json["protocol"].as<std::string>();
|
||||
port = json["port"] | 0;
|
||||
|
||||
txtRecords.clear();
|
||||
@@ -72,14 +73,14 @@ typedef struct {
|
||||
|
||||
class MDNSSettings {
|
||||
public:
|
||||
String hostname;
|
||||
String instance;
|
||||
std::string hostname;
|
||||
std::string instance;
|
||||
std::vector<mdns_service_t> services;
|
||||
std::vector<mdns_txt_record_t> globalTxtRecords;
|
||||
|
||||
static void read(MDNSSettings &settings, JsonVariant &root) {
|
||||
root["hostname"] = settings.hostname;
|
||||
root["instance"] = settings.instance;
|
||||
root["hostname"] = settings.hostname.c_str();
|
||||
root["instance"] = settings.instance.c_str();
|
||||
|
||||
JsonArray servicesArray = root["services"].to<JsonArray>();
|
||||
for (const auto &service : settings.services) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <Arduino.h>
|
||||
#include <template/state_result.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <string>
|
||||
|
||||
#ifndef FACTORY_NTP_ENABLED
|
||||
#define FACTORY_NTP_ENABLED true
|
||||
@@ -21,15 +22,15 @@
|
||||
class NTPSettings {
|
||||
public:
|
||||
bool enabled;
|
||||
String tzLabel;
|
||||
String tzFormat;
|
||||
String server;
|
||||
std::string tzLabel;
|
||||
std::string tzFormat;
|
||||
std::string server;
|
||||
|
||||
static void read(NTPSettings &settings, JsonVariant &root) {
|
||||
root["enabled"] = settings.enabled;
|
||||
root["server"] = settings.server;
|
||||
root["tz_label"] = settings.tzLabel;
|
||||
root["tz_format"] = settings.tzFormat;
|
||||
root["server"] = settings.server.c_str();
|
||||
root["tz_label"] = settings.tzLabel.c_str();
|
||||
root["tz_format"] = settings.tzFormat.c_str();
|
||||
}
|
||||
|
||||
static StateUpdateResult update(JsonVariant &root, NTPSettings &settings) {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <vector>
|
||||
#include <ArduinoJson.h>
|
||||
#include <template/state_result.h>
|
||||
#include <string>
|
||||
|
||||
/*
|
||||
* I2C software connection
|
||||
@@ -20,11 +21,11 @@
|
||||
class PinConfig {
|
||||
public:
|
||||
int pin;
|
||||
String mode;
|
||||
String type;
|
||||
String role;
|
||||
std::string mode;
|
||||
std::string type;
|
||||
std::string role;
|
||||
|
||||
PinConfig(int p, String m, String t, String r) : pin(p), mode(m), type(t), role(r) {}
|
||||
PinConfig(int p, std::string m, std::string t, std::string r) : pin(p), mode(m), type(t), role(r) {}
|
||||
};
|
||||
|
||||
class PeripheralsConfiguration {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <utils/json_utils.h>
|
||||
#include <utils/ip_utils.h>
|
||||
#include <template/state_result.h>
|
||||
#include <string>
|
||||
|
||||
#ifndef FACTORY_WIFI_SSID
|
||||
#define FACTORY_WIFI_SSID ""
|
||||
@@ -24,10 +25,10 @@
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
String ssid;
|
||||
std::string ssid;
|
||||
uint8_t bssid[6];
|
||||
int32_t channel;
|
||||
String password;
|
||||
std::string password;
|
||||
bool staticIPConfig;
|
||||
IPAddress localIP;
|
||||
IPAddress gatewayIP;
|
||||
@@ -37,8 +38,8 @@ typedef struct {
|
||||
bool available;
|
||||
|
||||
void serialize(JsonVariant &json) const {
|
||||
json["ssid"] = ssid;
|
||||
json["password"] = password;
|
||||
json["ssid"] = ssid.c_str();
|
||||
json["password"] = password.c_str();
|
||||
json["static_ip_config"] = staticIPConfig;
|
||||
if (staticIPConfig) {
|
||||
JsonUtils::writeIP(json, "local_ip", localIP);
|
||||
@@ -50,8 +51,8 @@ typedef struct {
|
||||
}
|
||||
|
||||
bool deserialize(const JsonVariant &json) {
|
||||
String newSsid = json["ssid"].as<String>();
|
||||
String newPassword = json["password"].as<String>();
|
||||
std::string newSsid = json["ssid"].as<std::string>();
|
||||
std::string newPassword = json["password"].as<std::string>();
|
||||
if (newSsid.length() < 1 || newSsid.length() > 31 || newPassword.length() > 64) {
|
||||
ESP_LOGE("WiFiSettings", "SSID or password length is invalid");
|
||||
return false;
|
||||
@@ -98,11 +99,11 @@ inline wifi_settings_t createDefaultWiFiSettings() {
|
||||
|
||||
class WiFiSettings {
|
||||
public:
|
||||
String hostname;
|
||||
std::string hostname;
|
||||
bool priorityBySignalStrength;
|
||||
std::vector<wifi_settings_t> wifiSettings;
|
||||
static void read(WiFiSettings &settings, JsonVariant &root) {
|
||||
root["hostname"] = settings.hostname;
|
||||
root["hostname"] = settings.hostname.c_str();
|
||||
root["priority_RSSI"] = settings.priorityBySignalStrength;
|
||||
JsonArray wifiNetworks = root["wifi_networks"].to<JsonArray>();
|
||||
for (const auto &wifi : settings.wifiSettings) {
|
||||
@@ -129,7 +130,7 @@ class WiFiSettings {
|
||||
networkCount++;
|
||||
}
|
||||
}
|
||||
} else if (String(FACTORY_WIFI_SSID).length() > 0) {
|
||||
} else if (std::string(FACTORY_WIFI_SSID).length() > 0) {
|
||||
ESP_LOGI("WiFiSettings", "No WiFi config found - using factory settings");
|
||||
settings.wifiSettings.push_back(createDefaultWiFiSettings());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user