Trouble reading through REST Api

Good Afternoon, I am attempting to read variables using the Rest API and HTML5/JS information located on the github. I am able to write to a variable, but for some reason I cannot read any values. The example files and support guide are a little vague regarding how to read a variable, and I was hoping someone here could assist me. Thanks!

Hello, We are planning to update the REST example on Github in the coming months - hopefully that will make it clearer. In the mean time, please try these steps: 1. Create a PLCnext Engineer project with one global variable named “Integer1”, and one program instance named “MainInstance”, which has an OUT port variable named “Integer2”. This OUT port variable should have the “HMI” attribute checked. 2. In the PLCnext Engineer project, in the “HMI Webserver” settings page, set the “Enforcement of User Levels” (in the Security section) to “None”. 3. Download the PLCnext Engineer project to the PLC and set the two integers to non-zero values. 4. On the PLC command line, run the following commands, substituting the IP address of your PLC if necessary: curl -L -k -s 192.168.1.10/_pxc_api/api/variables?paths=Arp.Plc.Eclr/Integer1 curl -L -k -s 192.168.1.10/_pxc_api/api/variables?paths=Arp.Plc.Eclr/MainInstance.Integer2 … and you will see the values of the variables in the PLC in JSON format. You can execute curl commands from a remote machine, and parse the resulting JSON to get the variable name and value. Note that the above example does not use authentication or encryption - for a real-world application, these issues should be considered. Hope this helps. - Martin.

Thank you for the quick response! I am able to read the variable’s value using the command line following your instructions. However, I would like to read from an EHMI page. I think I can use that same path to get the value, I just need to figure out the commands necessary. Would you be able to assist me on this with an example through the PXC_API JS page? Thanks again!

I don’t understand … you want to read the value of a variable that is shown on an eHMI page? The variables on an eHMI page are defined in the PLCnext Engineer project, and marked with the “HMI” attribute - just like variable “Integer2” in the example above. Will this give you the data you need?

Sorry, allow me to explain more. I am attempting to use Chart.JS on an HTML page to process data over time in a line graph. To do this, I need to use an eHMI page (HTML5 with JS) and link it in. Then I need to attach my process data variable (In this case, a global variable that is tagged for HMI). Once I can read this using the PXC_API, I will be able to insert it into the graph. My current problem is that I am unable to read any variables using the demo PXC_API on the github. I can write to variables, and now I can read variables in the command line, but not over an eHMI page. Unless I am misunderstanding this, I need to use the Read Variable Function listed on the github. Is this correct? And if so, how would you make this work with the program provided on the github. Thanks again!

OK, so the curl command is just doing a HTTP GET, which is what the Read Variables command in the table on Github talks about. In the " read a single variable" example on this page, you should be able to integrate the working curl commands above into the sample code - e.g. the url in the example would end up as something like:

192.168.1.10/_pxc_api/api/variables?paths=Arp.Plc.Eclr/Integer1