Plcnext exchanging data between plc and linux using REST
Hello, i am quite new to programming with the plcnext controller so any help would be appreciated.
I have a plcnext controller. I am trying to exchange data between the Linux side and the PLC side of the PLCNext controller.
It seems there are multiple methods to do this including OPCUA, REST, RSC.
I am currently trying to implement the Rest method to exchange data between the PLC side and the linux side.
i am currently following this tutorial here:
when i try to do a curl to get the authentication token: i seem to be running into a few errors:
the first error seems to be a missing SSL certificate. however i can bypass this by adding a "-k" option
the second error is that i am receiving a "400" response from the authentication request after adding a "-k" option
i have attached screenshots of the error and responses
Also is it possible to view some example code of how to implement the REST method of exchanging data between PLC and Linux.
Thank you.
Comments
Hello,
There are a few tricks to getting the REST API working. These steps create a minimal working example:
1. Create a PLCnext Engineer project with one global variable named "Integer1", and one program instance named "MainInstance", which has a Localvariable named "Integer2". This Local variable should have the "HMI" attribute checked.
2. The PLCnext Engineer project needs to contain a minimum of one HMI page (even an empty one) in order to initialize the PLCnext HMI component.
3. In the PLCnext Engineer project, in the "HMI Webserver" settings page, set the "Enforcement of User Levels" (in the Security section) to "None".
4. Download the PLCnext Engineer project to the PLC and set the two integers to non-zero values.
5. On the Linux command line (either on the PLC or on a PC connected to the PLC), run the commands:
... and you will see the values of the variables in the PLC.
We have an outstanding task here to provide more examples of working with the REST interface, but in the mean time, if you need more information than is shown in the Info Center, please let us know.
~ Martin.
Hello Martin
Thank you for the response
i have tried both these methods and i am able to read the result of MainInstance.Integer2, though Integer1 is giving a null value.
I am now trying to implement a write to these integers following the REST API tutorial using the following command:
however i am getting the following response:
is there any reason why i would be getting a 400 error? Would it possible to get an example of how to write to values using REST
thank you
Hi Kevin,
I guess the issue is a missunderstanding of the key "valuetype", think so because I also stumbled over it ;-)
The "valuetype" "variable" means that you want to copy a value from variable a to variable b, so your call must contain two variables.
As this is not the case you'll get an exception (and yeah the details could be better).
If you just want to write a value to an existing variable (as it seems) you've to use the value "Constant" instead.
So, your body should look something like this:
"variables": [{"path": "Arp.Plc.Eclr/MainInstance.Test_Out_Variable", "value": "true", "valueType": "<strong>Constant</strong>"}, {"path": "Arp.Plc.Eclr/MainInstance.Test_Out_Variable2", "value": "true", "valueType": "<strong>Constant</strong>"}]}'
Hope that helps,
Frank