MagentaTV Binding for Deutsche Telekom MR 4xx

Hi, I have been following this topic for a while now, since I also want to integrate my MR 401 and MR 201 into my OpenHAB2 setup.

I found a way to get/generate the UserID. It is the MD5ed UserID == ProfileID == SubscriberID, that is connected to your EntertainTV-Account. When you use the EntertainTV-Mobil-App it authenticates the MobilDevice with the EntertainBackend. In this course the app is provided with the UserID == ProfileID == SubscriberID which is then later used in the Pairing-Process.

I attach a PoC bashscript that retrieves the UserID needed for the pairing process by just supplying T-Com username and password. So no more need to retrieve the UserID from capturing network traffic. Perhaps this process can be integrated into the OpenHAB-binding?

The script was written on MacOS. So you might need to change some bash commands. It requires jq (https://stedolan.github.io/jq/) for JSON parsing and has no error checking.

Usage: ./getEntertainTVUserID.sh

#!/bin/bash
# requires "curl jq" - https://stedolan.github.io/jq/

APP_URL="https://appepmfk20003.prod.sngtv.t-online.de:33207"
USER_AGENT="Mozilla/5.0 (iPhone; CPU iPhone OS 12_0_1 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Mobile/14G60 (400962928)"

urlencode() {
	# https://gist.github.com/cdown/1163649
	local LANG=C i c e=''
	for ((i=0;i<${#1};i++)); do
                c=${1:$i:1}
		[[ "$c" =~ [a-zA-Z0-9\.\~\_\-] ]] || printf -v c '%%%02X' "'$c"
                e+="$c"
	done
        echo "$e"
}

function host_part() {
	host=`echo $1 | awk -F/ '{print $3}'`
}

function fail() {
	echo $1
	echo "*******************"
	echo "Usage: $0 <Benutzername> <Passwort>"
	exit 1
}

function gettingOAuthCredentials() {
	local json msg

	msg="Getting oAuthCredentials"
	printf "[?] $msg"

	host_part $APP_URL

	json=$(curl -H 'Host: '"$host"'' -H 'User-Agent: '"$USER_AGENT"'' -H 'Accept-Language: de-de' -H 'Accept: */*' -s --compressed ''"$APP_URL"'/EPG/JSON/Login?UserID=Guest')
	oAuthScope=`echo $json | jq -r '.sam3Para[] | select(.key|test("OAuthScope"))|.value'`
	oAuthService=`echo $json | jq -r '.sam3Para[] | select(.key|test("SAM3ServiceURL"))|.value'`
	oAuthClientSecret=`echo $json | jq -r '.sam3Para[] | select(.key|test("OAuthClientSecret"))|.value'`
	oAuthClientId=`echo $json | jq -r '.sam3Para[] | select(.key|test("OAuthClientId"))|.value'`

	printf "\r[+] $msg\n"

}


function gettingOAuthToken() {
	local json msg

	msg="Getting oAuthToken"
	printf "[?] $msg"

	host_part $oAuthService
	json=$(curl -H 'Host: '"$host"'' -H 'Accept-Language: de-de' -H 'Accept: */*' -H 'User-Agent: '"$USER_AGENT"'' -s --data "grant_type=password&username=$USERNAME&password=$PASSWORD&scope=$oAuthScope%20offline_access&client_id=$oAuthClientId&client_secret=$oAuthClientSecret&x_telekom.access_token.format=CompactToken&x_telekom.access_token.encoding=text%2Fbase64" --compressed ''"$oAuthService"'/oauth2/tokens')
	accessToken=`echo $json | jq -r '.access_token'`

	printf "\r[+] $msg\n"
}


function authenticateDevice() {
	local json msg uuid

	msg="Authenticate MobileDevice"
	printf "[?] $msg"

 	host_part $APP_URL
 	uuid=$(uuidgen | tr "A-Z" "a-z")
 	cnonce=$(echo -n $uuid | md5sum)
	json=$(curl -s -H 'Host: '"$host"'' -H 'Content-Type: text/plain;charset=UTF-8' -H 'Accept-Language: de-de' -H 'Accept: */*' -H 'User-Agent: '"$USER_AGENT"'' --data-binary '{"userType":1,"terminalid":"'"$uuid"'","mac":"'"$uuid"'","terminaltype":"Iphone","utcEnable":1,"timezone":"Europe/Berlin","terminalvendor":"iPhone10","osversion":"iOS12.0.1","softwareVersion":"2.3.10.26","terminalDetail":[{"key":"HardwareSupplier","value":"MyPhone"},{"key":"DeviceClass","value":"IPhone"},{"key":"DeviceStorage","value":"1"},{"key":"DeviceStorageSize","value":12475},{"key":"GUID","value":"'"$uuid"'"}],"connectType":1,"reconnect":true,"accessToken":"'"$accessToken"'","cnonce":"'"$cnonce"'","caDeviceInfo":[{"caDeviceType":6,"caDeviceId":"'"$uuid"'"}],"preSharedKeyID":"NGTV000001","areaid":"1","templatename":"NGTV","usergroup":"IPTV_DT","subnetId":"4901"}' --compressed ''"$APP_URL"'/EPG/JSON/DTAuthenticate?SID=user&T=Iphone')
	userID=$(echo $json | jq -r '.userID')
	userIDMD5=$(echo -n $userID | md5sum | tr "a-z" "A-Z")

	printf "\r[+] $msg\n"
}

#
# main:
#

USERNAME=$(urlencode $1)
PASSWORD=$(urlencode $2)

if [ -z $USERNAME ]; then
	fail "Bitte Benutzername eingeben!"
fi

if [ -z $PASSWORD ]; then
	fail "Bitte Passwort eingeben!"
fi


	echo
	echo
	echo Telekom Entertain UserID
	echo --------------------------------
	echo

	gettingOAuthCredentials
	gettingOAuthToken
	authenticateDevice

	echo 
	echo --------------------------------
	echo

	echo "UserID: $userID"
	echo "UserID (MD5ed): $userIDMD5"
	echo

sounds cool, would be the missing piece in the puzzle

I run the script with my credentials, but the output is not what I expected

Telekom Entertain UserID
--------------------------------

[+] Getting oAuthCredentials
[+] Getting oAuthToken
[+] Authenticate MobileDevice

--------------------------------

UserID: 
UserID (MD5ed): D41D8CD98F00B204E9800998ECF8427E  -

even when chaging the user id I get the same MD5

Did you already tried the binding?

No, I am just trying to install the binding. Will report later. As I said, there is so far no error checking in the processing of the JSON response.

Just tested. I integrated the JAR and configured the thing with the UserID form my script. I added two items VolumeUp and VolumeDown. They both work, except that VolumeDown raises the Volume :slight_smile: But that another question …

I will implement some more error checking into the script to find the reason why it is not working for you.

:+1: The channels should be easy to fix
which models did you tested?

I workey on the Key channel. The version in github already support most common ones. I between I found the key code table in the Huawai dev forum and added most of them - next update will have them.

I’m also working in decoding the STB events, which allows to get the info on player status, title and channel.

Another open topic is: How to detect if the receiver is running. The POWER button is a toggle, which means that you can’t force ON or OFF. Including a POWER in a scene requires that the receiver is in sync and nobody used the remote. In standby mode the eth interface is action and the stb replies to any valid http requests. The returned xml includes device data (like model, wol enabled etc), but no status information.

I found https://developer.huawei.com/en/ict/Products/TelecoSoftware/VideoExperienceCapbility/MEM-API/SDK%20Detail. This might include additional information.

It describes the interface to the EPG/backend and e.g. also allows to query the channel list. This might be useful to switch easier between programs or implement your own recording schedule.

Could you try the following version, which includes some DEBUG information.

#!/bin/bash
# requires "curl jq" - https://stedolan.github.io/jq/

APP_URL="https://appepmfk20003.prod.sngtv.t-online.de:33207"
USER_AGENT="Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Mobile/14G60 (400962928)"
DEBUG=1

urlencode() {
	# https://gist.github.com/cdown/1163649
	local LANG=C i c e=''
	for ((i=0;i<${#1};i++)); do
                c=${1:$i:1}
		[[ "$c" =~ [a-zA-Z0-9\.\~\_\-] ]] || printf -v c '%%%02X' "'$c"
                e+="$c"
	done
        echo "$e"
}

function host_part() {
	host=`echo $1 | awk -F/ '{print $3}'`
}

function fail() {
	echo "*******************"
	echo $1
	echo "*******************"
	echo "Usage: $0 <Benutzername> <Passwort>"
	exit 1
}

function gettingOAuthCredentials() {
	local json msg

	msg="Getting oAuthCredentials"
	printf "[?] $msg"

	host_part $APP_URL

	json=$(curl -H 'Host: '"$host"'' -H 'User-Agent: '"$USER_AGENT"'' -H 'Accept-Language: de-de' -H 'Accept: */*' -s --compressed ''"$APP_URL"'/EPG/JSON/Login?UserID=Guest')
	oAuthScope=`echo $json | jq -r '.sam3Para[] | select(.key|test("OAuthScope"))|.value'`
	oAuthService=`echo $json | jq -r '.sam3Para[] | select(.key|test("SAM3ServiceURL"))|.value'`
	oAuthClientSecret=`echo $json | jq -r '.sam3Para[] | select(.key|test("OAuthClientSecret"))|.value'`
	oAuthClientId=`echo $json | jq -r '.sam3Para[] | select(.key|test("OAuthClientId"))|.value'`

	if [ $DEBUG == 1 ]; then
		echo
		echo $json | jq '.'
	fi

	if [ -z $oAuthScope ] || [ -z $oAuthService ] || [ -z $oAuthClientSecret ] || [ -z $oAuthClientId ]; then
		echo
		fail "Getting oAuth-Credentials failed!"
	fi

	printf "\r[+] $msg\n"

}


function gettingOAuthToken() {
	local json msg

	msg="Getting oAuthToken"
	printf "[?] $msg"

	host_part $oAuthService
	json=$(curl -H 'Host: '"$host"'' -H 'Accept-Language: de-de' -H 'Accept: */*' -H 'User-Agent: '"$USER_AGENT"'' -s --data "grant_type=password&username=$USERNAME&password=$PASSWORD&scope=$oAuthScope%20offline_access&client_id=$oAuthClientId&client_secret=$oAuthClientSecret&x_telekom.access_token.format=CompactToken&x_telekom.access_token.encoding=text%2Fbase64" --compressed ''"$oAuthService"'/oauth2/tokens')
	accessToken=`echo $json | jq -r '.access_token'`

	if [ $DEBUG == 1 ]; then
		echo
		echo $json | jq '.'
	fi

	if [ -z $accessToken ] || [ $accessToken == null ]; then
		echo
		fail "Getting oAuth-AccessToken failed!"
	fi

	printf "\r[+] $msg\n"
}


function authenticateDevice() {
	local json msg uuid

	msg="Authenticate MobileDevice"
	printf "[?] $msg"

 	host_part $APP_URL
 	uuid=$(uuidgen | tr "A-Z" "a-z")
 	cnonce=$(echo -n $uuid | md5sum)
	json=$(curl -s -H 'Host: '"$host"'' -H 'Content-Type: text/plain;charset=UTF-8' -H 'Accept-Language: de-de' -H 'Accept: */*' -H 'User-Agent: '"$USER_AGENT"'' --data-binary '{"userType":1,"terminalid":"'"$uuid"'","mac":"'"$uuid"'","terminaltype":"Iphone","utcEnable":1,"timezone":"Europe/Berlin","terminalvendor":"iPhone5","osversion":"iOS10.3.3","softwareVersion":"2.3.10.26","terminalDetail":[{"key":"HardwareSupplier","value":"MyPhone"},{"key":"DeviceClass","value":"IPhone"},{"key":"DeviceStorage","value":"1"},{"key":"DeviceStorageSize","value":12475},{"key":"GUID","value":"'"$uuid"'"}],"connectType":1,"reconnect":true,"accessToken":"'"$accessToken"'","cnonce":"'"$cnonce"'","caDeviceInfo":[{"caDeviceType":6,"caDeviceId":"'"$uuid"'"}],"preSharedKeyID":"NGTV000001","areaid":"1","templatename":"NGTV","usergroup":"IPTV_DT","subnetId":"4901"}' --compressed ''"$APP_URL"'/EPG/JSON/DTAuthenticate?SID=user&T=Iphone')
	userID=$(echo $json | jq -r '.userID')
	userIDMD5=$(echo -n $userID | md5sum | tr "a-z" "A-Z")

	if [ $DEBUG == 1 ]; then
		echo
		echo $json | jq '.'
	fi

	printf "\r[+] $msg\n"
}

#
# main:
#

USERNAME=$(urlencode $1)
PASSWORD=$(urlencode $2)

if [ -z $USERNAME ]; then
	fail "Bitte Benutzername eingeben!"
fi

if [ -z $PASSWORD ]; then
	fail "Bitte Passwort eingeben!"
fi


	echo
	echo
	echo Telekom Entertain UserID
	echo --------------------------------
	echo

	gettingOAuthCredentials
	gettingOAuthToken
	authenticateDevice

	echo 
	echo --------------------------------
	echo

	echo "UserID: $userID"
	echo "UserID (MD5ed): $userIDMD5"
	echo

that’s the result is an invalid user id:

Telekom Entertain UserID
--------------------------------

[?] Getting oAuthCredentials
{
  "enctytoken": "F0427967D72A6BD759847EA19124F98A",
  "encryptiontype": "0002",
  "platformcode": "0200",
  "epgurl": "http://appepmfk20003.prod.sngtv.t-online.de:33200",
  "version": "MEM V200R008C15B070",
  "epghttpsurl": "https://appepmfk20003.prod.sngtv.t-online.de:33207",
  "rootCerAddr": "http://appepmfk20003.prod.sngtv.t-online.de:33200/EPG/CA/iptv_ca.der",
  "upgAddr4IPTV": "https://slbedifk11100.prod.sngtv.t-online.de:33428/EDS/jsp/upgrade.jsp",
  "upgAddr4OTT": "https://slbedmfk11100.prod.sngtv.t-online.de:33428/EDS/jsp/upgrade.jsp,https://slbedmfk11100.prod.sngtv.t-online.de:33428/EDS/jsp/upgrade.jsp",
  "sam3Para": [
    {
      "key": "SAM3ServiceURL",
      "value": "https://accounts.login.idm.telekom.com"
    },
    {
      "key": "OAuthClientSecret",
      "value": "21EAB062-C4EE-489C-BC80-6A65397F3F96"
    },
    {
      "key": "OAuthScope",
      "value": "ngtvepg"
    },
    {
      "key": "OAuthClientId",
      "value": "10LIVESAM30000004901NGTV0000000000000000"
    }
  ]
}
[+] Getting oAuthCredentials
[?] Getting oAuthToken
{
  "error_description": "Invalid username or password; Account locked temporarily; 2",
  "error": "invalid_grant"
}

*******************
Getting oAuth-AccessToken failed!
*******************

and this one with the correct credentials, but resulting in a wrong userid:

Telekom Entertain UserID
--------------------------------

[?] Getting oAuthCredentials
{
  "enctytoken": "689E5BAB5DF11D33BA18FF90E285182A",
  "encryptiontype": "0002",
  "platformcode": "0200",
  "epgurl": "http://appepmfk20003.prod.sngtv.t-online.de:33200",
  "version": "MEM V200R008C15B070",
  "epghttpsurl": "https://appepmfk20003.prod.sngtv.t-online.de:33207",
  "rootCerAddr": "http://appepmfk20003.prod.sngtv.t-online.de:33200/EPG/CA/iptv_ca.der",
  "upgAddr4IPTV": "https://slbedifk11100.prod.sngtv.t-online.de:33428/EDS/jsp/upgrade.jsp",
  "upgAddr4OTT": "https://slbedmfk11100.prod.sngtv.t-online.de:33428/EDS/jsp/upgrade.jsp,https://slbedmfk11100.prod.sngtv.t-online.de:33428/EDS/jsp/upgrade.jsp",
  "sam3Para": [
    {
      "key": "SAM3ServiceURL",
      "value": "https://accounts.login.idm.telekom.com"
    },
    {
      "key": "OAuthClientSecret",
      "value": "21EAB062-C4EE-489C-BC80-6A65397F3F96"
    },
    {
      "key": "OAuthScope",
      "value": "ngtvepg"
    },
    {
      "key": "OAuthClientId",
      "value": "10LIVESAM30000004901NGTV0000000000000000"
    }
  ]
}
[+] Getting oAuthCredentials
[?] Getting oAuthToken
{
  "access_token": "EKAg36Sya7tEJoW3hykM9lZgAAEHpQAAAWZtB8yFAAABZm6_QIUBAAgAAAFmbQfMhVm9LP-EANgm4dMxGLWwFMu1aHBqHZ_91yHwYaFb9ogaxLd9-kYppQPy2J6uczdqGxJQJOPntrKa2seg2ivvnw0g4acuqds2AusBuObRiceR0Omd1DC5iK8YRuuecY-Z-qxvAqdAgzTLidKenNXXXXXXXXXX",
  "expires_in": 28800,
  "refresh_token": "RT1:94ca93fa-7f18-454f-9cfc-3b8124f033be:0fd0a8d4-75f5-411d-bc37-fd7301fea2ad",
  "scope": "ngtvepg",
  "token_type": "Bearer"
}
[+] Getting oAuthToken
[?] Authenticate MobileDevice
[+] Authenticate MobileDevice

--------------------------------

UserID: 
UserID (MD5ed): D41D8CD98F00B204E9800998ECF8427E  -

Hi @markus7017,

here is my TRACE log of creating the entertain thing:

openhab.log.pdf (34.3 KB)

rename it to .log

it seems that the java returns 127.0.0.1 as ip adress

complete ifconfig:

eth0      Link encap:Ethernet  HWaddr 00:11:32:2D:16:40  
          inet addr:192.168.2.99  Bcast:192.168.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5496508 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3381958 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:218894570 (208.7 MiB)  TX bytes:2083654941 (1.9 GiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:18024 errors:0 dropped:0 overruns:0 frame:0
          TX packets:18024 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1997137 (1.9 MiB)  TX bytes:1997137 (1.9 MiB)

tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          inet addr:10.8.0.1  P-t-P:10.8.0.2  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:843 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100 
          RX bytes:0 (0.0 B)  TX bytes:88175 (86.1 KiB)

result of hostname:

Diskstation

please check the /etc/hosts file if it contains an entry for Diskstation

what’s the address 10.8.0.1? Does the system has a vpn connection (tun0)?

I did implement some more error checking.

#!/bin/bash
# requires "curl jq" - https://stedolan.github.io/jq/

USER_AGENT="Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Mobile/14G60 (400962928)"
UUID=$(uuidgen | tr "A-Z" "a-z")
CNONCE=$(echo -n $UUID | md5sum)
DEBUG=1


urlencode() {
	# https://gist.github.com/cdown/1163649
	local LANG=C i c e=''
	for ((i=0;i<${#1};i++)); do
                c=${1:$i:1}
		[[ "$c" =~ [a-zA-Z0-9\.\~\_\-] ]] || printf -v c '%%%02X' "'$c"
                e+="$c"
	done
        echo "$e"
}

function host_part() {
	host=`echo $1 | awk -F/ '{print $3}'`
}

function fail() {
	echo "*******************"
	echo $1
	echo "*******************"
	echo "Usage: $0 <Benutzername> <Passwort>"
	exit 1
}

function registerDeviceID() {
	local json msg

	msg="Registering DeviceID $UUID"
	printf "[?] $msg"

	APP_URL="https://slbedmfk11100.prod.sngtv.t-online.de:33428"
	host_part $APP_URL

	json=$(curl -L -b cookies.tmp -c cookies.tmp -s -H 'Cache-Control: no-cache' -H 'Host: '"$host"'' -H 'User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Mobile/14G60 (358080496)' -H 'Accept-Language: de-de' -H 'Accept: */*' --compressed ''"$APP_URL"'/EDS/JSON/Login?UserID=Guest')
	epghttpsurl=`echo $json | jq -r '.epghttpsurl'`

	host_part epghttpsurl
	json=$(curl -L -b cookies.tmp -c cookies.tmp -s -H 'Cache-Control: no-cache' -H 'Host: '"$host"'' -H 'Content-Type: text/plain;charset=UTF-8' -H 'Accept-Language: de-de' -H 'Accept: */*' -H 'User-Agent: '"$USER_AGENT"'' --data-binary '{"terminalid":"'"$UUID"'","mac":"'"$UUID"'","terminaltype":"Iphone","utcEnable":1,"timezone":"Europe/Berlin","userType":3,"terminalvendor":"iPhone5","osversion":"iOS10.3.3","softwareVersion":"2.3.10.26","terminalDetail":[{"key":"HardwareSupplier","value":"MyPhone"},{"key":"DeviceClass","value":"IPhone"},{"key":"DeviceStorage","value":"1"},{"key":"DeviceStorageSize","value":12475},{"key":"GUID","value":"'"$UUID"'"}],"connectType":1,"isFirst":true,"cnonce":"'"$CNONCE"'","preSharedKeyID":"NGTV000001"}' --compressed ''"$epghttpsurl"'/EPG/JSON/Authenticate?SID=firstup&T=Iphone')

	if [ $DEBUG == 1 ]; then
		echo
		echo $json | jq '.'
	fi

	printf "\r[+] $msg\n"
}

function gettingOAuthCredentials() {
	local json msg

	msg="Getting oAuthCredentials"
	printf "[?] $msg"

	APP_URL="https://slbedmfk11100.prod.sngtv.t-online.de:33428"
	host_part $APP_URL

	json=$(curl -L -b cookies.tmp -c cookies.tmp -H 'Cache-Control: no-cache' -H 'Host: '"$host"'' -H 'User-Agent: '"$USER_AGENT"'' -H 'Accept-Language: de-de' -H 'Accept: */*' -s --compressed ''"$APP_URL"'/EDS/JSON/Login?UserID=Guest')
	oAuthScope=`echo $json | jq -r '.sam3Para[] | select(.key|test("OAuthScope"))|.value'`
	oAuthService=`echo $json | jq -r '.sam3Para[] | select(.key|test("SAM3ServiceURL"))|.value'`
	oAuthClientSecret=`echo $json | jq -r '.sam3Para[] | select(.key|test("OAuthClientSecret"))|.value'`
	oAuthClientId=`echo $json | jq -r '.sam3Para[] | select(.key|test("OAuthClientId"))|.value'`
	epghttpsurl=`echo $json | jq -r '.epghttpsurl'`

	if [ $DEBUG == 1 ]; then
		echo
		echo $json | jq '.'
	fi

	if [ -z $oAuthScope ] || [ -z $oAuthService ] || [ -z $oAuthClientSecret ] || [ -z $oAuthClientId ]; then
		echo
		fail "Getting oAuth-Credentials failed!"
	fi

	printf "\r[+] $msg\n"

}


function gettingOAuthToken() {
	local json msg

	msg="Getting oAuthToken"
	printf "[?] $msg"

	host_part $oAuthService
	json=$(curl -b cookies.tmp -c cookies.tmp -H 'Cache-Control: no-cache' -H 'Host: '"$host"'' -H 'Accept-Language: de-de' -H 'Accept: */*' -H 'User-Agent: '"$USER_AGENT"'' -s --data "grant_type=password&username=$USERNAME&password=$PASSWORD&scope=$oAuthScope%20offline_access&client_id=$oAuthClientId&client_secret=$oAuthClientSecret&x_telekom.access_token.format=CompactToken&x_telekom.access_token.encoding=text%2Fbase64" --compressed ''"$oAuthService"'/oauth2/tokens')
	accessToken=`echo $json | jq -r '.access_token'`

	if [ $DEBUG == 1 ]; then
		echo
		echo $json | jq '.'
	fi

	if [ -z $accessToken ] || [ $accessToken == null ]; then
		echo
		fail "Getting oAuth-AccessToken failed!"
	fi

	printf "\r[+] $msg\n"
}


function authenticateDevice() {
	local json msg

	msg="Authenticate MobileDevice"
	printf "[?] $msg"

 	host_part $epghttpsurl

 	UUID=""
	json=$(curl -b cookies.tmp -c cookies.tmp -s -H 'Cache-Control: no-cache' -H 'Host: '"$host"'' -H 'Content-Type: text/plain;charset=UTF-8' -H 'Accept-Language: de-de' -H 'Accept: */*' -H 'User-Agent: '"$USER_AGENT"'' --data-binary '{"userType":1,"terminalid":"'"$UUID"'","mac":"'"$UUID"'","terminaltype":"Iphone","utcEnable":1,"timezone":"Europe/Berlin","terminalvendor":"iPhone5","osversion":"iOS10.3.3","softwareVersion":"2.3.10.26","terminalDetail":[{"key":"HardwareSupplier","value":"MyPhone"},{"key":"DeviceClass","value":"IPhone"},{"key":"DeviceStorage","value":"1"},{"key":"DeviceStorageSize","value":12475},{"key":"GUID","value":"'"$UUID"'"}],"connectType":1,"reconnect":true,"accessToken":"'"$accessToken"'","cnonce":"'"$CNONCE"'","caDeviceInfo":[{"caDeviceType":6,"caDeviceId":"'"$UUID"'"}],"preSharedKeyID":"NGTV000001"}' --compressed ''"$epghttpsurl"'/EPG/JSON/DTAuthenticate?SID=user&T=Iphone')
	userID=$(echo $json | jq -r '.userID')
	userIDMD5=$(echo -n $userID | md5sum | tr "a-z" "A-Z")

	if [ $DEBUG == 1 ]; then
		echo
		echo $json | jq '.'
	fi

	printf "\r[+] $msg\n"
}

#
# main:
#

USERNAME=$(urlencode $1)
PASSWORD=$(urlencode $2)

if [ -z $USERNAME ]; then
	fail "Bitte Benutzername eingeben!"
fi

if [ -z $PASSWORD ]; then
	fail "Bitte Passwort eingeben!"
fi


	echo
	echo
	echo Telekom Entertain UserID
	echo --------------------------------
	echo

	registerDeviceID
	gettingOAuthCredentials
	gettingOAuthToken
	authenticateDevice

	echo 
	echo --------------------------------
	echo

	echo "UserID: $userID"
	echo "UserID (MD5ed): $userIDMD5"
	echo

	rm cookies.tmp

@markus7017 weird is that in the last step “Authenticate MobileDevice” it is not producing any output in your test. Looks like the JSON request in that step is not send. If it would be there should at least be some output.

I added -v to the curl call and it shows a 404

> POST /EPG/JSON/DTAuthenticate?SID=user&T=Iphone HTTP/1.1
> Host: appepmfk20003.prod.sngtv.t-online.de:33207
> Accept-Encoding: deflate, gzip
> Content-Type: text/plain;charset=UTF-8
> Accept-Language: de-de
> Accept: */*
> User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Mobile/14G60 (400962928)
> Content-Length: 1010
> 
* upload completely sent off: 1010 out of 1010 bytes
< HTTP/1.1 404 Not Found
< Server: Apache-Coyote/1.1
< Access-Control-Allow-Headers: accept, origin, content-type,Authorization,authorization,X_CSRFToken,*
< Access-Control-Allow-Methods: *
< Access-Control-Allow-Credentials: true
< Strict-Transport-Security: max-age=31536000; includeSubDomains
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< Content-Type: text/plain;charset=UTF-8
< Content-Length: 0
< Date: Sat, 13 Oct 2018 15:58:26 GMT
< 
* Curl_http_done: called premature == 0
* Connection #0 to host appepmfk20003.prod.sngtv.t-online.de left intact

Yes, the hosts file:

127.0.0.1   Diskstation
::1     Diskstation

I commented out the lines but still same error

2018-10-13 18:13:11.290 [ERROR] [ertaintv.internal.EntertainTVNetwork] - EntertainTV: Unable to get local IP / MAC address: Diskstation: Diskstation: Name or service not known!

after that I add the IP Adress to the hostname Diskstation

192.168.2.99 Diskstation

Now it worked! I can connect and control the Media Receiver!

The only thing that not is working is the “Power On” status. It always showed me that the receiver is “ON”. Is that normal?

yep, goog shot:+1:
for whatever reasons the jvm get local ip tries to resolve the hostname locally, which usually results in 127.0.0.1; so you replaced this with the correct ip

However, I’m looking for more stable way by processing the local interface list and getting the ip from there.

I’ve rewritten the initialization code and it runs on my system. However, I’m not able to produce a build

Disappointing, but first I need to get the dev environment running again - not the first time :frowning:

Even automatic travis builds are failing atm, so you are not alone with your issue.

You are right, the Power channel doesn’t toggles the receiver’s power as you might expect. Instead send the key “POWER” to the EntertainTV_Key channel. See my notes here: EntertainTV Binding

sit and wait :slight_smile:

@hmerk Did you tried the binding? As I remember you still have a MR400. Would be interesting to see if it’s still running. The version in the repo is ok to test.

@Mat_Ias did you saw my last reply indicating 404?