This system provides a complete IoT device simulation environment with a central management dashboard. The project consists of three main components:
- MQTT Broker (palvelin): A Node.js-based MQTT message broker that routes messages between simulated devices
- IoT Device Simulator (laite): A Go-based simulator that creates virtual IoT devices with unique network identities
- Admin Dashboard: A web-based management interface with user authentication and simulator registration
REST API
┌───────────────────────────┐ ┌─────────────────┐
│ IoT Device Simulator │ │ MongoDB │
│ (laite) │ │ Database │
│ ┌──────────────────┐ │ └─────────────────┘
│ │ Simulated Device │ │ ▲
│ │ (coffee1) │ │ │
│ └──────┬───────────┘ │ ▼
│ │ │ ┌─────────────────┐
│ ┌──────┴───────────┐ │ │ │
│ │ Simulated Device │ │ │ Admin Dashboard │
│ │ (coffee2) │ │◄────────►│ (Web Server) │
│ └──────┬───────────┘ │ │ │
│ │ │ └─────────────────┘
│ ┌──────┴───────────┐ │ ▲
│ │ Simulated Device │ │ │
│ │ (doorLock1) │ │ ▼
│ └──────┬───────────┘ │ ┌─────────────────┐
│ │ │ │ Admin Dashboard │
└──────────┼────────────────┘ │ (Frontend) │
│ └─────────────────┘
▼
┌─────────────────┐
│ │
│ MQTT Broker │
│ (palvelin) │
│ │
└─────────────────┘
- Protocol: REST API
- Direction: Bidirectional
- Purpose:
- Device registration and control
- Simulator registration and management
- Configuration updates
- Status reporting
- Protocol: MQTT
- Direction: Bidirectional
- Purpose:
- Devices publish messages to topics
- Devices subscribe to receive messages on topics
- Simulates real IoT device communication patterns
- Protocol: MongoDB driver
- Direction: Bidirectional
- Purpose:
- User account storage
- Simulator registration records
- Room and organization data
- Device state persistence
The MQTT broker does NOT act as an intermediary between the simulator and dashboard. Instead, each simulated device connects directly to the MQTT broker using its own virtual network identity, just as real IoT devices would in a production environment.
Located in the palvelin/ directory, this Node.js application:
- Uses the Aedes MQTT broker library
- Routes messages between simulated devices
- Listens on port 1883 for MQTT connections
- Sends welcome messages to newly connected devices
Key Files:
main.js: MQTT broker implementationpackage.json: Node.js dependencies
Starting the Broker:
cd palvelin
npm startLocated in the laite/ directory, this Go application:
- Creates multiple simulated devices within a single process
- Uses macvlan to give each device its own virtual network interface and IP address
- Simulates various IoT device types (coffee machines, door locks, temperature sensors)
- Provides a REST API (port 8080) for device/simulator control and configuration
- Uses UUID-based identification for reliable simulator tracking
Key Files:
main.go: Main application entry pointdevice.go: Device simulation logicapi.go: REST API implementationconfig.go: Configuration handlingregistration.go: Server registration processdevices.toml: Device configuration (gitignored)devices.toml.template: Template configuration
Virtual Network: Each simulated device appears on the network as a separate entity with its own IP address through macvlan interfaces, creating a realistic simulation where multiple devices connect to the broker from different network locations.
Configuration:
The devices.toml file defines:
- Simulator UUID
- Network interface to use for virtual devices
- Server URL for registration
- Registration token
- Device definitions (ID, action type, broker address)
Starting the Simulator:
cd laite
sudo go run .- Clone the repository:
git clone cd adminDashboard - Install dependencies:
npm i
- Run frontend and backend:
Note: The MongoDB must be running for the frontend and backend to function properly.
npm run dev
Located in the server/ directory, this Node.js/Express application:
- Provides user authentication and management
- Manages simulator registration
- Offers a REST API for device control
- Stores persistent data in MongoDB
- Provides a web interface for device/simulator management
Key Files:
server.js: Main server implementationroutes/: API endpointsmodels/: MongoDB schema definitionsservices/: Business logic servicesmiddleware/: Express middleware
Data Models:
User: Authentication and ownershipSimulator: Registered simulation instancesDevice: IoT device recordsRoom: Logical grouping of simulators
Starting the Server:
cd server
npm i
npm startLocated in the frontend/ directory, this React-based application:
- Provides a modern, responsive user interface
- Visualizes simulator and device states
- Enables drag-and-drop organization of simulators into rooms
- Offers real-time device control and monitoring
- Includes user authentication and profile management
Technology Stack:
- React for component-based UI
- React Router for navigation
- Tailwind CSS for styling
- shadcn/ui component library for UI elements
- React Beautiful DND for drag-and-drop functionality
Key Features:
-
User Authentication:
- Secure login for users to access the dashboard.
-
Dashboard View:
- Visual representation of rooms and simulators.
- Drag-and-drop interface for organizing simulators.
- Real-time status updates.
-
Simulator Management:
- Add new simulators by generating registration tokens.
- Configure simulator settings.
- Monitor simulator status (online/offline).
-
Device Control and Management:
- Turn devices on/off.
- View device details and status.
- Add new devices to a simulator, either individually or in bulk.
- Remove devices from simulators.
Viewing and managing devices within a simulator. -
Room Organization:
- Group simulators into logical rooms (e.g., "Office Left Wing").
- Customize room settings.
- Organize simulators by purpose or location within the dashboard. (This is also visible in the Dashboard View image above)
Key Components:
SimulatorCard: Displays individual simulator with its devicesRoomGroup: Organizes simulators into roomsDeviceList: Shows devices associated with a simulatorSidebar: Provides navigation and quick simulator accessDashboard: Main layout for viewing and organizing simulators
Starting the Frontend:
cd frontend
npm i
npm run devBuild for Production:
cd frontend
npm run build/api/heartbeat: Get all simulators and rooms/api/rooms/add-instance: Add simulator to room/api/rooms/remove-instance: Remove simulator from room/api/instances/update-title: Update simulator title/api/simulators/token: Generate registration token/api/simulators/register: Register simulator with token
/api/devices: Get all device states/api/device/:id: Get specific device/api/device/:id/:action: Control device (on/off)/api/device/:id: Create/configure device/api/device/:id/delete: Delete device/api/configuration: Get/update configuration/api/reboot: Reboot simulator
/auth/login: Authenticate user/auth/register: Register new user/auth/profile: Get user profile
The system uses a token-based authentication system:
- User Authentication: JWT tokens for dashboard access
- Simulator Registration: One-time registration tokens
- Device Control: Implicit permission through simulator ownership
- The simulator authenticates only once during registration
- Token is required only for the initial connection
- Communication after registration does not use authentication
- The server identifies simulators by their UUID, not URL
- UUID persistence allows simulators to change networks and maintain identity
- Database can be setup with the following Docker functionality
This server uses Docker to provide a consistent MongoDB environment for development.
Steps to utilize: 1. Install Docker Desktop (and MongoDB if using Linux or Mac) 2. Start the MongoDB container by running following in project root: docker-compose up -d
Useful Commands: Stop containers: docker-compose down View logs: docker-compose logs -f mongodb Reset database: docker-compose down -v (removes volumes)
When deploying to production:
-
Network Configuration:
- Ensure the physical interface in
devices.tomlis correctly set - Configure network to allow MQTT traffic on port 1883
- Allow HTTP traffic for REST APIs
- Ensure the physical interface in
-
Security Practices:
- Use HTTPS for all REST API communications
- Use environment variables for sensitive configuration
- Consider enabling MQTT security features
-
MongoDB Setup:
- Configure a production MongoDB instance
- Set up proper authentication and network security
- Implement regular database backups





