# Dangerous Pi - Hardware Test Results

**Test Date**: 2026-01-23
**Tester**: Claude (via serial console)
**Hardware**: Raspberry Pi Zero 2 W + Proxmark3 Easy + PiSugar 2 Zero
**Image Version**: Custom pi-gen build (January 2026)
**Pi IP**: 192.168.0.129 (on NETGEAR13 network)

---

## Test Summary

| Component | Status | Notes |
|-----------|--------|-------|
| Serial Console | PASS | Connected via /dev/ttyUSB0 at 115200 baud |
| Boot & Login | PASS | Logged in as dt/proxmark3 |
| Backend Service | PASS | dangerous-pi.service running on port 8000 |
| Frontend | PASS | Remix.js serving on port 3000, HTTP 200 |
| PM3 Detection | PASS | Device at /dev/ttyACM0 detected |
| PM3 Commands | PASS | hw version, hw tune working |
| HF Card Search | PASS | MIFARE Classic 1K detected (UID: B9 78 42 3D) |
| LF Card Search | PASS | FDX-B Animal tag detected (ID: 941-000019966456) |
| WiFi Client Mode | PASS | Connected to NETGEAR13 (192.168.0.129) |
| WiFi Manager API | **ISSUE** | See Issue #1 |
| UPS Detection | **ISSUE** | See Issue #2 |
| BLE Advertising | **ISSUE** | See Issue #3 |
| Antenna Tuning | PASS | LF: 25.21V @ 126.32kHz, HF: 11.02V @ 13.56MHz |
| LED Control | PASS | hw led command returns success |
| Plugin System | PASS | Hello World plugin discovered |

---

## Issues Found

### Issue #1: WiFi Connect API Returns Failure Despite Success (HIGH)

**Component**: WiFi Manager API
**Endpoint**: `POST /api/wifi/connect`
**Severity**: High
**Reproducible**: Yes

**Description**:
When calling the WiFi connect API, the connection actually succeeds (device gets IP address), but the API returns a 503 error and falls back to AP mode.

**Steps to Reproduce**:
```bash
curl -X POST http://localhost:8000/api/wifi/connect \
  -H "Content-Type: application/json" \
  -d '{"ssid": "NETGEAR13", "password": "****"}'
```

**Expected**: `{"success": true, "ip_address": "192.168.0.129"}`
**Actual**: `{"detail":"Failed to connect to NETGEAR13"}`

**Log Evidence**:
```
[WiFi Connect] IP result: inet 192.168.0.129/24
Device 'wlan0' successfully activated with 'f931b358-80a4-4f81-93d8-690a5cff910e'.
Falling back to AP mode...
[NM Management] Setting wlan0 as unmanaged...
AP mode enabled
```

**Analysis**:
The NetworkManager successfully connects and obtains an IP, but the verification logic incorrectly determines failure and triggers AP mode fallback.

**Workaround**:
After API call, manually run `sudo nmcli device set wlan0 managed yes` to complete the connection.

---

### Issue #2: PiSugar 2 UPS Not Detected at Startup (HIGH)

**Component**: UPS Manager
**Severity**: High
**Hardware**: PiSugar 2 Zero at I2C address 0x75
**Reproducible**: Yes

**Description**:
PiSugar 2 is physically connected and responds to I2C probes, but the UPS manager fails to detect it during service startup.

**I2C Devices Detected**:
- 0x32 - RTC (SD3078)
- 0x75 - PiSugar 2 battery IC (IP5209)

**Manual Detection Test** (Works):
```python
# This works when run manually after boot
detected, driver = await PiSugarI2CDriver.detect(retries=3, retry_delay=1.0)
# Result: PiSugar I2C: Found PiSugar 2 at 0x75 (voltage regs: 92, 23)
# Detection result: True
```

**Service Startup Log** (Fails):
```
✅ UPS manager started
Failed to initialize I2C fuel gauge: [Errno 5] Input/output error
UPS not available: Failed to initialize I2C Fuel Gauge (MAX17040/MAX17048)
```

**Analysis**:
The error message "MAX17040/MAX17048" indicates the auto-detection is falling through to the generic I2C fuel gauge driver instead of using the PiSugar I2C driver. Possible race condition with I2C bus availability at boot time.

**Potential Fixes**:
1. Add longer startup delay before UPS detection (UPS_STARTUP_DELAY env var?)
2. Add retry logic in auto_detect_driver
3. Check if PiSugar detection is being attempted before generic I2C

---

### Issue #3: BLE Advertisement Registration Failure (MEDIUM)

**Component**: BLE Manager
**Severity**: Medium
**Reproducible**: Yes (at startup)

**Description**:
BLE advertising fails to register during service startup, falling back to "basic mode".

**Log Evidence**:
```
Failed to start BLE server: Failed to register advertisement
dbus_next.errors.DBusError: Failed to register advertisement
Failed to start GATT server, falling back to basic mode
✅ BLE manager started
```

**API Status** (Reports OK):
```json
{
  "enabled": true,
  "available": true,
  "advertising": true,
  "connected_devices": 0,
  "device_name": "DangerousPi"
}
```

**Analysis**:
The BLE manager reports success in "basic mode" despite the GATT server advertisement failure. The distinction between full mode and basic mode is unclear. Testing BLE advertising from a mobile device would help determine actual functionality.

---

### Issue #4: Missing i2c-tools Package (LOW)

**Component**: System Image
**Severity**: Low

**Description**:
The `i2cdetect` command is not available, making I2C debugging more difficult.

```
$ sudo i2cdetect -y 1
sudo: i2cdetect: command not found
```

**Recommendation**:
Add `i2c-tools` to the pi-gen package list.

---

### Issue #5: PM3 Firmware/Client Version Mismatch Warning (LOW)

**Component**: Proxmark3 Integration
**Severity**: Low (Cosmetic)

**Description**:
The PM3 hw version command shows a warning about firmware/client mismatch.

**Output**:
```
[!] ARM firmware does not match the source at the time the client was compiled
[!] Make sure to flash a correct and up-to-date version
```

**API Status**:
```json
"firmware_info": {
  "bootrom_version": "Iceman/DangerousPi/master/66c7374-dirty-suspect",
  "os_version": "Iceman/DangerousPi/master/66c7374-dirty-suspect",
  "compatible": false
}
```

**Analysis**:
The firmware (built 2026-01-04) and client (built 2026-01-13) were compiled at different times. This is expected when firmware and client are built separately, but the `compatible: false` flag may cause unnecessary warnings in the UI.

---

### Issue #6: Pydantic Protected Namespace Warning (LOW)

**Component**: Backend Models
**Severity**: Low (Cosmetic)

**Description**:
Pydantic logs a warning about field naming conflict.

**Log**:
```
Field "model_short" in PiModelResponse has conflict with protected namespace "model_".
You may be able to resolve this warning by setting `model_config['protected_namespaces'] = ()`.
```

**Recommendation**:
Either rename the field or add the protected_namespaces config to the Pydantic model.

---

## Passing Tests Detail

### Proxmark3 Hardware

**hw version**:
```
[ Client ] Iceman/DangerousPi/master/v4.20728-299-g91263b...-suspect 2026-01-13
[ ARM ]    Iceman/DangerousPi/master/66c7374-dirty-suspect 2026-01-04
[ FPGA ]   fpga_pm3_hf.ncd, fpga_pm3_lf.ncd, fpga_pm3_felica.ncd images present
[ Hardware ] AT91SAM7S512 Rev A, ARM7TDMI, 64K SRAM, 512K flash (71% used)
```

**hw tune**:
- LF Antenna: 25.21V @ 126.32kHz (optimal), Q factor OK
- HF Antenna: 11.02V @ 13.56MHz, OK

**hf search** (Card on HF antenna):
- Type: MIFARE Classic 1K
- UID: B9 78 42 3D (ONUID, re-used)
- Magic: Gen 1a
- PRNG: weak

**lf search** (Card on LF antenna):
- Type: FDX-B / ISO 11784/5 Animal tag
- Animal ID: 941-000019966456
- Chipset: T55xx

### System Info

**API Response** (`/api/system/info`):
```json
{
  "hostname": "dangerous-pi",
  "uptime": 2995.86,
  "cpu_temp": 45.08,
  "cpu": {
    "count": 2,
    "percent": 3.4,
    "temperature": 45.08
  },
  "memory_used": 115757056,
  "memory_total": 436301824,
  "disk_used": 6584954880,
  "disk_total": 7116754944
}
```

### WiFi Status (After manual fix)

**API Response** (`/api/wifi/status`):
```json
{
  "mode": "client",
  "interfaces": [{
    "name": "wlan0",
    "mac": "2c:cf:67:87:db:13",
    "is_usb": false,
    "is_up": true,
    "connected": true,
    "ssid": "NETGEAR13",
    "ip_address": "192.168.0.129",
    "mode": "managed"
  }],
  "current_ssid": "NETGEAR13",
  "current_ip": "192.168.0.129",
  "ap_ssid": "Dangerous-Pi",
  "supports_dual": false
}
```

### Plugins

**API Response** (`/api/plugins/list`):
```json
[{
  "metadata": {
    "id": "hello_world",
    "name": "Hello World Plugin",
    "version": "1.0.0",
    "description": "Example plugin demonstrating the plugin framework"
  },
  "status": "loaded",
  "enabled": false
}]
```

---

## Recommendations

### Priority 1 (Critical for User Experience)
1. **Fix WiFi Connect API** - Investigate why verification fails after successful connection
2. **Fix UPS Detection** - Add retry logic or increase startup delay for I2C initialization

### Priority 2 (Quality Improvements)
3. **Investigate BLE Basic Mode** - Document what features are available in basic vs full mode
4. **Add i2c-tools** - Include in pi-gen image for easier debugging

### Priority 3 (Nice to Have)
5. **Fix Pydantic Warning** - Clean up model namespace conflict
6. **Document PM3 Version Mismatch** - Either sync builds or suppress cosmetic warning

---

## Test Environment

```
Pi Model: Raspberry Pi Zero 2 W
Kernel: 6.12.62+rpt-rpi-v8 aarch64
Debian: Trixie
Python: 3.13.5
Serial: /dev/ttyUSB0 @ 115200 baud
PM3: /dev/ttyACM0 (Proxmark3 Easy)
I2C Bus: 1 (devices at 0x32, 0x75)
```

---

*Test conducted via serial console using Python pyserial library*
