mirror of
https://github.com/skot/ESP-Miner.git
synced 2025-10-04 18:33:32 +02:00
add option to configure hostname (#174)
This commit is contained in:
@@ -163,7 +163,7 @@ esp_netif_t * wifi_init_sta(const char * wifi_ssid, const char * wifi_pass)
|
|||||||
return esp_netif_sta;
|
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();
|
s_wifi_event_group = xEventGroupCreate();
|
||||||
|
|
||||||
@@ -192,6 +192,14 @@ void wifi_init(const char * wifi_ssid, const char * wifi_pass)
|
|||||||
/* Start WiFi */
|
/* Start WiFi */
|
||||||
ESP_ERROR_CHECK(esp_wifi_start());
|
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.");
|
ESP_LOGI(TAG, "wifi_init_sta finished.");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#define WIFI_SSID CONFIG_ESP_WIFI_SSID
|
#define WIFI_SSID CONFIG_ESP_WIFI_SSID
|
||||||
#define WIFI_PASS CONFIG_ESP_WIFI_PASSWORD
|
#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 toggle_wifi_softap(void);
|
||||||
void wifi_softap_on(void);
|
void wifi_softap_on(void);
|
||||||
void wifi_softap_off(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);
|
EventBits_t wifi_connect(void);
|
||||||
void generate_ssid(char * ssid);
|
void generate_ssid(char * ssid);
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
key,type,encoding,value
|
key,type,encoding,value
|
||||||
main,namespace,,
|
main,namespace,,
|
||||||
|
hostname,data,string,bitaxe
|
||||||
wifissid,data,string,myssid
|
wifissid,data,string,myssid
|
||||||
wifipass,data,string,mypass
|
wifipass,data,string,mypass
|
||||||
stratumurl,data,string,public-pool.io
|
stratumurl,data,string,public-pool.io
|
||||||
|
@@ -1,6 +1,12 @@
|
|||||||
<ng-container *ngIf="form != null">
|
<ng-container *ngIf="form != null">
|
||||||
<form [formGroup]="form">
|
<form [formGroup]="form">
|
||||||
|
|
||||||
|
<div class="field grid p-fluid">
|
||||||
|
<label htmlFor="hostname" class="col-12 mb-2 md:col-2 md:mb-0">Hostname:</label>
|
||||||
|
<div class="col-12 md:col-10">
|
||||||
|
<input pInputText id="hostname" type="text" formControlName="hostname" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="field grid p-fluid">
|
<div class="field grid p-fluid">
|
||||||
<label htmlFor="ssid" class="col-12 mb-2 md:col-2 md:mb-0">WiFi SSID:</label>
|
<label htmlFor="ssid" class="col-12 mb-2 md:col-2 md:mb-0">WiFi SSID:</label>
|
||||||
<div class="col-12 md:col-10">
|
<div class="col-12 md:col-10">
|
||||||
|
@@ -122,6 +122,7 @@ export class EditComponent implements OnInit {
|
|||||||
]],
|
]],
|
||||||
stratumUser: [info.stratumUser, [Validators.required]],
|
stratumUser: [info.stratumUser, [Validators.required]],
|
||||||
stratumPassword: ['password', [Validators.required]],
|
stratumPassword: ['password', [Validators.required]],
|
||||||
|
hostname: [info.hostname, [Validators.required]],
|
||||||
ssid: [info.ssid, [Validators.required]],
|
ssid: [info.ssid, [Validators.required]],
|
||||||
wifiPass: ['password'],
|
wifiPass: ['password'],
|
||||||
coreVoltage: [info.coreVoltage, [Validators.required]],
|
coreVoltage: [info.coreVoltage, [Validators.required]],
|
||||||
|
@@ -31,6 +31,7 @@ export class SystemService {
|
|||||||
freeHeap: 200504,
|
freeHeap: 200504,
|
||||||
coreVoltage: 1200,
|
coreVoltage: 1200,
|
||||||
coreVoltageActual: 1200,
|
coreVoltageActual: 1200,
|
||||||
|
hostname: "Bitaxe",
|
||||||
ssid: "default",
|
ssid: "default",
|
||||||
wifiPass: "password",
|
wifiPass: "password",
|
||||||
wifiStatus: "Connected!",
|
wifiStatus: "Connected!",
|
||||||
|
@@ -13,6 +13,7 @@ export interface ISystemInfo {
|
|||||||
bestDiff: string,
|
bestDiff: string,
|
||||||
freeHeap: number,
|
freeHeap: number,
|
||||||
coreVoltage: number,
|
coreVoltage: number,
|
||||||
|
hostname: string,
|
||||||
ssid: string,
|
ssid: string,
|
||||||
wifiStatus: string,
|
wifiStatus: string,
|
||||||
sharesAccepted: number,
|
sharesAccepted: number,
|
||||||
|
@@ -276,6 +276,9 @@ static esp_err_t PATCH_update_settings(httpd_req_t * req)
|
|||||||
if ((item = cJSON_GetObjectItem(root, "wifiPass")) != NULL) {
|
if ((item = cJSON_GetObjectItem(root, "wifiPass")) != NULL) {
|
||||||
nvs_config_set_string(NVS_CONFIG_WIFI_PASS, item->valuestring);
|
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) {
|
if ((item = cJSON_GetObjectItem(root, "coreVoltage")) != NULL) {
|
||||||
nvs_config_set_u16(NVS_CONFIG_ASIC_VOLTAGE, item->valueint);
|
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 * 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 * 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 * stratumUser = nvs_config_get_string(NVS_CONFIG_STRATUM_USER, CONFIG_STRATUM_USER);
|
||||||
char * board_version = nvs_config_get_string(NVS_CONFIG_BOARD_VERSION, 'unknown');
|
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, "coreVoltageActual", ADC_get_vcore());
|
||||||
cJSON_AddNumberToObject(root, "frequency", nvs_config_get_u16(NVS_CONFIG_ASIC_FREQ, CONFIG_ASIC_FREQUENCY));
|
cJSON_AddNumberToObject(root, "frequency", nvs_config_get_u16(NVS_CONFIG_ASIC_FREQ, CONFIG_ASIC_FREQUENCY));
|
||||||
cJSON_AddStringToObject(root, "ssid", ssid);
|
cJSON_AddStringToObject(root, "ssid", ssid);
|
||||||
|
cJSON_AddStringToObject(root, "hostname", hostname);
|
||||||
cJSON_AddStringToObject(root, "wifiStatus", GLOBAL_STATE->SYSTEM_MODULE.wifi_status);
|
cJSON_AddStringToObject(root, "wifiStatus", GLOBAL_STATE->SYSTEM_MODULE.wifi_status);
|
||||||
cJSON_AddNumberToObject(root, "sharesAccepted", GLOBAL_STATE->SYSTEM_MODULE.shares_accepted);
|
cJSON_AddNumberToObject(root, "sharesAccepted", GLOBAL_STATE->SYSTEM_MODULE.shares_accepted);
|
||||||
cJSON_AddNumberToObject(root, "sharesRejected", GLOBAL_STATE->SYSTEM_MODULE.shares_rejected);
|
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));
|
cJSON_AddNumberToObject(root, "fanspeed", nvs_config_get_u16(NVS_CONFIG_FAN_SPEED, 100));
|
||||||
|
|
||||||
free(ssid);
|
free(ssid);
|
||||||
|
free(hostname);
|
||||||
free(stratumURL);
|
free(stratumURL);
|
||||||
free(stratumUser);
|
free(stratumUser);
|
||||||
free(board_version);
|
free(board_version);
|
||||||
|
@@ -85,15 +85,16 @@ void app_main(void)
|
|||||||
|
|
||||||
ESP_LOGI(TAG, "Welcome to the bitaxe!");
|
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_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 * 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
|
// copy the wifi ssid to the global state
|
||||||
strncpy(GLOBAL_STATE.SYSTEM_MODULE.ssid, wifi_ssid, 20);
|
strncpy(GLOBAL_STATE.SYSTEM_MODULE.ssid, wifi_ssid, 20);
|
||||||
|
|
||||||
// init and connect to wifi
|
// init and connect to wifi
|
||||||
wifi_init(wifi_ssid, wifi_pass);
|
wifi_init(wifi_ssid, wifi_pass, hostname);
|
||||||
start_rest_server((void *) &GLOBAL_STATE);
|
start_rest_server((void *) &GLOBAL_STATE);
|
||||||
EventBits_t result_bits = wifi_connect();
|
EventBits_t result_bits = wifi_connect();
|
||||||
|
|
||||||
@@ -121,6 +122,7 @@ void app_main(void)
|
|||||||
|
|
||||||
free(wifi_ssid);
|
free(wifi_ssid);
|
||||||
free(wifi_pass);
|
free(wifi_pass);
|
||||||
|
free(hostname);
|
||||||
|
|
||||||
// set the startup_done flag
|
// set the startup_done flag
|
||||||
GLOBAL_STATE.SYSTEM_MODULE.startup_done = true;
|
GLOBAL_STATE.SYSTEM_MODULE.startup_done = true;
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#define NVS_CONFIG_WIFI_SSID "wifissid"
|
#define NVS_CONFIG_WIFI_SSID "wifissid"
|
||||||
#define NVS_CONFIG_WIFI_PASS "wifipass"
|
#define NVS_CONFIG_WIFI_PASS "wifipass"
|
||||||
|
#define NVS_CONFIG_HOSTNAME "hostname"
|
||||||
#define NVS_CONFIG_STRATUM_URL "stratumurl"
|
#define NVS_CONFIG_STRATUM_URL "stratumurl"
|
||||||
#define NVS_CONFIG_STRATUM_PORT "stratumport"
|
#define NVS_CONFIG_STRATUM_PORT "stratumport"
|
||||||
#define NVS_CONFIG_STRATUM_USER "stratumuser"
|
#define NVS_CONFIG_STRATUM_USER "stratumuser"
|
||||||
|
Reference in New Issue
Block a user