diff --git a/components/connect/connect.c b/components/connect/connect.c index 0a95ef5..d53da8b 100644 --- a/components/connect/connect.c +++ b/components/connect/connect.c @@ -163,7 +163,7 @@ esp_netif_t * wifi_init_sta(const char * wifi_ssid, const char * wifi_pass) return esp_netif_sta; } -void wifi_init(const char * wifi_ssid, const char * wifi_pass) +void wifi_init(const char * wifi_ssid, const char * wifi_pass, const char * hostname) { s_wifi_event_group = xEventGroupCreate(); @@ -192,6 +192,14 @@ void wifi_init(const char * wifi_ssid, const char * wifi_pass) /* Start WiFi */ ESP_ERROR_CHECK(esp_wifi_start()); + /* Set Hostname */ + esp_err_t err = esp_netif_set_hostname(esp_netif_sta, hostname); + if (err != ERR_OK) { + ESP_LOGW(TAG, "esp_netif_set_hostname failed: %s", esp_err_to_name(err)); + } else { + ESP_LOGI(TAG, "ESP_WIFI setting hostname to: %s", hostname); + } + ESP_LOGI(TAG, "wifi_init_sta finished."); return; diff --git a/components/connect/include/connect.h b/components/connect/include/connect.h index be5ff40..bd0b975 100644 --- a/components/connect/include/connect.h +++ b/components/connect/include/connect.h @@ -8,6 +8,7 @@ #define WIFI_SSID CONFIG_ESP_WIFI_SSID #define WIFI_PASS CONFIG_ESP_WIFI_PASSWORD +#define HOSTNAME CONFIG_LWIP_LOCAL_HOSTNAME @@ -31,6 +32,6 @@ typedef enum void toggle_wifi_softap(void); void wifi_softap_on(void); void wifi_softap_off(void); -void wifi_init(const char * wifi_ssid, const char * wifi_pass); +void wifi_init(const char * wifi_ssid, const char * wifi_pass, const char * hostname); EventBits_t wifi_connect(void); void generate_ssid(char * ssid); diff --git a/config.cvs.example b/config.cvs.example index 9dbc193..4c3ef97 100644 --- a/config.cvs.example +++ b/config.cvs.example @@ -1,5 +1,6 @@ key,type,encoding,value main,namespace,, +hostname,data,string,bitaxe wifissid,data,string,myssid wifipass,data,string,mypass stratumurl,data,string,public-pool.io diff --git a/main/http_server/axe-os/src/app/components/edit/edit.component.html b/main/http_server/axe-os/src/app/components/edit/edit.component.html index 3c7efbb..5af1eab 100644 --- a/main/http_server/axe-os/src/app/components/edit/edit.component.html +++ b/main/http_server/axe-os/src/app/components/edit/edit.component.html @@ -1,6 +1,12 @@
+
+ +
+ +
+
diff --git a/main/http_server/axe-os/src/app/components/edit/edit.component.ts b/main/http_server/axe-os/src/app/components/edit/edit.component.ts index 70f8409..8308924 100644 --- a/main/http_server/axe-os/src/app/components/edit/edit.component.ts +++ b/main/http_server/axe-os/src/app/components/edit/edit.component.ts @@ -122,6 +122,7 @@ export class EditComponent implements OnInit { ]], stratumUser: [info.stratumUser, [Validators.required]], stratumPassword: ['password', [Validators.required]], + hostname: [info.hostname, [Validators.required]], ssid: [info.ssid, [Validators.required]], wifiPass: ['password'], coreVoltage: [info.coreVoltage, [Validators.required]], diff --git a/main/http_server/axe-os/src/app/services/system.service.ts b/main/http_server/axe-os/src/app/services/system.service.ts index 616a908..ffa2017 100644 --- a/main/http_server/axe-os/src/app/services/system.service.ts +++ b/main/http_server/axe-os/src/app/services/system.service.ts @@ -31,6 +31,7 @@ export class SystemService { freeHeap: 200504, coreVoltage: 1200, coreVoltageActual: 1200, + hostname: "Bitaxe", ssid: "default", wifiPass: "password", wifiStatus: "Connected!", diff --git a/main/http_server/axe-os/src/models/ISystemInfo.ts b/main/http_server/axe-os/src/models/ISystemInfo.ts index dde0108..f1d8f0f 100644 --- a/main/http_server/axe-os/src/models/ISystemInfo.ts +++ b/main/http_server/axe-os/src/models/ISystemInfo.ts @@ -13,6 +13,7 @@ export interface ISystemInfo { bestDiff: string, freeHeap: number, coreVoltage: number, + hostname: string, ssid: string, wifiStatus: string, sharesAccepted: number, diff --git a/main/http_server/http_server.c b/main/http_server/http_server.c index d7354c4..efdb4ba 100644 --- a/main/http_server/http_server.c +++ b/main/http_server/http_server.c @@ -276,6 +276,9 @@ static esp_err_t PATCH_update_settings(httpd_req_t * req) if ((item = cJSON_GetObjectItem(root, "wifiPass")) != NULL) { nvs_config_set_string(NVS_CONFIG_WIFI_PASS, item->valuestring); } + if ((item = cJSON_GetObjectItem(root, "hostname")) != NULL) { + nvs_config_set_string(NVS_CONFIG_HOSTNAME, item->valuestring); + } if ((item = cJSON_GetObjectItem(root, "coreVoltage")) != NULL) { nvs_config_set_u16(NVS_CONFIG_ASIC_VOLTAGE, item->valueint); } @@ -336,6 +339,7 @@ static esp_err_t GET_system_info(httpd_req_t * req) } char * ssid = nvs_config_get_string(NVS_CONFIG_WIFI_SSID, CONFIG_ESP_WIFI_SSID); + char * hostname = nvs_config_get_string(NVS_CONFIG_HOSTNAME, CONFIG_LWIP_LOCAL_HOSTNAME); char * stratumURL = nvs_config_get_string(NVS_CONFIG_STRATUM_URL, CONFIG_STRATUM_URL); char * stratumUser = nvs_config_get_string(NVS_CONFIG_STRATUM_USER, CONFIG_STRATUM_USER); char * board_version = nvs_config_get_string(NVS_CONFIG_BOARD_VERSION, 'unknown'); @@ -354,6 +358,7 @@ static esp_err_t GET_system_info(httpd_req_t * req) cJSON_AddNumberToObject(root, "coreVoltageActual", ADC_get_vcore()); cJSON_AddNumberToObject(root, "frequency", nvs_config_get_u16(NVS_CONFIG_ASIC_FREQ, CONFIG_ASIC_FREQUENCY)); cJSON_AddStringToObject(root, "ssid", ssid); + cJSON_AddStringToObject(root, "hostname", hostname); cJSON_AddStringToObject(root, "wifiStatus", GLOBAL_STATE->SYSTEM_MODULE.wifi_status); cJSON_AddNumberToObject(root, "sharesAccepted", GLOBAL_STATE->SYSTEM_MODULE.shares_accepted); cJSON_AddNumberToObject(root, "sharesRejected", GLOBAL_STATE->SYSTEM_MODULE.shares_rejected); @@ -375,6 +380,7 @@ static esp_err_t GET_system_info(httpd_req_t * req) cJSON_AddNumberToObject(root, "fanspeed", nvs_config_get_u16(NVS_CONFIG_FAN_SPEED, 100)); free(ssid); + free(hostname); free(stratumURL); free(stratumUser); free(board_version); diff --git a/main/main.c b/main/main.c index 88e0dca..93d86a1 100644 --- a/main/main.c +++ b/main/main.c @@ -85,15 +85,16 @@ void app_main(void) ESP_LOGI(TAG, "Welcome to the bitaxe!"); - // pull the wifi credentials out of NVS + // pull the wifi credentials and hostname out of NVS char * wifi_ssid = nvs_config_get_string(NVS_CONFIG_WIFI_SSID, WIFI_SSID); char * wifi_pass = nvs_config_get_string(NVS_CONFIG_WIFI_PASS, WIFI_PASS); + char * hostname = nvs_config_get_string(NVS_CONFIG_HOSTNAME, HOSTNAME); // copy the wifi ssid to the global state strncpy(GLOBAL_STATE.SYSTEM_MODULE.ssid, wifi_ssid, 20); // init and connect to wifi - wifi_init(wifi_ssid, wifi_pass); + wifi_init(wifi_ssid, wifi_pass, hostname); start_rest_server((void *) &GLOBAL_STATE); EventBits_t result_bits = wifi_connect(); @@ -121,6 +122,7 @@ void app_main(void) free(wifi_ssid); free(wifi_pass); + free(hostname); // set the startup_done flag GLOBAL_STATE.SYSTEM_MODULE.startup_done = true; diff --git a/main/nvs_config.h b/main/nvs_config.h index d0c96ea..84dd4fe 100644 --- a/main/nvs_config.h +++ b/main/nvs_config.h @@ -7,6 +7,7 @@ #define NVS_CONFIG_WIFI_SSID "wifissid" #define NVS_CONFIG_WIFI_PASS "wifipass" +#define NVS_CONFIG_HOSTNAME "hostname" #define NVS_CONFIG_STRATUM_URL "stratumurl" #define NVS_CONFIG_STRATUM_PORT "stratumport" #define NVS_CONFIG_STRATUM_USER "stratumuser"