- Added cleanup_old_logs() function to app_v3_simplified.py - Deletes log.txt if older than 15 days at app startup - Sends notification to monitoring server when cleanup occurs - Archived all legacy modules and documentation to oldcode/ - Updated device_info.txt with correct IP (192.168.1.104) - All changes validated and tested
5.3 KiB
5.3 KiB
Quick Reference: What Changed
✅ What Stayed THE SAME
| Feature | Old v2.7 | New v3 | Status |
|---|---|---|---|
| Card detection | RFID reader on /dev/ttyS0 | RFID reader on /dev/ttyS0 | ✅ Same |
| Card insertion event | LED ON, POST to API | LED ON, POST to API | ✅ Same |
| Card removal event | LED OFF, POST to API | LED OFF, POST to API | ✅ Same |
| Offline backup | Save to tag.txt | Save to tag.txt | ✅ Same |
| WiFi recovery | Every 40 min check | Every 40 min check | ✅ Same |
| WiFi restart wait | 20 minutes | 20 minutes | ✅ Same |
| Monitoring server logs | Send status | Send status | ✅ Same |
| API endpoint | Harting URL | Harting URL | ✅ Same |
| Config card | 12886709 | 12886709 | ✅ Same |
| Device ID source | idmasa.txt | idmasa.txt | ✅ Same |
| GPIO LED | GPIO pin 23 | GPIO pin 23 | ✅ Same |
❌ What Changed
| Feature | Old v2.7 | New v3 | Reason |
|---|---|---|---|
| Code structure | ~2000 lines, 10+ modules | ~300 lines, 1 file | Simplicity |
| Batch logging | 5-second batches | Direct POST | Faster response |
| Message delay | ~5 seconds | <1 second | Better UX |
| Async posting | Async threads | Simple threads | Easier to debug |
| Flask server | Full HTTP server | None | Not needed for this use case |
| Auto-update | Full implementation | Removed | Can be re-added if needed |
| Command execution | Remote command server | None | Security risk, removed |
| Port 80 binding | Attempted | Removed | Not needed |
| Dependencies | Complex module loading | rdm6300 only | Fewer moving parts |
🚀 What's Better
1. Faster Card Detection
- Old: 5-second batch delay
- New: <1 second direct post
- Impact: Users get immediate LED feedback
2. Simpler Debugging
- Old: Check 10+ modules to find error
- New: All code in one file, easy to trace
- Impact: 10 minutes to debug vs 1 hour
3. Fewer Dependencies
- Old: rdm6300, requests, aiohttp, gpiozero, flask, ...
- New: rdm6300, requests, gpiozero
- Impact: Fewer things to break
4. More Reliable
- Old: Multiple threads, race conditions possible
- New: Simple sequential logic
- Impact: Fewer random failures
5. Less Memory
- Old: ~80-100 MB (batch logger threads, Flask server)
- New: ~30-40 MB
- Impact: Raspberry Pi doesn't struggle
📊 Code Comparison
Old Way: Sending Card Event
# rfid_module.py
queue_log_message(msg, hostname, device_ip)
# This goes to logger_batch_module.py
def queue_log_message(msg, hostname, device_ip):
batch_queue.put((msg, hostname, device_ip))
# Waits for 5 messages or 5 seconds...
# Then batch_logger_worker thread processes it
def batch_worker():
# Every 5 seconds or 10 items:
send_log_to_server(batch_data)
Result: 0-5 second delay
New Way: Sending Card Event
# app_v3_simplified.py (same file)
send_log_to_server(f"Card {card_id} inserted", hostname, device_ip, name)
def send_log_to_server(message, hostname, device_ip, name):
response = requests.post(server_url, json=log_data, timeout=5)
Result: Immediate post, <1 second
🔄 Migration Checklist
- Backup current app.py
- Test old version works (insert card, verify log)
- Stop old app
- Ensure idmasa.txt is set correctly
- Run new app:
python3 app_v3_simplified.py - Insert test card
- Verify LED feedback
- Check monitoring server logs
- Check Harting API received card event
- Simulate WiFi loss and recovery
- Check tag.txt backup works
- If all OK, delete old modules (optional)
📝 File Summary
| File | Purpose | Keep? |
|---|---|---|
| app_v3_simplified.py | NEW simplified version | ✅ Use this |
| app.py | OLD modular version | ⚠️ Backup, can delete after testing |
| rfid_module.py | OLD RFID handler | ⚠️ Not used in v3 |
| led_module.py | OLD LED control | ⚠️ Not used in v3 |
| logger_batch_module.py | OLD batch logger | ⚠️ Not used in v3 |
| connectivity_module.py | OLD connectivity | ⚠️ Not used in v3 |
| wifi_recovery_module.py | OLD WiFi recovery | ⚠️ Not used in v3 |
| config_settings.py | Configuration | ✅ Keep (just in case) |
| data/idmasa.txt | Device ID | ✅ Keep |
| data/tag.txt | Card backup | ✅ Keep |
| data/log.txt | Application logs | ✅ Keep |
🎯 Expected Behavior After Update
On Startup
✓ Logging configured: ./data/log.txt
✓ LED initialized on GPIO 23
Device: raspberry (192.168.1.50)
Name ID: mesa_1
✓ RFID reader started on /dev/ttyS0
✓ WiFi monitor started
✓ RFID Client operational - waiting for cards...
On Card Insert
[LED turns ON immediately]
🔴 CARD INSERTED - ID: 12345678
✓ Card event posted to API: 12345678
On Card Remove
[LED turns OFF immediately]
⚪ CARD REMOVED - ID: 12345678
✓ Card event posted to API: 12345678
On WiFi Loss (every 40 minutes)
✗ Connection lost - disabling WiFi for recovery
WiFi disabled, waiting 1200s for recovery...
[waits 20 minutes]
WiFi re-enabled
On WiFi Recovery with Backup Data
✓ Connection OK - checking for backed-up data
Posted backed-up data: https://....../12345678/1/2025-12-18&14:23:45
Posted backed-up data: https://....../12345678/0/2025-12-18&14:24:12
TL;DR: Same functionality, much simpler code, faster response, easier debugging.