Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ jobs:
with:
esp_idf_version: v5.4.2
target: esp32s3
command: GITHUB_ACTIONS="true" idf.py build
command: |
GITHUB_ACTIONS="true" idf.py add-dependency "espressif/mdns^1.8.2"
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 needed if it's already added in the root CMakeLists.txt?

GITHUB_ACTIONS="true" idf.py build
path: '.'
- uses: actions/setup-python@v5
with:
Expand Down
67 changes: 27 additions & 40 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,35 @@ name: Unit Test
on: [push, pull_request]

permissions:
checks: write
pull-requests: write
contents: read

jobs:
build-and-test:
build:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should these changes on the tests be in a separate PR?

runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: esp-idf build
uses: espressif/esp-idf-ci-action@v1
with:
esp_idf_version: v5.4.2
target: esp32s3
command: GITHUB_ACTIONS="true" idf.py build
path: 'test-ci'

- name: Run tests
uses: bitaxeorg/esp32-qemu-test-action@main
with:
path: 'test-ci'

- name: Upload event file
uses: actions/upload-artifact@v4
with:
name: event-file
path: ${{ github.event_path }}

- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: report.xml

- name: Check for test failures
if: always()
run: |
FAILURES=$(grep -oP 'failures="\K[0-9]+' report.xml || echo 0)
if [ "$FAILURES" -gt 0 ]; then
echo "::error ::Detected $FAILURES test failures."
exit 1
fi
- name: Checkout repo
uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: esp-idf build
uses: espressif/esp-idf-ci-action@v1
with:
esp_idf_version: v5.4.2
target: esp32s3
command: |
GITHUB_ACTIONS="true" idf.py add-dependency "espressif/mdns^1.8.2"
GITHUB_ACTIONS="true" idf.py build
path: 'test-ci'
- name: Run tests and show result
uses: bitaxeorg/esp32-qemu-test-action@main
with:
path: 'test-ci'
- name: Inspect log
run: cat report.xml
- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
if: always()
with:
files: report.xml
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"
"mdns"
)
71 changes: 66 additions & 5 deletions components/connect/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "lwip/sys.h"
#include "nvs_flash.h"
#include "esp_wifi_types_generic.h"
#include "mdns.h"

#include "connect.h"
#include "global_state.h"
Expand Down Expand Up @@ -61,6 +62,7 @@ static int clients_connected_to_ap = 0;
static const char *get_wifi_reason_string(int reason);
static void wifi_softap_on(void);
static void wifi_softap_off(void);
static void mdns_init_hostname(void);

esp_err_t get_wifi_current_rssi(int8_t *rssi)
{
Expand Down Expand Up @@ -190,12 +192,12 @@ static void event_handler(void * arg, esp_event_base_t event_base, int32_t event
ESP_LOGI(TAG, "Retrying Wi-Fi connection...");
esp_wifi_connect();
}

if (event_id == WIFI_EVENT_AP_START) {
ESP_LOGI(TAG, "Configuration Access Point enabled");
GLOBAL_STATE->SYSTEM_MODULE.ap_enabled = true;
}

if (event_id == WIFI_EVENT_AP_STOP) {
ESP_LOGI(TAG, "Configuration Access Point disabled");
GLOBAL_STATE->SYSTEM_MODULE.ap_enabled = false;
Expand All @@ -204,7 +206,7 @@ static void event_handler(void * arg, esp_event_base_t event_base, int32_t event
if (event_id == WIFI_EVENT_AP_STACONNECTED) {
clients_connected_to_ap += 1;
}

if (event_id == WIFI_EVENT_AP_STADISCONNECTED) {
clients_connected_to_ap -= 1;
}
Expand All @@ -222,6 +224,8 @@ static void event_handler(void * arg, esp_event_base_t event_base, int32_t event
ESP_LOGI(TAG, "Connected to SSID: %s", GLOBAL_STATE->SYSTEM_MODULE.ssid);

wifi_softap_off();

mdns_init_hostname();
}
}

Expand All @@ -230,8 +234,8 @@ esp_netif_t * wifi_init_softap(char * ap_ssid)
esp_netif_t * esp_netif_ap = esp_netif_create_default_wifi_ap();

uint8_t mac[6];
esp_wifi_get_mac(ESP_IF_WIFI_AP, mac);
// Format the last 4 bytes of the MAC address as a hexadecimal string
esp_wifi_get_mac(WIFI_IF_STA, mac);
// Format the last 4 bytes of the Station MAC address as a hexadecimal string
snprintf(ap_ssid, 32, "Bitaxe_%02X%02X", mac[4], mac[5]);

wifi_config_t wifi_ap_config;
Expand Down Expand Up @@ -474,3 +478,60 @@ static const char *get_wifi_reason_string(int reason) {
}
return "Unknown error";
}

static void mdns_init_hostname(void) {
char * hostname = nvs_config_get_string(NVS_CONFIG_HOSTNAME, CONFIG_LWIP_LOCAL_HOSTNAME);

ESP_LOGI(TAG, "Starting mDNS service");
esp_err_t err = mdns_init();
if (err != ESP_OK) {
ESP_LOGE(TAG, "mDNS initialization failed: %s", esp_err_to_name(err));
free(hostname);
return;
}

ESP_LOGI(TAG, "Setting mDNS hostname to: %s", hostname);
err = mdns_hostname_set(hostname);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to set mDNS hostname: %s", esp_err_to_name(err));
free(hostname);
return;
}

ESP_LOGI(TAG, "Setting mDNS instance name to: %s", hostname);
err = mdns_instance_name_set(hostname);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to set mDNS instance name: %s", esp_err_to_name(err));
free(hostname);
return;
}

ESP_LOGI(TAG, "Adding mDNS service: _http._tcp on port 80");
err = mdns_service_add(NULL, "_http", "_tcp", 80, NULL, 0);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to add mDNS HTTP service: %s", esp_err_to_name(err));
free(hostname);
return;
}

// Add _bitaxe._tcp service with apiSecret as TXT record
char * api_secret = nvs_config_get_string(NVS_CONFIG_API_SECRET, "");

ESP_LOGI(TAG, "Adding mDNS service: _bitaxe._tcp on port 80");

mdns_txt_item_t bitaxe_txt_data[1];
bitaxe_txt_data[0].key = "apiSecret";
bitaxe_txt_data[0].value = api_secret;

err = mdns_service_add(NULL, "_bitaxe", "_tcp", 80, bitaxe_txt_data, 1);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to add mDNS _bitaxe._tcp service: %s", esp_err_to_name(err));
} else {
ESP_LOGI(TAG, "mDNS _bitaxe._tcp service added successfully");
}

free(api_secret);

ESP_LOGI(TAG, "mDNS service started successfully");
free(hostname);
}
1 change: 1 addition & 0 deletions config-102.cvs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
key,type,encoding,value
main,namespace,,
hostname,data,string,bitaxe
apisecret,data,string,
wifissid,data,string,
wifipass,data,string,
stratumurl,data,string,public-pool.io
Expand Down
1 change: 1 addition & 0 deletions config-201.cvs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
key,type,encoding,value
main,namespace,,
hostname,data,string,bitaxe
apisecret,data,string,
wifissid,data,string,
wifipass,data,string,
stratumurl,data,string,public-pool.io
Expand Down
1 change: 1 addition & 0 deletions config-202.cvs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
key,type,encoding,value
main,namespace,,
hostname,data,string,bitaxe
apisecret,data,string,
wifissid,data,string,
wifipass,data,string,
stratumurl,data,string,public-pool.io
Expand Down
1 change: 1 addition & 0 deletions config-203.cvs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
key,type,encoding,value
main,namespace,,
hostname,data,string,bitaxe
apisecret,data,string,
wifissid,data,string,
wifipass,data,string,
stratumurl,data,string,public-pool.io
Expand Down
1 change: 1 addition & 0 deletions config-204.cvs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
key,type,encoding,value
main,namespace,,
hostname,data,string,bitaxe
apisecret,data,string,
wifissid,data,string,
wifipass,data,string,
stratumurl,data,string,public-pool.io
Expand Down
1 change: 1 addition & 0 deletions config-205.cvs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
key,type,encoding,value
main,namespace,,
hostname,data,string,bitaxe
apisecret,data,string,
wifissid,data,string,
wifipass,data,string,
stratumurl,data,string,public-pool.io
Expand Down
1 change: 1 addition & 0 deletions config-207.cvs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
key,type,encoding,value
main,namespace,,
hostname,data,string,bitaxe
apisecret,data,string,
wifissid,data,string,
wifipass,data,string,
stratumurl,data,string,public-pool.io
Expand Down
1 change: 1 addition & 0 deletions config-401.cvs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
key,type,encoding,value
main,namespace,,
hostname,data,string,bitaxe
apisecret,data,string,
wifissid,data,string,
wifipass,data,string,
stratumurl,data,string,public-pool.io
Expand Down
1 change: 1 addition & 0 deletions config-402.cvs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
key,type,encoding,value
main,namespace,,
hostname,data,string,bitaxe
apisecret,data,string,
wifissid,data,string,
wifipass,data,string,
stratumurl,data,string,public-pool.io
Expand Down
1 change: 1 addition & 0 deletions config-403.cvs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
key,type,encoding,value
main,namespace,,
hostname,data,string,bitaxe
apisecret,data,string,
wifissid,data,string,
wifipass,data,string,
stratumurl,data,string,public-pool.io
Expand Down
1 change: 1 addition & 0 deletions config-601.cvs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
key,type,encoding,value
main,namespace,,
hostname,data,string,bitaxe
apisecret,data,string,
wifissid,data,string,
wifipass,data,string,
stratumurl,data,string,public-pool.io
Expand Down
1 change: 1 addition & 0 deletions config-602.cvs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
key,type,encoding,value
main,namespace,,
hostname,data,string,bitaxe
apisecret,data,string,
wifissid,data,string,
wifipass,data,string,
stratumurl,data,string,public-pool.io
Expand Down
1 change: 1 addition & 0 deletions config-800x.cvs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
key,type,encoding,value
main,namespace,,
hostname,data,string,bitaxe
apisecret,data,string,
wifissid,data,string,myssid
wifipass,data,string,password
stratumurl,data,string,public-pool.io
Expand Down
1 change: 1 addition & 0 deletions config-custom.cvs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
key,type,encoding,value
main,namespace,,
hostname,data,string,bitaxe
apisecret,data,string,
wifissid,data,string,
wifipass,data,string,
stratumurl,data,string,public-pool.io
Expand Down
1 change: 1 addition & 0 deletions config.cvs.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
key,type,encoding,value
main,namespace,,
hostname,data,string,bitaxe
apisecret,data,string,
wifissid,data,string,myssid
wifipass,data,string,mypass
stratumurl,data,string,public-pool.io
Expand Down
2 changes: 2 additions & 0 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ PRIV_REQUIRES
"esp_adc"
"esp_app_format"
"esp_event"
"esp_http_client"
"esp_http_server"
"esp_netif"
"esp_psram"
Expand All @@ -64,6 +65,7 @@ PRIV_REQUIRES
"spiffs"
"vfs"
"esp_driver_i2c"
"mdns"

EMBED_FILES "http_server/recovery_page.html"
)
Expand Down
4 changes: 2 additions & 2 deletions main/http_server/axe-os/api/system/asic_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
static GlobalState *GLOBAL_STATE = NULL;

// Function declarations from http_server.c
extern esp_err_t is_network_allowed(httpd_req_t *req);
extern esp_err_t is_request_authorized(httpd_req_t *req);
extern esp_err_t set_cors_headers(httpd_req_t *req);

// Initialize the ASIC API with the global state
Expand All @@ -20,7 +20,7 @@ void asic_api_init(GlobalState *global_state) {
/* Handler for system asic endpoint */
esp_err_t GET_system_asic(httpd_req_t *req)
{
if (is_network_allowed(req) != ESP_OK) {
if (is_request_authorized(req) != ESP_OK) {
return httpd_resp_send_err(req, HTTPD_401_UNAUTHORIZED, "Unauthorized");
}

Expand Down
Loading
Loading