How to send matrices to ThingSpeak?
Show older comments
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.
Accepted Answer
More Answers (1)
Image Analyst
on 16 Jul 2018
Edited: Image Analyst
on 16 Jul 2018
1 vote
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 Comments
James Holland
on 17 Jul 2018
Image Analyst
on 17 Jul 2018
Not without seeing your cell2table command.
James Holland
on 17 Jul 2018
Edited: James Holland
on 17 Jul 2018
Image Analyst
on 17 Jul 2018
Well of course you need to actually put the actual numerical channel ID (501358) in there instead of the string 'channelID'. Did you do that?
James Holland
on 17 Jul 2018
James Holland
on 17 Jul 2018
Image Analyst
on 17 Jul 2018
I just got my devices and haven't yet set up my channel so you're a bit ahead of me. Maybe you can ask Hans Scharler at the Mathworks. That's who I've been talking to and he's very helpful.
James Holland
on 17 Jul 2018
Héctor Cruz Guardo
on 11 Oct 2019
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
Communities
More Answers in the ThingSpeak Community
Categories
Find more on ThingSpeak in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!