upload a matlab cell to a channel | ThingSpeak API | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
upload a matlab cell to a channel
No permission to create posts
September 27, 2018
12:38 pm
Avatar
teratoulis

Silver
Members
Forum Posts: 18
Member Since:
July 20, 2018
sp_UserOfflineSmall Offline

Hi there,

i'm trying to upload a vector a=[1 2 3 4 5] to a thing speak channel, by converting it as a cell first.

However, I get an error.

Is there any way to do it?

thanks

Nikolas

October 5, 2018
10:01 am
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 442
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

What error do you get? Are you trying to upload 1 2 3 4 5 to field 1, or do you want 1 to field 1, and 2 to field 2 etc?
a=[1 2 3 4 5];
I used thingSpeakWrite(chid, a,'WriteKey','XXXXXXXXXXXXXXXX);
and when I read back the data got:
{
"created_at": "2018-10-05T09:54:58-04:00",
"entry_id": 6,
"field1": "1",
"field2": "2",
"field3": "3",
"field4": "4",
"field5": "5",
"field6": null,
"field7": null,
"field8": null
}

October 8, 2018
12:08 pm
Avatar
teratoulis

Silver
Members
Forum Posts: 18
Member Since:
July 20, 2018
sp_UserOfflineSmall Offline

Hi there,

actually I want to upload all the values (1,2,3,4,5) to field 1. So I tried to convert matrix A into cell and then upload it.

However I get an error "Data must be a 1-D cell array."

here is the code:

channelID_1 = xxxxxx;
writeKey_1='xxxxxxxxx';

A=[1 2 3 4 5];

Cell = num2cell(A,1);

thingSpeakWrite(channelID_1,'Fields',[1],'Values', {Cell},'WriteKey',writeKey_1);

thanks a lot

Nikolas

October 9, 2018
8:55 pm
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 442
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

This seemed to work for me:
a=[12 3 4 5 6]
thingSpeakWrite(266256,{a},'writeKey','xxxxxxxxxxxxxxxx');
ned=thingSpeakRead(266256,'readKey','yyyyyyyyyyyyyyyy','outputformat','timetable','field',1)
output:
ned=

Timestamps FieldLabel1
____________________ ________________________________________________________________________________________________

09-Oct-2018 20:52:40 '12 3 4 5 6'

Its a string though, so you might have to do some more conversion after you read it back to get your matrix/array. Ill note your interest in the ability to upload different data types to your channel.
Note that I forgot a space between 1 and 2. (sorry)

October 10, 2018
9:54 am
Avatar
teratoulis

Silver
Members
Forum Posts: 18
Member Since:
July 20, 2018
sp_UserOfflineSmall Offline

Hi again,

thanks for the reply

It actually works but only for 12 values! the problem is that I have 900!!

so imagine something like a=[1 2 3 4.....900];

is it possible to do it?

I used timestamps, but it gets confused! After the first iteration I get the values with a timestamp lets say 1minute (900 minutes)

However, when I re-run it I get different values probably because it gets confused with the time

do you have any ideas how to fix it?

thanks

Nikolas

October 10, 2018
9:56 am
Avatar
teratoulis

Silver
Members
Forum Posts: 18
Member Since:
July 20, 2018
sp_UserOfflineSmall Offline

I have post a similar question named "Clear channels using matlab commands"
thanks!

October 10, 2018
11:25 am
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 442
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

The two questions seem slightly different, so I will address them separately. Hopefully one of my suggestions will help you 😉

You cannot post 900 values to the same field. The limit is 256 characters. Since it posts as a string, you can get to about 80 consecutive integers starting at 1 (with spaces).
Since there are 8 fields, I think you can post about 600 if you split them (but they get longer after 99). You can also use the status and elevation fields. Latitude and longitude have to be numbers so you can only fit one value in there. So I think you might make 700 if lucky in one feed. A feed is a single entry including all fields. You could consider encoding them to get it shorter.

The other method (in your other post) seems to fit your data shape better and makes it easier to track. It will consume more messages though.

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
40 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 261

Vinod: 196

piajola: 85

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Newest Members:

Williampes, esmeraldagx11, lilacs16, loriexo60, ThomasHut, WernerDernnida

Administrators: Hans: 387, lee: 457