Home > Forum > IEC 61131 Programming (LogicLab) > New FB HTTPClient released
tagged: HTTPClient
- This topic has 9 replies, 3 participants and was last updated 4 years, 6 months ago da Rubox.
-
AuthorPost
-
May 10, 2018 at 4: 04 pm #44043Sergio BertanaAdministrator Forum
The HTTPGetPage FB has evolved to become a true HTTP client, so we've changed its name to HTTPClient (Manual extract). The possibility has been added to send parameters both in GET and in POST and to receive pages of any length in response. In the case of very large pages, the page data received can also be transferred to a file.
I attach a sample program to the topic (Download) with the new FB, in the example the request is made of a page on the Altervista site, the program passes in GET or POST the Dividend and Divisor parameters to a PHP script that performs the division between the past values. It is possible to test the operation of the script directly from here. If the script is active, a page is returned with: The result is: 50.
It is obvious that you can test the script by modifying the values in the browser address obtaining different results. The purpose of the FB is precisely this support by program SlimLine on a web service in the cloud to perform operations.
June 25, 2019 at 2: 29 pm #48327MarcelloParticipantI am successfully using the HTTPClient FB and now that I am enjoying it, I would like to be able to use this FB to configure via HTTP devices connected to the network, in particular to change the IP address, set parameters etc ... I asked one of our suppliers for the commands to change the IP address of some probes (KMTronic) and they sent me this series of commands (including the reboot one).
Cambio IP:
POST /net_config.htm HTTP / 1.1
Host: 192.168.1.199
Connection: keep-alive
Content-Length: 57
Cache-Control: max-age = 0
Authorization: Basic YWRtaW46YWRtaW4 =
Origin: http://192.168.1.199
Upgrade-Insecure-Requests: 1
Content-Type: application / x-www-form-urlencoded
User Agent: Mozilla / 5.0 (Windows NT 10.0; Win64; x64) AppleWebKit / 537.36 (KHTML, like Gecko) Chrome / 75.0.3770.100 Safari / 537.36
Accept: text / html, application / xhtml + xml, application / xml; q = 0.9, image / webp, image / apng, * / *; q = 0.8, application / signed-exchange; v = b3
Referer: http://192.168.1.198/net_config.htm
Accept-Encoding: gzip, deflate
Accept-Language: en-US, en; q = 0.9, bg; q = 0.8
ip = 192.168.1.190 & gw = 192.168.1.1 & sub = 255.255.255.0 & htpt = 80Reboot:
GET /reboot.cgi HTTP / 1.1 r Authorization: Basic YWRtaW46YWRtaW4 = r Accept: * / * r n \ t
I configured the FB like this:
Cambio IP:
Method: 1
HostAddress: 192.168.1.199
HostName: 192.168.1.198
Hostport: 80
Page: net_config.htm HTTP / 1.1
Request: ip = 192.168.1.190 & gw = 192.168.1.1 & sub = 255.255.255.0 & htpt = 80
DBSize: 57Reboot:
Method: 0
HostAddress: 192.168.1.199
HostName: 192.168.1.198
Hostport: 80
Page: reboot.cgi HTTP / 1.1
Request: nAuthorization: Basic YWRtaW46YWRtaW4 = r Accept: * / * r n
DBSize: 61Did I "translate" well?
June 25, 2019 at 3: 14 pm #48330Sergio BertanaAdministrator ForumI see some confused ideas ...
The request for parameter sets is a request in POST, therefore Method: 1 is correct, but HostAddress e HostName they must be the IP address of the server they cannot be different… at the limit HostName could be the host name in the case of multidomain servers.
In Page you just have to put the page HTPP / 1.1 automatically puts it in the FB.
In Request you correctly put the required data, but DBSize put it much larger (I would put 1000).
I see in the example that the field is mentioned Authorization: Basic YWRtaW46YWRtaW4=, this seems to me to be a field to pass in the header of the request to enable the parameter set command. Then switch to the parameter Header:=ADR(Authorization: Basic YWRtaW46YWRtaW4=).
The rest seems to be Ok, but I suggest you try the command with programs like Insomnia o Postman, and when the command works it spies with Wireshark what passes so that it can be compared with what the HTTPClient FB generates.
Simpler is the reboot command, a simple GET command
Method: 0
HostAddress: 192.168.1.199
HostName: 192.168.1.199
Hostport: 80
Page: reboot.cgi
Request: Authorization: Basic YWRtaW46YWRtaW4 =June 26, 2019 at 6: 55 am #48336MarcelloParticipantOn the FB I don't see the Header parameter, my HTTPClient I got it from the eLLabNetworkLib_B210.plclib library.
June 26, 2019 at 6: 56 am #48338Sergio BertanaAdministrator ForumI published the new version of the library you can download it from the download section.
October 19, 2019 at 7: 09 am #50230RuboxParticipantHello, I downloaded the eLLabNetworkLib_B300 library from the download section. I import the HTTPClient_v1 FB in LogicLab and if I compile everything I get an error eLLabNetworkLib_B300.plclib (938) error C002: LD => Invalid token.
If I delete the FB from the project, compile without errors. Where am I wrong?
October 19, 2019 at 7: 11 am #50234Sergio BertanaAdministrator ForumIt seems that you have defined some variable with the name "LD" or something similar, to understand you should send your Logiclab project to our support mail so we can check directly to understand the error.
October 21, 2019 at 6: 47 am #50258RuboxParticipantGood evening, my problem is that it is enough that I define a new empty project, import the HTTPClient FB, create a minimal program by defining a variable "a" and assigning it an arbitrary value (so a single program line of the type a: = 0 ;) and compiling in LogicLab I get that error, even without defining a variable of type HTTPClient.
If I import the other FBs of the library in the same project there is no error, if I import HTTPClient it gives me the error. And I don't know how to fix it, or where I'm wrong.
October 21, 2019 at 6: 55 am #50265Sergio BertanaAdministrator ForumYour problem arises from the fact that you have not put the check on the respect of case letters in the project, by default LogicLab leaves it inactive, you need to manually check it. You will find an indication like this in many forum posts.
The tick should always be activated in the project Case sensivity, in the menu Project-> Options (Screenshot). In this way the case of the letters is checked in the names of variables and functions avoiding to give names to variables that can be in contrast with already predefined names.
Then if you want a complete example of use you can refer to relative knowledge.
October 22, 2019 at 12: 18 pm #50297RuboxParticipantHello, thanks for solving my mistake: I hit my head for two days without it occurred to me that the respect of upper / lower case could cause that error.
Now build me without problems and the most important thing is that it works.
-
AuthorPost
- You must be logged in to reply to this topic.