This time we will use the blocks from the LSQL library based on the example that Siemens has posted on their page, to register in a SQL database with S7-1500 PLC, later intercepted with Wireshark.
We will do this quickly to focus later on how to capture the packets that the PLC sends to the database and try to gain access to it, similar to what we did with Modbus. We can perform it on a local network, or all on localhost; for the example, it doesn't matter.
1- Writing Variables
In this example, we use a simulated 1515-2 PN to send queries to a database where we want to store historical data of our variables.
1- We instantiate the block "Lsql_Microsoft", generating the associated DB and parameterizing it with the variables from the DB itself. In Siemens' example, everything is prepared for this, and the manual explains it well.
2- We parameterize the connection data, which we will obtain from where we have the database that we want to write to.
- We write an appropriate INSERT command according to the structure of the database; in my case, there are 3 temperatures, two pressures, and one date (Timestamp). At this point, it is important to work correctly with the formats, especially with dates.
- You can pass fixed values directly or parameterize it with PLC variables (which is the idea); for this, I had to create a function that does all this: