Siemens S7-1500 PLC JSON RPC Web API - Integrating Control Systems to Higher Level Systems with HTTP

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
integration between control systems and higher level it systems such as erp mes and mom have historically proven a challenge due to a lack of common protocols between these systems getting these systems to talk to each other has proved somewhat of a task the opcua protocol was released as a solution to this problem and is gaining traction but what if we could use a protocol that is heavily utilized in the world of i.t and bring it down to the shop floor level to do exactly that i would like to share with you the json rpc web api for the siemens s7 1500 programmable logic controller now there's quite a lot going on in that name so let's break it down first of all this is a web api meaning that this is an application programming interface provided by the web server of the s7 1500 plc this means that other systems can open a http connection to the web server the plc and read and write data from inside the control system now the reason why it's good to do this over the http protocol is because it's been around for a very long time nearly all modern programming languages are able to support http and if they cannot there's a good chance that there's a library available http is also widely accepted by firewalls as companies are using this all day every day this means that we can seamlessly integrate these plc apis into existing network infrastructures without too much pain the http protocol is normally used to carry web pages from a web server to a web browser on your computer in this application we're not carrying web pages but carrying plc data in order for us to understand what is in this plc data it must conform to some standard the standard that has been chosen for this plc api is json rpc json stands for javascript object notation and rpc stands for remote procedure call so what this means is we can open a http connection to the plc and send strings of json which contain methods and we can get data back from that control system let's have a look at how we configure this in tia and what it looks like in action inside a tia portal we need to add ourselves an s7 1500 controller once the controller has been added we need to go to the properties of the plc and access the web server pane at the bottom here we need to turn on the web server and we need to permit access only with encrypted http as the data that's been transmitted through the web api is sensitive we don't want third-party man-in-the-middle attacks compromising it so if we do not have the https enabled the web api will not work if we scroll down we then need to make ourselves a user i've already added the user lowercase.json with a password in the access level we then need to either choose read tags and write tags or at one or the other so if we were providing access to a third-party system and we only wanted them to be able to read data throughout the control system we could obviously choose this tick box here for the security conscious among you you're probably thinking it might be a bit dangerous to allow a third party to read every bit of the control system so throughout the program you will notice these columns accessible from hmi opc ua and web api writable as well as visible so this gives us another level of control over who can view these different bits of information from third-party systems in my example i've just got three random numbers being generated and i've also got this hidden field down here just to show you that you're unable to see the data let's connect up the plc and get ready to download to it to test the web api we can use a third-party tool like postman for those of you not familiar with postman it is a http client for testing web apis so what this allows you to do is make sure the web api is functioning as expected before you start to integrate it into your third-party system the way postman works is we have the http request which is what my computer is sending and on the right hand side we have the response from the plc api at the top here we have the ip address of the plc prefixed with https and then the endpoint for the api which is forward slash api json rpc we shall send this command here and we can now see that our login has been successful and we've been given a token on the left hand side we can see the bits that go together to make a json rpc message the bits of main interest are the method which is api.login for logging in and the parameters so the login method takes a username and a password and this is what we set earlier on the right hand side here the plc has responded with a token so this token now allows me to have a session enabled on the plc so i don't need to continually log in in every subsequent request i need to use this token to prove to the plc api that i am authenticated and this is the way that we get the security in this system without this authentication token after a login the plc is not going to give us any data and not going to allow us to write to it we need to embed this in the header of the request and tools like postman can do this for us so in this body it's a bit more interesting i'm sending three commands at the same time in an array so i've incremented the id of each request so that when the server responds i can match my requests to my replies you'll also see the method has now changed the plc program.read and we're now putting the variable in the parameter that we wish to read if we were doing a write we would have plc program dot write and then we'd have the parameter we want to write into with a value so if i fire this off now we're straight away getting the values back from my data block which i showed you in tia earlier and we can keep sending this and we'll keep getting refreshed data so that's a look at using a tool to test the web api but let's have a look at this embedded in a web page for the sake of simplicity i'm hosting a simple web page inside of the plc itself but this could be hosted anywhere on the screen now we can see a dynamic chart which is drawn using javascript using html5 objects so here we can see the three values that are being read straight from the plc if we open the developer tools of my web browser and have a look at the web requests what we can see here is my web browser has a bit of javascript running in it that every 500 milliseconds is requesting the values from the plc if we have a look at one of these requests we can see here that the response is exactly the same as we saw in postman so what my web browser is doing is taking the response from the api of the plc and rendering it inside of our web page that's only one of the examples of what you can do with this api so for example any net application or java or any third party that understands the http protocol can now be integrated into the plc system without too much pain so thank you for watching i hope this has been informative and showed you a good way of integrating a plc control system into a higher level it system using existing widely adopted protocols if you have any questions or comments please leave them below and i'll do my best to answer them see you next time
Info
Channel: AutomationStation
Views: 6,043
Rating: undefined out of 5
Keywords:
Id: d9EX2FixY1A
Channel Id: undefined
Length: 8min 40sec (520 seconds)
Published: Mon Feb 08 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.