ESP32 Mining
Distributed IoT mining on microcontrollers and embedded devices.
Overview
PoT-O challenges are specifically designed to be solvable by ESP32S and ESP8266 microcontrollers. This enables distributed, low-power mining across IoT networks while maintaining full network participation.
Device Constraints
Different devices have varying computational and memory constraints:
| Device | Max Tensor Dims | Working Memory | Flash | Supported Ops |
|---|---|---|---|---|
| ESP32-S3 | 128x128 | 520 KB | 16 MB | matrix_multiply, convolution, relu, sigmoid, dot_product, normalize, gelu |
| ESP32 | 64x64 | 320 KB | 4 MB | matrix_multiply, convolution, relu, sigmoid, dot_product, normalize |
| ESP8266 | 32x32 | 80 KB | 4 MB | relu, sigmoid, dot_product, normalize |
| Raspberry Pi Pico (RP2040) | 48x48 | 264 KB | 2 MB | relu, sigmoid, dot_product |
The challenge generator respects the most restrictive registered device's limits, ensuring all miners can participate in every round.
Hardware Setup
Required Components
Minimal Setup:
- ESP32-S3 board (~$15)
- USB-C cable for power and programming
- WiFi connectivity
Recommended Setup:
- ESP32-S3-DevKit with external antenna
- Industrial enclosure for protection
- Ethernet module (for stable connectivity)
- Battery with solar panel (for true IoT deployment)
Wiring Diagram
┌─────────────────┐
│ ESP32-S3 │
│ +5V ──────────┼─→ USB Power
│ GND ──────────┼─→ USB Ground
│ IO GPIO47 │ (Optional: External antenna)
│ WiFi antenna │ Built-in antenna
└─────────────────┘Setup & Installation
1. Install Arduino IDE
Download Arduino IDE 2.0+
2. Add ESP32 Board Support
In Arduino IDE:
- Go to Preferences → Additional Board Manager URLs
- Add:
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json - Go to Tools → Board Manager
- Search for
esp32and installesp32 by Espressif Systems
3. Clone PoT-O Arduino Library
cd ~/Documents/Arduino/libraries
git clone https://github.com/TribeWarez/pot-o-arduino.git4. Load Example Sketch
Open pot-o-arduino/examples/ESP32Miner/ESP32Miner.ino in Arduino IDE
5. Configure Credentials
Edit secrets.h:
#define SSID "your_wifi_ssid"
#define PASSWORD "your_wifi_password"
#define VALIDATOR_URL "pot.rpc.gateway.tribewarez.com"
#define VALIDATOR_PORT 443
#define MINER_PUBKEY "your_solana_pubkey_here"6. Upload Sketch
- Connect ESP32 via USB
- Select Tools → Board → ESP32-S3 Dev Module
- Select the COM port
- Click Upload
7. Monitor Serial Output
Open Tools → Serial Monitor (115200 baud):
[startup] PoT-O ESP32 Miner v1.0.0
[wifi] Connecting to "MyNetwork"...
[wifi] Connected! IP: 192.168.1.100
[mining] Registering device: esp32s
[mining] Challenge #1 received (operation: matmul, size: 64x64)
[mining] Computing... (estimated 45 seconds)
[mining] ✓ Proof found! MML: 0.68
[mining] Submitting proof...
[mining] ✓ Accepted! Reward: 42 TRIBECOINArduino Sketch Reference
Minimal Miner Example
#include <WiFi.h>
#include <PotOMiner.h>
const char* ssid = "your_ssid";
const char* password = "your_password";
const char* validator_url = "pot.rpc.gateway.tribewarez.com";
const char* miner_pubkey = "your_solana_pubkey";
PotOMiner miner(miner_pubkey, validator_url);
void setup() {
Serial.begin(115200);
delay(100);
// Connect to WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnected!");
// Initialize miner
miner.initialize();
}
void loop() {
// Mine one step (non-blocking, ~100ms per iteration)
if (miner.is_ready_for_challenge()) {
miner.fetch_challenge();
} else if (miner.is_computing()) {
miner.compute_step();
} else if (miner.has_proof()) {
miner.submit_proof();
}
// Print stats every 60 seconds
static unsigned long last_print = 0;
if (millis() - last_print > 60000) {
Serial.printf("Challenges solved: %d, Success rate: %.1f%%\n",
miner.solved_count(), miner.success_rate() * 100.0);
last_print = millis();
}
}Advanced Features
Dynamic Challenge Processing:
// Process multiple challenges in parallel
miner.set_num_parallel_tasks(2);
miner.enable_pipelining(true); // Fetch next while computing currentPower Management:
// Reduce power consumption
miner.set_cpu_freq(80); // MHz
miner.set_wifi_power(WIFI_POWER_8dBm);
miner.enable_light_sleep(true);
// Deep sleep between challenges
esp_sleep_enable_timer_wakeup(60 * 1000000); // 60 seconds
esp_deep_sleep_start();Persistent State:
// Save mining statistics to flash
miner.enable_nvs_persistence(true); // Survives rebootNetwork Connectivity
WiFi Configuration
For stable operation in challenging environments:
// Configure WiFi with fallback
WiFi.mode(WIFI_STA);
WiFi.config(IPAddress(192,168,1,100), // Static IP
IPAddress(192,168,1,1), // Gateway
IPAddress(255,255,255,0)); // Subnet
WiFi.begin(ssid, password);
// Enable 802.11b mode (longer range)
esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N);
// Use persistent connection
esp_wifi_set_ps(WIFI_PS_MIN_MODEM);Ethernet Alternative
For industrial deployments, use Ethernet for reliability:
#include <ETH.h>
void setup() {
ETH.begin(17, 16, 23, 18, ETH_CLOCK_GPIO17_OUT);
while (!ETH.localIP()) {
delay(100);
}
Serial.println(ETH.localIP());
}Troubleshooting
Device Won't Connect to WiFi
- Check WiFi credentials in
secrets.h - Verify SSID is not hidden
- Test WiFi strength:
Serial.println(WiFi.RSSI()); - Try 2.4GHz WiFi (not 5GHz)
Crashes or Reboots
- Reduce computation:
miner.set_tensor_size(32) - Check PSRAM availability:
Serial.println(ESP.getFreePsram()) - Update ESP32 core:
Tools → Board Manager → Update esp32
Very Slow Mining
- Monitor temperature:
Serial.println(temperatureRead()); - Device may be throttling due to heat
- Ensure adequate CPU frequency:
setCpuFrequencyMhz(240)
Lost WiFi Connection
- Enable auto-reconnect:
WiFi.setAutoReconnect(true); - Check validator availability:
ping pot.rpc.gateway.tribewarez.com - Implement manual reconnect logic in your loop
Distributed Deployment
Mining Fleet Management
Deploy multiple ESP32 miners with centralized monitoring:
// Fleet ID for grouping
const char* fleet_id = "garage_miners_1";
// Register in fleet
miner.register_fleet(fleet_id, miner_pubkey);
// Send metrics to monitoring server
miner.enable_metrics(true);
miner.set_metrics_endpoint("metrics.tribewarez.com");Docker Compose for Fleet Monitoring
Monitor all devices from one dashboard:
version: '3'
services:
prometheus:
image: prom/prometheus
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
grafana:
image: grafana/grafana
ports:
- "3000:3000"
environment:
GF_SECURITY_ADMIN_PASSWORD: adminPerformance Optimization
Tensor Operation Timing
Expected computation times on ESP32-S3:
| Operation | Size | Time |
|---|---|---|
| matrix_multiply | 64x64 | ~30s |
| convolution | 32x32 | ~25s |
| dot_product | 1024 | ~2s |
| relu | 64x64 | ~0.5s |
Choosing Optimal Device
- Most scalable: ESP32-S3 (largest tensors, fastest)
- Best value: ESP32 (good balance)
- Ultra-low power: ESP8266 (battery-powered)
Next Steps
- CPU Mining - Higher performance mining
- GPU Mining - Maximum throughput
- Pool Mining - Coordinate with other miners
- Rewards - How rewards are distributed