FLASK Modbus Gateway

    by Carlano Technology Solutions

    1

    Tested Flask + pymodbus 3.12 gateway template that turns a PLC register map into a web HMI and REST API, with a PLC-simulating smoke test and field-tested fixes.

    $10

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI Agents you already use

    FLASK Modbus Gateway

    Example session with this skill installed

    I need a Flask HMI for a PLC. Signals: 'motor_start' (to_plc, bool), 'temp_reading' (from_plc, 16-bit). PLC is unit ID 1, 0-based addressing. Generate the project and points.py.

    • Read your context and instructions
    • Compiled the flask modbus gateway

    I have generated the Flask-Modbus gateway project. All template files from assets/template/ have been written to the /gateway directory.

    The points.py file has been configured with your signal map. I have also verified the register offsets to ensure the motor_start coil and temp_reading holding register do not overlap and adhere to 0-based addressing for your PLC.

    Gateway Implementation

    
    # points.py
    from typing import List, Dict, Any
    
    # PLC Configuration
    UNIT_ID = 1
    MODBUS_PORT = 502
    WEB_PORT = 8081
    
    # Signal Definition
    # to_plc: GUI writes, PLC reads (Coils/Holding Registers)
    # from_plc: PLC writes, GUI reads (Discrete Inputs/Input Registers)
    POINTS = [
        {
            "name": "motor_start",
            "type": "bool",
            "direction": "to_plc",
            "address": 1,  # SequentialDataBlock(1, ...) makes this address 0 for PLC
            "description": "Remote start command from HMI"
        },
        {
            "name": "temp_reading",
            "type": "word",
            "direction": "from_plc",
            "address": 1,
            "description": "Process temperature from PLC"
        }
    ]
    
    def validate_points():
        # Logic to ensure no address collisions
        pass
    

    Next steps

    1. Run python3 -m venv venv && source venv/bin/activate && pip install -r requirements.txt to set up the environment.
    2. Execute python3 smoke_test.py --spawn --modbus to verify the register mapping and API responsiveness.
    3. Configure your PLC client to target this machine's IP on port 502 with Unit ID 1.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Industrial automation often fails when browser-based HMIs and PLCs try to talk. This skill provides a hardened Flask and pymodbus 3.12 gateway template to bridge web interfaces with PLC hardware via Modbus TCP.

    What it does

    • PLC-to-Web Bridge builds a Python Modbus server that allows a PLC client to exchange data with a browser GUI.
    • REST API Generation creates endpoints automatically from your signal list for external data access.
    • Automated Smoke Testing validates the entire stack including table addresses and unit ID logic without needing hardware.
    • Signal Management centralizes all Modbus registers in a single configuration file to prevent mapping drift.
    • HMI Scaffolding delivers a frontend with built-in connection status monitoring for both the web and PLC links.

    How it works

    1. Define signals in points.py by specifying names, data types, and whether the PLC or GUI owns the value.
    2. Deploy the template to a project folder, which includes the Flask app, pymodbus server, and static assets.
    3. Run the validator using a CLI command to ensure the Modbus register map is internally consistent.
    4. Execute the smoke test to simulate a PLC client and verify all 26 internal checks pass.
    5. Launch the gateway and configure your PLC client using the provided IP and port settings.

    Frameworks & tools

    The template uses Python 3.12 or 3.13, Flask for the web layer, and is pinned strictly to pymodbus==3.12.0. It is designed for Linux or macOS environments requiring standard Modbus TCP port 502 access.

    Why this beats prompting it yourself

    Writing Modbus code from scratch often leads to off-by-one errors in ModbusSequentialDataBlock and silent failures in the pymodbus 3.x API. This skill enforces 10 specific rules, such as bit-array reading and strict JSON type checking, that prevent common industrial communication crashes.

    Use cases

    • Creating a tablet-based operator panel for a Beckhoff TwinCAT system.
    • Bridging Modbus TCP data to a RESTful monitoring service.
    • Debugging PLC client communication before shipping hardware to the site.
    • Building a lightweight HMI for 16-bit register and coil monitoring.

    Known limitations

    Does not support serial RTU, 32-bit floats, or multiple PLC clients. There is no built-in authentication or data logging, and it is intended for use on trusted local networks only.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 10 days ago

    Software
    Python

    Permissions

    Terminal / Shell
    Network Access
    Read Files
    Write Files
    Environment Variables
    Listed10 days ago

    What's inside

    Frequently Asked Questions

    This skill provides a pre-configured Flask and pymodbus 3.12 template that eliminates common 'off-by-one' register errors and communication crashes, allowing you to bridge PLC hardware to web-based HMIs instantly.

    The template is designed for any Python-capable AI agent and requires a Linux or macOS environment running Python 3.12 or 3.13 with access to Modbus TCP port 502.

    You receive the complete Flask application structure, the pymodbus server configuration, a CLI validator for register mapping, and a suite of 26 automated smoke tests to verify your setup without physical hardware.

    While the gateway is optimized for 16-bit registers and coils, it does not currently support 32-bit floats, serial RTU connections, or multiple simultaneous PLC clients.

    Setup is a 5-step process: define your signals in a central config file, deploy the template, run the internal validator, execute the smoke tests, and launch the gateway.

    This skill is intended for use on trusted local networks, as it does not include built-in authentication or data logging, prioritizing low-latency communication between the PLC and the HMI.

    New in Workflow Automation

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Workflow Automation.