TimeControl/React App with MATLAB Analysis Code Errors | 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
TimeControl/React App with MATLAB Analysis Code Errors
Avatar
Adarsh_Murthy

Forum Posts: 59
sp_UserOfflineSmall Offline
1
September 22, 2016 - 4:33 pm
sp_Permalink sp_Print sp_EditHistory

When you have MATLAB Analysis code that uses a TimeControl, the TimeControl stops running if there are a number of consecutive errors in the MATLAB Analysis code. You can choose to receive an alert via email by checking the box Notify me via email if this MATLAB Analysis fails when triggered by TimeControl or React in the MATLAB Analysis app. 

To restart the TimeControl, fix the error in the associated MATLAB Analysis App and press the Save and Run button. 

Avatar
piajola

Gold
Forum Posts: 75
sp_UserOfflineSmall Offline
2
September 23, 2016 - 4:22 pm
sp_Permalink sp_Print

Hi Adarsh,

From my Analysis and TimeControls (1 hour frequency). I have "troubles" with two of them

First Analysis ends with Webwrite to Pushingbox server that sometimes reply 502 error and I have a red line in the corresponding Analysis and TimeControl
Second Analysis ends with a try-catch as this:
      try
         webwite(text for 1st try+Timestamp)
      catch
         webwite(text for 2nd try+Timestamp)
until now 1.4 % error 4 red lines in 2 weeks (and 40 catch 263 OK)

* * No one ThingSpeak error email in any case * *

Example of today

First column from first Analysis fired by a TimeControl
Second column from another Analysis fired by another TimeControl

??? is some text plus the timestamp from Thingspeak server

??? >> 20160923T150013           ???--20160923T150406
??? >> 20160923T140011           ???--20160923T140405
??? >> 20160923T130015           ???--20160923T130407
??? >> 20160923T120014           ???--20160923T120408
??? >> 20160923T110014           ???--20160923T110409
??? >> 20160923T100016           ???--20160923T100407
??? >> 20160923T090013           ???--20160923T090407
??? >> 20160923T080014           ???--20160923T080407
??? >> 20160923T070014           ???--20160923T070408
??? >> 20160923T060013           ???--20160923T060406
??? >> 20160923T050017             RED line - No email
??? >> 20160923T040013           ???--20160923T040407
??? >> 20160923T030011           ???--20160923T030406
??? >> 20160923T020014           ???--20160923T020407
??? >> 20160923T010015           ???--20160923T010410
??? >> 20160923T000014           ???--20160923T000406

I understood that a check in Notify sends email?

Thank you in advance

Avatar
Vinod

Forum Posts: 183
sp_UserOfflineSmall Offline
3
September 23, 2016 - 6:11 pm
sp_Permalink sp_Print

The behavior is documented here as "When you have MATLAB Analysis code that uses a React, React stops running if there are a number of consecutive errors in the MATLAB Analysis code. You can choose to receive an alert via email by checking the box Notify me via email if this MATLAB Analysis fails when triggered by TimeControl or React in the MATLAB Analysis app." It is similar for TimeControl apps.

The email is only triggered after the analysis code fails after a number a consecutive errors exceeds a predetermined limit. In the example you gave, the 20160923T050017 execution errored, but the immediate next execution of the analysis at 20160923T040013 executed successfully. This caused the counter on number of consecutive failures is reset back to zero, and since this number never exceeded our predetermined limit, you didn't get an email.

The idea is that we do not want to shut off the MATLAB analysis if it was a temporary failure, such as in your case a failure code from the pushingbox service. If there is a consistent, repeated number of failures, then it needs user intervention, which is when the email is generated.

Also, if you try-catch errors in your code and do not let the errors propagate out of your analyses, the counter of the number of failed executions will not be incremented, ultimately resulting in not getting an email since you will not hit the predetermined limit.

Hope this helps clarify the behavior.

Avatar
piajola

Gold
Forum Posts: 75
sp_UserOfflineSmall Offline
4
September 23, 2016 - 6:31 pm
sp_Permalink sp_Print

Hi Vinod,

Thank you for answering me.Smile

So as the try - catch reduces a lot the Pushingbox server error in accepting data from TS, I would try then a wait before the webwrite in catch, in pseudo code:

               try

                    webwrite

               catch

                    WAIT <- how to put here a 2 seconds "wait" here.  I think a two second wait and then "insist" will work

                    webwrite

 

Is that possible? It seems that there is a slot of time for us to "run" our Analysis in your servers (I think)

 

Thank you in advance for any help Smile

Avatar
Vinod

Forum Posts: 183
sp_UserOfflineSmall Offline
5
September 24, 2016 - 10:06 pm
sp_Permalink sp_Print

If you are looking to send email from MATLAB on some error condition, you can do so following the directions here.

You can generate an app specific password in gmail and use the SENDMAIL function in MATALB inside of your exception handling CATCH clause to send an email on every failure, instead of waiting until the failure count exceeds the limit in ThingSpeak.

I hope this helps!

Avatar
piajola

Gold
Forum Posts: 75
sp_UserOfflineSmall Offline
6
September 26, 2016 - 3:37 pm
sp_Permalink sp_Print

Vinod,

Thank you for your help. And apologies for the delay I was waiting for monday

I will try send SENDMAIL but it seems it sends fixed strings ...

I use pushingbox (the only I am aware) because I can send variables (character strings) so I can report the "alarming" values.

My Analysis work fine every time. When after the process wish to write values to another channel it does that perfectly. No need emails here.

When some process has "alarming" values uses the webwrite to send to pushingbox these variables. Pushingbox composes an email with those variables and are sent to my smartphone service provider (free) email server that also composes a (free) SMS sent to my phone. So I have the email subject in less than 30 seconds after the "alarming" condition. Also report values hourly. Also if there are more than 5 minutes of "no recording data" in my ThingSpeak (base) channel

All my tribulations start when pushingbox refuses the Thingspeak sendings with the "502" response and subsequent red line. And I have no email. That occurs with 2% of sent values. When I can see the red line and "save and run" inmediately (on time) this "repetition" is now accepted by pushingbox and all works. So the question if "catch" is a little delayed the second webwrite will be accepted this time.

Anyway thank you for your time

Avatar
Vinod

Forum Posts: 183
sp_UserOfflineSmall Offline
7
September 26, 2016 - 7:41 pm
sp_Permalink sp_Print sp_EditHistory

Turns out I was wrong and the SENDMAIL function in MATLAB is not supported in MATLAB Analysis apps on ThingSpeak at this time. Let me think of a different solution for you.

Avatar
rw950431

Forum Posts: 252
sp_UserOfflineSmall Offline
8
September 27, 2016 - 2:57 am
sp_Permalink sp_Print

piajola

    Not sure of the details but you can capture the result of webwrite

    resp=webwrite(...)

    then (this is the bit that I dont know)

    if resp.status_code != 200

       pause(60)

       webwrite()

 

Hopefully one of the Matlab gurus will chime in with the correct syntax..

 

      

Avatar
jvasudev

Forum Posts: 12
sp_UserOfflineSmall Offline
9
September 27, 2016 - 1:54 pm
sp_Permalink sp_Print

Piajola,

 

You can use the try, catch construct in MATLAB to catch the errors in your MATLAB Analysis code and add a delay of two seconds as shown below,

try

    webwrite(<Your call>);

catch exception

   % pause the execution for 2 seconds

    pause(2);

    webwrite(<Your call>);

See the documentation for the pause command. Note that pausing for more than 2 seconds is not allowed in MATLAB Analysis code. 

Avatar
piajola

Gold
Forum Posts: 75
sp_UserOfflineSmall Offline
10
September 27, 2016 - 3:10 pm
sp_Permalink sp_Print

Hi Vinod,

Again thank you for your time. After writing my prior response to you I tried sendmail with a red output saying that is not for users of thingspeak I think 

Anyway thank you for your concern 

Avatar
piajola

Gold
Forum Posts: 75
sp_UserOfflineSmall Offline
11
September 27, 2016 - 3:12 pm
sp_Permalink sp_Print

Hi rw950431,

Thank you very much for your post. Will try that magic word "pause" I was thinking it was "wait" or "delay"
Search mathworks help is complicated if you do not have the "exact word"

Regards Smile

Avatar
piajola

Gold
Forum Posts: 75
sp_UserOfflineSmall Offline
12
September 27, 2016 - 3:13 pm
sp_Permalink sp_Print

Hi jvasudev,

Thank you very much for your post.
I have my code with try-catch but sometimes both webwrites fail. It seems the time to catch the "catch exception" is not always enough for the "insist".
So "the ask" for the magical word that can get some more wait before the insist.
Besides now I know the server slot time for us users is 2 sec.
Once, trying a loop that become eternal ended in a red output sayimg I occuped all my turn and get out!

Thanks again

Avatar
rw950431

Forum Posts: 252
sp_UserOfflineSmall Offline
13
September 27, 2016 - 10:21 pm
sp_Permalink sp_Print

Interested to find out if webwrite throws an exception when the remote site returns a 502 error.  My guess is that it wont..

Avatar
piajola

Gold
Forum Posts: 75
sp_UserOfflineSmall Offline
14
September 28, 2016 - 5:07 pm
sp_Permalink sp_Print

Hello rw950431,

Delay ... you know when you write I am sleeping and send my answer when you sleep, and also you live the next day Laugh

The code that ends in webwrite variables fails about 15 % so 15/100 rejects with 502 and the red line in my Analysis.

The code that ends in
       try
          webwrite
       catch
          webwrite

failed about 1 %

Now with pause(1.5) in catch before webwrite 0 fails in almost 2 days. Time will tell ...

I have webwrite in 3 analysis, 2 report each XXhour-0 min and XXHr-4 min. The third runs each 5 min checking there are 5 points of data (each minute I send 1 value) if there are 2 or less points I webwrite how many points are recorded, so this is "random"

In my Analysis when I send
      response = webwrite(....)
it returns
      response =

        1×0 empty char array

When webwrite fails in the Output box I find in red

Error using readContentFromWebService
The server returned the message: "Bad Gateway" for URL, 'http://api.pushingbox.com/pushingbox' (with HTTP response code 502).
Error in webwrite
[varargout{1:nargout}] = readContentFromWebService(connection, options);

In try-catch each webwrite has a very slight different text to know wich one was succesful or the red line if none

Regards Smile

Avatar
rw950431

Forum Posts: 252
sp_UserOfflineSmall Offline
15
September 30, 2016 - 1:01 am
sp_Permalink sp_Print

Thats good news!   Glad to find that try/catch does work as expected.

Forum Timezone: America/New_York

Most Users Ever Online: 114

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