Is it possible to send HTTP GET Requests from a Simulink Block ?
Afficher commentaires plus anciens
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!
Réponse acceptée
Plus de réponses (3)
Walter Roberson
le 3 Sep 2017
1 vote
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.
... Is it possible that you are using Real Time Target? If so then see https://www.mathworks.com/company/newsletters/articles/tcpip-communication-for-real-time-and-embedded-systems.html
Mario Frischmann
le 2 Sep 2017
0 votes
Same question here!
3 commentaires
Timo Müller
le 4 Sep 2017
Mario Frischmann
le 8 Sep 2017
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
le 5 Jan 2019
0 votes
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
Catégories
En savoir plus sur Simulink Coder dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!