2020-04-23 02:04:48 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "esp_log.h"
|
|
|
|
#include "esp_console.h"
|
|
|
|
#include "argtable3/argtable3.h"
|
2020-04-24 15:56:14 -04:00
|
|
|
#include "nvs_flash.h"
|
|
|
|
#include "esp_vfs_dev.h"
|
2020-04-23 02:04:48 -04:00
|
|
|
|
|
|
|
#include "esp32-lora.h"
|
|
|
|
#include "lorcomm.h"
|
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
struct arg_str *hostname;
|
|
|
|
struct arg_end *end;
|
|
|
|
lora32_cfg_t *lora;
|
|
|
|
} hostname_args;
|
|
|
|
|
|
|
|
int hostname(int argc, char **argv) {
|
|
|
|
int nerrors = arg_parse(argc, argv, (void **)&hostname_args);
|
|
|
|
|
|
|
|
if (nerrors != 0) {
|
|
|
|
arg_print_errors(stderr, hostname_args.end, argv[0]);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(argc == 1) {
|
|
|
|
printf(" > %s\n", lorcomm_cfg.hostname);
|
|
|
|
} else {
|
|
|
|
asprintf(&lorcomm_cfg.hostname, "%s", hostname_args.hostname->sval[0]);
|
2020-04-24 15:56:14 -04:00
|
|
|
|
|
|
|
nvs_set_str(lorcomm_cfg.nvs_handle, "hostname", hostname_args.hostname->sval[0]);
|
|
|
|
esp_err_t err = nvs_commit(lorcomm_cfg.nvs_handle);
|
|
|
|
printf((err != ESP_OK) ? "Failed!\n" : "Done\n");
|
2020-04-23 02:04:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmd_hostname_register(lora32_cfg_t *lora) {
|
|
|
|
hostname_args.hostname = arg_strn(NULL, NULL, "\"hostname\"", 0, 1, "hostname");
|
|
|
|
hostname_args.end = arg_end(1);
|
|
|
|
hostname_args.lora = lora;
|
|
|
|
|
2020-04-24 15:56:14 -04:00
|
|
|
/*
|
|
|
|
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";
|
|
|
|
|
2020-04-23 02:04:48 -04:00
|
|
|
const esp_console_cmd_t hostname_cmd = {
|
|
|
|
.command = "hostname",
|
|
|
|
.help = "Set/Get Hostname",
|
|
|
|
.hint = NULL,
|
|
|
|
.func = &hostname,
|
|
|
|
.argtable = &hostname_args
|
|
|
|
};
|
|
|
|
|
|
|
|
ESP_ERROR_CHECK(esp_console_cmd_register(&hostname_cmd));
|
|
|
|
}
|