diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c
index 67648dd90..71c553fa8 100644
--- a/src/httpserver/http_fns.c
+++ b/src/httpserver/http_fns.c
@@ -467,6 +467,46 @@ int http_fn_cfg_wifi(http_request_t *request) {
return 0;
}
+int http_fn_cfg_name(http_request_t *request) {
+ // for a test, show password as well...
+ const char *shortName, *name;
+ char tmpA[128];
+ int i;
+
+ http_setup(request, httpMimeTypeHTML);
+ poststr(request,htmlHeader);
+ poststr(request,g_header);
+
+ poststr(request,"
Change device names for display.
Remember that short name is used by MQTT.
");
+ if(http_getArg(request->url,"shortName",tmpA,sizeof(tmpA))) {
+ CFG_SetShortDeviceName(tmpA);
+ }
+ if(http_getArg(request->url,"name",tmpA,sizeof(tmpA))) {
+ CFG_SetDeviceName(tmpA);
+ }
+ poststr(request," Use this to change device names
");
+ poststr(request," ");
+ poststr(request,htmlReturnToCfg);
+ HTTP_AddBuildFooter(request);
+ poststr(request,htmlEnd);
+
+ poststr(request, NULL);
+ return 0;
+}
int http_fn_cfg_wifi_set(http_request_t *request) {
char tmpA[128];
addLogAdv(LOG_INFO, LOG_FEATURE_HTTP,"HTTP_ProcessPacket: generating cfg_wifi_set \r\n");
@@ -968,6 +1008,7 @@ int http_fn_cfg(http_request_t *request) {
poststr(request,"");
poststr(request,"");
poststr(request,"");
+ poststr(request,"");
poststr(request,"");
poststr(request,"");
poststr(request,"");
diff --git a/src/httpserver/http_fns.h b/src/httpserver/http_fns.h
index 5f653c0a1..ba11026d6 100644
--- a/src/httpserver/http_fns.h
+++ b/src/httpserver/http_fns.h
@@ -10,6 +10,7 @@ int http_fn_cfg_webapp(http_request_t *request);
int http_fn_config_dump_table(http_request_t *request);
int http_fn_cfg_webapp_set(http_request_t *request);
int http_fn_cfg_wifi_set(http_request_t *request);
+int http_fn_cfg_name(http_request_t *request);
int http_fn_cfg_loglevel_set(http_request_t *request);
int http_fn_cfg_wifi(http_request_t *request);
int http_fn_cfg_mac(http_request_t *request);
diff --git a/src/httpserver/new_http.c b/src/httpserver/new_http.c
index ed91ecfbb..7e375cea5 100644
--- a/src/httpserver/new_http.c
+++ b/src/httpserver/new_http.c
@@ -504,6 +504,7 @@ int HTTP_ProcessPacket(http_request_t *request) {
if(http_checkUrlBase(urlStr,"cfg_webapp_set")) return http_fn_cfg_webapp_set(request);
if(http_checkUrlBase(urlStr,"cfg_wifi")) return http_fn_cfg_wifi(request);
+ if(http_checkUrlBase(urlStr,"cfg_name")) return http_fn_cfg_name(request);
if(http_checkUrlBase(urlStr,"cfg_wifi_set")) return http_fn_cfg_wifi_set(request);
if(http_checkUrlBase(urlStr,"cfg_loglevel_set")) return http_fn_cfg_loglevel_set(request);
diff --git a/src/new_cfg.c b/src/new_cfg.c
index 3698e4450..8455e1cc3 100644
--- a/src/new_cfg.c
+++ b/src/new_cfg.c
@@ -10,7 +10,7 @@
mainConfig_t g_cfg;
-
+int g_configInitialized = 0;
int g_cfg_pendingChanges = 0;
#define CFG_IDENT_0 'C'
@@ -45,8 +45,6 @@ static byte CFG_CalcChecksum(mainConfig_t *inf) {
return crc;
}
-
-
static void CFG_SetDefaultConfig() {
// must be unsigned, else print below prints negatives as e.g. FFFFFFFe
unsigned char mac[6] = { 0 };
@@ -57,6 +55,8 @@ static void CFG_SetDefaultConfig() {
WiFI_GetMacAddress((char *)mac);
#endif
+ g_configInitialized = 1;
+
memset(&g_cfg,0,sizeof(mainConfig_t));
g_cfg.mqtt_port = 1883;
g_cfg.ident0 = CFG_IDENT_0;
@@ -107,14 +107,32 @@ int CFG_SetWebappRoot(const char *s) {
}
const char *CFG_GetDeviceName(){
+ if(g_configInitialized==0)
+ return "";
return g_cfg.longDeviceName;
}
const char *CFG_GetShortDeviceName(){
+ if(g_configInitialized==0)
+ return "";
return g_cfg.shortDeviceName;
}
int CFG_GetMQTTPort() {
return g_cfg.mqtt_port;
+}
+void CFG_SetShortDeviceName(const char *s) {
+ // this will return non-zero if there were any changes
+ if(strcpy_safe_checkForChanges(g_cfg.shortDeviceName, s,sizeof(g_cfg.shortDeviceName))) {
+ // mark as dirty (value has changed)
+ g_cfg_pendingChanges++;
+ }
+}
+void CFG_SetDeviceName(const char *s) {
+ // this will return non-zero if there were any changes
+ if(strcpy_safe_checkForChanges(g_cfg.longDeviceName, s,sizeof(g_cfg.longDeviceName))) {
+ // mark as dirty (value has changed)
+ g_cfg_pendingChanges++;
+ }
}
void CFG_SetMQTTPort(int p) {
// is there a change?
@@ -249,4 +267,5 @@ void CFG_InitAndLoad() {
} else {
addLogAdv(LOG_WARN, LOG_FEATURE_CFG, "CFG_InitAndLoad: Correct config has been loaded with %i changes count.",g_cfg.changeCounter);
}
+ g_configInitialized = 1;
}
diff --git a/src/new_cfg.h b/src/new_cfg.h
index a870a5112..c8b1e6bb0 100644
--- a/src/new_cfg.h
+++ b/src/new_cfg.h
@@ -5,6 +5,8 @@ extern int g_cfg_pendingChanges;
const char *CFG_GetDeviceName();
const char *CFG_GetShortDeviceName();
+void CFG_SetShortDeviceName(const char *s);
+void CFG_SetDeviceName(const char *s);
void CFG_CreateDeviceNameUnique();
int CFG_GetMQTTPort();
void CFG_SetMQTTPort(int p);