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

16 次查看(过去 30 天)
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!

采纳的回答

Timo Müller
Timo Müller 2017-9-4
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.

更多回答(3 个)

Walter Roberson
Walter Roberson 2017-9-3
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.

Mario Frischmann
Mario Frischmann 2017-9-2
Same question here!
  3 个评论
Mario Frischmann
Mario Frischmann 2017-9-8
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

请先登录,再进行评论。


Rodolfo Ribeiro
Rodolfo Ribeiro 2019-1-5
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

类别

Help CenterFile Exchange 中查找有关 Embedded Coder 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by