Hello,
I am trying to access the plcnext variables using REST api. Per the following documentation, I need to create at least one HMI page in order to use Rest data interface. Introduction (plcnext.help)
I did create a basic HMI page and I was able to view the page successfully. However, when I enable rest interface in the HMI Web server setting, I see 404 Not Found (nginx). I have PLCNext 2022.3 and AXCF 3152 firmware 2022.0.5 LTS.
I tried to access the REST server using putty and I see 'GET command not found ’ error. Here is the command I am using to access the variables
GET https://192.168.1.10/_pxc_api/api/variables?paths=Arp.Plc.Eclr/Main1
Can you please help. Thanks!
Hello Teegala3,
the REST API Checkbox is to be used to enable the REST API if you do not wish to use any EHMI pages.
As soon as that checkbox is activated and the Project downloaded the EHMI will be disabled but the REST API activated.
As soon as you have a EHMI Page and a variable active the Rest api is activated automatically.
I guess this is a problem with putty.
Try to paste this line into your browser this should work as well. (if you deactivate authentiaction in the EHMI setting in PLCnext Engineer)
Otherwise you will have to go through the authentication procedure.
https://192.168.1.10/_pxc_api/api/variables?paths=Arp.Plc.Eclr/Main1
Oliver,
Thank you for the clarification. browser access works as you suggested. Documentation says variables can be access by REST api, however I do not see those variables in the browser.
I have few boolean variables in my Main1 program and the hmi flag is selected as well. Is there a way to access these variables using REST api without recreating them in the HMI web server data list? Please advise.
Hello Teegala,
here you find all the information about the REST API Introduction (plcnext.help)
With this command you can recieve a list of available variables.
https://%PlcAddress%/ehmi/data.dictionary.json
If they are visible there you will be able to call them via the REST Api.
kind regards,
Oliver
Hello,
I can retrieve a variable (data type I created myself) via the REST API.
The response comes as JSON.
https://10.0.0.10/_pxc_api/v1.1/variables?pathPrefix=Arp.Plc.Eclr/&paths=ConfigDtoScreenshot 2022-06-01 091107.png
However, if I want to set this variable via the REST API, this does not work.
Is it possible to set a variable that is not a default type via the Rest API?
https://10.0.0.10/_pxc_api/v1.1/variables
Body from PUT-Request:
{„pathPrefix“: „Arp.Plc.Eclr/“, „variables“: [ { „path“: „ConfigDto“, „value“: { „eins“: true ,„zwei“: true ,„drei“: false} } ]}
The answer is the variable with not updated values.
Screenshot 2022-06-01 091936.png
Read and write of normal variables (INT, BOOL…) works without problems.
kind regards,
Daniel
Hello Daniel,
I dont think writing struct values as one is supported. I will inquire if any plans in this regard have been made.
Try it like this please:
{„pathPrefix“: „Arp.Plc.Eclr/“, „variables“: [
{ „path“: „ConfigDto.eins“, „value“: false},
{ „path“: „ConfigDto.zwei“, „value“: false}
{ „path“: „ConfigDto.drei“, „value“: false}
]}
kind regards,
Oliver
Hello,
thank you very much for the quick reply.
The hint with setting the variables via the individual paths in one single request worked great.
kind regards,
Daniel