Get DSL status from Fritzbox
Posted: Thursday 22 October 2015 22:18
Hi,
I came across some script that uses upnp to read out some information of the FritzBox!.
I have this script in my /domoticz/scripts folder and in my crontab:It updates a dummy switch if the status of the reply fro Fritzbox changed.
For the upnp-request is uses a linkstatusrequest.xml file that should be in the same folder:
I use this setup for a lua-script that checks this dummy switch. If Internet is down for more then 20 minutes, i turn off the power to the modem, and a few minutes later turn it back on.
Just made the last bit today, so needs some testing, but looks ok for now.
Hope some other Fritzbox user can use this
I came across some script that uses upnp to read out some information of the FritzBox!.
I have this script in my /domoticz/scripts folder and in my crontab:
Code: Select all
#!/bin/sh
#FritzBox settings
FRITZUSER=root
FRITZPASS=<passwd>
FRITZIP=<ip>
FRITZPORT=49443
#domoticz settings
dom_host=<ip>
dom_port=<port>
dom_url="json.htm"
dom_status_idx=<idx_dummyswitch>
cd ~/domoticz/scripts
wget --quiet --user=$FRITZUSER --password=$FRITZPASS --post-file=linkstatusrequest.xml \
--header="Content-Type: text/xml" \
--header="SOAPAction: \"urn:dslforum-org:service:WANCommonInterfaceConfig:1#GetCommonLinkProperties\"" --no-check-certificate \
https://$FRITZIP:$FRITZPORT/upnp/control/wancommonifconfig1 -O linkstatusanswer.xml
Internet=`cat linkstatusanswer.xml | grep PhysicalLinkStatus | cut -d '>' -f 2 | cut -d '<' -f 1`
DOMO_STATUS=`curl -s "http://$dom_host:$dom_port/$dom_url?type=devices&rid=$dom_status_idx" | grep Status | grep -v Name | cut -d '"' -f 4`
case $Internet in
Up)
if [ $DOMO_STATUS != "On" ]
then
URL_DOMO=`curl -s "http://$dom_host:$dom_port/$dom_url?type=command¶m=switchlight&idx=$dom_status_idx&switchcmd=On"`
fi
;;
*)
if [ $DOMO_STATUS != "Off" ]
then
URL_DOMO=`curl -s "http://$dom_host:$dom_port/$dom_url?type=command¶m=switchlight&idx=$dom_status_idx&switchcmd=Off"`
fi
;;
esac
For the upnp-request is uses a linkstatusrequest.xml file that should be in the same folder:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:GetCommonLinkProperties xmlns:u="urn:dslforum-org:service:WANCommonInterfaceConfig:1">
</u:GetCommonLinkProperties>
</s:Body>
</s:Envelope>
Just made the last bit today, so needs some testing, but looks ok for now.
Hope some other Fritzbox user can use this