From e8fc417c83302bec404c5e7744c5dbe46c2673d3 Mon Sep 17 00:00:00 2001 From: "Morgan 'ARR\\!' Allen" Date: Fri, 24 Apr 2020 21:19:32 -0700 Subject: [PATCH] successful saving/reloading of hostname --- main/cmd_hostname.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/main/cmd_hostname.c b/main/cmd_hostname.c index 5a0107a..dd9894f 100644 --- a/main/cmd_hostname.c +++ b/main/cmd_hostname.c @@ -43,16 +43,21 @@ void cmd_hostname_register(lora32_cfg_t *lora) { hostname_args.end = arg_end(1); hostname_args.lora = lora; - /* size_t hostname_len; printf("nvs_handle: %d\n\n\n", lorcomm_cfg.nvs_handle); nvs_get_str(lorcomm_cfg.nvs_handle, "hostname", NULL, &hostname_len); - nvs_get_str(lorcomm_cfg.nvs_handle, "hostname", lorcomm_cfg.hostname, &hostname_len); - printf("hostname: %s\n", lorcomm_cfg.hostname); - */ - lorcomm_cfg.hostname = "lorcomm"; + if(hostname_len > 0) { + printf("hostname_len: %d\n", hostname_len); + lorcomm_cfg.hostname = malloc(hostname_len); + + nvs_get_str(lorcomm_cfg.nvs_handle, "hostname", lorcomm_cfg.hostname, &hostname_len); + printf("hostname: %s\n", lorcomm_cfg.hostname); + } else { + lorcomm_cfg.hostname = malloc(7); + memcpy(lorcomm_cfg.hostname, "lorcomm", 7); + } const esp_console_cmd_t hostname_cmd = { .command = "hostname",