Hello community
I have developed a CtrlExtention where It gets information about some devices in a web platform that has an API that uses HTTPS and this information is formatted in JSON, in my CtrlExtention development, I use the WaitCondition class to wait certain seconds the thread until the information is given from the API for prevent the blocking state. In the CTRL SCRIPT, I get all the devices with its corresponding ID with the dpQuery function, then, for each device that contains its ID, I create a thread that calls the CtrlExtention function that I developed for communicate with the Web platform and get the info.
the problem happens that, even if I have implemented a WaitCondition class, the script pass to state blocked (State 3). I would like to know if the WaitCondition class or the Ctrl Extention has some limitations about this implementation, also, if you have some improvements or doubts about this development, let me know.
Many thanks!!!!!
Ctrl Extention Thread WaitCondition
- Gertjan van Schijndel
- Posts:634
- Joined: Mon Aug 02, 2010 10:37 am
Re: Ctrl Extention Thread WaitCondition
When the WaitCondition is implemented and used correctly it should work without getting into the blocked state.
From your description I cannot see any limitation that might prevent your solution from working correctly.
From your description I cannot see any limitation that might prevent your solution from working correctly.
- jeissonsierrac
- Posts:62
- Joined: Wed Jun 03, 2015 9:37 pm
Re: Ctrl Extention Thread WaitCondition
Hello Gertjan
Thanks for your answer, I debug my code and it works, but always the Ctrl Manager goes into a blocked state. I publish the code in C++ of the class that I Use to connect to the server and it inherits from WaitCondition. I don't know if I have an error in the implementation, I appreciate you if you see something unusual.
Thanks
Thanks for your answer, I debug my code and it works, but always the Ctrl Manager goes into a blocked state. I publish the code in C++ of the class that I Use to connect to the server and it inherits from WaitCondition. I don't know if I have an error in the implementation, I appreciate you if you see something unusual.
Thanks
Code: Select all
/*Case in Ctrl Extention where I instance the WaitForAnswer class*/
case F_ConnectApi:
{
param.thread->clearLastError();
if (!hasNumArgs(2, param))
return &errorIntVar;
TextVar txLink, *txData;
Variable *vData;
txLink = *(param.args->getFirst()->evaluate(param.thread));
vData = getTarget(param.args->getNext(), param);
txData = static_cast(vData);
WaitForAnswer* WaitFunction = new WaitForAnswer(txLink, txData);
param.thread->setWaitCond(WaitFunction);
}//Close case
/*Constructor of Class*/
WaitForAnswer::WaitForAnswer(TextVar txLink, TextVar *data)
{
//std::cout- mkoller
- Posts:741
- Joined: Fri Sep 17, 2010 9:03 am
Re: Ctrl Extention Thread WaitCondition
You are using the curl library and the call curl_easy_perform() is a blocking call doing the communication with the server, waiting until you receive the response, which might take a while.
This is the wrong approach.
Never use blocking code in a CTRL extension, since this blocks the whole manager!
Note that CTRL is single-threaded (in terms of OS threads).
General question: are you aware of the http functions CTRL already provides, like netGet(), netPut() etc. and also jsonEncode/jsonDecode which you
could use to implement what you need in a script without the need to use yet another http library ?
This is the wrong approach.
Never use blocking code in a CTRL extension, since this blocks the whole manager!
Note that CTRL is single-threaded (in terms of OS threads).
General question: are you aware of the http functions CTRL already provides, like netGet(), netPut() etc. and also jsonEncode/jsonDecode which you
could use to implement what you need in a script without the need to use yet another http library ?
- jeissonsierrac
- Posts:62
- Joined: Wed Jun 03, 2015 9:37 pm
Re: Ctrl Extention Thread WaitCondition
Hello Martin
Thanks for the information. To use the server API, it is necessary to install a security certificate (.p12 file), on the computer where I will bring and manage the information, first I try with these Ctrl functions but they never recognized the installed certificate, besides there is not a parameter where they specify the certificate that I am going to use, it is for this reason that I decided to develop a Ctrl Extention and use the CURL library, on a previous occasion I had asked a question of this topic in the forum, There is the link: https://portal.etm.at/index.php?option= ... 15&id=6288
Thanks!!!!
Thanks for the information. To use the server API, it is necessary to install a security certificate (.p12 file), on the computer where I will bring and manage the information, first I try with these Ctrl functions but they never recognized the installed certificate, besides there is not a parameter where they specify the certificate that I am going to use, it is for this reason that I decided to develop a Ctrl Extention and use the CURL library, on a previous occasion I had asked a question of this topic in the forum, There is the link: https://portal.etm.at/index.php?option= ... 15&id=6288
Thanks!!!!
- mkoller
- Posts:741
- Joined: Fri Sep 17, 2010 9:03 am
Re: Ctrl Extention Thread WaitCondition
I checked the mentioned forum posting, however it's not entirely clear to me.
Is the problem here really that THE CLIENT (your CTRL script) needs to provide a certificate which the server checks ?
Usually with http servers it's the other way round: the client receives a certificate and it decides if it trusts the server.
Is the problem here really that THE CLIENT (your CTRL script) needs to provide a certificate which the server checks ?
Usually with http servers it's the other way round: the client receives a certificate and it decides if it trusts the server.
- jeissonsierrac
- Posts:62
- Joined: Wed Jun 03, 2015 9:37 pm
Re: Ctrl Extention Thread WaitCondition
The server generates an SSL certificate to connect to the API.
The API uses JSON format to send and receive information and uses HTTPS as communication protocol.
The certificate is build within the IP address, so only the client with the corret IP can access to the API.
The certificate (p12 or PEM file) is installed on the client side (WinCC OA - Server).
The certificate is installed correctly because from a browser I can access the service without error.
Using netGet function in CTRL, the function answer with: "Error while reading: error: 14094410: SSL routines: SSL3_READ_BYTES: sslv3 alert handshake failure, error: 140940E5: SSL routines: SSL3_READ_BYTES: ssl handshake failure".
It seems that the netGet function doesnt provide a way to set the client cerfiticate/key.
That is the reason why I develop a Ctrl Extention with CURL library.
The API uses JSON format to send and receive information and uses HTTPS as communication protocol.
The certificate is build within the IP address, so only the client with the corret IP can access to the API.
The certificate (p12 or PEM file) is installed on the client side (WinCC OA - Server).
The certificate is installed correctly because from a browser I can access the service without error.
Using netGet function in CTRL, the function answer with: "Error while reading: error: 14094410: SSL routines: SSL3_READ_BYTES: sslv3 alert handshake failure, error: 140940E5: SSL routines: SSL3_READ_BYTES: ssl handshake failure".
It seems that the netGet function doesnt provide a way to set the client cerfiticate/key.
That is the reason why I develop a Ctrl Extention with CURL library.