S7TinyMySQL Client
S7TinyMySQL Client
TinyMySQL Client
Savechka Andriy
[email protected]
15.10.2016
S7-1200/1500 TinyMySQL Client doc. v0.1
Contents
INFORMATION........................................................................................................... 3
CLIENT CAPABILITIES/LIMITATION .............................................................................. 4
MYSQL BASIC SETUP. ................................................................................................ 5
LIBRARY INTERFACE .................................................................................................. 9
USING DEMO PROJECT ............................................................................................. 10
Page 2 from 11
S7-1200/1500 TinyMySQL Client doc. v0.1
INFORMATION
LICENSE
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
REQUIREMENTS
Port: 3306
Server: (Ubuntu)
Version: 5.5.52-0ubuntu0.14.04.1
Login User: root
Current User: root@%
SSL: Disabled
There only one major difference, free version has hardcoded MySQL server credentials that
you cannot change.
Page 3 from 11
S7-1200/1500 TinyMySQL Client doc. v0.1
CLIENT CAPABILITIES/LIMITATION
Client library has following
Capabilities:
SQL Server authentication protocol: v4.1
SSL:no
Host: can connect only using IP Address of the MySQL server.
Supported commands: INSERT, UPDATE, DELETE.
Limitations:
SQL query MAX 254 characters long including white spaces.
Not supported SELECT Query
Free version has hardcoded server credentials
user:root,
pass:12345678,
DB:Stats,
Host:192.168.0.20
Page 4 from 11
S7-1200/1500 TinyMySQL Client doc. v0.1
Run the installer and follow the wizard. I recommend leave all settings default.
Page 5 from 11
S7-1200/1500 TinyMySQL Client doc. v0.1
After finishing the wizard, launch the MySQL Workbench and connect to your server.
On next step we need change user permissions. Because by default, user is allowed to
connect only from localhost.
Click Users and Privileges, then in user list select root and change Limit to Hosts Matching
from localhost to %. This means that user can connect from any host. For stronger security
you can type something like this 192.168.0.% in this case user can connect from any ip that
starts with 192.168.0.
Page 6 from 11
S7-1200/1500 TinyMySQL Client doc. v0.1
After modifying setting press Apply button. Now test if everything is Ok. Close MYSQL
Workbench, open again, add new connection as Hostname type your local IP and try
connect.
Page 7 from 11
S7-1200/1500 TinyMySQL Client doc. v0.1
Copy/paste code below into Query tab and press execute button
USE `Stats`;
CREATE TABLE `data` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`ts` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`var1` float DEFAULT NULL,
`var2` float DEFAULT NULL,
PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=848 DEFAULT CHARSET=utf8;
This script will create database Stats and table data. Press refresh SCHEMAS on navigator
tab, there should be structure like in picture below.
Page 8 from 11
S7-1200/1500 TinyMySQL Client doc. v0.1
LIBRARY INTERFACE
Normally in ladder logic block looks like this
On each error, except SQL Query error, you need reconnect to the server by triggering
Connect input.
Page 9 from 11
S7-1200/1500 TinyMySQL Client doc. v0.1
Network #1
Network used for generating each two seconds two random float values in range 0-100.
Network #2
This block combines an SQL query string. This can be done in more elegant way using s7-
1500 series PLC, because there is some advanced instructions for string manipulations.
Anyway, variant below will work for both of them. How realize this functionality is up to you.
Page 10 from 11
S7-1200/1500 TinyMySQL Client doc. v0.1
Network #3
Here we call MySQL client block. As we can see if client successfully connected all outputs
should be in zero state. Now when set marker M0.2, query at input SQL will be send to
server and executed. If everything ok, all outputs remains in zero state.
Page 11 from 11