Skip to content

refactor: internal refactoring and optimization of Brucegotchi - #2724

Merged
bmorcelli merged 1 commit into
BruceDevices:devfrom
Mysteriza:brucegotchi-optimize
Aug 3, 2026
Merged

refactor: internal refactoring and optimization of Brucegotchi#2724
bmorcelli merged 1 commit into
BruceDevices:devfrom
Mysteriza:brucegotchi-optimize

Conversation

@Mysteriza

Copy link
Copy Markdown
Contributor

Proposed Changes

This PR cleans up and improves the Brucegotchi feature (Pwnagotchi) to make the code easier to maintain while reducing unnecessary memory usage on ESP32 devices.

pwnagotchi.cpp

  • Broke the large brucegotchi_start() function into three smaller functions:

    • reconPhase()
    • interactPhase()
    • advertisePhase()
  • Added a BruceState struct to keep related state variables organized.

  • Replaced the long chain of if statements with a switch statement to make the flow easier to follow.

  • Removed brucegotchi_update() since it is no longer used anywhere in the project.

pwngrid.cpp

  • Improved how inactive peers are removed, reducing unnecessary memory allocations.
  • Optimized string building in pwnSnifferCallback() to avoid repeated memory reallocations and improve efficiency.
  • Added #include <algorithm> for the STL functions used in the new implementation.

No functional changes were made. The feature behaves the same as before, with all existing timing and logic preserved.

Types of Changes

  • Refactor — reorganized the Brucegotchi state machine
  • Optimization — reduced unnecessary memory allocations
  • Code cleanup — removed unused code

Verification

  • Build verified against reaper target (ESP32-S3): SUCCESS

Testing

Tested on my device, and everything worked as expected with no issues observed.

Linked Issues

N/A

User-Facing Change

NONE — internal refactoring and optimization only, no user-facing changes.

Further Comments

The main goal of this refactoring is to make the Brucegotchi code easier to read, understand, and maintain. Splitting the main function into smaller parts makes future changes and debugging much simpler. The memory optimizations also help reduce unnecessary allocations during long-running Brucegotchi sessions.

@bmorcelli bmorcelli added the enhancement New feature or request label Jul 28, 2026
@Mysteriza Mysteriza changed the title refactor: modularize state machine into phase functions and optimize … refactor: internal refactoring and optimization of Brucegotchi Jul 28, 2026
@bmorcelli
bmorcelli merged commit 720ea47 into BruceDevices:dev Aug 3, 2026
7 checks passed
0Zane pushed a commit to 0Zane/firmware that referenced this pull request Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants