Please correct my | General | 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
Please correct my
Avatar
schabanow

Silver
Forum Posts: 6
sp_UserOfflineSmall Offline
1
December 19, 2017 - 8:35 am
sp_Permalink sp_Print

Hi everybody!
I try to get a dew point' plot (diagram) out of the data from my test channel that successfully represents two fields (humidity and temperature in my garage). It's a pity but I'm not familiar with programming, I just try to write something mine over the pattern is offered in 'Apps' tab at thingspeak.com - below is the text that contains the error(s) in the line that goes 'tempC = thingSpeakRead(readChannelID ... and so on. I just can't understand what that evil compiler wants from poor ignorant user... Please help!

 

% Channel ID to read data from
readChannelID = 177255;
% Humidity Field ID
HumidityFieldID = 2;
% Temperature Field ID
TemperatureFieldID = 1;

% Channel Read API Key
% If your channel is private, then enter the read API
% Key between the '' below:
readAPIKey = 'UV3YQVTASG28SIXF';

tempC = thingSpeakRead(readChannelID, '1', 'readAPIKey');
humidity = thingSpeakRead(readChannelID, '2', 'readAPIKey');

b = 17.62;
c = 243.5;

gamma = log(humidity/100) + b*tempC ./ (c + tempC);
dewpoint = c*gamma ./ (b-gamma);

display (dewPoint, 'Dew point');

% To store the calculated dew point, write it to a channel other
% than the one used for reading data. To write to a channel, assign the
% write channel ID to the 'writeChannelID' variable, and the write API Key
% to the 'writeAPIKey' variable below. Find the write API Key in the right
% side pane of this page.

% TODO - Replace the [] with channel ID to write data to:
writeChannelID = 387198;
% TODO - Enter the Write API Key between the '' below:
writeAPIKey = 'S1CU0CAF9KCQZYG5';

Avatar
cstapels

Gold
Forum Posts: 126
sp_UserOnlineSmall Online
2
December 19, 2017 - 9:08 am
sp_Permalink sp_Print

Welcome to ThingSpeak!  Modifying the template code is definitely a good way to get started.  

You took out the part that lets the thingSpeakRead function know what you mean by '1'.  I've linked the documentation so you can have a look.  

MATLAB functions usually take some standard inputs, and then you need to tell the function if you are adding extra inputs.  Your extras are 'fields' and 'readKey', and the values are 1 and readAPIKey.  The readAPIKey is a variable that holds the data you entered at the top of the script, so it does not get quotes.

Try this syntax, and apply the same thing to the next line:

tempC = thingSpeakRead(readChannelID, 'fields',1,'readKey', readAPIKey);

humidity = thingSpeakRead(readChannelID, 'fields',2,'readKey', 'readAPIKey');

Let us know if that works for you.  

Avatar
schabanow

Silver
Forum Posts: 6
sp_UserOfflineSmall Offline
3
December 20, 2017 - 9:59 am
sp_Permalink sp_Print

Sorry, I haven't any results. It writes errors those I cannot clear out of template offered. Would you please give me a kind of compilable text for this:

readChannelID = 177255;
HumidityFieldID = 2;
TemperatureFieldID = 1;

readAPIKey = 'UV3YQVTASG28SIXF';

tempC = thingSpeakRead(177255, TemperatureFieldID, 'ReadKey', readAPIKey);
humidity = thingSpeakRead(177255, HumidityFieldID, 'ReadKey', readAPIKey);

b = 17.62;
c = 243.5;

gamma = log(humidity/100) + b*tempC ./ (c + tempC);
dewpoint = c*gamma ./ (b-gamma);

display (dewpoint, 'Dew point');

writeChannelID = 387198;
writeAPIKey = 'S1CU0CAF9KCQZYG5'

- - - - - - - - - -

I hope you can understand what I want to do by the text above. Sorry again. I just need a compilable variant, in order to see the differences and understand my mistakes in syntax.

Avatar
cstapels

Gold
Forum Posts: 126
sp_UserOnlineSmall Online
4
December 20, 2017 - 11:25 am
sp_Permalink sp_Print

Your code is almost complete.

thingSpeakRead expects to read from a channel, so the first thing is the channel number.  If its a private channel, you tell the function you are giving it the API key with 'ReadKey' and then you give the read key.  This part you have done fine.  But you also gave it a 1 (or TemperatureFieldID) which it doesn't know what to do with until you tell it.  What you want is to read from field 1 of that channel.  So tell the function what the value 1 is for first.  Add 'fields' before the 1:

tempC = thingSpeakRead(177255,'fields', TemperatureFieldID, 'ReadKey', readAPIKey)

And the same thing for the next line.  If you fix both, it will compile.  Let us know if it doesn't.

 

I see you also included channel information for writing to a channel at the end, but you aren't calling thingSpeakWrite.  If you are trying to write to a channel, have a look at the doc and the Getting started tutorial for more help with that task.  

Avatar
schabanow

Silver
Forum Posts: 6
sp_UserOfflineSmall Offline
5
December 20, 2017 - 1:27 pm
sp_Permalink
Awaiting Moderation

Avatar
schabanow

Silver
Forum Posts: 6
sp_UserOfflineSmall Offline
6
December 21, 2017 - 5:19 am
sp_Permalink sp_Print

WOW it works!
Please don't pay attention to previous post.

Well I put 'fields' before its argument in both strings with called 'thingSpeakRead', and voila - I've got pretty nice result of 4.9 C of dew point in my garage! Great! 

But in the last string I didn't specify 'fields' and its argument - nevertheless plot gets its points and everything works well. Why?

***********

readChannelID = 177255;
readAPIKey = 'UV3YQVTASG28SIXF';
HumidityFieldID = 2;
TemperatureFieldID = 1;
writeChannelID = 387198;
writeAPIKey = 'S1CU0CAF9KCQZYG5';
DewPointFieldID = 1;

tempC = thingSpeakRead(readChannelID, 'fields', TemperatureFieldID, 'ReadKey', readAPIKey);
humidity = thingSpeakRead(readChannelID, 'fields', HumidityFieldID, 'ReadKey', readAPIKey);

b = 17.62;
c = 243.5;

gamma = log(humidity/100) + b*tempC ./ (c + tempC);
dewpoint = c*gamma ./ (b-gamma);

display (dewpoint);
thingSpeakWrite(writeChannelID, dewpoint, 'Writekey', writeAPIKey);

***********

Avatar
schabanow

Silver
Forum Posts: 6
sp_UserOfflineSmall Offline
7
December 21, 2017 - 5:26 am
sp_Permalink sp_Print

And the code above doesn't work without the string

display (dewpoint);

The plot doesn't upgrade in this case. 

Avatar
schabanow

Silver
Forum Posts: 6
sp_UserOfflineSmall Offline
8
December 21, 2017 - 5:50 am
sp_Permalink sp_Print sp_EditHistory

Hahaha... The plot doesn't update itself even with the string 'display (dewpoint)'. It does it only once, when I hit the green button 'Save and Run'. I suspect there's a lack of text in my code...

 

Does the string

display (dewpoint);

work in this code?

 

Update: I've understood the situation with plot's updating. I just set 'recurrence' every 5 min, and the problem was solved.

Update2: 'display' displays the result in the field below the code field. The question's closed.

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online: cstapels, jacktheripper125
18 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:

Nsneilotof

angieus2

goldiepw11

BinanceoSt

gnarender123@gmail.com

edenderest

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

 

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee