Skip to content

Commit

Permalink
add option to configure hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
MoellerDi committed May 5, 2024
1 parent 47b0293 commit c084d3f
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 4 deletions.
10 changes: 9 additions & 1 deletion components/connect/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion components/connect/include/connect.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#define WIFI_SSID CONFIG_ESP_WIFI_SSID
#define WIFI_PASS CONFIG_ESP_WIFI_PASSWORD
#define HOSTNAME CONFIG_LWIP_LOCAL_HOSTNAME

#define WIFI_MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY

Expand All @@ -30,6 +31,6 @@ typedef enum

void toggle_wifi_softap(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);
1 change: 1 addition & 0 deletions config.cvs.example
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<ng-container *ngIf="form != null">
<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">
<label htmlFor="ssid" class="col-12 mb-2 md:col-2 md:mb-0">WiFi SSID:</label>
<div class="col-12 md:col-10">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
Expand Down
1 change: 1 addition & 0 deletions main/http_server/axe-os/src/app/services/system.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class SystemService {
freeHeap: 200504,
coreVoltage: 1200,
coreVoltageActual: 1200,
hostname: "Bitaxe",
ssid: "default",
wifiPass: "password",
wifiStatus: "Connected!",
Expand Down
1 change: 1 addition & 0 deletions main/http_server/axe-os/src/models/ISystemInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface ISystemInfo {
bestDiff: string,
freeHeap: number,
coreVoltage: number,
hostname: string,
ssid: string,
wifiStatus: string,
sharesAccepted: number,
Expand Down
6 changes: 6 additions & 0 deletions main/http_server/http_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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');
Expand All @@ -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);
Expand All @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions main/nvs_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit c084d3f

Please sign in to comment.