#!/bin/sh
#
# WeMo Control Script
#
# rich@netmagi.com
#
# Usage: ./wemo_control IP_ADDRESS ON/OFF/GETSTATE/GETSIGNALSTRENGTH/GETFRIENDLYNAME
#
#
IP=$1
COMMAND=$2
PORTTEST=$(curl -s $IP:49152 | grep "404")
if [ "$PORTTEST" = "" ]
then
PORT=49153
else
PORT=49152
fi
if [ "$1" = "" ]
then
echo "Usage: ./wemo_control IP_ADDRESS ON/OFF/GETSTATE/GETSIGNALSTRENGTH/GETFRIENDLYNAME"
else
if [ "$2" = "GETSTATE" ]
then
curl -0 -A '' -X POST -H 'Accept: ' -H 'Content-type: text/xml; charset="utf-8"' -H "SOAPACTION: \"urn:Belkin:service:basicevent:1#GetBinaryState\"" --data '1' -s http://$IP:$PORT/upnp/control/basicevent1 |
grep "" -f2 | cut -d "<" -f1 | sed 's/0/OFF/g' | sed 's/1/ON/g'
elif [ "$2" = "ON" ]
then
curl -0 -A '' -X POST -H 'Accept: ' -H 'Content-type: text/xml; charset="utf-8"' -H "SOAPACTION: \"urn:Belkin:service:basicevent:1#SetBinaryState\"" --data '1' -s http://$IP:$PORT/upnp/control/basicevent1 |
grep "" -f2 | cut -d "<" -f1
elif [ "$2" = "DIM" ]
then
curl -0 -A '' -X POST -H 'Accept: ' -H 'Content-type: text/xml; charset="utf-8"' -H "SOAPACTION: \"urn:Belkin:service:basicevent:1#SetBinaryState\"" --data '1'"$3"'' -s http://$IP:$PORT/upnp/control/basicevent1 |
grep "" -f2 | cut -d "<" -f1
elif [ "$2" = "OFF" ]
then
curl -0 -A '' -X POST -H 'Accept: ' -H 'Content-type: text/xml; charset="utf-8"' -H "SOAPACTION: \"urn:Belkin:service:basicevent:1#SetBinaryState\"" --data '0' -s http://$IP:$PORT/upnp/control/basicevent1 |
grep "" -f2 | cut -d "<" -f1
elif [ "$2" = "GETSIGNALSTRENGTH" ]
then
curl -0 -A '' -X POST -H 'Accept: ' -H 'Content-type: text/xml; charset="utf-8"' -H "SOAPACTION: \"urn:Belkin:service:basicevent:1#GetSignalStrength\"" --data '0' -s http://$IP:$PORT/upnp/control/basicevent1 |
grep "" -f2 | cut -d "<" -f1
elif [ "$2" = "GETFRIENDLYNAME" ]
then
curl -0 -A '' -X POST -H 'Accept: ' -H 'Content-type: text/xml; charset="utf-8"' -H "SOAPACTION: \"urn:Belkin:service:basicevent:1#ChangeFriendlyName\"" --data 'Pool Filter' -s http://$IP:$PORT/upnp/control/basicevent1 |
grep "" -f2 | cut -d "<" -f1
else
echo "COMMAND NOT RECOGNIZED"
echo ""
echo "Usage: ./wemo_control IP_ADDRESS ON/OFF/GETSTATE/GETSIGNALSTRENGTH/GETFRIENDLYNAME"
echo ""
fi
fi