Skip to content

Commit

Permalink
Add CONTENT_LENGTH to SOAP UPNP Request and Improving README
Browse files Browse the repository at this point in the history
Specify the possibility of TOKEN expiring in some TV models (#9)
  • Loading branch information
sermayoral committed Apr 2, 2020
1 parent 9d7ba52 commit 1b922d4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ After a correct installation, your configuration directory should look like the

# Configuration

1. Use get_token.py to get your Samsung TV token (use --port 8080). Store CTX <TOKEN> and <SESSION_ID> output. Your TV must be turned on and connected to Internet with the specific IP. Terminal where you have executed get_token.py will ask for a PIN, that will be showed in your TV screen.
1. Use get_token.py to get your Samsung TV token (use --port 8080). Store TOKEN (CTX) and SESSION_ID output. Your TV must be turned on and connected to Internet with the specific IP. Terminal where you have executed get_token.py will ask for a PIN, that will be showed in your TV screen.
**Note**: In some models the TOKEN can expire after a time (maybe a week, month), or even the TOKEN can be invalidated due to a loss of TV power.
In that case you have to repeat this process again.
2. Enable the component by editing the configuration.yaml file (within the config directory as well).
Edit it by adding the following lines:
### Example configuration.yaml
Expand Down
6 changes: 3 additions & 3 deletions custom_components/samsungtv_encrypted/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,7 @@ async def async_select_source(self, source):

def SendSOAP(self, port, path, urn, service, body, XMLTag):
CRLF = "\r\n"
xmlBody = "";
xmlBody += '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.' \
xmlBody = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.' \
'xmlsoap.org/soap/encoding/">'
xmlBody += '<s:Body>'
xmlBody += '<u:{service} xmlns:u="{urn}">{body}</u:{service}>'
Expand All @@ -417,11 +416,12 @@ def SendSOAP(self, port, path, urn, service, body, XMLTag):
soapRequest = "POST {path} HTTP/1.0%s" % (CRLF)
soapRequest += "HOST: {host}:{port}%s" % (CRLF)
soapRequest += "CONTENT-TYPE: text/xml;charset=\"utf-8\"%s" % (CRLF)
soapRequest += "CONTENT-LENGTH: {cont_len}%s" % (CRLF)
soapRequest += "SOAPACTION: \"{urn}#{service}\"%s" % (CRLF)
soapRequest += "%s" % (CRLF)
soapRequest += "{xml}%s" % (CRLF)
soapRequest = soapRequest.format(host=self._config['host'], port=port, xml=xmlBody, path=path,
urn=urn, service=service)
urn=urn, service=service, cont_len=len(xmlBody))

client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.settimeout(2)
Expand Down
4 changes: 3 additions & 1 deletion info.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ After a correct installation, your configuration directory should look like the

# Configuration

1. Use get_token.py to get your Samsung TV token (use --port 8080). Store CTX <TOKEN> and <SESSION_ID> output. Your TV must be turned on and connected to Internet with the specific IP. Terminal where you have executed get_token.py will ask for a PIN, that will be showed in your TV screen.
1. Use get_token.py to get your Samsung TV token (use --port 8080). Store TOKEN (CTX) and SESSION_ID output. Your TV must be turned on and connected to Internet with the specific IP. Terminal where you have executed get_token.py will ask for a PIN, that will be showed in your TV screen.
**Note**: In some models the TOKEN can expire after a time (maybe a week, month), or even the TOKEN can be invalidated due to a loss of TV power.
In that case you have to repeat this process again.
2. Enable the component by editing the configuration.yaml file (within the config directory as well).
Edit it by adding the following lines:
### Example configuration.yaml
Expand Down

0 comments on commit 1b922d4

Please sign in to comment.