Files
prezenta_work/oldcode/QUICKSTART.md

6.8 KiB

Quick Start Guide - Modular App

🚀 Getting Started

1. Run the New Modular App

cd /srv/prezenta_work
python3 app_modular.py

2. Expected Output

======================================================================
PREZENTA WORK - Attendance Tracking System v2.7 (Modular)
======================================================================

[1/5] Checking dependencies...
[2/5] Verifying dependencies...
[3/5] Performing system initialization...
[4/5] Retrieving device information...
Final result - Hostname: rpi-prezenta-1, Device IP: 192.168.1.50
[5/5] Setting up logging...

======================================================================
Initialization complete!
======================================================================

Registering API routes...
✓ API routes registered

======================================================================
Starting Flask server...
======================================================================

 * Serving Flask app 'Flask'
 * Running on http://0.0.0.0:80

3. Test the API

# In another terminal

# Get device status
curl http://localhost/status

# Execute a command
curl -X POST http://localhost/execute_command \
  -H "Content-Type: application/json" \
  -d '{"command": "uptime"}'

# Check for updates
curl -X POST http://localhost/auto_update

🔧 Configuration

Method 1: Environment Variables

export MONITORING_SERVER_HOST=192.168.1.100
export FLASK_PORT=8080
python3 app_modular.py

Method 2: .env File

Create .env in /srv/prezenta_work/:

MONITORING_SERVER_HOST=192.168.1.100
AUTO_UPDATE_SERVER_PASSWORD=your_password
FLASK_PORT=80

Then run:

python3 app_modular.py

Method 3: Edit config_settings.py

Directly modify /srv/prezenta_work/config_settings.py


📁 Important Files

File Purpose
config_settings.py All configuration settings
./data/idmasa.txt Table/room name (used in all logs)
./data/device_info.txt Cached device hostname & IP
./data/log.txt Application logs
.env Environment-specific secrets

🌐 API Endpoints

GET /status

Returns device status information.

Response:

{
  "hostname": "rpi-prezenta-1",
  "device_ip": "192.168.1.50",
  "nume_masa": "TABLE_05",
  "timestamp": "2025-12-18 14:30:45",
  "uptime": " 14:30:45 up 45 days, 23:15, 1 user",
  "disk_usage": "Filesystem...",
  "memory_usage": "Mem: 3888 2156 1732"
}

POST /execute_command

Execute allowed system commands.

Request:

{
  "command": "uptime"
}

Response:

{
  "status": "success",
  "message": "Command executed successfully",
  "output": " 14:30:45 up 45 days, 23:15, 1 user, load average: 0.12, 0.15, 0.10"
}

Allowed Commands:

  • sudo apt update
  • sudo apt upgrade -y
  • sudo apt autoremove -y
  • sudo apt autoclean
  • sudo reboot
  • sudo shutdown -h now
  • df -h
  • free -m
  • uptime
  • systemctl status
  • sudo systemctl restart networking
  • sudo systemctl restart ssh

POST /auto_update

Trigger automatic application update.

Response (No Update):

{
  "status": "no_update_needed",
  "current_version": 2.7,
  "remote_version": 2.7,
  "message": "Application is already up to date"
}

Response (Update Available):

{
  "status": "success",
  "message": "Updated from version 2.7 to 2.8. Device restarting...",
  "old_version": 2.7,
  "new_version": 2.8,
  "restart_scheduled": true
}

📊 Logging

Local Logs

  • Location: ./data/log.txt
  • Format: YYYY-MM-DD HH:MM:SS - LEVEL - message
  • Retention: 10 days (auto-rotated)

Remote Logs

  • Endpoint: http://rpi-ansible:80/logs
  • Format: JSON with hostname, IP, table name, and message
  • Sent automatically when events occur

🔍 Troubleshooting

Port 80 Permission Denied

# Solution: Run with sudo or set port capability
sudo setcap cap_net_bind_service=ep $(which python3)
python3 app_modular.py

Cannot Connect to Monitoring Server

# Check configuration
cat config_settings.py | grep MONITORING

# Test connectivity
ping rpi-ansible

RFID Reader Not Detected

# Check if user is in dialout group
sudo usermod -a -G dialout $USER
sudo reboot

# Verify device exists
ls -l /dev/ttyS0 /dev/ttyAMA0 /dev/ttyUSB0

Logs Not Sending to Server

# Check network connectivity
ping 8.8.8.8

# Check log file
tail -f ./data/log.txt

# Verify server is running on expected port
curl http://rpi-ansible:80/logs

📝 Configuration Examples

Example 1: Custom Server Address

export MONITORING_SERVER_HOST=192.168.1.100
export FLASK_PORT=8080
python3 app_modular.py

Example 2: Different Update Server

export AUTO_UPDATE_SERVER_HOST=update-server.local
export AUTO_UPDATE_SERVER_USER=admin
export AUTO_UPDATE_SERVER_PASSWORD=secure_pass
python3 app_modular.py

Example 3: Using .env File

cat > .env << EOF
MONITORING_SERVER_HOST=192.168.1.100
AUTO_UPDATE_SERVER_PASSWORD=Initial01!
CONNECTIVITY_CHECK_HOST=10.76.140.17
FLASK_PORT=80
EOF

python3 app_modular.py

🔄 Module Dependencies

When running app_modular.py, the startup sequence is:

  1. config_settings.py - Load configuration
  2. dependencies_module.py - Check/install packages
  3. system_init_module.py - Initialize system
  4. device_module.py - Get device info
  5. logger_module.py - Setup logging
  6. connectivity_module.py - Start background monitor
  7. rfid_module.py - Initialize RFID reader
  8. api_routes_module.py - Register Flask routes
  9. Flask - Start HTTP server

Each step must complete (with possible warnings) before proceeding.


Verification Checklist

  • App starts without errors
  • Can reach /status endpoint
  • Can execute /execute_command endpoint
  • Logs appear in ./data/log.txt
  • Logs send to monitoring server
  • Configuration changes via environment variables work
  • RFID reader initializes (or graceful failure)
  • Connectivity monitor runs in background

📞 Support

Issue Check
Port conflict lsof -i :80
Permission denied whoami, check sudoers
Missing packages `pip list
Network issues ping 8.8.8.8
Server not responding curl http://server:port/logs


Ready to go! 🚀

Run: python3 app_modular.py