Page 3 of 4

Re: Telnet Type Data to Domoticz Help

Posted: Sunday 03 April 2016 17:54
by simon_rb
NickHead wrote:There is, but I aint done that yet, and wether it would work is another story.

You could always try entering other commands in to the text string to see if it changes channels/volume or whatever/

I simple read of about 10 bytes would suffice I would reckon.

i am doing too many things here at the moment , I have to rewrite my SolarPanel programs as well
not only that , I have to to work in a bit :(
Bless ya, well I appreciate your help! :-)

Telnet Type Data to Domoticz Help

Posted: Sunday 03 April 2016 17:59
by simon_rb
And this

http://forum.micasaverde.com/index.php?topic=22950.15

Looks like response is PWON if on and PWSTANDBY if in standby.

Re: Telnet Type Data to Domoticz Help

Posted: Monday 04 April 2016 0:28
by NickHead
This is what I got up to now:

I have done a trial run and can get it to work with my Domoticz ( Emulating Denon Send/Requests )

Code: Select all

 #!/usr/bin/env python
import os
import sys
import socket
import urllib
DStart = " "
###############################################
# Denon Amp Settings

denon_host = "192.168.0.231"			#IP of Denon Amp
denon_port = 8081				#Port of Denon Amp
###############################################
#domoticz settings

domoticz_host = '192.168.0.148'			#IP of Domoticz	
domoticz_port = '8080'				#Port of Domoticz
domoticz_url    = 'json.htm'
avr_switch        = '379'	                                                     #This Number is the same as the Device ID of the Switch 
################################################
def SendInit_PW():
	Text = "PW?"
	s.send(Text)

def ReceiveData():
	global DStart
    	while DStart != "P":
  		DStart = (s.recv(1))		# Wait for a response "Pxxx"
     	DStart = (s.recv(3))			# Get next 3 characters
	if DStart == "WON":
		print " Denon Power is ON"
		Switch = ("http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url + "?type=command&param=switchlight&idx=" + avr_switch + "&switchcmd=On")
		urllib.urlopen(Switch)
	if DStart == "WST":
		print "Denon Power is OFF"		 
		Switch = ("http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url + "?type=command&param=switchlight&idx=" + avr_switch + "&switchcmd=Off")
		urllib.urlopen(Switch) 
     		
try:
    	
 	s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 	print "			 Socket successfully created"
except socket.error as err:
		print" "
s.connect((denon_host,denon_port))
print "                      Host =",denon_host," Port = ",denon_port
print "			 Connecting to Denon Amplifier"

SendInit_PW()
ReceiveData()

  

Re: Telnet Type Data to Domoticz Help

Posted: Monday 04 April 2016 0:47
by simon_rb
Brilliant - Thanks.

Just saved the script and filled in the details and I got this when trying to run it (assuming I have ran it correctly)

Code: Select all

File "/home/pi/domoticz/scripts/Denon_Airplay_Check.py", line 10
SyntaxError: Non-ASCII character '\xe2' in file /home/pi/domoticz/scripts/Denon_Airplay_Check.py on line 10, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
UPDATE:- I added # -*- coding: utf-8 -*- to the top of the file, then it didn't like the " " for denon_host = "192.168.1.12" so changed to ' ' and got this:-

Code: Select all

pi@raspberrypi ~ $ python /home/pi/domoticz/scripts/Denon_Airplay_Check.py
  File "/home/pi/domoticz/scripts/Denon_Airplay_Check.py", line 11
    denon_host = '192.168.1.12’         #IP of Denon Amp
                                                         ^
SyntaxError: EOL while scanning string literal

Re: Telnet Type Data to Domoticz Help

Posted: Monday 04 April 2016 0:59
by NickHead
mmm no error on line 10 is there ?>

Re: Telnet Type Data to Domoticz Help

Posted: Monday 04 April 2016 1:03
by NickHead
Are you running it by

python Denon_Airplay_Check.py

???

if not , your doing it wrong

Re: Telnet Type Data to Domoticz Help

Posted: Monday 04 April 2016 1:21
by simon_rb
Got as far as this so far

Code: Select all

pi@raspberrypi ~ $ python /home/pi/domoticz/scripts/Denon_Airplay_Check.py
  File "/home/pi/domoticz/scripts/Denon_Airplay_Check.py", line 27
    while DStart != "P":
    ^
IndentationError: unexpected indent

Re: Telnet Type Data to Domoticz Help

Posted: Monday 04 April 2016 1:26
by NickHead
yer, python has to be perfect on indentations

maybe the cut/paste messed it up

Re: Telnet Type Data to Domoticz Help

Posted: Monday 04 April 2016 1:28
by NickHead

Code: Select all

def ReceiveData():
	global DStart
    	while DStart != "P":
  		DStart = (s.recv(1))		# Wait for a response "Pxxx"
     	DStart = (s.recv(3))			# Get next 3 characters
	if DStart == "WON":





Should look like that
If its the same when i press enter

and it isnt

Re: Telnet Type Data to Domoticz Help

Posted: Monday 04 April 2016 1:29
by NickHead
i'll attach it as a file

Re: Telnet Type Data to Domoticz Help

Posted: Monday 04 April 2016 1:29
by simon_rb
Got past that, Stuck on this now

Code: Select all

pi@raspberrypi ~ $ python /home/pi/domoticz/scripts/Denon_Airplay_Check.py
  File "/home/pi/domoticz/scripts/Denon_Airplay_Check.py", line 30
    if DStart == "WON":
                      ^
IndentationError: unindent does not match any outer indentation level

Re: Telnet Type Data to Domoticz Help

Posted: Monday 04 April 2016 1:32
by NickHead
wont let me do it for some reason

Re: Telnet Type Data to Domoticz Help

Posted: Monday 04 April 2016 1:34
by simon_rb
NickHead wrote:wont let me do it for some reason
I'm half way through the code.. any ideas why the error above is there? Python is so temperamental lol

Re: Telnet Type Data to Domoticz Help

Posted: Monday 04 April 2016 1:36
by NickHead
if Dstart != "P":
goes directly under DSTART == "WON"

all in the same line other then DSTART = (s.recv(1))

Re: Telnet Type Data to Domoticz Help

Posted: Monday 04 April 2016 1:38
by NickHead
if there is a colon (:) then there is an indentation on the NEXT line

Python Program Rules

Re: Telnet Type Data to Domoticz Help

Posted: Monday 04 April 2016 1:40
by simon_rb
I have ran it in an online python editor and I get the same error. Can't figure it out lol

UPDATE:- It needed one more space - seems to have opened socket now.. :D

Re: Telnet Type Data to Domoticz Help

Posted: Monday 04 April 2016 1:41
by NickHead
Sorry

if Dstart != "P":
goes directly under global DSTART

all in the same line other then DSTART = (s.recv(1))


I am Soooo tired now, so off to bed, will try again tomorrow
making too many errors now, I have been at work and knackud

Re: Telnet Type Data to Domoticz Help

Posted: Monday 04 April 2016 1:43
by NickHead
if you can PM me, dont know wether its on, then send me an email and i'll send you the file.

should be in order then


gnite

Re: Telnet Type Data to Domoticz Help

Posted: Monday 04 April 2016 1:47
by simon_rb
NickHead wrote: I am Soooo tired now, so off to bed, will try again tomorrow
making too many errors now, I have been at work and knackud
Don't be sorry, I'm off to be now too - up at 6. I have it running now but it doesn't do anything after it says connecting to denon.

Code: Select all

pi@raspberrypi ~ $ python /home/pi/domoticz/scripts/Denon_Airplay_Check.py
          Socket successfully created
                      Host = 192.168.1.12  Port =  23
          Connecting to Denon Amplifier
Speak tomorrow and thank you so so so much :D

Re: Telnet Type Data to Domoticz Help

Posted: Monday 04 April 2016 22:11
by simon_rb
Got the script to run but it stops after it displays Connecting to Denon... After a couple of mins I hit ctrl c and this is what it displays.. We are too close... Well you are ;)

Code: Select all

pi@raspberrypi ~ $ python /home/pi/domoticz/scripts/Denon_Airplay_Check.py
          Socket successfully created
                      Host = 192.168.1.12  Port =  23
          Connecting to Denon Amplifier
^CTraceback (most recent call last):
  File "/home/pi/domoticz/scripts/Denon_Airplay_Check.py", line 49, in <module>
    ReceiveData()
  File "/home/pi/domoticz/scripts/Denon_Airplay_Check.py", line 28, in ReceiveData
    DStart = (s.recv(3))         # Get next 3 characters
KeyboardInterrupt
pi@raspberrypi ~ $