Update Channel from output | MATLAB | 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
Update Channel from output
No permission to create posts
January 18, 2018
1:49 pm
Avatar
jacktheripper125

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

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.

January 19, 2018
10:51 am
Avatar
jacktheripper125

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

Bumpy road

January 19, 2018
11:48 am
Avatar
jacktheripper125

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

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  🙁

January 19, 2018
1:01 pm
Avatar
turgo

Gold
Members
Forum Posts: 70
Member Since:
June 16, 2013
sp_UserOfflineSmall Offline

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!

January 19, 2018
1:43 pm
Avatar
jacktheripper125

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

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.

January 19, 2018
9:34 pm
Avatar
Vinod

MathWorks
Members
Forum Posts: 206
Member Since:
May 1, 2016
sp_UserOfflineSmall Offline

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.

January 20, 2018
1:40 am
Avatar
turgo

Gold
Members
Forum Posts: 70
Member Since:
June 16, 2013
sp_UserOfflineSmall Offline

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:
20 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:

terranceqh2, DianeEmids, Alanawaype, uqovitay, ufijifode, manish01

Administrators: Hans: 387, lee: 457