How to upload an array of numbers to a single field in Thingspeak?
Show older comments
I'm trying to upload data to a field in my ThingSpeak channel. So far I have been able to upload a single number to the field. But when I tried to upload array like x = [1,2,3,4] it would give me this error: "'Values' must be a scalar, a 1-by-n numeric vector, or a cell array and must have the same dimensions as the 'Fields' value."
I'm using thingspeakwrite function like this : thingSpeakWrite(id,'Fields',1,'Values',x,'WriteKey',apikey).
Answers (2)
Walter Roberson
on 10 Dec 2020
x = [1, 2, 3, 4];
thingSpeakWrite(id, 'Fields', length(x), 'Values', x, 'WriteKey', apikey)
5 Comments
Mostafa Ibrahim
on 10 Dec 2020
Walter Roberson
on 10 Dec 2020
Edited: Walter Roberson
on 10 Dec 2020
Hmmm... just maybe
fieldnums = 2;
thingSpeakWrite(id, 'Fields', fieldnums, 'Values', {{x}}, 'WriteKey', apikey)
No promises. I do not have any experience with thingspeak myself, and some of what I read in the past has suggested that for multiple values to the same channel, the mechanism to use is to generate data for multiple timestamps.
Mostafa Ibrahim
on 10 Dec 2020
Walter Roberson
on 10 Dec 2020
You might have to use the timetable form. The examples seem to show one timestamp for each row of the array, and seem to imply that each column is sent to a different field.
Christopher Stapels
on 16 Dec 2020
I think Mostafa wants to write to one field? If so, then 'fields' is just the field number, its not a number of fields to write to unfortunately. To write to multiple fields, use 'Fields', [1 3 4 5],... to write to those four fields. (all with the same timestamp)
That said, Timetables are usually the easiest way to write multiple things as Walter says.
Christopher Stapels
on 16 Dec 2020
Here is one possibility.
thingSpeakWrite(958725, 'Fields', 1, 'Values', join(string(x)), 'WriteKey', writeKey)
or
y = "[ 1 2 3 4]";
thingSpeakWrite(958725, 'Fields', 1, 'Values', y, 'WriteKey', writeKey)
Communities
More Answers in the ThingSpeak Community
Categories
Find more on Data Import and Analysis 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!