Get DSL status from Fritzbox

Moderator: leecollings

Post Reply
User avatar
cyberclwn
Posts: 103
Joined: Thursday 20 August 2015 22:53
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: The Netherlands
Contact:

Get DSL status from Fritzbox

Post by cyberclwn »

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:

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&param=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&param=switchlight&idx=$dom_status_idx&switchcmd=Off"`
                fi
                ;;
esac
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:

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>
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 :)
3xPi 2B (Domoticz "live", Domoticz "sandbox", PhotoFrame)
RFXCom433(E), KaKu, Oregon Scientific, Keyes 2-relay, Logitech Media Server, MiLight, Smartwares heating controller(2x), IR Send/Receive, Keyes PIR, XH-M131 DuskSensor, DHT22/11
joshimosh
Posts: 58
Joined: Friday 29 May 2015 7:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Get DSL status from Fritzbox

Post by joshimosh »

Good morning,
thank you for this script - very interesting.
Would you mind to share where you found the script ? It would be usefull to try to get some other information out of the Fritzbox and use it in domoticz.

Thanks a lot !

Cheers
Josh
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: Get DSL status from Fritzbox

Post by ThinkPad »

What's the benefit of this? The modem will try to reconnect by itself i guess?
By powercycling the modem, the 'line training' (Dutch: 'intrainen op lijnsnelheid') (determining fastest speed achievable) will start over again i guess?

I do the same, but that is with internet over coax, where there is no line traning: http://thinkpad.tweakblogs.net/blog/120 ... tproblemen
And with the Ziggo modem it sometimes requires a reboot after they have done maintenance works.

Reason i say this: i once read somewhere there was someone that wanted to turn off his ADSL / VDSL modem at night with a timer clock, to reduce energy consumption. But someone responded that it was not advisable because of the line training process.
I am not active on this forum anymore.
User avatar
cyberclwn
Posts: 103
Joined: Thursday 20 August 2015 22:53
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: The Netherlands
Contact:

Re: Get DSL status from Fritzbox

Post by cyberclwn »

Hi,
joshimosh wrote: Would you mind to share where you found the script ? It would be usefull to try to get some other information out of the Fritzbox and use it in domoticz.
The script upnp/xml bit comes from http://idefix.net/~koos/newsitem.cgi/1417032285
There is some a tiny bit more info in the output-xml, but i don't use that. I tried to get more info with other input .xml's but i did't get that working.

ThinkPad wrote:What's the benefit of this? The modem will try to reconnect by itself i guess?
Sometimes it happens, after some maintenance i guess, that the modem doesn't recover the DSL-status. A powercycle will fix it then.
The 'line training' is only with a new modem, or when disconnect for a longer amount of time, i think.
Before i had some issues with wifi and a reset of the modem fixed that too, but didn't effect my DSl-speed (which occur at a reset of the line-training).

I don't expect it to happen on a daily/weekly/monthly base, but thought it would be nice to have.
3xPi 2B (Domoticz "live", Domoticz "sandbox", PhotoFrame)
RFXCom433(E), KaKu, Oregon Scientific, Keyes 2-relay, Logitech Media Server, MiLight, Smartwares heating controller(2x), IR Send/Receive, Keyes PIR, XH-M131 DuskSensor, DHT22/11
roman1528
Posts: 10
Joined: Friday 09 October 2015 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: lat.beta
Contact:

Re: Get DSL status from Fritzbox

Post by roman1528 »

hi .. maybe anyone can use this attachement to implement a full FritzBox support. it's perl...

would be nice to check wifi and some other settings... note: telnet is required and have to be activatetd on fritzbox via telephone^^
Attachments
72_FRITZBOX.zip
(39.4 KiB) Downloaded 105 times
Raspberry Pi 2 Model B,
RFLink Gateway,
'OBI' RF Outlets,
some DS18B20 1-wire Temp.Sensors,
TSL2561 I2C Luminosity Sensor (not working at all)
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: Get DSL status from Fritzbox

Post by ThinkPad »

To reboot it, it doesn't even seems necessary to interrupt the power. See this page for a script that tells the Fritz!box to reboot.

Code (in case the page isn't working anymore):

Code: Select all

#!/bin/bash
_BOXURL="http://fritz.box"
_USERNAME=""
_PASSWORD="GEHEIM"
_CHALLENGE=$(curl -s ${_BOXURL}/login.lua | grep "^g_challenge" | awk -F '"' '{ print $2 }')
_MD5=$(echo -n ${_CHALLENGE}"-"${_PASSWORD} | iconv -f ISO8859-1 -t UTF-16LE | md5sum -b | awk '{print substr($0,1,32)}')
_RESPONSE="${_CHALLENGE}-${_MD5}"
_SID=$(curl -i -s -k -d 'response='${_RESPONSE} -d 'page=' -d "username=${_USERNAME}" "${_BOXURL}/login.lua" | grep "Location:" | awk -F'=' '{print $NF}' | grep -Po '[a-f\d]+')

# Box rebooten
echo 'Reboot in progress ... please allow up to 2 minutes for the box to come up!'
curl -s "${_BOXURL}/reboot.lua?sid=${_SID}&extern_reboot=1&ajax=1" >/dev/null
The author also made some scripts to extract information from the webinterface: http://www.administrator.de/contentid/214598
I am not active on this forum anymore.
User avatar
cyberclwn
Posts: 103
Joined: Thursday 20 August 2015 22:53
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: The Netherlands
Contact:

Re: Get DSL status from Fritzbox

Post by cyberclwn »

Oh, that looks interesting :)

My German is not that great, hehe. And it seems it needs telnet-support, altho i don't see that in the script itself. (or does it mean you don't need the telnet ? :) )
Allowing telnet on the Fritzbox makes it display "Unsupported changes made", or something. I had it on old modem, and don't want to do it again, to be honest.

I'll look into the script tho, thanks for pointing them out, i had searched for scripts like these, but didn't find this.
3xPi 2B (Domoticz "live", Domoticz "sandbox", PhotoFrame)
RFXCom433(E), KaKu, Oregon Scientific, Keyes 2-relay, Logitech Media Server, MiLight, Smartwares heating controller(2x), IR Send/Receive, Keyes PIR, XH-M131 DuskSensor, DHT22/11
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: Get DSL status from Fritzbox

Post by ThinkPad »

It doesn't need Telnet. It logs in via curl and scrapes the values.
I am not active on this forum anymore.
DutchHans
Posts: 229
Joined: Friday 03 April 2015 20:44
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Germany (near dutch border)
Contact:

Re: Get DSL status from Fritzbox

Post by DutchHans »

Hello,
Is there any progress made on getting information from the fritzbox?
I am very interested.

Regards, Hans
User avatar
cyberclwn
Posts: 103
Joined: Thursday 20 August 2015 22:53
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: The Netherlands
Contact:

Re: Get DSL status from Fritzbox

Post by cyberclwn »

Hey,

I didn't put any effort in it for the last .. well, year it seems :)
But last week I had some time on my hands and tried to expand the information i extract from the FritxBox!.
With a new script and some extra .xml-information I had the Upstream and Downstream bytes put into a counterfield.
It was showing some good numbers, but sometimes bad numbers also. Not sure if that is because i used a counter-device or something.

When i wanted to fix it last weekend, my SD-card in the Pi got corrupted, twice ...
(Yes, now there is a new shiny SD-card in it, with a backup SD-card with a backup-image of the first right besides it)

And you'll see, the folder i had these scripts in, wasn't in the backup-job :(

I'll try to recreate them from memory, but not sure when.

But don't expect to much/complicated things (from me anyway) :)
3xPi 2B (Domoticz "live", Domoticz "sandbox", PhotoFrame)
RFXCom433(E), KaKu, Oregon Scientific, Keyes 2-relay, Logitech Media Server, MiLight, Smartwares heating controller(2x), IR Send/Receive, Keyes PIR, XH-M131 DuskSensor, DHT22/11
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest