Ping and relay with rule

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
skorc99
New user
Posts: 6
Joined: 01 Oct 2019, 10:28

Ping and relay with rule

#1 Post by skorc99 » 24 Oct 2022, 20:50

Hello,
i would like to create rule with ping an reset in case of ping fail. (reset ip cam and router- 2 relays)
Both are connected to relay NC-COM.

This is my rule but at boot relay still goes on to NO. Second problem is that ipcam takes 2 minutes before it is up and running so i at the end i also need delay.

I need to set 2 delays (after boot and after reset)
RULE FOR IPCAM:
__________________________
on System#Boot do
gpio,13,1 // relay NC
endon

HOW TO SET DELAY BEFORE PING SCRIPT

on ipcam_ping#Ping do
if [ipcam_ping#Ping]=0
timerSet,1,5 // 5 s relay to NO
gpio,13,0 // Turn NO
endif
endon
on Rules#Timer=1 do
gpio,13,1 // Turn on relay
endon

HOW TO SET DELAY FOR 2 minutes that Ipcam IS ONLINE AGAIN
___________________________
Thank you,
U

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Ping and relay with rule

#2 Post by TD-er » 24 Oct 2022, 21:08

Not sure if you use an ESP8266 or ESP32.
Anyway, please check this list to pick the best GPIO for this relay: https://espeasy.readthedocs.io/en/lates ... on-esp8266

See here for the timerset command: https://espeasy.readthedocs.io/en/lates ... html#timer

What you can do is you can set a variable.

Code: Select all

on ipcam_ping#Ping do
  if [int#2]=0 and [ipcam_ping#Ping]=0
    timerSet,1,5 // 5 s relay to NO
    gpio,13,0 // Turn NO
  endif
endon

on Rules#Timer=1 do
  gpio,13,1 // Turn on relay
  timerSet,2,120 // 120 sec  timer #2
  let,2,1 // Set [int#2] to 1
endon

on Rules#Timer=2 do
    let,2,0 // Set [int#2] to 0
endon
This way you have set a flag ([int#2]) to 1 to indicate you're still waiting.

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Ping and relay with rule

#3 Post by Ath » 24 Oct 2022, 21:23

skorc99 wrote: 24 Oct 2022, 20:50
I need to set 2 delays (after boot and after reset)

...

HOW TO SET DELAY BEFORE PING SCRIPT

...

HOW TO SET DELAY FOR 2 minutes that Ipcam IS ONLINE AGAIN
A flag in var 1 is used to enable/disable the ping-check

Code: Select all

on System#Boot do
  gpio,13,1   // relay NC
  AsyncEvent,Rules#Timer=1 // just execute that timer 1 event once
endon
on ipcam_ping#Ping do
  if %v1%=0 and [ipcam_ping#Ping]=0
    timerSet,1,5 // 5 s relay to NO
    gpio,13,0 // Turn NO
  endif
endon
on Rules#Timer=1 do
  gpio,13,1 // Turn on relay
  Let,1,1 // Inhibit pingcheck
  TimerSet,2,120 // Reset inhibit after 2 minutes
endon
on Rules#Timer=2 do
  Let,1,0 // Release check inhibit
endon
NB: I'd avoid resetting the router, vs. fixing the actual cause for poor WiFi performance. Resetting the cam isn't unusual, mostly because of poor software quality of many of those cheap cams :?
If you still need/want to check and reset the router too, either you add a separate check, using a separate ping check and timer 3 and 4 (there are 256 timers available), or use just switch another relay at the same time the cam-relay is switched.
/Ton (PayPal.me)

skorc99
New user
Posts: 6
Joined: 01 Oct 2019, 10:28

Re: Ping and relay with rule

#4 Post by skorc99 » 24 Oct 2022, 21:38

I am using wemos d1 mini- gpio is OK.

I tested this script and after boot relays are OK not switching.

Timer is not working and not switching relay.
debug is:
506110: EVENT: ipcam_ping#Ping=1.00
506162: Lev.1: [if 1=0]=false
506182: EVENT: ipcam_ping#Ping=1.00 Processing time:73 milliSeconds
506409: Ping result for:192.168.200.123 1

1005847: EVENT: ipcam_ping#Ping=0.00
1005897: Lev.1: [if 0=0]=false
1005918: EVENT: ipcam_ping#Ping=0.00 Processing time:72 milliSeconds
1006145: Ping result for:192.168.200.123 0

u

skorc99
New user
Posts: 6
Joined: 01 Oct 2019, 10:28

Re: Ping and relay with rule

#5 Post by skorc99 » 24 Oct 2022, 21:57

Ath wrote: 24 Oct 2022, 21:23
skorc99 wrote: 24 Oct 2022, 20:50
I need to set 2 delays (after boot and after reset)

...

HOW TO SET DELAY BEFORE PING SCRIPT

...

HOW TO SET DELAY FOR 2 minutes that Ipcam IS ONLINE AGAIN
A flag in var 1 is used to enable/disable the ping-check

Code: Select all

on System#Boot do
  gpio,13,1   // relay NC
  AsyncEvent,Rules#Timer=1 // just execute that timer 1 event once
endon
on ipcam_ping#Ping do
  if %v1%=0 and [ipcam_ping#Ping]=0
    timerSet,1,5 // 5 s relay to NO
    gpio,13,0 // Turn NO
  endif
endon
on Rules#Timer=1 do
  gpio,13,1 // Turn on relay
  Let,1,1 // Inhibit pingcheck
  TimerSet,2,120 // Reset inhibit after 2 minutes
endon
on Rules#Timer=2 do
  Let,1,0 // Release check inhibit
endon
NB: I'd avoid resetting the router, vs. fixing the actual cause for poor WiFi performance. Resetting the cam isn't unusual, mostly because of poor software quality of many of those cheap cams :?
If you still need/want to check and reset the router too, either you add a separate check, using a separate ping check and timer 3 and 4 (there are 256 timers available), or use just switch another relay at the same time the cam-relay is switched.
Hello,

router and ipcam are on remote location… Router is mobile-5G - it works 99% of time. ipcam is cloud connected because of port blocked on mobile network.. and as you said cheap sw. first i will try only with ipcam reset but i also dont know if ipcam is online on local network when not reachable from cloud.
Shoul i create 2 rules? reset every night at 0:00 and this
ping script to be on shure side?

Your script timer is working- it waits 2 min but at boot relay is switched on- that is not ok.

u

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Ping and relay with rule

#6 Post by Ath » 24 Oct 2022, 22:04

skorc99 wrote: 24 Oct 2022, 21:57 ... but at boot relay is switched on- that is not ok.
I copied that from your original message...
/Ton (PayPal.me)

skorc99
New user
Posts: 6
Joined: 01 Oct 2019, 10:28

Re: Ping and relay with rule

#7 Post by skorc99 » 24 Oct 2022, 22:18

Ath wrote: 24 Oct 2022, 22:04
skorc99 wrote: 24 Oct 2022, 21:57 ... but at boot relay is switched on- that is not ok.
I copied that from your original message...
:D
How to avoid switching on?

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Ping and relay with rule

#8 Post by Ath » 24 Oct 2022, 22:45

Then replace the System#Boot rule with this:

Code: Select all

on System#Boot do
  Let,1,1   // Disable pingcheck until after cam is started
  TimerSet,1,120 // Delay start of cam with 2 minutes
endon
/Ton (PayPal.me)

skorc99
New user
Posts: 6
Joined: 01 Oct 2019, 10:28

Re: Ping and relay with rule

#9 Post by skorc99 » 25 Oct 2022, 08:27

Hello,
TNX- i will test now.

U

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests