Need help with custom command

Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Atheros WiSOC based Hardware
Author Message
integlikewhoa
DD-WRT Novice


Joined: 22 Apr 2014
Posts: 1

PostPosted: Wed Apr 23, 2014 0:14    Post subject: Need help with custom command Reply with quote
Hello guys,

I'm looking for some help on moving a working script from a Broadcom unit to an Atheros based unit. I'm using this script to ping MAC's on two cell phones and local computers to set different virtual switches on or off depending on state in a VERA (home automation) controller. ( Better then a normal geofence to tell the system when I'm home or away, or a lan box is down)

It's currently working fine on the main router, but I have 3 more AP's around the house and I need help to accomplish two things if possible. First get a working script for these atheros devices and test that. Next I can either change the commands for all 4 to play nice together and all flip the same virtual switch or I can give each one a switch and work out combining them on the other end.

Here is the commands.
Code:
while [ ! -e "/tmp/custom.sh" ]; do
  sleep 1 # wait till /tmp/custom.sh gets generated
done
/tmp/custom.sh &


Code:
#!/bin/sh
WATCHDOG_SLEEP_SEC=10
MAC_ADDRESS_1="00:XX:XX:XX:XX:XX" # Phone 1 MAC
c1_last_state="0"
MAC_ADDRESS_2="00:XX:XX:XX:XX:XX" # Phone 2 MAC
c2_last_state="0"
HOST_1="htpc-lan.XXXXX.local"
h1_last_state="x"
HOST_2="htpc-wlan.XXXXX.local"
h2_last_state="x"
HOST_3="alfa-usb-wlan.XXXXX.local"
h3_last_state="x"
HOST_4="alfa-spoofed.XXXXX.local"
h4_last_state="x"
HOST_5="mackentorsken.XXXXX.local"
h5_last_state="x"
HOST_10="www.sunet.se"
h10_last_state="x"
VERAURL="http://xxx.xxx.xxx.xxx:3480/data_request?id=variableset&DeviceNum=xxx&serviceId=urn:dcineco-com:serviceId:MSwitch1&Variable="
x=0
y=0
offcount1=0
offcount2=0

while sleep $WATCHDOG_SLEEP_SEC
do
   if [ "$x" == 180 ]; then
      # Every 30 minutes or so we do them all again, just in case Vera missed something
      x=0
      c1_last_state="0"
      c2_last_state="0"
      h1_last_state="x"
      h2_last_state="x"
      h3_last_state="x"
      h4_last_state="x"   
      h10_last_state="x"   
   fi
   x=$(( $x + 1 ))

   c1_new_state=`wl assoclist | grep $MAC_ADDRESS_1`
   if [ "$c1_new_state" == "$c1_last_state" ] ; then
      sleep 0
   else
      if [ "$c1_new_state" == "assoclist $MAC_ADDRESS_1" ]; then
         c1_last_state="$c1_new_state"
         wget -qs "${VERAURL}Status1&Value=1"
         offcount1=0
      else
         offcount1=$(( $offcount1 + 1 ))
      fi
   fi

   c2_new_state=`wl assoclist | grep $MAC_ADDRESS_2`
   if [ "$c2_new_state" == "$c2_last_state" ] ; then
      sleep 0
   else
      if [ "$c2_new_state" == "assoclist $MAC_ADDRESS_2" ]; then
         c2_last_state="$c2_new_state"
         wget -qs "${VERAURL}Status2&Value=1"
         offcount2=0
      else
         offcount2=$(( $offcount2 + 1 ))
      fi
   fi

   if [ $offcount1 -lt 6 ]; then
      # give not responding devices 1 minute to respond
      sleep 0
   else
      c1_last_state="$c1_new_state"
      wget -qs "${VERAURL}Status1&Value=0"
      offcount1=0
   fi

   if [ $offcount2 -lt 6 ]; then
      #give not responding devices 1 minute to respond
      sleep 0
   else
      c2_last_state="$c2_new_state"
      wget -qs "${VERAURL}Status2&Value=0"
      offcount2=0
   fi


   # Ping LAN hosts
   h1_new_state=`ping -w 1 -c 1 $HOST_1 | grep 'received' | awk -F',' '{ print $2}' | awk '{ print $1}'`
   if [ "$h1_new_state" == "$h1_last_state" ] ; then
      sleep 0
   else
      h1_last_state="$h1_new_state"
      if [ "$h1_new_state" == 1 ]; then
         wget -qs "${VERAURL}Status4&Value=1"
      else
         wget -qs "${VERAURL}Status4&Value=0"
      fi
   fi

   h3_new_state=`ping -w 1 -c 1 $HOST_3 | grep 'received' | awk -F',' '{ print $2}' | awk '{ print $1}'`
   if [ "$h3_new_state" == "$h3_last_state" ] ; then
      sleep 0
   else
      h3_last_state="$h3_new_state"
      if [ "$h3_new_state" == "1" ]; then
         wget -qs "${VERAURL}Status6&Value=1"
      else
         wget -qs "${VERAURL}Status6&Value=0"
      fi
   fi

   h4_new_state=`ping -w 1 -c 1 $HOST_4 | grep 'received' | awk -F',' '{ print $2}' | awk '{ print $1}'`
   if [ "$h4_new_state" == "$h4_last_state" ] ; then
      sleep 0
   else
      h4_last_state="$h4_new_state"
      if [ "$h4_new_state" == "1" ]; then
         wget -qs "${VERAURL}Status5&Value=1"
      else
         wget -qs "${VERAURL}Status5&Value=0"
      fi
   fi
   h5_new_state=`ping -w 1 -c 1 $HOST_5 | grep 'received' | awk -F',' '{ print $2}' | awk '{ print $1}'`
   if [ "$h5_new_state" == "$h5_last_state" ] ; then
      sleep 0
   else
      h5_last_state="$h5_new_state"
      if [ "$h5_new_state" == "1" ]; then
         wget -qs "${VERAURL}Status3&Value=1"
      else
         wget -qs "${VERAURL}Status3&Value=0"
      fi
   fi

   if [ "$y" == 11 ]; then
      # We dont want to ping an external site so often, might be considered as abuse
      y=0
   fi
   y=$(( $y + 1 ))

   if [ "$y" == 1 ] ; then
      h10_new_state=`ping -w 5 -c 1 $HOST_10 | grep 'received' | awk -F',' '{ print $2}' | awk '{ print $1}'`
      if [ "$h10_new_state" == "$h10_last_state" ] ; then
         sleep 0
      else
         h10_last_state="$h10_new_state"
         if [ "$h10_new_state" == "1" ]; then
            wget -qs "${VERAURL}Status8&Value=1"
         else
            wget -qs "${VERAURL}Status8&Value=0"
         fi
      fi
   fi

done


Thanks,
Sponsor
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Atheros WiSOC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum