Siemens Tia Portal v11 PLC s7-1200 and SQL database

BartPeters88

Member
Join Date
Feb 2015
Location
Asten
Posts
18
Hey there!

I've got some questions/problems with the tia portal v11 and the PLC s7-1200. I don't know how to log my data into a mysql database.

I'm using the webserver and I got my own user defined webpage. I've got some values showing on the page. But now I want to log the values that I display on the website to a mysql Datbase. I want to show some historylogs on my webpage aswell.

I've searched for google on this but I couldn't find something easy and simple about this.:confused:

That's why I want to ask you people here if you can help me out with this issue.

Thanks in advance!
 
Hi,

I guess you have two webservers, a) is the webserver of the plc, and b) the webserver with the mysql server.

On a) you can't directly display data from the mysql-database on b).

If you want to readout data from the plc and write it into your sql database, you need a script on b) which reads out data from the plc and writes it into the sql database. Therefore you need a communication library which supports s7 communication to "speak" with your plc.
Or without any additional library, you can create a user defined webpage in json format for example which contains the data which you want to log, and readout the json object by http from b).
There are many other possible soultions how you can realize this.

If the amount of data you want to log is not so huge, you can use the plc internal datalog functions (see S7-1200 manual in chapter "Data logging"), or simply save your data into an datablock array (as FIFO queue for example).
 
Well whats a lot of data, I just want to load the machine activity. And I only want to show when the machine is turned off/on. So sometimes it's like only 6 times per day and sometimes it's alot more due to errors etc.

Just simple information:

13-3-2015, 8:00, Machine ON (Start of day)
13-3-2015, 10:25, Machine OFF (Error X)
13-3-2015, 10:45, Machine ON
13-3-2015, 13:30, Machine OFF (Error X)
13-3-2015, 14:30, Machine ON
13-3-2015, 15:15, Machine OFF (Error X)
13-3-2015, 15:45, Machine ON
13-3-2015, 16:00, Machine OFF (End of day)

But I want to load this information to get a history log and I can't save 200 days of these logs in an array :p. So I kinda need to send the information per day/week to a database.
 
Must the data in the sql database be online?
Of not, and if you want to use standard communication on the PC side I would do it in this way:

Make a data array with a number of events as FIFO.
Make a user-defined website where you can access these logfiles of the last number n of events. You can use a json-style format for this, to get easy access with most common script langauges like php or python.
Example:
Code:
[
    {
        "timestamp": :="LOG".message[0].timestamp:,
        "event": :="LOG".message[0].event:
    },
    {
        "timestamp": :="LOG".message[1].timestamp:,
        "event": :="LOG".message[1].event:
    },
    {
        "timestamp": :="LOG".message[2].timestamp:,
        "event": :="LOG".message[2].event:
    }
]
Don't use too many variables / events on a single page, this will make the response extremly slow.
On the computer with the sql-server, write a cyclic script which reads the json dataset from the plc, and inserts it into your database table.
You have to check that you only add new events into the database. Using a unique event-id which is incremented in the plc would be a solution, but this may cause problems when you upload new program parts, and data gets reset to zero.
And you have to poll the plc faster than the messages can occur, so that no data gets lost. Otherwise you would need a handshake between pc and plc.

Remember the problems with timestamps, regarding to daylight saving time.
 

Similar Topics

I am currently am in a PLC class and need urgent help on how the ladder logic would be laid out. I understand how to get the traffic lights to...
Replies
19
Views
438
Hello, If the date on the license manager of tia Portal has expired, can I still work with it? or is this just to keep the program up to date...
Replies
7
Views
205
Hi everyone I've created an FC that includes the blocks TCON, TDISCON, TSEND and TRCV. This block has to be as generic as possible across...
Replies
15
Views
1,515
Hello, i can find the CPU when searching for it. But when I go Online i just get the icon for "Not compatible" everywhere. I get no additional...
Replies
4
Views
1,165
Hi, I want to initialise some tags on first scan only. As they are related to wall-clock time, I want to do the initialisation when the PLC first...
Replies
4
Views
1,168
Back
Top Bottom