Function 'webread' not supported for code generation Matlab - ThingSpeak - Raspberry Pi

8 ビュー (過去 30 日間)
Hello everybody!
I need to use a Raspberry Pi that get data from a ThingSpeak channel in a standalone configuration, but the problem is that functions ThingSpeakRead and webread are not supported. What can I do?
direccion=['https://api.thingspeak.com/channels/' chId '/feeds.json?api_key=' Read '&results=' cPoints];
datos=webread(direccion);
Function 'webread' not supported for code generation

採用された回答

Vinicio Moya
Vinicio Moya 2021 年 6 月 29 日
commandStr = [ 'sudo curl -s "https://api.thingspeak.com/update.json?api_key=' sprintf('%s', Write) '&field1=' sprintf( '%f', dato1 ) ' &field2=' sprintf( '%f', dato2) ' &field3=' sprintf( '%f', dato3) ' &field4=' sprintf( '%f', dato4) ' " ' ];
response = system(mypi, commandStr);

その他の回答 (2 件)

Denis Gurchenkov
Denis Gurchenkov 2021 年 6 月 29 日
Yes, you are right, webread() does not support code generation. As a workaround, you can use coder.ceval functon to call a hand-written C function that opens the connection, reads and decodes the data, and returns the data back to MATLAB code. It is a bit complicated : you would need to maintain two branches in your MATLAB code, one for normal MATLAB execution, the other one for Raspberry Pi, and use coder.target to switch between those.
In order to impelment the C fucntion that does the http read, you can use one of the opensource free HTTP libraries that are available (libcurl is availalbe on raspberry pi?). An alternative is to just invoke curl using system() command. Would this approach work for you?

Vinod
Vinod 2021 年 6 月 27 日
編集済み: Vinod 2021 年 6 月 27 日
Rather than use webread, why not use the blocks in the support package ?
  1 件のコメント
Vinicio Moya
Vinicio Moya 2021 年 6 月 27 日
Because those blocks are used in Simulink, and I only want to use Matlab.

サインインしてコメントする。

コミュニティ

その他の回答  ThingSpeak コミュニティ

カテゴリ

Help Center および File ExchangeThingSpeak についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by