MATLAB Answers

0

Is it possible to send HTTP GET Requests from a Simulink Block ?

Asked by Timo Müller on 18 Aug 2017
Latest activity Answered by Rodolfo Ribeiro on 5 Jan 2019
Hey there,
basically the title says it all. I'm working on a model that needs (there is no way around it) to load data from a website, parse it and pass it onto another block. I thought I could use an S-Function written in C++, which didn't properly work, then I tried to use
webread()
which also didn't work in Simulink because I can't use extrinsic functions on the device this will run on.
I thought I could work around it by downloading the file externally and then reading it through
fscanf
but it turned out that Matlab CODER doesn't support that as well. After putting 2 1/2 days into this now, I'm asking myself whether it is even possible to do something like an HTTP Request through a Simulink block. That's why I went here to ask exactly that question. Thanks for every answer!

  0 Comments

Sign in to comment.

4 Answers

Answer by Timo Müller on 4 Sep 2017
 Accepted Answer

First of all, thank you for your answers! I figured out how I could do it with C++ and S-Functions, so I now got a working demo that I uploaded to GitHub.
For everyone who also has a similar problem, take a look at it, i'm sure it will help you.
Click here for the GitHub Repository.

  0 Comments

Sign in to comment.


Answer by Walter Roberson
on 3 Sep 2017

You should generally be able to use a C or C++ S-function. You should generally also be able to use a MATLAB Function Block with a coder.ceval()
You mention a device that this has to run on, implying that you are using Deploy To Target. Whatever C or C++ you call must link to an implementation of TCP for that device. Finding an appropriate library can be a problem.
If you just happen to be using Arduino, then there are TCP blocks for Arduino that I think can be deployed.
The TCP blocks from the Instrument Control Toolbox cannot be deployed.

  0 Comments

Sign in to comment.


Answer by Mario Frischmann on 2 Sep 2017

Same question here!

  3 Comments

Take a look at this. It's a repository I created with Matlab Simulink S-Function (C++) Code, that can be compiled. It is a demo that performs an HTTP GET Request with cURL.
Thanks a lot Timo! I tried to compile the sfunction but I am getting this error!
Creating library sfunc.lib and object sfunc.exp
sfunc.obj : error LNK2019: unresolved external symbol __imp_curl_global_init referenced in function "void __cdecl mdlOutputs(struct
SimStruct_tag *,int)" (?mdlOutputs@@YAXPEAUSimStruct_tag@@H@Z)
sfunc.obj : error LNK2019: unresolved external symbol __imp_curl_easy_init referenced in function "void __cdecl mdlOutputs(struct
SimStruct_tag *,int)" (?mdlOutputs@@YAXPEAUSimStruct_tag@@H@Z)
sfunc.obj : error LNK2019: unresolved external symbol __imp_curl_easy_setopt referenced in function "void __cdecl mdlOutputs(struct
SimStruct_tag *,int)" (?mdlOutputs@@YAXPEAUSimStruct_tag@@H@Z)
sfunc.obj : error LNK2019: unresolved external symbol __imp_curl_easy_perform referenced in function "void __cdecl mdlOutputs(struct
SimStruct_tag *,int)" (?mdlOutputs@@YAXPEAUSimStruct_tag@@H@Z)
sfunc.mexw64 : fatal error LNK1120: 4 unresolved externals
Did I include/installed the libaries wrong?
Grettings and Thanks

Sign in to comment.


Answer by Rodolfo Ribeiro on 5 Jan 2019

Hello,
I struggled for a day to find the solution for this. Those errors are actually related to the "Linker". Basically what you have to do is to pass as arguments to the mex command the lib files that contain those missing definitions. I successfully compiled his cpp file with the follwing line
mex sfunc.cpp -Ibuilds\libcurl-vc15-x64-release-static-ipv6-sspi-winssl\include\ -lbuilds\libcurl-vc15-x64-release-static-ipv6-sspi-winssl\lib\libcurl_a.lib -lWS2_32.lib -lWldap32.lib -lCrypt32.lib -lNormaliz.lib -DCURL_STATICLIB

  0 Comments

Sign in to comment.