How do I send a "Power Cycled" e-mail?

PERFECT! (Almost…)
This event driven check does not properly set the VPN Active flag (My_Bit@) if the script is stopped and restarted. It reads as OFFLINE, when in fact it is ONLINE.

So, by combining your two code examples, I wound up with the following, which seems to work pretty well. There’s still a delay for the Offline event after I unplug the WAN cable of up to 30 seconds… however, that’s better than what I had.

INIT Section:
SETSYS INF, “LOAD”
a$ = GETSYS INF, “VPNIP”
IF(a$ <> “0.0.0.0”) THEN
PRINT “eWON is online”
eWON_Online@ = 1
ELSE
PRINT “eWON is offline”
eWON_Online@ = 0
ENDIF
ONVPN “GOTO ONLINE_TEST”
End

ONLINE_TEST:
w% = GETSYS PRG, “EVTINFO”
IF w% = 1 THEN
Print “VPN ONLINE”
eWON_Online@ = 1
ELSE
Print “VPN OFFLINE”
eWON_Online@ = 0
ENDIF
End

Thanks for your help!

1 Like

Hello again!

Well, this solution has worked well for the last few months, but I’m back with a slight bug that maybe you can help me with.

From time to time, we will have a power outage that resets our eWON, but does NOT power cycle the PLC or vice versa. As a result, we may have a case where the PUTHTTP command in our script fails a POST command transmission. It looks like that PUTHTTP command will return a fault value in the status code.

Do you have some sort of retry sample code written to show how to wait a while and then execute that PUTHTTP command again… and what to do if it fails over and over?

Hey Mitchell,

How long do you want to wait before it sends out the PUTHTTP command?

In many cases, the internet connection comes back within 3-5 minutes. In other cases, it might be down for an hour.

Our thought was we would wait one minute for the first retry, and if that failed we would rebroadcast every five minutes until connectivity was restored. We have a local tag that tells us if the VPN is Offline, so there’s no need to rebroadcast in that condition.

This re-broadcasting would only be needed when the VPN is showing as ONLINE, but the PUTHTTP message fails.

I think I can write up something for a case like this, I’ll just need a little time to put it together

You’re saying that you have a tag that lets you know if you’re connected to your plc though right?

Take your time… I’m sure you could come up with it better and quicker than I could.

As far as the tag, no… we have a PLC tag that tells us if the eWON loses the VPN.
We could always add a new tag to determine eWON connectivity to the PLC, but I’m not sure how we’d do that either.

hmmmm…
Is there a GETSYS read that would tell me if the PLC is connected to the eWON??

I had written something earlier that would send out an email if the ewon stopped reading a device’s heartbeat. Do you know if there’s a heartbeat on this PLC that I could use and just modify that old code?

I could certainly add a tag with a heartbeat (watchdog). What time period should it be?

I guess it doesn’t really matter how fast the heartbeat is, but the way it worked was it was a binary heartbeat and would send out an email if it didn’t see a change in value of either a 1 or 0 over the course of a time period. For the example I did, I think it would go off if it was idle for 5 minutes

We might have gotten a little off track here.

Our current system copies all of our alarm variables over to the eWON’s registers ONLY if the eWON tells us that the VPN is active. The watchdog part wouldn’t hurt but is a secondary concern.

If the VPN is active and the PLC successfully passes the alarm registers over to the eWON, and some alarm bits have changed state, then the script sends out POST commands to our web server.

The part we’re having issues with is that if we try to send the POST commands and the SETHTTP instruction faults, there is no retry mechanism… so the message never makes it to the web server and is lost forever. We would like to retry until successful (and temporarily suspend retry attempts while the VPN is offline).

Hey Mitchell,

Could you give me a call at 312 893 5636 tomorrow morning? I just want to make sure we both have an idea on what we’re planning on doing.

Thanks,
Tim

Just as a heads up,

This was the code I was planning on basing the code for you on.

-Tim

Hey Mitchell,

I think that this should work

sendtomitch.txt (1.8 KB)

Hey Mitchell,

Just wanted to do a follow up on this ticket to see if that code worked for you

Thanks,
-Tim

My boss gave me a different (more urgent) task to complete, and I have not had a chance to get back on this issue. I do appreciate how quickly you put this together. I will certainly get back on this in the next week or so and let you know.

Hi Tim,

To adapt your code example to our own application, the script command we are looking to check in our existing program is :
PUTHTTP “m2u.talk2m.com”,"/post_ewon.php",z$,"","POSTERROR"

In the event that this command returns a fault, I assume that the string “POSTERROR” would be returned somehow? If so, what line(s) of code would make this an actionable trigger? I’m guessing that I’d need to do something like this:
e% = GETSYS Prg,"EVTINFO"
in order to acquire the “was it faulted” flag???

If that’s correct…
Could I use e% = “POSTERROR” to trigger a fault event?
What would e% be in the case of no fault? A null string?

If so, I then assume that:
IF e% = POSTERROR" THEN
TSET 1,120
ONTIMER 1,"@Retry()"
ENDIF
…would be a way to activate a timer to define a timer and resend the failed command after 120 seconds? …or do I not want to keep doing TSET commands for each new instance of an error?

If this is all good, then I assume that we’d need to do the test backwards and disable the timer if there was NO error. So… something like this?

Function Retry()
PUTHTTP “m2u.talk2m.com”,"/post_ewon.php",z$,"","POSTERROR"
e% = GETSYS Prg,"EVTINFO"
IF e% <> POSTERROR" THEN
(How do you turn off a timer??)
EndIf
EndFn

Let me know if I’m in the neighborhood or out in the suburbs.
Thanks!

Hmmm… after digging a little further, the “POSTERROR” isn’t a problem with a lack of communication, it’s the string our website returns if it can’t interpret the POST command.

That is NOT what I’m looking for.

I want to react to the GETHTTP command failing to execute properly due to a loss of communication to the outside world (for example).

My coworker just sent me a link he found a while back…
I wonder if THIS is what I’m really looking for??

https://developer.ewon.biz/content/use-onstatus-function-check-result-scheduled-action

Hi Mitchell,

Tim is out this week so I wanted to check if this issue is urgent and you need help right away or if you want to wait for him to get back to follow up.

Thanks,
Kyle

It’s all good… this is not urgent.

However, if there is a resource on your side that knows the scripting language as good as Tim, perhaps they could look this over and get back to me this week. The thread should have enough information for them to comment or make a suggestion.