Skip to content

innovaassolutions/MQTTtoMCP

Repository files navigation

SynExisAI Factory Monitoring Platform

Overview

SynExisAI is a full-stack, containerized platform for real-time factory machine monitoring and analytics. It collects machine data via MQTT, stores it in a time-series database, and provides a modern web interface for visualization and AI-powered data queries.


Project Vision & Value Proposition

The primary goal of this project is to empower users to interact with their industrial operating environments using natural language queries. This enables users in industries such as manufacturing, oil & gas, or data centers to ask questions like:

  • "What's the stock level of product A in store B?"
  • "What's my OEE for factory C over the past 4 months?"
  • "What's the current temperature of machine B on line 2?"
  • "What line has the capacity to run this new production order?"
  • "What's the status to complete on production order 256?"

To achieve this, the platform contextualizes and organizes real-time operational data (following ISA 95 naming conventions and Unified Namespace best practices) and connects it to a Large Language Model (LLM) using the Model Context Protocol (MCP). This allows users to gain actionable insights from live data through simple, conversational queries.

Benthos plays a key role in this architecture by enabling advanced, real-time data processing—such as running complex calculations (e.g., OEE) or transforming data streams—before the data is made available for natural language querying.


Architecture Overview

The system consists of five main components:

  1. MQTT Broker (Mosquitto): Receives real-time machine data from factory devices.
  2. Benthos Stream Processor: Subscribes to MQTT topics, performs real-time calculations (like OEE), and outputs processed data to the database and/or backend API.
  3. Backend API (FastAPI):
    • Subscribes to MQTT topics, ingests and processes messages (optionally from Benthos).
    • Stores data in TimescaleDB (a time-series extension of PostgreSQL).
    • Exposes REST endpoints for the frontend.
    • Integrates with OpenAI GPT for natural language data queries.
  4. Database (TimescaleDB): Stores all machine status, metrics, production, and order progress data.
  5. Frontend (React + Chakra UI):
    • Visualizes machine data in real time.
    • Allows users to ask questions about the data using natural language.

High-Level Architecture Diagram

+-------------------+        MQTT        +-------------------+        Stream        +-------------------+        SQL        +-------------------+
|                   |  <--------------  |                   |  <--------------->  |                   |  <------------->  |                   |
|  Factory Devices  |  (machine data)   |   Mosquitto MQTT  |     (processed     |      Benthos      |   (data ingest)   |   TimescaleDB     |
|                   |  -------------->  |     Broker        |      events)       |   Stream Proc.    |  -------------->  |   (Postgres)      |
+-------------------+                   +-------------------+                    +-------------------+                   +-------------------+
                                                                                          |
                                                                                          | (optional HTTP)
                                                                                          v
                                                                                 +-------------------+
                                                                                 |                   |
                                                                                 |   FastAPI App     |
                                                                                 |   (Python)        |
                                                                                 +-------------------+
                                                                                          |
                                                                                          v
                                                                                 +-------------------+
                                                                                 |                   |
                                                                                 |   React Frontend  |
                                                                                 |   (Chakra UI)     |
                                                                                 +-------------------+

Component Details

1. MQTT Broker (Mosquitto)

  • Receives real-time messages from factory equipment.
  • Publishes messages to topics that the backend and Benthos subscribe to.
  • Configured via mosquitto/config/mosquitto.conf.

2. Benthos Stream Processor

  • Subscribes to MQTT topics.
  • Performs real-time calculations and data transformations (e.g., OEE, aggregations, or other advanced analytics) to contextualize and enrich operational data.
  • Outputs processed data to the database and/or backend API, making it available for natural language queries via the LLM.
  • Configured via a YAML file.

3. Backend API (FastAPI)

  • Located in the app/ directory.
  • Subscribes to MQTT topics, parses messages, and writes to TimescaleDB.
  • Exposes REST endpoints for the frontend (e.g., /machine_status, /machine_metrics, /ask).
  • Integrates with OpenAI GPT for natural language queries.
  • Main entrypoint: app/main.py.

4. Database (TimescaleDB)

  • Stores all time-series data for machines, production, and orders.
  • Runs as a Docker service, data persisted in a Docker volume.

5. Frontend (React + Chakra UI)

  • Located in the frontend/ directory.
  • Modern, responsive UI for data visualization and AI-powered queries.
  • Main entrypoint: frontend/src/App.js.

Data Flow

  1. Factory devices send real-time data to the Mosquitto MQTT broker.
  2. Benthos subscribes to MQTT topics, processes data, and outputs results to the TimescaleDB and/or FastAPI backend.
  3. The FastAPI backend can also subscribe to MQTT topics, process incoming messages, and store them in TimescaleDB.
  4. The React frontend fetches data from the backend via REST endpoints and displays it to users.
  5. Users can ask questions in natural language; the backend uses OpenAI GPT to generate SQL queries and return results.

Example Natural Language Queries

  • "Show me the status of all machines in Area 1."
  • "What was the average temperature for Line 2 last week?"
  • "How many bad products were produced today?"

License

MIT


Setup Instructions

1. Clone the Repository

git clone [email protected]:yourusername/MQTTtoMCP.git
cd MQTTtoMCP

2. Install Python Dependencies

cd app
pip install -r requirements.txt

3. Run the MQTT Broker (Mosquitto)

If using Docker:

docker-compose up -d mosquitto

4. Start the Data Simulator

python simulate_factory.py

5. Run the Main Application

python main.py

6. Start the Frontend

cd ../frontend
npm install
npm start

Usage

  • The backend ingests and processes factory data.
  • The frontend displays metrics and allows for queries.
  • (Planned) Benthos can be added for advanced real-time calculations.

How to Contribute

  1. Fork the repo and create your branch: git checkout -b feature/your-feature
  2. Commit your changes: git commit -am 'Add some feature'
  3. Push to the branch: git push origin feature/your-feature
  4. Open a pull request

Troubleshooting

  • MQTT connection issues: Ensure Mosquitto is running and accessible.
  • Database errors: Check your database service and credentials.
  • Frontend not loading: Make sure you've run npm install and npm start in the frontend/ directory.

This project is a work in progress. Contributions and suggestions are welcome!

Unified Namespace (UNS) Management System

Overview

This project now supports a robust, multi-UNS (Unified Namespace) management system. You can manage multiple namespaces, add/remove elements at any level, and safely collaborate with others. All changes are reflected in both the backend (FastAPI) and the frontend UI.


API Endpoints

  • List all UNSs
    • GET /api/unified_namespaces
  • Create a new UNS
    • POST /api/unified_namespaces (body: { "name": "my_uns", "data": {} })
  • Get a specific UNS
    • GET /api/unified_namespace/{name}
  • Add element to a UNS
    • POST /api/unified_namespace/{name}/add (body: { "path": ["Enterprise", "Site"], "key": "Area", "value": {} })
  • Remove element from a UNS
    • POST /api/unified_namespace/{name}/remove (body: { "path": ["Enterprise", "Site", "Area"] })
  • Update/replace a UNS
    • PUT /api/unified_namespace/{name} (body: full JSON structure)

Frontend Usage

  • UNS Selector: Use the dropdown at the top to select which namespace to view or edit.
  • Create New UNS: Enter a name and click "Create" to start a new namespace.
  • Add/Remove Elements: Use the + icon to add, and the trash icon to remove, at any level. When adding, an inline input appears for the new name.
  • All changes are saved to the backend and reflected in the UI.

Multi-UNS Workflow

  • You can manage multiple namespaces (e.g., for different enterprises, projects, or environments).
  • Each UNS is stored as a separate JSON file in app/unified_namespaces/.
  • Switch between namespaces using the selector; changes are isolated to the selected UNS.

Example JSON Structure

{
  "Demo Enterprise Inc.": {
    "Alberta Subsidiary": {
      "Assembly Plant": {
        "Cell Tower Assembly": {
          "CNC Welding": {
            "CNCWelderR25": {}
          }
        }
      }
    }
  }
}

Screenshots & GIFs

Example: UNS Editor Screenshot UNS Editor Screenshot


Troubleshooting

  • If you see errors about missing endpoints, ensure your FastAPI backend is running and up to date.
  • If the UI does not update after changes, try refreshing the page.
  • For CORS or network errors, check your backend and frontend server addresses/ports.
  • If you see extra "+" icons, update to the latest code (see NamespaceLevel logic).

Migration Notes

  • Existing unified_namespace.json files should be moved to app/unified_namespaces/ and renamed (e.g., demo_enterprise.json).
  • The new system supports multiple namespaces; you can create as many as needed from the UI.

For more details, see the project file: app/UNS_management_project.md

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published