Index: tools/flash-ns5m
===================================================================
--- tools/flash-ns5m	(revision 12357)
+++ tools/flash-ns5m	(revision 12358)
@@ -6,4 +6,5 @@
 #
 DIRNAME=`dirname $0`
+TOTAL_TRIES=60
 
 # Argument helpers
@@ -30,9 +31,18 @@
 
 # Verify connectivity
-ping -c 1 192.168.1.20
-if [ $? -ne 0 ]; then
-  echo "Unable to connect to NanoStation"
-  exit 1
-fi
+TRY=0
+while true; do
+  sshpass -p ubnt ssh -oUserKnownHostsFile=/dev/null ubnt@192.168.1.20 'uname -a'
+  if [ $? -eq 0 ]; then
+    break
+  fi
+
+  TRY=`expr $TRY + 1`
+  echo "Unable to connect to NanoStation (attempt $TRY of $TOTAL_TRIES)"
+  if [ $TRY -ge $TOTAL_TRIES ]; then
+    exit 1
+  fi
+  sleep 1
+done
 
 # Variables needed from Nanostaion, as to be filled into configuration
@@ -44,6 +54,6 @@
 
 # Flash node
-sshpass -p ubnt scp -oUserKnownHostsFile=/dev/null system.cfg.new fwupdate.bin ubnt@192.168.1.20:/tmp
-sshpass -p ubnt ssh -oUserKnownHostsFile=/dev/null ubnt@192.168.1.20 'cfgmtd -w -f /tmp/system.cfg.new && fwupdate -m'
+sshpass -p ubnt scp -oUserKnownHostsFile=/dev/null system.cfg.new fwupdate.bin ubnt@192.168.1.20:/tmp || exit 1
+sshpass -p ubnt ssh -oUserKnownHostsFile=/dev/null ubnt@192.168.1.20 'cfgmtd -w -f /tmp/system.cfg.new && fwupdate -m' || exit 1
 
 echo "Ones the leds are off configuration is done"
