How to send matrices to ThingSpeak?

2 次查看(过去 30 天)
Greetings! My project is to read in data from two arduinos and then separate the data into four matrices. These matrices are comprised of 8 values and are sent to ThingSpeak when filled (to 8). My issue is that I am attempting to send 4 matrices to ThingSpeak via this line :
thingSpeakWrite('ChID',{heartRateInputA,temperatureInputA,heartRateInputB,temperatureInputB},'WriteKey','myWriteKey');
When I execute this, the data goes through but only the first column of the 1-D array. How do I send the whole array? Attached below is the rest of my code.
%Uses two sets of nested 'if' loops and variables and ThingSpeak channels
%to read in and parse data from each controller
a = Bluetooth('HC-05',1);
b = Bluetooth('IN',1);
a.ReadAsyncMode = 'continuous';
b.ReadAsyncMode = 'continuous';
fopen(a); %data collector A
fopen(b); %data collector B
%A data points
heartRateVarA=0;
temperatureVarA=0;
%B data points
heartRateVarB=0;
temperatureVarB=0;
col = 1; %column counter for matrices
heartRateInputA = [];
temperatureInputA = [];
heartRateInputB = [];
temperatureInputB = [];
while (a.Status == 'open')&(b.Status=='open')
%if data has been sent to thingSpeak, reset the column counter
if(col == 15)
col=0;
end
col = col+1;
for i=1 : 1 : 2
matchA = fgets(a);
matchB = fgets(b);
testA = contains(matchA,'Celsius');
testB = contains(matchB,'Celsius');
%Test A parsing
if (testA==1)
temperatureVarA=matchA;
else
testA=contains(matchA,'BPM');
if(testA==1)
heartRateVarA=matchA;
end
end
%Test B parsing
if (testB==1)
temperatureVarB=matchB;
else
testB=contains(matchB,'BPM');
if(testB==1)
heartRateVarB=matchB;
end
end
end
%Display read and parsed in data
fprintf('Device 1 : \n\n');disp(col);
fprintf('Heart Rate A : '); disp(heartRateVarA);
fprintf('Temperature A : '); disp(temperatureVarA);
fprintf('Device 2 : \n\n');
fprintf('Heart Rate B : '); disp(heartRateVarB);
fprintf('Temperature B : '); disp(temperatureVarB);
%Removes non-numeric characters from data and sends to respective
%matrix
hInputA = str2double(strrep(heartRateVarA,'BPM: ',''));
tInputA = str2double(strrep(temperatureVarA,'Celsius: ',''));
hInputB = str2double(strrep(heartRateVarA,'BPM: ',''));
tInputB = str2double(strrep(temperatureVarB,'Celsius: ',''));
heartRateInputA(1,col) = hInputA;
temperatureInputA(1,col) = tInputA;
heartRateInputB(1,col) = hInputB;
temperatureInputB(1,col) = tInputB;
%create arbitrary time stamps of same size as data points to send data to
%thingspeak
stamps = [datetime('now')-minutes(length(matchA)-1):minutes(1):datetime('now')]';
pause(2); %pauses for 2 seconds to coincide with arduinos
if(col==8)
col=1;
thingSpeakWrite(501358,{heartRateInputA,temperatureInputA,heartRateInputB,temperatureInputB},'WriteKey','JLS6DXUINWFGI6QD');
end
end
Thanks in advanced.

采纳的回答

James Holland
James Holland 2018-7-17
I was unable to find a way to send an entire matrix into a single ThingSpeak field but found a different method. Refer to my last comment for the method I used.
https://www.mathworks.com/matlabcentral/answers/410613-how-to-send-matrices-to-thingspeak#comment_590228

更多回答(1 个)

Image Analyst
Image Analyst 2018-7-16
编辑:Image Analyst 2018-7-16
You're sending in a cell array since you have braces around your arrays, but since you say it's not working, maybe try converting it to a table variable and sending that in instead.
  9 个评论
James Holland
James Holland 2018-7-17
Thank you! Fortunately, it seems that I have found another method. Since MATLAB was able to send 8 data points to each channel, I just created a channel for each sensor. To display the data neatly, I created a MATLAB visualization to plot the pairs for their corresponding device as such:
hrB = thingSpeakRead(541121,'ReadKey','readKey'); %heart rate from device B
tempB = thingSpeakRead(541123,'ReadKey','readKey'); %temperature data from device B
%create line plot for deviceB
y3 = hrB;
y4 = (tempB/100);
x = (0.1:length(hrB));
thingSpeakPlotYY(x,y3,x,y4,'Color1','red','Color2','blue','YLabel1','Heart Rate','YLabel2','Temperature','Title','Device A');
The above was for Device B but Device A is almost the same.
Héctor Cruz Guardo
Héctor Cruz Guardo 2019-10-11
Hola James Holland, quisiera preguntarte un pequeño problema que manejo con una Tarjeta de Adquisicion de datos DAQ la cual de una entrada me entrega una matriz de salida, como hago para transferir dato por dato obtenido de la matriz a Thingspeak por medio de simulink, gracias

请先登录,再进行评论。

社区

更多回答在  ThingSpeak Community

类别

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

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by