Skip to content

aTrapDeer/rf-controls-simulation

Repository files navigation

RF Controls Mock System

A comprehensive mock implementation of RF Controls RFID tracking system for development and demonstration purposes. This system simulates real-time RFID tag reads, provides REST APIs for metadata, and includes a React-based dashboard for visualization.

Features

Backend (Python FastAPI)

  • Real-time STOMP-over-WebSocket simulation - Mimics RF Controls' tag event streams
  • REST API endpoints - Zones, products, antennas, and tag history
  • Mock data generation - Continuous tag reads with realistic timestamps and positions
  • Cross-origin support - CORS enabled for frontend integration

Frontend (React)

  • Real-time visualization - Live map showing tag positions across zones
  • Interactive map - React Leaflet with zone overlays and tag markers
  • Data tables - TanStack Table for live tag event history
  • Connection monitoring - Real-time status of WebSocket connection
  • Responsive design - Works on desktop and mobile devices

Simulated Data

  • 5 Zones: Electronics Aisle, Clothing Section, Home & Garden, Storage Area, Point of Sale
  • 2 Antennas: ant1, ant2
  • 8 Products: Various categories (electronics, clothing, home) with EPC-to-SKU mappings
  • Generated Events: Realistic tag reads with coordinates, signal strength, timestamps

Quick Start

Prerequisites

  • Python 3.8+
  • Node.js 16+
  • npm or yarn

Backend Setup

# Navigate to backend directory
cd backend

# Create virtual environment
python -m venv venv

# Activate virtual environment
# Windows:
venv\Scripts\activate
# macOS/Linux:
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Start the server
python main.py

The backend will start on http://localhost:8000

Frontend Setup

# Navigate to frontend directory
cd frontend

# Install dependencies
npm install

# Start the development server
npm start

The frontend will start on http://localhost:3000

API Endpoints

REST Endpoints

Endpoint Method Description
/ GET API status and version
/api/zones GET List all zones with boundaries
/api/products GET List all products with EPC mappings
/api/antennas GET List all available antennas
/api/tags/history GET Historical tag read data

WebSocket Endpoint

Endpoint Protocol Description
/ws/tags WebSocket/STOMP Real-time tag event stream

Data Formats

Tag Event (WebSocket)

{
  "epc": "EPC0001",
  "antennaId": "ant1",
  "zoneId": "zone1",
  "regionId": "zone1", 
  "timestamp": 1703123456789,
  "x": 5.2,
  "y": 2.8,
  "rssi": -45,
  "messageId": "uuid-string"
}

Zone Definition

{
  "id": "zone1",
  "name": "Electronics Aisle",
  "boundary": [[0, 0], [10, 0], [10, 5], [0, 5]]
}

Product Definition

{
  "epc": "EPC0001",
  "sku": "SKU123", 
  "category": "electronics",
  "name": "Bluetooth Speaker"
}

Architecture

┌─────────────────┐    WebSocket/STOMP    ┌─────────────────┐
│   React App     │◄──────────────────────│  FastAPI Server │
│                 │                       │                 │
│ - Map View      │      REST API         │ - Mock Data Gen │
│ - Tag Table     │◄──────────────────────│ - STOMP Frames  │
│ - Status Panel  │                       │ - REST Routes   │
└─────────────────┘                       └─────────────────┘

Development

Adding New Zones

Edit the MOCK_ZONES array in backend/main.py:

MOCK_ZONES = [
    {"id": "zone6", "name": "New Zone", "boundary": [[20, 0], [30, 0], [30, 10], [20, 10]]},
    # ... existing zones
]

Adding New Products

Edit the MOCK_PRODUCTS array in backend/main.py:

MOCK_PRODUCTS = [
    {"epc": "EPC0009", "sku": "SKU100", "category": "books", "name": "Programming Guide"},
    # ... existing products
]

Customizing Tag Generation

Modify the generate_mock_tag_read() function in backend/main.py to change:

  • Generation frequency
  • Position algorithms
  • Signal strength simulation
  • Tag movement patterns

Troubleshooting

Backend Issues

  • Port 8000 in use: Change port in main.py: uvicorn.run(app, port=8001)
  • CORS errors: Check CORS middleware configuration in main.py
  • WebSocket connection fails: Verify firewall settings and port accessibility

Frontend Issues

  • Map not loading: Check Leaflet CSS import in public/index.html
  • WebSocket connection fails: Verify backend is running on correct port
  • Table not updating: Check browser console for JavaScript errors

Common Issues

  • No tag events: Backend generates events every 1-3 seconds automatically
  • Map positioning issues: Zone boundaries use simple coordinate system (not lat/lng)
  • Performance: Large tag history (100+ items) may slow table rendering

Production Considerations

This is a mock system for development/demo purposes. For production:

  1. Authentication: Add API authentication (JWT, Basic Auth, etc.)
  2. Database: Replace in-memory data with persistent storage
  3. Rate Limiting: Implement API rate limiting
  4. Monitoring: Add logging, metrics, and health checks
  5. Security: Enable HTTPS/WSS, validate inputs, sanitize data
  6. Scalability: Add database connection pooling, caching

Based On RF Controls Documentation

This implementation follows patterns from:

  • RF Controls wms-demo-app (Spring Boot + Angular reference)
  • RF Controls rfcos-websocket-py (Python WebSocket client)
  • RFC-OS API documentation and samples

The mock system provides realistic simulations suitable for:

  • Development against RF Controls APIs
  • Customer demonstrations
  • Integration testing
  • Training and education

License

This project is for educational and development purposes. RF Controls is a trademark of RF Controls, LLC.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published