diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d4a4d1036..2b397e033 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,13 +5,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repo - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: submodules: 'recursive' - name: Setup Node.js - uses: actions/setup-node@v2 + uses: actions/setup-node@v3 with: - node-version: '16' + node-version: '20' - name: Build web dist working-directory: ./main/http_server/axe-os run: | @@ -22,6 +22,7 @@ jobs: with: esp_idf_version: v5.1 target: esp32s2 + command: GITHUB_ACTIONS="true" idf.py build path: '.' - name: upload esp-miner.bin uses: actions/upload-artifact@v3 diff --git a/components/connect/include/connect.h b/components/connect/include/connect.h index 4bd387d88..cff09b73d 100644 --- a/components/connect/include/connect.h +++ b/components/connect/include/connect.h @@ -32,3 +32,4 @@ void toggle_wifi_softap(void); void wifi_softap_off(void); void wifi_init(const char * wifi_ssid, const char * wifi_pass); EventBits_t wifi_connect(void); +void generate_ssid(char * ssid); diff --git a/components/stratum/include/stratum_api.h b/components/stratum/include/stratum_api.h index e7eedfd52..7409bb84c 100644 --- a/components/stratum/include/stratum_api.h +++ b/components/stratum/include/stratum_api.h @@ -57,7 +57,7 @@ void STRATUM_V1_initialize_buffer(); char *STRATUM_V1_receive_jsonrpc_line(int sockfd); -int STRATUM_V1_subscribe(int socket, char **extranonce, int *extranonce2_len); +int STRATUM_V1_subscribe(int socket, char ** extranonce, int * extranonce2_len, char * model); void STRATUM_V1_parse(StratumApiV1Message *message, const char *stratum_json); diff --git a/components/stratum/stratum_api.c b/components/stratum/stratum_api.c index f6dd96952..3f4cdb7a6 100644 --- a/components/stratum/stratum_api.c +++ b/components/stratum/stratum_api.c @@ -266,14 +266,14 @@ int _parse_stratum_subscribe_result_message(const char *result_json_str, return 0; } -int STRATUM_V1_subscribe(int socket, char **extranonce, int *extranonce2_len) +int STRATUM_V1_subscribe(int socket, char ** extranonce, int * extranonce2_len, char * model) { // Subscribe char subscribe_msg[BUFFER_SIZE]; - sprintf(subscribe_msg, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": [\"bitaxe %s\"]}\n", send_uid++, CONFIG_ASIC_MODEL); + sprintf(subscribe_msg, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": [\"bitaxe %s\"]}\n", send_uid++, model); debug_stratum_tx(subscribe_msg); write(socket, subscribe_msg, strlen(subscribe_msg)); - char *line; + char * line; line = STRATUM_V1_receive_jsonrpc_line(socket); ESP_LOGI(TAG, "Received result %s", line); diff --git a/config.cvs.example b/config.cvs.example index d2c849f5e..0f617fc62 100644 --- a/config.cvs.example +++ b/config.cvs.example @@ -6,5 +6,8 @@ stratumurl,data,string,public-pool.io stratumport,data,u16,21496 stratumuser,data,string,1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa.bitaxe stratumpass,data,string,x -asicfrequency,data,u16,450 -asicvoltage,data,u16,1400 \ No newline at end of file +asicfrequency,data,u16,485 +asicvoltage,data,u16,1320 +asicmodel,data,string,BM1366 +devicemodel,data,string,ultra +boardversion,data,string,0.11 diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 3d7644711..8fc456312 100755 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -27,9 +27,37 @@ INCLUDE_DIRS ) set(WEB_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/http_server/axe-os") -if(EXISTS ${WEB_SRC_DIR}/dist/axe-os) + +if("$ENV{GITHUB_ACTIONS}" STREQUAL "true") + message(STATUS "Running on GitHub Actions. Web ui will be prebuilt.") + spiffs_create_partition_image(www ${WEB_SRC_DIR}/dist/axe-os FLASH_IN_PROJECT) else() - message(FATAL_ERROR "${WEB_SRC_DIR}/dist doesn't exit. Please run 'npm i && npm run build' in ${WEB_SRC_DIR}") + find_program(NPM_EXECUTABLE npm) + if(NOT NPM_EXECUTABLE AND NOT EXISTS ${WEB_SRC_DIR}/dist) + message(FATAL_ERROR "npm is not found! Please install it to proceed.") + endif() + + ExternalProject_Add( + web_ui_dist + PREFIX ${CMAKE_BINARY_DIR}/web_ui_dist + SOURCE_DIR ${WEB_SRC_DIR} + DOWNLOAD_COMMAND "" + CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env + PATH=$ENV{PATH} + ${NPM_EXECUTABLE} i + USES_TERMINAL_BUILD true + BUILD_COMMAND ${CMAKE_COMMAND} -E env + PATH=$ENV{PATH} + ${NPM_EXECUTABLE} run build + INSTALL_COMMAND "" + BUILD_ALWAYS OFF + BUILD_IN_SOURCE TRUE + BUILD_BYPRODUCTS + "${WEB_SRC_DIR}/dist/axe-os/index.html" + ) + + add_dependencies(${COMPONENT_LIB} web_ui_dist) -endif() \ No newline at end of file + spiffs_create_partition_image(www ${WEB_SRC_DIR}/dist/axe-os FLASH_IN_PROJECT DEPENDS web_ui_dist) +endif() diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild index cb18f1c89..fbcfcc0f3 100755 --- a/main/Kconfig.projbuild +++ b/main/Kconfig.projbuild @@ -1,11 +1,4 @@ menu "Bitaxe Configuration" - - config ASIC_MODEL - string "ASIC Model" - default "BM1397" - help - BM1397 or BM1366 - config ASIC_VOLTAGE int "ASIC Core Voltage (mV)" range 1000 1800 diff --git a/main/global_state.h b/main/global_state.h index eadd5b69f..51184fb0d 100644 --- a/main/global_state.h +++ b/main/global_state.h @@ -1,29 +1,30 @@ #ifndef GLOBAL_STATE_H_ #define GLOBAL_STATE_H_ -#include "work_queue.h" -#include "bm1397.h" -#include "bm1366.h" -#include "system.h" -#include "stratum_api.h" #include "asic_task.h" +#include "bm1366.h" +#include "bm1397.h" +#include "common.h" #include "power_management_task.h" #include "serial.h" -#include "common.h" +#include "stratum_api.h" +#include "system.h" +#include "work_queue.h" #define STRATUM_USER CONFIG_STRATUM_USER typedef struct { void (*init_fn)(u_int64_t); - task_result *(*receive_result_fn)(void *GLOBAL_STATE); + task_result * (*receive_result_fn)(void * GLOBAL_STATE); int (*set_max_baud_fn)(void); void (*set_difficulty_mask_fn)(int); - void (*send_work_fn)(void *GLOBAL_STATE, bm_job *next_bm_job); + void (*send_work_fn)(void * GLOBAL_STATE, bm_job * next_bm_job); } AsicFunctions; typedef struct { + char * asic_model; AsicFunctions ASIC_functions; double asic_job_frequency_ms; @@ -35,11 +36,11 @@ typedef struct AsicTaskModule ASIC_TASK_MODULE; PowerManagementModule POWER_MANAGEMENT_MODULE; - char *extranonce_str; + char * extranonce_str; int extranonce_2_len; int abandon_work; - uint8_t *valid_jobs; + uint8_t * valid_jobs; pthread_mutex_t valid_jobs_lock; uint32_t stratum_difficulty; diff --git a/main/http_server/http_server.c b/main/http_server/http_server.c index 45aaa8168..ce29fb618 100644 --- a/main/http_server/http_server.c +++ b/main/http_server/http_server.c @@ -258,7 +258,7 @@ static esp_err_t GET_system_info(httpd_req_t * req) cJSON_AddNumberToObject(root, "sharesAccepted", GLOBAL_STATE->SYSTEM_MODULE.shares_accepted); cJSON_AddNumberToObject(root, "sharesRejected", GLOBAL_STATE->SYSTEM_MODULE.shares_rejected); cJSON_AddNumberToObject(root, "uptimeSeconds", (esp_timer_get_time() - GLOBAL_STATE->SYSTEM_MODULE.start_time) / 1000000); - cJSON_AddStringToObject(root, "ASICModel", CONFIG_ASIC_MODEL); + cJSON_AddStringToObject(root, "ASICModel", GLOBAL_STATE->asic_model); cJSON_AddStringToObject(root, "stratumURL", stratumURL); cJSON_AddNumberToObject(root, "stratumPort", nvs_config_get_u16(NVS_CONFIG_STRATUM_PORT, CONFIG_STRATUM_PORT)); cJSON_AddStringToObject(root, "stratumUser", stratumUser); diff --git a/main/main.c b/main/main.c index 410ebfad7..709ced4aa 100644 --- a/main/main.c +++ b/main/main.c @@ -17,8 +17,6 @@ #include "stratum_task.h" #include "user_input_task.h" -#define ASIC_MODEL CONFIG_ASIC_MODEL - static GlobalState GLOBAL_STATE = {.extranonce_str = NULL, .extranonce_2_len = 0, .abandon_work = 0, .version_mask = 0}; static const char * TAG = "miner"; @@ -30,7 +28,8 @@ void app_main(void) ESP_LOGI(TAG, "NVS_CONFIG_ASIC_FREQ %f", (float) nvs_config_get_u16(NVS_CONFIG_ASIC_FREQ, CONFIG_ASIC_FREQUENCY)); GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value = nvs_config_get_u16(NVS_CONFIG_ASIC_FREQ, CONFIG_ASIC_FREQUENCY); - if (strcmp(ASIC_MODEL, "BM1366") == 0) { + GLOBAL_STATE.asic_model = nvs_config_get_string(NVS_CONFIG_ASIC_MODEL, ""); + if (strcmp(GLOBAL_STATE.asic_model, "BM1366") == 0) { ESP_LOGI(TAG, "ASIC: BM1366"); AsicFunctions ASIC_functions = {.init_fn = BM1366_init, .receive_result_fn = BM1366_proccess_work, @@ -40,7 +39,7 @@ void app_main(void) GLOBAL_STATE.asic_job_frequency_ms = BM1366_FULLSCAN_MS; GLOBAL_STATE.ASIC_functions = ASIC_functions; - } else if (strcmp(ASIC_MODEL, "BM1397") == 0) { + } else if (strcmp(GLOBAL_STATE.asic_model, "BM1397") == 0) { ESP_LOGI(TAG, "ASIC: BM1397"); AsicFunctions ASIC_functions = {.init_fn = BM1397_init, .receive_result_fn = BM1397_proccess_work, @@ -53,7 +52,8 @@ void app_main(void) GLOBAL_STATE.ASIC_functions = ASIC_functions; } else { - ESP_LOGI(TAG, "Invalid ASIC model"); + ESP_LOGE(TAG, "Unable to determine ASIC model. Please make sure the model has been written into NVS at main/asicmodel."); + vTaskDelay(10000 / portTICK_PERIOD_MS); exit(EXIT_FAILURE); } diff --git a/main/nvs_config.h b/main/nvs_config.h index b20b8b465..58dc9fe31 100644 --- a/main/nvs_config.h +++ b/main/nvs_config.h @@ -11,11 +11,13 @@ #define NVS_CONFIG_STRATUM_PASS "stratumpass" #define NVS_CONFIG_ASIC_FREQ "asicfrequency" #define NVS_CONFIG_ASIC_VOLTAGE "asicvoltage" -#define NVS_CONFIG_ASIC_MODEL "asicModel" +#define NVS_CONFIG_ASIC_MODEL "asicmodel" +#define NVS_CONFIG_DEVICE_MODEL "devicemodel" +#define NVS_CONFIG_BOARD_VERSION "boardversion" -char *nvs_config_get_string(const char *key, const char *default_value); -void nvs_config_set_string(const char *key, const char *default_value); -uint16_t nvs_config_get_u16(const char *key, const uint16_t default_value); -void nvs_config_set_u16(const char *key, const uint16_t value); +char * nvs_config_get_string(const char * key, const char * default_value); +void nvs_config_set_string(const char * key, const char * default_value); +uint16_t nvs_config_get_u16(const char * key, const uint16_t default_value); +void nvs_config_set_u16(const char * key, const uint16_t value); #endif // MAIN_NVS_CONFIG_H diff --git a/main/system.c b/main/system.c index 36b0686b8..992ce0831 100644 --- a/main/system.c +++ b/main/system.c @@ -29,14 +29,12 @@ static const char * TAG = "SystemModule"; -#define ASIC_MODEL CONFIG_ASIC_MODEL - static void _suffix_string(uint64_t, char *, size_t, int); static esp_netif_t * netif; static esp_netif_ip_info_t ip_info; -static void _init_system(SystemModule * module) +static void _init_system(GlobalState * global_state, SystemModule * module) { module->duration_start = 0; module->historical_hashrate_rolling_index = 0; @@ -80,7 +78,7 @@ static void _init_system(SystemModule * module) // Fan Tests EMC2101_init(); - if (strcmp(ASIC_MODEL, "BM1366") == 0) { + if (strcmp(global_state->asic_model, "BM1366") == 0) { EMC2101_set_fan_speed(0); } else { EMC2101_set_fan_speed(1); @@ -246,6 +244,17 @@ static void _update_system_performance(GlobalState * GLOBAL_STATE) } } +static void show_ap_information() +{ + if (OLED_status()) { + _clear_display(); + OLED_writeString(0, 0, "connect to ssid:"); + char ap_ssid[13]; + generate_ssid(ap_ssid); + OLED_writeString(0, 2, ap_ssid); + } +} + static double _calculate_network_difficulty(uint32_t nBits) { uint32_t mantissa = nBits & 0x007fffff; // Extract the mantissa from nBits @@ -336,14 +345,24 @@ void SYSTEM_task(void * pvParameters) GlobalState * GLOBAL_STATE = (GlobalState *) pvParameters; SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE; - _init_system(module); + _init_system(GLOBAL_STATE, module); _clear_display(); _init_connection(module); + wifi_mode_t wifi_mode; + esp_err_t result; + // show the connection screen while (!module->startup_done) { - _update_connection(module); + result = esp_wifi_get_mode(&wifi_mode); + if (result == ESP_OK && (wifi_mode == WIFI_MODE_APSTA || wifi_mode == WIFI_MODE_AP) && + strcmp(module->wifi_status, "Failed to connect") == 0) { + show_ap_information(module); + vTaskDelay(5000 / portTICK_PERIOD_MS); + } else { + _update_connection(module); + } vTaskDelay(100 / portTICK_PERIOD_MS); } diff --git a/main/tasks/power_management_task.c b/main/tasks/power_management_task.c index 041791118..632c990f1 100644 --- a/main/tasks/power_management_task.c +++ b/main/tasks/power_management_task.c @@ -20,7 +20,6 @@ #define VOLTAGE_START_THROTTLE 4900 #define VOLTAGE_MIN_THROTTLE 3500 #define VOLTAGE_RANGE (VOLTAGE_START_THROTTLE - VOLTAGE_MIN_THROTTLE) -#define ASIC_MODEL CONFIG_ASIC_MODEL static const char * TAG = "power_management"; @@ -58,7 +57,7 @@ void POWER_MANAGEMENT_task(void * pvParameters) } power_management->fan_speed = EMC2101_get_fan_speed(); - if (strcmp(ASIC_MODEL, "BM1397") == 0) { + if (strcmp(GLOBAL_STATE->asic_model, "BM1397") == 0) { power_management->chip_temp = EMC2101_get_external_temp(); @@ -115,7 +114,7 @@ void POWER_MANAGEMENT_task(void * pvParameters) last_frequency_increase++; } } - } else if (strcmp(ASIC_MODEL, "BM1366") == 0) { + } else if (strcmp(GLOBAL_STATE->asic_model, "BM1366") == 0) { power_management->chip_temp = EMC2101_get_internal_temp() + 5; if (power_management->fan_speed < 10) { diff --git a/main/tasks/stratum_task.c b/main/tasks/stratum_task.c index b74432554..38cfa8217 100644 --- a/main/tasks/stratum_task.c +++ b/main/tasks/stratum_task.c @@ -113,7 +113,8 @@ void stratum_task(void *pvParameters) break; } - STRATUM_V1_subscribe(GLOBAL_STATE->sock, &GLOBAL_STATE->extranonce_str, &GLOBAL_STATE->extranonce_2_len); + STRATUM_V1_subscribe(GLOBAL_STATE->sock, &GLOBAL_STATE->extranonce_str, &GLOBAL_STATE->extranonce_2_len, + GLOBAL_STATE->asic_model); STRATUM_V1_configure_version_rolling(GLOBAL_STATE->sock);