SSCP to MySQL Bridge

This daemon-based service allows bi-directional data transfer between an Unipi unit running Mervis and a MySQL database through an SSCP protocol (the proprietary protocol used by Mervis). The daemon can run on any Linux machine (database server or another remote machine) or directly on the unit.

  • Daemon runs on the unit
    • In this case, the daemon runs on the unit right next to the Mervis RT and send the data to a remote database. Requires IP connection between the unit and the database server.
  • Daemon runs on a different machine/server
    • This can be divided into two scenarios depending on the network connection.
    • Daemon has IP access to the unit
      • This is the reverse installation of the first case, where the Daemon runs on the unit.
      • The Daemon is installed to a server and communicates with the unit and send the data to the database server.
      • The database server can run on the same server as the daemon or different machine.
    • Daemon does NOT have IP access to the unit
      • This option will be available soon
      • This scenario uses Mervis Proxy server to read the data from the unit and send them to the database server. The advantage is that the Daemon does not require IP access to the unit so the server running the Daemon can be on the other side of the World (behind NAT or firewall limiting access to the internal network).
      • Requires the unit to be connected to the Proxy server.
      • Limited by the speed of the Proxy.
  1. SELECT - This action will read a row from the specified table and force the values to the relevant Mervis variables within the unit. The row can be specified using the “where” parameter, which will be directly used as a “WHERE” clause in the SQL query. (Set Mervis variable according to the DB)
  2. UPDATE - This action will update a row in the specified table with the variable values in the unit. The row can be specified using the “where” parameter, which will be directly used as a “WHERE” clause in the SQL query. (Set DB row according to the Mervis variable)
  3. INSERT - This action will insert a row with current unit values into the specified table each time the variable state is read from the unit. (Log Mervis variable to the DB)
  • The program is designed to work on both x64 and ARM* platforms including all Unipi units.
  • The SW is distributed as a binary Debian (.deb) package tested on the Debian 9/10 based Linux distributions.
  • As the SW is not an open-source product, contact Unipi support in case you need to operate the SW on another platform.

*Currently arm64 and armhf are supported

Installation

  1. Add the Unipi Debian repostiory into your apt-sources list (skip this step if you are working with an Unipi unit). Replace the <distro> placeholder with your Debian distribution name – stretch or buster.
    sudo su
    echo "deb https://repo.unipi.technology/debian <distro> main" >> /etc/apt/sources.list.d/unipi.list
    wget https://repo.unipi.technology/debian/unipi_pub.gpg -O - | apt-key add apt-get update 
  2. Install the application package.
    apt-get install sscp-sql-bridge

Packages with external libraries (libyaml, libmysqlcppconn, libboost-system, libssl) are installed automatically if necessary. By default, binary executable is installed into /opt/unipi/tools directory.

Configuration

All configuration consists of these two files:

  1. /etc/unipi/sscp-sql-bridge.d/mapping.yaml is the main configuration file containing IP addresses and credentials for both database server(s) and mervis-running machine(s) as well as all settings related to the variables transferred. By default, the file contains a commented example configuration that must be replaced by the right values according to the application.
  2. One or more .vlist file(s) containing a list of all variables in the Mervis project(s). These files are generated automatically by the Mervis IDE and are located in the main Mervis project folder in your Windows PC. These files should be copied (eg. using SCP) from the PC to the unit/server where this toll will run. Default path within the unit/server is /opt/unipi/data/ and can be changed in the mapping.yaml file. This .vlist file should not be edited manually.

Make sure the configuration files follow the valid YAML format. An online YAML validator (such as this one https://codebeautify.org/yaml-validator) can be used to ensure this. Do not add any extra fields that are not listed in the example.

The structure of the mapping.yaml file is described below.

Service enable

Right after the configuration is done, it is recommended to verify function by executing the binary on the terminal foreground:

cd /opt/unipi/tools/
./sscp-sql-bridge

If no error message appears in the output, the service can be enabled and started in the background (ie in daemon mode):

systemctl enable sscp-sql-bridge
systemctl start sscp-sql-bridge

Respect YAML structure of the file. The best way is to edit the example installed by default.

  • plc_n list of addressed units running Mervis — More than 1 unit can be defined
    • sscp_ip — IP of machine with mervisrt running (can be 127.0.0.1 if the daemon runs locally)
    • sscp_port — TCP port which mervisr listen on (default 12346)
    • sscp_username — sscp credentials, can be set through Mervis IDE
    • sscp_password — sscp credentials, can be set through Mervis IDE
    • db_user — DB server login
    • db_pass — DB server password
    • db_ip — DB server IP (can be 127.0.0.1 if the daemon runs on the same machine)
    • db_port — Database server port (3306 is usually the default)
    • db_mysql_schema — DB schema name
    • vlist_filename — list of variables (file generated by the Mervis IDE)
    • variable_sets list of operation groups — More than 1 operation group can be defined per every unit.
      • type — type of operation (select, update and insert operations are supported)
      • set_name — name of the set consisting of one or more variables
      • table_name — name of table within db_mysql_schema
      • reading_period — given in 100ms steps
      • vars — list of variables belonging to the group
        • var_name — variable name in Mervis project
        • field_name — column name in table_name