Socket-proxy guide

Author
Thomas Dalla PiazzaIn this guide, you will be guided through the setup of the required socket proxy/bridge used for plc-playground.
Setup
The simulation models on plc-playground are running in the browser meaning that all the code is run in a sandbox for security reasons. This sandbox allows only limited access to the network through mainly two protocols, HTTP requests en Websockets. Plc-playground models uses the second to establish the communication between the plc and the simulated model.
Because standard industrial communications are build on raw sockets (TCP, UDP, etc...), a proxy translating the websocket to raw socket is needed. The simulated systems on plc-playground are using a custom made proxy. The source code can be found on github at the following address, https://github.com/tdallapiazza/modbus_ws_adapter.
The websocket proxy is a little software hosting two services, the first is a modbus server (slave) listenning for connections on port 8502. On the other hand, a websocket server is listening on port 8765. When a modification on the data are made from Modbus clients, the websocket clients are automatically notified and can act accordingly. It is also possible for websocket clients to modify the data. In that case, the modbus clients can't be notified as the modbus protocole is a pure request/response protocol. So the modbus clients needs to regularly poll the server to see any modification of the data.
This proxy server is a simple python script. Choose between the three options bellow to run that service on your computer.
#1 Download and run the executable
The script has been released in a all-in-one executable available from the release page of the github repo. Visit release page and download the executable.
As the executable is not signed, Windows Defender will warn you about the unknown publisher of the executable. Select "execute anyway" to start the service. Feel free to review the source code to get convinced that this script is not doing anything harmfull.
#2 Run it from python
First clone the repository.
git clone https://github.com/tdallapiazza/modbus_ws_adapter.git
Create a python virtual environment, install the required packages and run the script.
cd modbus_ws_adapter
python -m venv ./
.\Scripts\activate
pip install pymodbustcp websockets
python app.py
cd modbus_ws_adapter
sudo install python3-venv
python3 -m venv ./
source bin/activate
pip3 install pymodbustcp websockets
python3 app.py
#3 Run it in Docker
Docker is a container system. You can think of a container as a small machine running a strictly limited amount of services. This is particularly usefull for development of distributed services systems but it is also a practical way of deploying simple service application like the websocket_proxy.
To install docker, simply visit the following link and follow the instruction for your operating system: https://docs.docker.com/get-started/get-docker/.
The image of the websocket proxy is hosted on dockerhub (https://hub.docker.com/repository/docker/thomasdallapiazza/modbus_ws_proxy)
Downloading and setting up the container is as simple as running a single command in your prefered command prompt (like powershell on windows). Start your docker engine as simply issue the following command in a terminal:
docker run -d -p 8765:8765 -p 8502:8502 thomasdallapiazza/modbus_ws_proxy
Your docker container shoulb be downloaded and started. Visit the page of a simple module like the Simple axis and verify the the error message concerning the modbus_ws_adapter doesn't shows up. You are ready to start playing in plc-playground! Enjoy!