Need some failover help

I have been deploying a lot of routerboards lately. They are powerful and reliable but I am completely stuck on something. The scenario is I have a customer that has two WAN links. The primary is business class high speed and the other is a DSL that needs to be a backup. Both of these links pull an IP address via PPPoE client. What I would like set up is the primary link to probe to an external public IP address (say google's public DNS) and after so many failed pings it fail over to the DSL. A co-worker and I have been playing around with the following script:

Please fill the WAN interface names

:local InterfaceISP1 ether1-wireless
:local InterfaceISP2 ether2-DSL

Please fill the gateway IPs (or interface names in case of PPP)

:local GatewayISP1 pppoe-outwireless
:local GatewayISP2 pppoe-outdsl

Please fill the ping check host - currently: resolver1.opendns.com

:local PingTarget 8.8.8.8

Please fill how many ping failures are allowed before fail-over happens

:local FailTreshold 5

Define the distance increase of a route when it fails

:local DistanceIncrease 2

Editing the script after this point may break it

-------------- stop editing here --------------



\

Declare the global variables

:global PingFailCountISP1
:global PingFailCountISP2

This inicializes the PingFailCount variables, in case this is the 1st time the script has ran

:if ([:typeof $PingFailCountISP1] = "nothing") do={:set PingFailCountISP1 0}
:if ([:typeof $PingFailCountISP2] = "nothing") do={:set PingFailCountISP2 0}

This variable will be used to keep results of individual ping attempts

:local PingResult


\

Check ISP1

:set PingResult [ping $PingTarget count=1 interface=$InterfaceISP1]
:put $PingResult

:if ($PingResult = 0) do={
:if ($PingFailCountISP1 < ($FailTreshold+2)) do={
:set PingFailCountISP1 ($PingFailCountISP1 + 1)

:if ($PingFailCountISP1 = $FailTreshold) do={
:log warning "ISP1 has a problem en route to $PingTarget - increasing distance of routes."
:foreach i in=[/ip route find gateway=$GatewayISP1 && static] do=
{/ip route set $i distance=([/ip route get $i distance] + $DistanceIncrease)}
:log warning "Route distance increase finished."
}
}
}
:if ($PingResult = 1) do={
:if ($PingFailCountISP1 > 0) do={
:set PingFailCountISP1 ($PingFailCountISP1 - 1)

:if ($PingFailCountISP1 = ($FailTreshold -1)) do={
:log warning "ISP1 can reach $PingTarget again - bringing back original distance of routes."
:foreach i in=[/ip route find gateway=$GatewayISP1 && static] do=
{/ip route set $i distance=([/ip route get $i distance] - $DistanceIncrease)}
:log warning "Route distance decrease finished."
}
}
}


\

Check ISP2

:set PingResult [ping $PingTarget count=1 interface=$InterfaceISP2]
:put $PingResult

:if ($PingResult = 0) do={
:if ($PingFailCountISP2 < ($FailTreshold+2)) do={
:set PingFailCountISP2 ($PingFailCountISP2 + 1)

:if ($PingFailCountISP2 = $FailTreshold) do={
:log warning "ISP2 has a problem en route to $PingTarget - increasing distance of routes."
:foreach i in=[/ip route find gateway=$GatewayISP2 && static] do=
{/ip route set $i distance=([/ip route get $i distance] + $DistanceIncrease)}
:log warning "Route distance increase finished."
}
}
}

It seems once the primary WAN is disconnected, a default route isn't created for the backup. Anyone see a problem or have a different solution that may work better? Either way I would really like to keep the probing method. I attached the actual script since tab spaces don't show up in the body of text on here.

Edit: I realized I posted this in the incorrect section. Can I have this moved to scripting?
Mikrotik PPPoE failover.rsc (3.24 KB)

This is where the script is from.
http://wiki.mikrotik.com/wiki/Failover_Scripting

Follow the instructions.

i believe the problem here is that the 2nd route needs to be already set up with a distance of 2.

on another note. does this need to be set up on a scheduler so it keeps checking or is that built in to the script already?

When I set up multiple WAN last I used PCC, but it works best if you have even speed links, and I’m not sure how you would implement PPPOE into it.
http://wiki.mikrotik.com/wiki/Manual:PCC#Example