필터 지우기
필터 지우기

How do I write to a ThingSpeak channel from a Raspberry pi via code deployed using the Matlab Coder?

조회 수: 4 (최근 30일)
I am making use of the Matlab Coder to deploy Matlab functionality to a Raspberry pi. I would like to be able to deploy the ability to write to a ThingSpeak channel from the pi. I realise that this is possible using Simulink (via the ThingSpeak block) but was wondering if there is a simple way to do this via code deployed using the Matlab Coder. I have tried the obvious and found that the Matlab Coder does not recognise the ThingSpeakWrite command. However, it also doesn’t appear to be very straightforward to deploy http methods to enable updating the channel via the POST method. Any advice welcome.
  댓글 수: 1
John Anderson
John Anderson 2019년 6월 21일
Using curl via the system command deploys via the coder without any problems. Not sure if it the most sensible way but does enable updating of a thingSpeak channel and is very easy to implement. Example code below adds random number to field 1 of channel.
% raspberry pi object
r = raspi();
% log file
fid = fopen( 'logFile.log', 'w' );
% write random number to thingSpeak channel
v = rand;
commandStr = [ 'sudo curl -s "https://api.thingspeak.com/update.json?api_key=<your api key here>&field1=' sprintf( '%f', v ) '"' ];
result = system( r, commandStr );
% log command
fprintf( fid, '%s \n', commandStr );
% log result
fprintf( fid, '%s \n', result );
% close log
fclose( fid );

댓글을 달려면 로그인하십시오.

답변 (1개)

Vinod
Vinod 2019년 9월 10일
편집: Vinod 2019년 9월 10일
As you said, there is a block in the Raspberry Pi Support Package that you can use.
Curious why you don't want to use the built-in blocks.
  댓글 수: 5
Raphael Mukaro
Raphael Mukaro 2020년 11월 24일
John, thanks man for your brilliance! I can now update my thingspeak channel using the pi via code deployed using MATLAB coder. I have been struggling for months. Appreciated!!!

댓글을 달려면 로그인하십시오.

커뮤니티

더 많은 답변 보기:  ThingSpeak 커뮤니티

카테고리

Help CenterFile Exchange에서 Modeling에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by