KNoT Modbus Simulator is part of the KNoT project. It aims to provide an industry protocol simulator by creating a tcp server instance so that KNoT Things can be described and tested by KNoT ecosystem.
Check out our currently supported protocols.
- python 3.8.2 (other versions may work but are not officially supported)
- pip
- venv
In order to use this project it's necessary to install its dependencies and add the pre-commit hooks, to simplify this process a Makefile
was used. Since not all users may like the idea of using a makefile in a python project, this README was separated in two sections: the first explaining how to build and run the project with the Makefile and the second without it.
- Make.
First, change your current working directory to the project's root directory and bootstrap the project:
# change current working directory
$ cd <path/to/knot-thing-simulator>
# install project dependencies
$ make bootstrap
In order to run the main script simply use the make run
command.
First, change your current working directory to the project's root and then setup up a new Python virtual environment:
# change current working directory
$ cd <path/to/knot-thing-simulator>
# setup a new python virtual environment
$ python -m venv venv
Now, activate the newly create virtual so that dependencies are installed there and not to your global Python installation:
# activate virtual environment
$ source venv/bin/activate
Now, install the project's dependencies with the following command:
# install project's dependencies
$ pip install -r requirements.txt
note: in order to leave the virtual environment you created for the project, use the
deactivate
command (from anywhere).
Finally, prepare the project's custom pre-commit hooks:
# copy the custom hook to the .git folder
$ cp hooks/pre-commit .git/hooks/pre-commit
# install the pre-commit hooks
$ pre-commit install
From the root dir run:
sudo env PYTHONPATH=. python <file>
To install the project's Docker installation pre-requisites, please follow the instructions in the link below:
Note: if you're using a Linux system, please take a look at Docker's post-installation steps for Linux!
Once you have all pre-requisites installed, change your current working directory to the project's root:
# change current working directory
$ cd <path/to/knot-thing-simulator>
In order to build the Docker development image, use the command below:
# build docker image from Dockerfile-dev
$ docker build . --file Dockerfile-dev --tag knot-thing-simulator:dev
Finally, run the development container with the following command:
# start the container and clean up upon exit.
$ docker run --rm --publish 502:502 --volume `pwd`:/usr/src/app --tty --interactive knot-thing-simulator:dev
Note: the
--volume
flag binds and mountspwd
(your current working directory) to the container's/usr/src/app
directory. This means that the changes you make outside the container will be reflected inside (and vice-versa). You may use your IDE to make code modifications, additions, deletions and so on, and these changes will be persisted both in and outside the container.
In order to build the Docker production image, use the command below:
# build docker image from Dockerfile
$ docker build . --file Dockerfile --tag knot-thing-simulator
Finally, run the production container with the following command:
# start the container and clean up upon exit.
$ docker run --rm --publish 502:502 --volume `pwd`:/usr/src/app --tty --interactive knot-thing-simulator
The simulator provides an easy configuration template (config/config.json). In order to create a data server model of industrial things you need to follow the config template, where the fields are explained bellow:
- id: Specifies the data-server id to be modeled, id > 0.
- register_data: Represents a non-discrete (non-binary) data-block.
- Each register_data has the following fields:
- address: Identifies data inside the data-block related to non-discrete block.
- value: List of values with little-endian representation in Hexa-decimal.
- Each register_data has the following fields:
- digital_data: Represents a discrete (binary) data-block.
- Each digital_data has the following fields:
- address: Identifies data inside the data-block related to discrete block.
- value: List of values with little-endian representation in binary.
- Each digital_data has the following fields:
- Modbus
All KNoT Simulator files are under LGPL v2.1 license, you can check COPYING
file for details.