Home > Forum > IEC 61131 Programming (LogicLab) > Use FB HTTPClient for data exchange in JSON
- This topic has 2 replies, 2 participants and was last updated 5 years, 9 months ago da Sergio Bertana.
-
AuthorPost
-
July 10, 2018 at 3: 24 pm #45119Sergio BertanaAdministrator Forum
The JSON format is increasingly used for data scrambling with HTTP servers, so here is a simple example that shows how to send data in JSON to a server. Here is the simple listing of the PHP script to load on the server.
if (isset ($ _ REQUEST ['Post']))
$ RxMessage = $ _ REQUEST ['Post']; //Message received
else
$ RxMessage = file_get_contents (“php: // input”); //Message received// I collect JSON request and return the values.
$ ARx = json_decode ($ RxMessage, true); // Rx data array
echo “IdProbe =”. $ ARx ['IdProbe']. ”, Temperature =”. $ ARx ['Temperature'];To simply test the script from the browser it is possible to pass the parameters in GET, for this reason I have managed the variable "Post". Then from browser to test the script type:
"http://URL/Test.php?Post={"IdProbe": 10, "Temperature": 20.5} "
You will get the answer:
IdProbe = 10, Temperatures = 20.5
Here is the complete program printing HTTPClientExample to transfer to a system SlimLine (Download program).
July 19, 2018 at 2: 34 pm #45126AuthorlessIdleWhere can you download the “eLLabNetworkLib_A700” library necessary to use the “HTTPClient” FB?
July 19, 2018 at 2: 36 pm #45128Sergio BertanaAdministrator ForumYou don't need the library, if you download the post program you will find everything you need inside. If you want to use the HTTPClient FB in other projects, you can simply import it from this project.
Anyway, I put the new version of the library online to download it from the site.
-
AuthorPost
- You must be logged in to reply to this topic.