--- /rom/usr/lib/rooter/connect/get_profile.sh	2020-01-29 11:06:05.000000000 -0500
+++ /usr/lib/rooter/connect/get_profile.sh	2020-03-30 10:40:40.000000000 -0400
@@ -9,6 +9,11 @@
 	logger -t "Get Profile" "$@"
 }
 
+nth() {
+	shift $1
+	echo $1
+}
+
 CURRMODEM=$1
 
 MODEL=$(uci get modem.modem$CURRMODEM.model)
@@ -174,6 +179,15 @@
 							uci add_list modem.pinginfo$CURRMODEM.trackip=$value
 						}
 						config_list_foreach "$config" trackip handle_trackip
+						config_get methods $1 methods
+						[ -n "$methods" ] || methods=$alive
+						handle_methods() {
+							local value="$1"
+							uci add_list modem.pinginfo$CURRMODEM.methods=$value
+						}
+						config_list_foreach "$config" methods handle_methods
+						alive=$(nth 1 $methods)
+						uci set modem.pinginfo$CURRMODEM.alive=$alive
 						TIP=$(uci get modem.pinginfo$CURRMODEM.trackip)
 						if [ -z $TIP ]; then
 							uci add_list modem.pinginfo$CURRMODEM.trackip="1.1.1.1"
@@ -235,6 +249,15 @@
 			uci add_list modem.pinginfo$CURRMODEM.trackip=$value
 		}
 		config_list_foreach "default" trackip handle_trackip1
+		config_get methods "default" methods
+		[ -n "$methods" ] || methods=$alive
+		handle_methods() {
+			local value="$1"
+			uci add_list modem.pinginfo$CURRMODEM.methods=$value
+		}
+		config_list_foreach "default" methods handle_methods
+		alive=$(nth 1 $methods)
+		uci set modem.pinginfo$CURRMODEM.alive=$alive
 		TIP=$(uci get modem.pinginfo$CURRMODEM.trackip)
 		if [ -z $TIP ]; then
 			uci add_list modem.pinginfo$CURRMODEM.trackip="1.1.1.1"
--- /rom/usr/lib/rooter/connect/conmon.sh	2020-01-29 11:06:05.000000000 -0500
+++ /usr/lib/rooter/connect/conmon.sh	2020-03-31 11:13:23.000000000 -0400
@@ -8,6 +8,17 @@
 	logger -t "Connection Monitor" "$@"
 }
 
+nth() {
+	shift $1
+	echo $1
+}
+
+success() {
+	UP_SINCE_LAST_RECONNECT=YES
+	METHOD_INDEX=1
+	echo 1 >/tmp/method_index
+}
+
 CURRMODEM=$1
 
 power_toggle() {
@@ -32,16 +43,31 @@
 
 do_down() {
 	echo 'MONSTAT="'"DOWN$1"'"' > /tmp/monstat$CURRMODEM
+	if [ "$UP_SINCE_LAST_RECONNECT" = "YES" ]; then
+		METHOD_INDEX=1
+	else
+		config_get MAX_INDEX pinginfo$CURRMODEM methods_LENGTH
+		if [ $METHOD_INDEX -lt $MAX_INDEX ]; then
+			let METHOD_INDEX++
+		fi
+	fi
+	echo $METHOD_INDEX >/tmp/method_index
+	ACTIVE=$(nth $METHOD_INDEX $METHODS)
+	uci set modem.pinginfo$CURRMODEM.alive=$ACTIVE
+	UP_SINCE_LAST_RECONNECT=NO
 	case $ACTIVE in
 	"1" )
 		log "Modem $CURRMODEM Connection is Down$1"
+		log "Reconnection method: none"
 		;;
 	"2" )
 		log "Modem $CURRMODEM Connection is Down$1"
+		log "Reconnection method: router reboot"
 		reboot -f
 		;;
 	"3" )
 		log "Modem $CURRMODEM Connection is Down$1"
+		log "Reconnection method: modem reconnect"
 		PROT=$(uci get modem.modem$CURRMODEM.proto)
 		if [ $PROT -eq "30" ]; then
 			CPORT=$(uci get modem.modem$CURRMODEM.commport)
@@ -58,13 +84,30 @@
 		;;
 	"4" )
 		log "Modem $CURRMODEM Connection is Down$1"
+		log "Reconnection method: power toggle (or modem reconnect)"
 		power_toggle
 		;;
+	"5" )
+		log "Modem $CURRMODEM Connection is Down$1"
+		log "Reconnection method: DHCP renewal or restart"
+		/usr/lib/rooter/connect/dhcp_renew.sh $CURRMODEM
+		;;		
 	esac
 }
 
 
 CURSOR="-"
+if grep -iqw UP /tmp/monstat$CURRMODEM 2>/dev/null; then
+	UP_SINCE_LAST_RECONNECT=YES
+else
+	UP_SINCE_LAST_RECONNECT=NO
+fi
+if [ -r /tmp/method_index ]; then
+	METHOD_INDEX=$(cat /tmp/method_index)
+else
+	METHOD_INDEX=1
+	echo 1 >/tmp/method_index
+fi
 
 log "Start Connection Monitor for Modem $CURRMODEM"
 
@@ -84,6 +127,7 @@
 		COUNT=$(uci get modem.pinginfo$CURRMODEM.count)
 		PACKETSIZE=$(uci get modem.pinginfo$CURRMODEM.packetsize)
 		INTERF=$(uci get modem.modeminfo$CURRMODEM.inter)
+		METHODS=$(uci get modem.pinginfo$CURRMODEM.methods)
 
 		list_track_ips() {
 			track_ips="$1 $track_ips"
@@ -106,11 +150,13 @@
 					do_down " (using Failover)"
 				else
 					echo 'MONSTAT="'"Up ($CURSOR) (using Failover)"'"' > /tmp/monstat$CURRMODEM
+					success
 				fi
 				sleep 20
 
 			else
 				# check to see if modem iface has an IP address, if not try a reconnect/power toggle
+				sleep 10
                         	if [ -z "$(ifconfig ${INTER} 2>&1 | sed '/inet\ /!d;s/.*r://g;s/\ .*//g')" ]; then
                                 	do_down " (no IP address)"
                         	fi
@@ -121,6 +167,7 @@
 						do_down " (using Load Balance)"
 					else
 						echo 'MONSTAT="'"Up ($CURSOR) (using Load Balance)"'"' > /tmp/monstat$CURRMODEM
+						success
 					fi
 					sleep $(uci get mwan3.wan${INTERF}.interval)
 				else
@@ -165,6 +212,7 @@
 						do_down " (using Ping Test)"
 					else
 						echo 'MONSTAT="'"UP ($CURSOR) (using Ping Test)"'"' > /tmp/monstat$CURRMODEM
+						success
 					fi
 					sleep $INTERVAL
 				fi
--- /dev/null	1969-12-31 19:00:10.310000000 -0500
+++ /usr/lib/rooter/connect/dhcp_renew.sh	2020-03-31 11:23:59.000000000 -0400
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+CURRMODEM=$1
+IFACE=$(uci get modem.modem$CURRMODEM.interface)
+PID=$(cat /var/run/udhcpc-$IFACE.pid 2>/dev/null)
+PID6=$(pgrep -f "odhcp6c.* $IFACE")
+
+log() {
+        logger -t "Reconnect Modem" "$@"
+}
+
+if [ -n "$PID" ]; then
+        log "Renewing DHCP lease on $IFACE"
+        kill -USR2 $PID
+        kill -USR1 $PID
+else
+        log "Restarting udhcpc on $IFACE"
+        udhcpc -p /var/run/udhcpc-$IFACE.pid -s /lib/netifd/dhcp.script -f -t 0 -i $IFACE -x hostname:ROOter -C -O 121
+fi
+if [ -n "$PID6" ]; then
+        kill -USR2 $PID6
+        kill -USR1 $PID6
+else
+        odhcp6c -s /lib/netifd/dhcpv6.script -P0 -t120 $IFACE
+fi
