Skip to content

This project demonstrates a complete workflow for real-time machine data monitoring, from a native C++ engine (mock or real, via DLL) to a .NET backend (with SignalR and EF Core) to a modern React frontend. It is designed for learning, prototyping, and as a reference for real-world industrial or IoT dashboards.

Notifications You must be signed in to change notification settings

arnobt78/Embedded-Motor-Engine-Speed-Temperature-Measurement--CPP-DotNet-React

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Embedded Motor Engine Speed Temperature Measurement Dashboard C++, .Net, React Project

Screenshot 2025-07-25 at 23 11 13 Screenshot 2025-07-25 at 23 11 36 Screenshot 2025-07-25 at 23 11 49 Screenshot 2025-07-25 at 23 13 54


Project Overview (motor-dashboard, motor-speed-backend, motor-speed-frontend)

This project demonstrates a complete workflow for real-time machine data monitoring, from a native C++ engine (mock or real, via DLL) to a .NET backend (with SignalR and EF Core) to a modern React frontend. It is designed for learning, prototyping, and as a reference for real-world industrial or IoT dashboards.


Features

  • Real-time motor readings with SignalR
  • Animated 3D gear and shadow
  • Grouped reading list by date with color-coded cards
  • Notification sidebar for highest/lowest temp and RPM
  • Real-time charts with Recharts
  • Unit & integration tests (backend: xUnit, frontend: React Testing Library)
  • Nginx config for routing, HTTPS/SSL
  • Dockerized backend, frontend, and Nginx
  • Responsive, modern UI

Table of Contents

  1. Project Overview
  2. Architecture & Technology Stack
  3. Project Structure
  4. How It Works: C++ β†’ C# β†’ React
  5. Backend: .NET, C++ DLL, and Real-World Integration
  6. Frontend: React, Vite, Tailwind, shadcn/ui
  7. Real-Time Communication with SignalR
  8. Database & Persistence (EF Core)
  9. API Endpoints & Data Flow
  10. Running the Project
  11. Testing
  12. Docker Usage
  13. Features & Functionality
  14. Extending & Reusing Components
  15. Real-World Practical Notes
  16. Keywords
  17. Conclusion

Architecture & Technology Stack

  • C++ (EngineMock): Native library simulating motor data (speed, temperature).
  • .NET 8+ (ASP.NET Core): Backend API, SignalR hub, P/Invoke to C++ DLL, EF Core for persistence.
  • React (Vite): Frontend UI, real-time charts, notifications, settings, CSV export.
  • SignalR: Real-time WebSocket-style updates from backend to frontend.
  • Entity Framework Core: Database ORM for storing readings.
  • Tailwind CSS + shadcn/ui: Modern, responsive, and accessible UI.
  • Docker & Nginx: Containerized deployment, HTTPS, and routing.

Project Structure

motor-dashboard/
β”œβ”€β”€ motor-speed-backend/
β”‚   β”œβ”€β”€ EngineMock/           # C++ mock engine (DLL/SO/DYLIB)
β”‚   β”œβ”€β”€ Server/
β”‚   β”‚   β”œβ”€β”€ MotorServer/      # ASP.NET Core backend
β”‚   β”‚   β”‚   β”œβ”€β”€ Controllers/  # API endpoints
β”‚   β”‚   β”‚   β”œβ”€β”€ Data/         # EF Core DbContext
β”‚   β”‚   β”‚   β”œβ”€β”€ Hubs/         # SignalR hub
β”‚   β”‚   β”‚   β”œβ”€β”€ Models/       # Data models
β”‚   β”‚   β”‚   β”œβ”€β”€ Services/     # EngineService (P/Invoke)
β”‚   β”‚   β”‚   β”œβ”€β”€ Migrations/   # EF Core migrations
β”‚   β”‚   β”‚   β”œβ”€β”€ ...           # Config, Program.cs, etc.
β”‚   β”‚   └── Tests/            # Backend tests
β”‚   └── Tests/                # Integration/unit tests
β”œβ”€β”€ motor-speed-frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/       # React UI components
β”‚   β”‚   β”œβ”€β”€ lib/              # Utilities (date, etc.)
β”‚   β”‚   β”œβ”€β”€ services/         # API/auth helpers
β”‚   β”‚   β”œβ”€β”€ types/            # TypeScript types
β”‚   β”‚   └── ...               # App, main, etc.
β”‚   β”œβ”€β”€ public/               # Static assets
β”‚   β”œβ”€β”€ ...                   # Config, Dockerfile, etc.
β”œβ”€β”€ nginx.conf                # Nginx config for HTTPS/routing
└── README.md                 # This file

How It Works: C++ β†’ C# β†’ React

  1. C++ EngineMock:

    • Simulates a real motor controller, exporting GetMotorSpeed() and GetMotorTemperature() via a shared library (DLL/SO/DYLIB).

    • In a real project, this could be replaced with a library that reads from CAN, USB, EtherCAT, or other industrial protocols.

    • Example:

      extern "C" {
          int GetMotorSpeed();
          int GetMotorTemperature();
      }
  2. .NET Backend:

    • Uses P/Invoke ([DllImport]) to call the C++ functions directly from C#.

    • EngineService samples the engine, stores readings in SQLite (via EF Core), and broadcasts new readings to all clients using SignalR.

    • API endpoints allow fetching all readings, sampling new data, and health checks.

    • Example:

      [DllImport(LIB_NAME)]
      public static extern int GetMotorSpeed();
  3. React Frontend:

    • Connects to the backend SignalR hub for real-time updates.
    • Fetches historical data via REST API (using axios).
    • Displays readings in charts, lists, and notifications, with CSV export and settings.

Backend: .NET, C++ DLL, and Real-World Integration

C++ Mock Engine

  • EngineMock/motor_engine.cpp and motor_engine.hpp define and export mock functions.
  • Compiled as a shared library (libmotor_engine.dylib, .so, or .dll).

P/Invoke in C#

  • EngineService.cs uses [DllImport] to call C++ functions.

  • Example:

    [DllImport(LIB_NAME)]
    public static extern int GetMotorSpeed();

Real-World Integration

  • Replace EngineMock with your real C++/C library for CAN/USB/EtherCAT.
  • Use P/Invoke for direct calls, or C++/CLI wrappers for more complex interop.
  • For advanced scenarios, use a message queue, gRPC, or a microservice for hardware abstraction.

Entity Framework Core

  • AppDbContext manages the MotorReadings table.
  • Migrations and schema are managed via EF Core CLI.

SignalR

  • MotorHub broadcasts new readings to all connected clients in real time.

Frontend: React, Vite, Tailwind, shadcn/ui

  • Vite for fast dev/build.
  • React for UI, with functional components and hooks.
  • Tailwind CSS and shadcn/ui for styling and accessibility.
  • Recharts for real-time data visualization.
  • SettingsModal, NotificationSidebar, AnimatedMotor, etc., are reusable components.

Real-Time Communication with SignalR

  • Backend pushes new readings instantly to all clients via SignalR.
  • Frontend uses @microsoft/signalr to subscribe and update UI in real time.

Database & Persistence (EF Core)

  • All readings are stored in SQLite by default (can be swapped for SQL Server, PostgreSQL, etc.).
  • Migrations ensure schema is up to date.

API Endpoints & Data Flow

  • GET /api/motor β€” fetch latest readings
  • GET /api/motor/sample β€” trigger a new reading (from C++ engine)
  • GET /health β€” health check
  • GET /swagger/index.html β€” OpenAPI docs

Frontend uses axios to call these endpoints and SignalR for real-time updates.


Running the Project

Prerequisites

  • Docker & Docker Compose
  • Node.js (for frontend dev)
  • .NET 8+ SDK (for backend dev)
  • C++ compiler (for building EngineMock)

Local Development

docker-compose up --build

Or run backend and frontend separately:

Backend:

cd motor-speed-backend/Server/MotorServer
dotnet run

Frontend:

cd motor-speed-frontend
npm install
npm run dev

Testing

Backend (xUnit)

  • Unit and integration tests are in motor-speed-backend/Tests/ and motor-speed-backend/Server/Tests/.

  • To run all backend tests:

    dotnet test motor-speed-backend/Tests/
    dotnet test motor-speed-backend/Server/Tests/
  • Example test (C#):

    [Fact]
    public async Task Sample_ShouldReturnValidReading() {
        var svc = new EngineService(...);
        var reading = await svc.Sample();
        Assert.InRange(reading.Speed, 800, 3000);
    }

Frontend (React Testing Library)

  • Tests are in motor-speed-frontend/src/components/__tests__/.

  • To run all frontend tests:

    cd motor-speed-frontend
    npm test
  • Example test (React):

    import { render } from '@testing-library/react';
    import AnimatedMotor from '../AnimatedMotor';
    test('renders without crashing', () => {
      render(<AnimatedMotor rpm={1200} />);
    });

Docker Usage

Overview

  • Both backend and frontend have their own Dockerfile for containerization.
  • The project uses docker-compose.yml to orchestrate backend, frontend, and Nginx for HTTPS/routing.

Building and Running with Docker Compose

docker-compose up --build

This will:

  • Build the C++ engine, .NET backend, and React frontend
  • Start all services and Nginx for HTTPS
  • Serve the dashboard at https://localhost/ (or as configured)

Backend Dockerfile Example

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
COPY . .
RUN dotnet build
ENTRYPOINT ["dotnet", "MotorServer.dll"]

Frontend Dockerfile Example

FROM node:20-alpine AS build
WORKDIR /app
COPY . .
RUN npm install && npm run build
EXPOSE 5173
CMD ["npm", "run", "preview"]

Nginx

  • Handles HTTPS, static file serving, and reverse proxy to backend/frontend.
  • Self-signed certs for dev in /etc/nginx/certs/ (see nginx.conf)
  • For production, replace with real certs

Features & Functionality

  • Real-time motor readings (SignalR)
  • Animated 3D gear and shadow
  • Grouped reading list by date, color-coded
  • Notification sidebar for highest/lowest temp and RPM
  • Real-time charts (Recharts)
  • CSV export
  • Health check endpoint
  • OpenAPI/Swagger docs
  • Dark mode toggle
  • Settings modal (max readings, dark mode)
  • Responsive, modern UI

Extending & Reusing Components

  • All React components are modular and reusable.
  • Backend services and controllers are easily extensible for new endpoints or hardware.
  • To use in another project, copy the relevant component/service and update types as needed.

Real-World Practical Notes

  • Hardware Integration: Replace the mock C++ engine with your real hardware library. Use P/Invoke or C++/CLI as needed.
  • Protocols: For CAN/USB/EtherCAT, use a vendor SDK or open-source stack, and expose a C API for .NET interop.
  • Security: Add authentication/authorization for production.
  • Scalability: Swap SQLite for a production DB, use Redis for SignalR backplane if scaling out.

Keywords

C++, C#, .NET, ASP.NET Core, React, Vite, SignalR, WebSocket, EF Core, SQLite, Docker, Tailwind CSS, shadcn/ui, CAN, USB, EtherCAT, P/Invoke, C++/CLI, real-time, dashboard, IoT, industrial, chart, notification, CSV, OpenAPI, Swagger, modular, reusable, microservice, hardware integration


Conclusion

This project is a practical, modern, and extensible template for real-time machine dashboards, bridging native C++ code, .NET backend, and a beautiful React frontend. Use it for learning, prototyping, or as a foundation for your next industrial or IoT project.


Happy coding! πŸš€
Thank you!


About

This project demonstrates a complete workflow for real-time machine data monitoring, from a native C++ engine (mock or real, via DLL) to a .NET backend (with SignalR and EF Core) to a modern React frontend. It is designed for learning, prototyping, and as a reference for real-world industrial or IoT dashboards.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published