ThingSpeak : Read & Write Multiple Field

30 views (last 30 days)
Ravi Ghimire
Ravi Ghimire on 27 Jan 2021
Edited: Vinod on 14 Oct 2021
Hello, Could you please recommend me best method for multiple fields read & right in ThingSpeak?
  1. I want to write in MATLAB Simulink via ThingSpeak Cloud from MIT APP Inventer Application , 4 fields with ( digital write 0,1)?
  2. I want to read 3 field value and read it from MIT App inventor via ThingSpeak Cloud?
i have problem in reading and writing multiple channels , can somebody recommend be the best way.

Answers (3)

Christopher Stapels
Christopher Stapels on 27 Jan 2021
Can you describe the data flow a bit more?
"in MATLAB Simulink via ThingSpeak Cloud from MIT APP Inventer Application "
What is the MIT App interacting with? Is it a deployed simulink model on hardware?
The MIT app will support POST commands (I'm pretty sure), you can post to you channel using the REST API write endpoint. You can update multiple fields simultaneously.
POST https://api.thingspeak.com/update
api_key=XXXXXXXXXXXXXXXX
field1=73
field2=37
etc...
You can also use the GET command and append additional fields
Similarly, you can read the whole feed (all fields ) at once with read data. I would use the JSON format, then you can parse the response for the fields you want.
https://api.thingspeak.com/channels/<channel_id>/feeds.<format>

BEHNAM MOBARAKI .
BEHNAM MOBARAKI . on 20 May 2021
Hi every body.
I am sending temperature measurement of 3 sensors to 3 fields of a channel in ThinSpeak (through NODEMCU ESP8266). What I need is that to do calculation of data from these 3 fields. For instance, I need to take the average of temperature of the 3 sensors at time n, then taking average the 3 measurements at time n+1 then at time n+2. Finaly illustrate the average curve on a single graph.
Could you please help me in this way?!
  3 Comments
BEHNAM MOBARAKI .
BEHNAM MOBARAKI . on 20 May 2021
Many thanks Christopher,
I folloewd the example and it was very usefull. This example takes the average value of the measurements in a single field (lets say a single sensor). In my case, I have 3 fields (each filed is receiving temperature measuremnt from individual sensor). All the sensors have the same measurement frequency. What I need is that to read/take the temperature at time N from all the 3 sensors (in 3 fields), take the average of them and send the average value to a new channel. The second input of the new channel gonna be average value of temperature from the 3 sensors at time N+1.
I mean I wanna do calculation on the inputs of multiple fields and send it to another channel.
Thanks in advance for your help
SHUAI TAN
SHUAI TAN on 19 Aug 2021
brother may i know your code for reading a specific timestep

Sign in to comment.


Nazmi Rosly
Nazmi Rosly on 16 Aug 2021
Edited: Vinod on 14 Oct 2021
Hi. Im trying to send data from matlab which is the data from serial monitor from arduino. It is fine until 9th of data and then it stopped and says :
Error using Untitled (line 27)
'Values' must have a maximum of 9 elements, including the timestamp.
My coding is:
clear all
s = serial('com4');
fopen(s);
i = 1;
while(1)
data(i)= str2double(fscanf(s));
plot(data);
title('Temperature Monitoring')
xlabel('Time')
ylabel('Temperature')
pause(30);
i=i+1;
%thingSpeakWrite(1463959,data,'WriteKey','MYWRITEAPIKEY')
% Generate timestamps for the data
%tStamps = datetime('now')-minutes(9):minutes(1):datetime('now');
channelID = 1463959; % Change to your Channel ID
writeKey = 'MYWRITEAPIKEY'; % Change to your Write API Key
% Write 10 values to each field of your channel along with timestamps
tStamp = datetime('now')
thingSpeakWrite(1463959,data,'WriteKey','MYWRITEAPIKEY','TimeStamp',tStamp)
end
  1 Comment
Christopher Stapels
Christopher Stapels on 14 Oct 2021
You've put too many values in your data array. ThingSpeak only had 8 fields. Perhaps you meant data(i) in your thingSpeakWrite command

Sign in to comment.

Communities

More Answers in the  ThingSpeak Community

Categories

Find more on Write Data to Channel in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!