Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
with:
esp_idf_version: v5.5
target: esp32s3
command: GITHUB_ACTIONS="true" idf.py build
command: idf.py add-dependency "espressif/mdns^1.8.0" ; GITHUB_ACTIONS="true" idf.py build
path: 'test-ci'

- name: Run tests
Expand Down
1 change: 1 addition & 0 deletions components/connect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ REQUIRES
"esp_wifi"
"esp_event"
"stratum"
"espressif__mdns"
)
56 changes: 56 additions & 0 deletions components/connect/connect.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <string.h>
#include "esp_event.h"
#include "esp_log.h"
#include "mdns.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "freertos/FreeRTOS.h"
Expand Down Expand Up @@ -389,6 +390,45 @@ void wifi_init(void * pvParameters)
ESP_LOGI(TAG, "ESP_WIFI setting hostname to: %s", hostname);
}

/* Initialize mDNS */
err = mdns_init();
if (err != ESP_OK) {
ESP_LOGW(TAG, "mDNS/Avahi initialization failed: %s", esp_err_to_name(err));
ESP_LOGW(TAG, "Device will not be discoverable via mDNS/Bonjour/Avahi");
} else {
ESP_LOGI(TAG, "mDNS/Avahi initialized successfully - device discoverable on network");

/* Set mDNS hostname */
err = mdns_hostname_set(hostname);
if (err != ESP_OK) {
ESP_LOGW(TAG, "mDNS hostname setup failed: %s", esp_err_to_name(err));
ESP_LOGW(TAG, "Device hostname not set for mDNS discovery");
} else {
ESP_LOGI(TAG, "mDNS hostname set to: %s.local", hostname);
ESP_LOGI(TAG, "Access device at: http://%s.local", hostname);
}

/* Set mDNS instance name */
err = mdns_instance_name_set("ESP-Miner Web Server");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this instance name exposed somewhere, or is it internal only? If exposed, maybe we can give it a bit nicer name. Maybe device model, f.e. Bitaxe Gamma from DeviceConfig?

if (err != ESP_OK) {
ESP_LOGW(TAG, "mDNS instance name setup failed: %s", esp_err_to_name(err));
} else {
ESP_LOGI(TAG, "mDNS instance: ESP-Miner Web Server");
}

/* Add HTTP service */
err = mdns_service_add("ESP32 WebServer", "_http", "_tcp", 80, NULL, 0);
if (err != ESP_OK) {
ESP_LOGW(TAG, "mDNS HTTP service registration failed: %s", esp_err_to_name(err));
ESP_LOGW(TAG, "HTTP service not advertised via mDNS");
} else {
ESP_LOGI(TAG, "mDNS HTTP service registered: _http._tcp port 80");
ESP_LOGI(TAG, "Discover with: avahi-browse _http._tcp");
}

ESP_LOGI(TAG, "mDNS/Avahi setup complete - device ready for network discovery");
}

free(hostname);

ESP_LOGI(TAG, "wifi_init_sta finished.");
Expand Down Expand Up @@ -466,6 +506,22 @@ static const wifi_reason_desc_t wifi_reasons[] = {
{0, NULL},
};

esp_err_t update_mdns_hostname(const char *new_hostname) {
if (new_hostname == NULL || strlen(new_hostname) == 0) {
ESP_LOGW(TAG, "Invalid hostname provided for mDNS update");
return ESP_ERR_INVALID_ARG;
}

esp_err_t err = mdns_hostname_set(new_hostname);
if (err != ESP_OK) {
ESP_LOGW(TAG, "Failed to update mDNS hostname to: %s, error: %s", new_hostname, esp_err_to_name(err));
return err;
}

ESP_LOGI(TAG, "mDNS hostname updated to: %s", new_hostname);
return ESP_OK;
}

static const char *get_wifi_reason_string(int reason) {
for (int i = 0; wifi_reasons[i].reason != 0; i++) {
if (wifi_reasons[i].reason == reason) {
Expand Down
1 change: 1 addition & 0 deletions components/connect/include/connect.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ void toggle_wifi_softap(void);
void wifi_init(void * GLOBAL_STATE);
esp_err_t wifi_scan(wifi_ap_record_simple_t *ap_records, uint16_t *ap_count);
esp_err_t get_wifi_current_rssi(int8_t *rssi);
esp_err_t update_mdns_hostname(const char *new_hostname);

#endif /* CONNECT_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<tr>
<th *ngFor="let field of [
{
name: 'IP',
label: 'IP'
name: 'address',
label: 'Address'
},
{
name: 'hostname',
Expand Down Expand Up @@ -85,11 +85,11 @@
<tr>
<td>
<a
[ngClass]="'text-'+axe.swarmColor+'-500'"
[href]="'http://'+axe.IP"
target="_blank"
[pTooltip]="axe.deviceModel || 'Other'"
tooltipPosition="top">{{axe.IP}}</a>
[ngClass]="'text-'+axe.swarmColor+'-500'"
[href]="'http://'+axe.address"
target="_blank"
[pTooltip]="axe.deviceModel || 'Other'"
tooltipPosition="top">{{axe.address}}</a>
</td>
<td>{{axe.hostname}}</td>
<td>{{axe.hashRate * 1000000000 | hashSuffix}}</td>
Expand Down Expand Up @@ -155,10 +155,10 @@
<div class="card p-3 mt-4">
<form [formGroup]="form">
<div class="field grid p-fluid mb-0">
<label htmlFor="ip" class="col-12 mb-2 md:col-4 md:mb-0">Manual Addition</label>
<label htmlFor="manualAddAddress" class="col-12 mb-2 md:col-4 md:mb-0">Manual Addition</label>
<div class="col-12 md:col-8">
<p-inputGroup>
<input pInputText id="manualAddIp" formControlName="manualAddIp" type="text" />
<input pInputText id="manualAddAddress" formControlName="manualAddAddress" type="text" placeholder="192.168.1.100 or bitaxe.local" />
<button pButton [disabled]="form.invalid" (click)="add()">Add</button>
</p-inputGroup>

Expand Down Expand Up @@ -187,6 +187,6 @@
</div>
</div>

<app-modal [headline]="selectedAxeOs?.IP">
<app-edit *ngIf="selectedAxeOs" [uri]="'http://' + selectedAxeOs.IP"></app-edit>
<app-modal [headline]="selectedAxeOs?.address">
<app-edit *ngIf="selectedAxeOs" [uri]="'http://' + selectedAxeOs.address"></app-edit>
</app-modal>
Loading
Loading