Update Channel from output | MATLAB | Forum

Avatar

Please consider registering
Guest

Search

— Forum Scope —






— Match —





— Forum Options —





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

Register Lost password?
sp_Feed sp_TopicIcon
Update Channel from output
Avatar
jacktheripper125

Silver
Forum Posts: 15
sp_UserOfflineSmall Offline
1
January 18, 2018 - 1:49 pm
sp_Permalink sp_Print sp_EditHistory

ANYONE OUT THERE WHO CAN HELP??

 

can anyone help on what i need to send the data from a matlab output to a field on thingspeak?

this is my current code.......

% Enter your MATLAB Code below

opts = weboptions('Timeout',15);
data = webread('https://api.thingspeak.com/apps/thinghttp/send_request?api_key=PC4EOCTMNDPPQOSW',opts)
writeChannelID = xxxxx;

% TODO - Enter the Write API Key between the '' below:
writeKey = 'xxxxxxxxxx';

thingSpeakWrite(writeChannelID,data', writeKey);

but it comes up with this in the output????

 
data =

'
18
6
60
88
'

Error using READ TEMP (line 10)
Error using thingSpeakWrite
Expected a string scalar or character vector for the parameter name.

Avatar
jacktheripper125

Silver
Forum Posts: 15
sp_UserOfflineSmall Offline
2
January 19, 2018 - 10:51 am
sp_Permalink sp_Print

Bumpy road

Avatar
jacktheripper125

Silver
Forum Posts: 15
sp_UserOfflineSmall Offline
3
January 19, 2018 - 11:48 am
sp_Permalink sp_Print

I have now got to 

this is my current code.......

% Enter your MATLAB Code below
opts = weboptions('Timeout',15);
data = webread('https://api.thingspeak.com/apps/thinghttp/send_request?api_key=PC4EOCTMNDPPQOSW',opts)
writeChannelID = xxxxx;
% TODO - Enter the Write API Key between the '' below:
writeKey = 'xxxxxxxxxx';
thingSpeakWrite(writeChannelID, data, writeKey);

but it comes up with this in the output????

Lounge_Temp
18
Loft_Temp
6
Lounge_Humidity
62
Loft_Humidity
88
' must be a string scalar or character vector that can represent a field name.

Any ideas how to fix?

im not sure the blank lines are causing this but there is no help at all for thingspeak. such a shame as im sure it is just a little bit of code im missing but no one on the forum no help, and no real support unless i want to pay 200 for it?. maybe I should abandon thingspeak  🙁

Avatar
turgo

Gold
Forum Posts: 70
sp_UserOfflineSmall Offline
4
January 19, 2018 - 1:01 pm
sp_Permalink sp_Print

Use "display(data);" to see what exactly you are sending to thingspeakwrite.  Check out the data format expectations in the documentation for thingspeak write.  Change your code to get the format right.  Good luck!

Avatar
jacktheripper125

Silver
Forum Posts: 15
sp_UserOfflineSmall Offline
5
January 19, 2018 - 1:43 pm
sp_Permalink sp_Print

Thank you for your help, But the data comming in seems fine. I have even got rid of the the spaces before and after from the server but now I just cant get the code to push it to the fields into the channel

my code is below (including your display data) and the output.

What i need is the code to get the it to the fields. but nothing I try has worked? why is it so difficult??

the field names are there and they match my fields I am guessing that I need to push them to the database but nothing I have tried gets any part of it to the database.

 

data = webread('https://api.thingspeak.com/apps/thinghttp/send_request?api_key=PC4EOCTMNDPPQOSW',opts)
writeChannelID = 405063;

writeKey = 'UGEUH8A5T1V9AFA9';

display(data);

thingSpeakWrite(writeChannelID, data, writeKey);

 

 my output is 

data =

'Lounge_Temp
17
Loft_Temp
6
Lounge_Humidity
64
Loft_Humidity
88'

data =

'Lounge_Temp
17
Loft_Temp
6
Lounge_Humidity
64
Loft_Humidity
88'

Error using READ TEMP (line 13)
Error using thingSpeakWrite
Unmatched parameter name 'Lounge_Temp
17
Loft_Temp
6
Lounge_Humidity
64
Loft_Humidity
88' must be a string scalar or character vector that can represent a field name.

Avatar
Vinod

Forum Posts: 189
sp_UserOfflineSmall Offline
6
January 19, 2018 - 9:34 pm
sp_Permalink sp_Print sp_EditHistory

You can use a single MATLAB analysis to scrape your data, parse the different fields and write it to 4 fields of a channel, or 4 different channels, if that is what you wish.

The example I wrote is in this post.

Avatar
turgo

Gold
Forum Posts: 70
sp_UserOfflineSmall Offline
7
January 20, 2018 - 1:40 am
sp_Permalink sp_Print

It looks to me like your 'data' is a string with line feeds in it.  I bet that thingspeakwrite doesn't like that.  The documentation shows that thingspeakwrite expects data types:

data

— Data to write to channel
array | numeric | table | timetable

 

I'd look for some slick matlab command to load your string with line feeds into a table.

You could also try commas instead of line feeds.

This stuff is hard.  You'll get it.

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
35 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 252

Vinod: 164

cstapels: 96

piajola: 75

vespapierre: 63

Adarsh_Murthy: 59

Newest Members:

ibgedubo

aogomaeqaza

ureomug

itixuwidouzuv

eilimir

memozupi

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

 

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee