# Testing & Verification Checklist ## Phase 1: Pre-Deployment Checks ### Code Quality - [x] Single file (app_v3_simplified.py) - 300 lines - [x] Clear function separation - [x] Proper error handling - [x] Logging at all critical points - [x] Meaningful variable names ### Dependencies Check ```bash # Verify required packages installed python3 -c "import rdm6300; print('✓ rdm6300')" python3 -c "import requests; print('✓ requests')" python3 -c "from gpiozero import OutputDevice; print('✓ gpiozero')" 2>/dev/null || echo "⚠ gpiozero not installed (optional, LED won't work)" ``` ### Hardware Prerequisites ```bash # Check serial devices ls /dev/tty* # Should show at least: /dev/ttyS0 or /dev/ttyAMA0 or /dev/ttyUSB0 # Check GPIO available gpio readall 2>/dev/null | head -5 # If not available, app will use dummy LED (still works) # Check permissions groups | grep dialout # Should include 'dialout' group # If not: sudo usermod -a -G dialout $USER (then logout/login) ``` --- ## Phase 2: Startup Test ### Step 1: Set Device Name ```bash # Edit device ID nano ./data/idmasa.txt # Change 'noconfig' to actual device name, e.g.: # mesa_1 # Save and exit ``` ### Step 2: Start Application ```bash cd /home/pi/Desktop/prezenta_work # Make executable chmod +x app_v3_simplified.py # Run it python3 app_v3_simplified.py ``` ### Expected Output ``` ============================================================ RFID CARD READER - Simplified v3.0 ============================================================ ✓ Logging configured: ./data/log.txt ✓ LED initialized on GPIO 23 Device: raspberry (192.168.1.50) Name ID: mesa_1 Monitoring: http://rpi-ansible:80/logs API: https://dataswsibiusb01.sibiusb.harting.intra/RO_Quality_PRD/api/record ✓ RFID reader started on /dev/ttyS0 ✓ WiFi monitor started ✓ RFID Client operational - waiting for cards... ``` ### Verification - [ ] No error messages - [ ] All ✓ marks present - [ ] Device IP correct - [ ] Device name correct (from idmasa.txt) - [ ] WiFi monitor started --- ## Phase 3: Card Detection Test ### Test 1: Insert Regular Card ``` Expected Behavior: 1. LED turns ON immediately 2. Console shows: "🔴 CARD INSERTED - ID: [card_number]" 3. Next line: "✓ Card event posted to API: [card_number]" 4. Check log.txt shows: "INFO - 🔴 CARD INSERTED" ``` ### Test 2: Remove Card ``` Expected Behavior: 1. LED turns OFF immediately 2. Console shows: "⚪ CARD REMOVED - ID: [card_number]" 3. Next line: "✓ Card event posted to API: [card_number]" 4. Check log.txt shows: "INFO - ⚪ CARD REMOVED" ``` ### Test 3: Multiple Rapid Cards ``` Insert 3 cards rapidly, remove them. Expected: - Each insert → LED ON, "🔴 CARD INSERTED" - Each remove → LED OFF, "⚪ CARD REMOVED" - All POSTs successful - No crashes or hangs ``` ### Verification Checklist - [ ] LED feedback immediate (no 5-second delay) - [ ] Console output shows card events - [ ] log.txt records all events with timestamps - [ ] No error messages - [ ] API POSTs show success (✓) --- ## Phase 4: Offline Mode Test ### Setup ```bash # Stop WiFi to simulate offline sudo rfkill block wifi # Wait for connection loss sleep 10 ``` ### Test 1: Insert Card While Offline ``` Expected: 1. LED turns ON 2. Console: "🔴 CARD INSERTED - ID: [number]" 3. Console: "✗ Offline: Saving card [number] to backup" 4. Check tag.txt: Should contain the API URL 5. Check log.txt: Shows "WARNING - ✗ Offline: Saving card" ``` ### Test 2: Remove Card While Offline ``` Expected: 1. LED turns OFF 2. Console: "⚪ CARD REMOVED - ID: [number]" 3. Console: "✗ Offline: Saving card [number] to backup" 4. Check tag.txt: Should have 2 lines now (insert + remove) ``` ### Test 3: Restore WiFi ```bash # Re-enable WiFi sudo rfkill unblock wifi # Wait for reconnection sleep 10 ``` ### Expected After WiFi Restored ``` Console should show: ✓ Connection OK - checking for backed-up data INFO - Posted backed-up data: https://....../[card_id]/1/... INFO - Posted backed-up data: https://....../[card_id]/0/... Check tag.txt: Should be EMPTY now ``` ### Verification Checklist - [ ] tag.txt created with card URLs when offline - [ ] Console shows "✗ Offline: Saving" messages - [ ] After WiFi restored, shows "Posted backed-up data" - [ ] tag.txt cleared after posting - [ ] log.txt records all events --- ## Phase 5: WiFi Recovery Test ### Monitor WiFi Checks ```bash # Terminal 1: Watch logs tail -f ./data/log.txt | grep -E "(Connection|WiFi|offline)" ``` ### Test WiFi Loss & Recovery ```bash # Terminal 2: Wait for next WiFi check (happens every 40 min) # Or force a check by restarting the app # Simulate connection loss sudo rfkill block wifi # Monitor terminal 1 # Should see: "Connection lost - disabling WiFi for recovery" # Wait 20 minutes # Should see: "WiFi re-enabled" # Re-enable WiFi sudo rfkill unblock wifi ``` ### Expected Log Output ``` INFO - ✓ Connection OK - checking for backed-up data WARNING - ✗ Connection lost - disabling WiFi for recovery INFO - WiFi disabled, waiting 1200s for recovery... INFO - WiFi re-enabled INFO - ✓ Connection OK - checking for backed-up data ``` ### Verification Checklist - [ ] WiFi check happens every 40 minutes - [ ] WiFi recovery initiates on connection loss - [ ] WiFi disabled for 20 minutes - [ ] WiFi re-enabled automatically - [ ] Monitoring server receives WiFi event logs - [ ] backed-up data posted after WiFi restored --- ## Phase 6: Server Communication Test ### Monitoring Server Check ```bash # On monitoring server (rpi-ansible): # Check if logs are being received tail -f /path/to/monitoring/app/logs # Should show entries like: # hostname: raspberry # device_ip: 192.168.1.50 # nume_masa: mesa_1 # log_message: Card 12345678 inserted ``` ### Harting API Check ```bash # Test with curl curl -X POST "https://dataswsibiusb01.sibiusb.harting.intra/RO_Quality_PRD/api/record/mesa_1/12345678/1/2025-12-18&14:23:45" \ --insecure \ -v ``` ### Verification Checklist - [ ] Monitoring server receives card event logs - [ ] Harting API logs card insertions/removals - [ ] All events timestamped correctly - [ ] Device name matches idmasa.txt --- ## Phase 7: Error Handling Test ### Test 1: Serial Port Error ```bash # Disconnect RFID reader (physically) # Or block the device: sudo chmod 000 /dev/ttyS0 ``` ### Expected ``` ✗ RFID reader failed - application cannot continue ERROR: RFID reader initialization failed - exiting ``` ### Fix ```bash # Restore permissions sudo chmod 644 /dev/ttyS0 # Restart app python3 app_v3_simplified.py ``` ### Test 2: Network Error (Firewall) ```bash # Block outbound HTTPS sudo ufw deny out 443 # (if ufw enabled) # Insert card # Expected: "✗ Offline: Saving card to backup" ``` ### Test 3: Server Down ```bash # Stop monitoring server # Insert card # Expected: "WARNING - Failed to send log to server" # But card still posts to Harting API and LED works ``` ### Verification Checklist - [ ] App handles serial port errors gracefully - [ ] App handles network timeouts - [ ] App falls back to backup when server down - [ ] No crashes, proper error messages - [ ] Recovery when service restored --- ## Phase 8: Performance Checks ### Memory Usage ```bash # In another terminal while app is running: ps aux | grep app_v3_simplified # Check RSS column (resident memory) # Should be ~30-50 MB, not 80+ MB ``` ### CPU Usage ```bash # Should be <1% idle, <5% when processing cards top ``` ### Response Time ```bash # Insert card, measure time to LED response # Should be <100ms (instant visual feedback) # Should post within <1 second ``` ### Verification Checklist - [ ] Memory usage <50 MB - [ ] CPU usage <5% during operation - [ ] LED feedback <100ms - [ ] API post <1 second - [ ] Startup time <2 seconds --- ## Phase 9: Stability Test ### 24-Hour Test ```bash # Run overnight python3 app_v3_simplified.py > app.log 2>&1 & # Next day check: wc -l ./data/log.txt # Should grow steadily ps aux | grep app_v3 # Still running? free -m # Memory stable? ``` ### Expected - [ ] App still running - [ ] No zombie processes - [ ] Memory stable (not growing) - [ ] WiFi monitor checks happened - [ ] Any card events logged properly ### 7-Day Test - [ ] No crashes - [ ] WiFi recovery worked multiple times - [ ] Monitored card events working - [ ] System still responsive --- ## Phase 10: Production Readiness ### Final Checklist - [ ] All tests passed - [ ] Old app.py backed up - [ ] New app.py ready for production - [ ] idmasa.txt configured correctly - [ ] Monitoring server receiving logs - [ ] Harting API receiving card events - [ ] WiFi recovery tested - [ ] Offline backup working - [ ] LED feedback working - [ ] Documentation updated ### Deployment Steps ```bash # 1. Stop old app (if running) # 2. Start new app python3 app_v3_simplified.py # 3. (Optional) Create systemd service for auto-start sudo nano /etc/systemd/system/rfid-reader.service # Content: [Unit] Description=RFID Card Reader After=network.target [Service] Type=simple User=pi WorkingDirectory=/home/pi/Desktop/prezenta_work ExecStart=/usr/bin/python3 /home/pi/Desktop/prezenta_work/app_v3_simplified.py Restart=on-failure RestartSec=10 [Install] WantedBy=multi-user.target # Then: sudo systemctl enable rfid-reader sudo systemctl start rfid-reader sudo systemctl status rfid-reader ``` --- ## Troubleshooting During Tests ### App crashes immediately ```bash # Check logs tail -50 ./data/log.txt # Common issues: # 1. rdm6300 not installed: pip3 install rdm6300 # 2. Serial device not found: ls /dev/tty* # 3. Permission denied: sudo usermod -a -G dialout $USER ``` ### Card inserted but no LED/log ```bash # 1. Check RFID reader connected: cat /dev/ttyS0 (present card, should see data) # 2. Check LED wired to GPIO 23 # 3. Check device permissions: ls -la /dev/ttyS0 # 4. Restart app ``` ### Server not receiving logs ```bash # 1. Check network: ping 10.76.140.17 # 2. Check server running: ps aux | grep monitoring # 3. Check firewall: sudo ufw status # 4. Check log for errors: grep ERROR ./data/log.txt ``` ### WiFi recovery not working ```bash # 1. Check WiFi can be blocked: sudo rfkill block wifi # 2. Check it was unblocked: sudo rfkill unblock wifi # 3. Check sudo permissions: sudo -l | grep rfkill # 4. Test manual: sudo rfkill block wifi && sleep 5 && sudo rfkill unblock wifi ``` --- ## Sign-Off Once all tests pass, app is ready for production: ``` Date Tested: _________________ Tester: _____________________ Status: [ ] PASS [ ] FAIL Notes: _______________________ ``` --- **Need Help?** Check: 1. Console output for immediate errors 2. `./data/log.txt` for detailed logs 3. `./data/tag.txt` for offline backup status 4. Monitoring server logs for received events