is it possible to store a state variable, which can be read from different sessions of matlab analysis ? | MATLAB IoT Analytics | 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
is it possible to store a state variable, which can be read from different sessions of matlab analysis ?
No permission to create posts
June 27, 2019
1:08 am
Avatar
quaxman
New Member
Members
Forum Posts: 1
Member Since:
June 27, 2019
sp_UserOfflineSmall Offline

Hello everybody,

I send a data point in a fixed interval to thing speak - e.g. every hour. When no data is available after 80 minutes - there is a problem and a Twitter alarm message shall be sent.
There should be only one message. The next time the analysis is called, it should know that the message has already been sent.

I would like to store a flag "message_sent" which is available in the next thingspeak analysis session - but this seems not to be possible.

Is there a way how to do this ?

Background
I monitor the electrical power at home - when no data point is sent this usually means that the fuse shut down the electricity - which should be fixed soon as the refrigerator will get warm.

June 28, 2019
10:40 am
Avatar
cstapels
Moderator
Members


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

for my plant monitor, I use a thingspeak field to store the state variable that tells me i've already set en email to water the plant.. You have to make sure to update the value on every write, or use a seperate channel for the derived data, as I do, but it is definitely possible.
You can also write to the metadata for the channel to store a flag. That will not effect the feeds.

Here is the MATLAB analysis I use.

% Enter your MATLAB Code below
channelID=276330;

data=thingSpeakRead(channelID,'ReadKey','xxxxxxxxxxxxxxxxx','NumDays',90,'Fields',[1 7 8 ]);
dryValue=prctile(data(:,1),15)

%find out if an email has already been sent
email_flag=str2num(webread('https://api.thingspeak.com/channels/472367/fields/6/last.txt'));
wetValue=prctile(data(:,1),90)
midValue=(dryValue+wetValue)/2
currentValue=data(end,1)
if (currentValue>midValue)
if (currentValue>wetValue)
message='The plant is too wet.'
email_flag=0;
else
message='The soil is wet.'
email_flag=0;
end
end
if (currentValue<midValue)
if (currentValue>dryValue)
message='Water needed soon!'
else
message='Dry!'
if email_flag==0
webwrite('email API service');
email_flag=1;
end
end
end

webwrite('https://api.thingspeak.com/update','api_key','xxxxxxxxxxxxxxxx','status',message,...
'timeout',10,'field1',data(end,1)/wetValue,'field2',data(end,2),'field3',data(end,3),...
'field6',string(email_flag),'field8',wetValue);

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
17 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

khanhNguyen_CT, susyburr, quijano__, meosuckhoe, briskpanda, Dejw0089

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457