I am using a Siemens S7-1200 PLC with integrated webserver. I want to show multiple analog values from the PLC in the webpage using javascript. With one tag it works great, but how do I add and present multiple tags using JSON structure?
I have done the following: - Updated the javascript with a suggested code - Updated the htm file that the script reads from
But I do not know if i have done this correct and how do I then call for the different variables.
THIS IS THE TABLE I WANT TO DISPKLAY THE DATA IN:
<table>
<tr>
<td class="static_field">Nivå [m]:</td>
<td class="output_field"><label id="HMI_skalert">0</label></td>
</tr>
<tr>
<td class="static_field">Masse [tonn]:</td>
<td class="output_field"><label id="Tank1_masse">0</label></td>
</tr>
</table>
SCRIPT:
<script type="text/Javascript">
$(document).ready(function(){
$.ajaxSetup({ cache: false });
setInterval(function() {
$.getJSON("IOwebserver.htm", function(result){
HMI_skalert= result.HMI_skalert
Tank1_masse=result.Tank1_masse
});
},1000);
});
</script>
FILE: IOwebserver.htm
{
":="webdata".HMI_skalert:",
":="webdata".Tank1_masse:"
}
Thank you so much.
I think you should look on this article... https://api.jquery.com/jquery.getjson/
You haven´t a return key in JSON in IOwebserver.htm file.
":="webdata".HMI_skalert:" -> value of JSON object which use AWP command in this case.. :="Name_of_DataBlock".variable: -> Symbols (:=) and (:) are boundaries of AWP command used in Simatic WebServer
So try to remake this file like this:
If this will not work try to swap apostrophes dobule quotes (") by one (').
For example I use a interval loading XML file to load 57 variables for Simatic S7-S1200 WebServer. For more information contact me..