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

14 Ansichten (letzte 30 Tage)
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!

Akzeptierte Antwort

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

Weitere Antworten (3)

Walter Roberson
Walter Roberson am 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.

Mario Frischmann
Mario Frischmann am 2 Sep. 2017
Same question here!
  3 Kommentare
Mario Frischmann
Mario Frischmann am 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

Melden Sie sich an, um zu kommentieren.


Rodolfo Ribeiro
Rodolfo Ribeiro am 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

Kategorien

Mehr zu Block and Blockset Authoring finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by