Skip to main content

Modbus2Websocket

Modbus2Websocket (further, M2W) is an python-based application that routes data between Modbus TCP protocol and Websockets.

m2w logo

Purpose

The main goal of M2W router is to deliver data between industrial system and web application. Modbus TCP - industrial protocol, used to exchange information between industrial devices and HMIs. Usually, to visualize data engineers have to use heavy and expensive SCADA or HMI. On other hand web technologies provide easy and powerful tools for data visualization in your own web browser, without any thick client. That is why M2W was created in first place - to make simple webHMI server that works with Industrial systems.

Components

  • async Modbus TCP server async_modbus_server.py
  • async Modbus TCP client async_modbus_client.py
  • async Websocket server async_websocket_server.py
  • Router router.py

What it supports

  • Reading Input Registers, Digital Inputs, Coils and Holding Registers$
  • Sending to the websocket client.

Future development:

  • Async Modbus Server
  • Async Modbus Client
  • Async Websocket Server
  • Router
  • Html example page
  • Database connection

Installation steps

Installation

Module installation

Modbus2websocket library installs with pip:

pip install modbus2websocket

Details

Before creating you application you have to specify following:

  • Websocket server IP, for example, 192.168.220.10
  • Websocket port, by default, it is 8888
  • Modbus/TCP server's IP, for example, 192.168.220.5

Modbus server

If you don't have running Modbus/TCP server, you can use server simulator.

Creating app

Class Router will manage data between Modbus/TCP and websockets client, that runs in your browser

from modbus2websocket.router import Router

Router has two public methods:

  • Router.add_modbus_reg() - that adds registers you want to read
  • Router.run() - that runs router.

You should add registers that you want to read, as a list of dictionaries. Structure of single registers looks like that:

Input_register_1 = {'ir':
    {
        'adr': 0,
        'num': 1,
        'name': 'Input Register 1',
        },
    },

Where:

  • ir - registers type. (see Modbus details).
  • adr - regsiter's address. It starts from 0 to 65535.
  • num - number of registers to read. It is limited between 1 to 2000.
  • name - unique name for your register.

Example

from modbus2websocket.router import Router


if __name__ == '__main__':
    ws_ip = '192.168.220.10'         # websocket ip address
    ws_port = 8888              # websocket port
    modbus_ip = '192.168.220.5'     # Modbus ip address
    router = Router(ws_ip, ws_port, modbus_ip)
    # Modbus registers to read
    regs = [
        {'ir':
            {
                'adr': 0,
                'num': 1,
                'name': 'Reg1',
            },
         },
        {'hr':
            {
                'adr': 1,
                'num': 1,
                'name': 'Reg2',
            },
         },
        {'ir':
            {
                'adr': 2,
                'num': 1,
                'name': 'Reg3',
            },
         },
    ]
    router.add_modbus_reg(regs)
    router.run()

Modbus details

Registers type Short name Description
Digital Input DI Read only, bool, 1-bit
Input Register IR Read only, float/int, 16-bit
Coil C Read/write, bool, 1-bit
Holding register HR Read/write, float/int, 16-bit

Metadata

Release files for modbus2websocket 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for modbus2websocket 0.0.5
File Size Uploaded Provenance Actions
modbus2websocket-0.0.5.tar.gz 5.6 kB Without provenance Details for modbus2websocket-0.0.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for modbus2websocket 0.0.5
File Interpreter ABI Platform Actions
modbus2websocket-0.0.5-py3-none-any.whl Python 3 none any Details for modbus2websocket-0.0.5-py3-none-any.whl

Total release size: 13.8 kB

Release files / modbus2websocket-0.0.5.tar.gz

Download URL modbus2websocket-0.0.5.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
521fb5b8fb1cc69fdca71043341e0762e35b95edab49a41952baa34873848098
BLAKE2b-256 checksum
How to use checksums
c2e9c4f2ae98cbe7431595f3126af4b59832dfae4a11f89872b87339974f86e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.7.4

Release files / modbus2websocket-0.0.5-py3-none-any.whl

Download URL modbus2websocket-0.0.5-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ac8dffb07063a39886a4762c655fda1b33137ff5021bc4a1c2ed7e9528a1ef76
BLAKE2b-256 checksum
How to use checksums
35b913d2c2451142b748fd69aaeefca4f5f0a3c6d485cf22e438c349fc37fcdd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.7.4

Security for modbus2websocket 0.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page