Skip to content

Conversation

@timrosenbach
Copy link
Contributor

This PR adds the option to disable and enable the mining without powering of the whole ESP.

Add two endpoints /api/mining/stop and /api/mining/start as well as a card to the home.component.ts:

grafik
grafik

When mining is resumed, it hovers at roughly 800 GH/s for a minute or two before going up to normal levels again.

Tested on my 601 for a week with multiple starts and stops.

@WantClue WantClue requested review from WantClue and mutatrum May 16, 2025 18:51
@WantClue WantClue linked an issue May 16, 2025 that may be closed by this pull request
@WantClue WantClue added enhancement New feature or request accepted This issue will be worked on labels May 16, 2025
@duckaxe
Copy link
Collaborator

duckaxe commented May 17, 2025

Would it be a good idea to put the stop/start button on the dashboard? I think, no. This button isn't something anyone needs every day. I would put the button in the settings. After all, it's just a setting to turn the miner on or off, so it's not important to put it on the dashboard.

@mutatrum
Copy link
Collaborator

@GIGIG4 Can you resolve the tiny conflict?

And I agree with duckAxe, we need to think a bit on where in the UI it should sit. A big button on the dashboard doesn't feel right. It's a bit in the same category as the 'Restart' button, maybe add a toggle below that one in the sidebar?

Copy link
Collaborator

@mutatrum mutatrum left a comment

Choose a reason for hiding this comment

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

I really like this functionality, but I think it can be achieved with quite a bit less code. See comments.

"./power/INA260.c"
"./power/power.c"
"./power/vcore.c"
"mining_controller.c" # Added mining controller
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to add a comment here

bool ASIC_initalized;
bool psram_is_available;

// New fields for mining state and task handles
Copy link
Collaborator

Choose a reason for hiding this comment

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

Commends should be timeless, remove the New.

<p-button (click)="restart()" id="restart" label="Restart" severity="primary"></p-button>
</li>

</ul>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Try to avoid white-space edits in files you're otherwise not editing in this PR. Try to keep the number of changed files as low as possible.


httpd_uri_t mining_start_options_uri = {
.uri = "/api/mining/start",
.method = HTTP_OPTIONS,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not that familiar with the AxeOS api, so maybe a silly question, why does this need both an OPTIONS as well as a PATCH handler? Why is this not just a POST?

VCORE_set_voltage((double) core_voltage / 1000.0, GLOBAL_STATE);
last_core_voltage = core_voltage;
}
// Read the state of plug sense pin
Copy link
Collaborator

Choose a reason for hiding this comment

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

Whitespace here as well.


static const char * TAG = "mining_controller";

esp_err_t start_mining(GlobalState * global_state)
Copy link
Collaborator

Choose a reason for hiding this comment

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

A general comment, it looks like this class has too much responsibility. Ideally, it should only toggle the flag, and start tasks, and the tasks themselves should handle all responsibilities. F.e. retrieving frequency and logging about it, that should be done inside POWER_MANAGEMENT_task.

Secondary remark: it looks like some stuff is duplicated from main.c. Ideally, the cold boot should use the exact same startup sequence and code as a restart.

} else if (stratum_api_v1_message.method == CLIENT_RECONNECT) {
ESP_LOGE(TAG, "Pool requested client reconnect...");
stratum_close_connection(GLOBAL_STATE);
if (!GLOBAL_STATE->mining_enabled) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this check and the stop block so many times in stratum_task.c? Is it possible to have one stop block per task? I see it logs a different stop reason, but in all cases an error is already logged, so having a specific stop reason doesn't add a lot.

Copy link
Collaborator

@mutatrum mutatrum left a comment

Choose a reason for hiding this comment

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

See comments

@mutatrum mutatrum changed the title Add option to disable or enable mining via API and UI Add mining enable/disable API and UI May 26, 2025
@mutatrum mutatrum mentioned this pull request Jun 2, 2025
@mutatrum mutatrum added this to the 2.9.0 milestone Jun 4, 2025
@WantClue
Copy link
Collaborator

@GIGIG4 please resolve the conflict so we can proceed with reviewing it.

@WantClue WantClue modified the milestones: 2.9.0, 2.10.0 Jun 30, 2025
@WantClue WantClue removed this from the 2.10.0 milestone Aug 8, 2025
@WantClue WantClue added accepted This issue will be worked on and removed accepted This issue will be worked on labels Sep 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accepted This issue will be worked on enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable / Disable TPS - Start / Stop mining

4 participants