Everything about esp8266 and more.
Moderator: leecollings
simon_rb
Posts: 612 Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:
Post
by simon_rb » Sunday 03 April 2016 17:54
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!
NickHead
Posts: 83 Joined: Tuesday 29 October 2013 18:30
Target OS: Linux
Domoticz version:
Location: North East Coast of the UK
Contact:
Post
by NickHead » Monday 04 April 2016 0:28
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¶m=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¶m=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()
A lot of stuff that is doing my head in.
simon_rb
Posts: 612 Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:
Post
by simon_rb » Monday 04 April 2016 0:47
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
Last edited by
simon_rb on Monday 04 April 2016 1:06, edited 4 times in total.
NickHead
Posts: 83 Joined: Tuesday 29 October 2013 18:30
Target OS: Linux
Domoticz version:
Location: North East Coast of the UK
Contact:
Post
by NickHead » Monday 04 April 2016 0:59
mmm no error on line 10 is there ?>
A lot of stuff that is doing my head in.
NickHead
Posts: 83 Joined: Tuesday 29 October 2013 18:30
Target OS: Linux
Domoticz version:
Location: North East Coast of the UK
Contact:
Post
by NickHead » Monday 04 April 2016 1:03
Are you running it by
python Denon_Airplay_Check.py
???
if not , your doing it wrong
A lot of stuff that is doing my head in.
simon_rb
Posts: 612 Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:
Post
by simon_rb » Monday 04 April 2016 1:21
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
NickHead
Posts: 83 Joined: Tuesday 29 October 2013 18:30
Target OS: Linux
Domoticz version:
Location: North East Coast of the UK
Contact:
Post
by NickHead » Monday 04 April 2016 1:26
yer, python has to be perfect on indentations
maybe the cut/paste messed it up
A lot of stuff that is doing my head in.
NickHead
Posts: 83 Joined: Tuesday 29 October 2013 18:30
Target OS: Linux
Domoticz version:
Location: North East Coast of the UK
Contact:
Post
by NickHead » Monday 04 April 2016 1:28
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
A lot of stuff that is doing my head in.
NickHead
Posts: 83 Joined: Tuesday 29 October 2013 18:30
Target OS: Linux
Domoticz version:
Location: North East Coast of the UK
Contact:
Post
by NickHead » Monday 04 April 2016 1:29
i'll attach it as a file
A lot of stuff that is doing my head in.
simon_rb
Posts: 612 Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:
Post
by simon_rb » Monday 04 April 2016 1:29
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
NickHead
Posts: 83 Joined: Tuesday 29 October 2013 18:30
Target OS: Linux
Domoticz version:
Location: North East Coast of the UK
Contact:
Post
by NickHead » Monday 04 April 2016 1:32
wont let me do it for some reason
A lot of stuff that is doing my head in.
simon_rb
Posts: 612 Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:
Post
by simon_rb » Monday 04 April 2016 1:34
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
NickHead
Posts: 83 Joined: Tuesday 29 October 2013 18:30
Target OS: Linux
Domoticz version:
Location: North East Coast of the UK
Contact:
Post
by NickHead » Monday 04 April 2016 1:36
if Dstart != "P":
goes directly under DSTART == "WON"
all in the same line other then DSTART = (s.recv(1))
A lot of stuff that is doing my head in.
NickHead
Posts: 83 Joined: Tuesday 29 October 2013 18:30
Target OS: Linux
Domoticz version:
Location: North East Coast of the UK
Contact:
Post
by NickHead » Monday 04 April 2016 1:38
if there is a colon (:) then there is an indentation on the NEXT line
Python Program Rules
A lot of stuff that is doing my head in.
simon_rb
Posts: 612 Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:
Post
by simon_rb » Monday 04 April 2016 1:40
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..
Last edited by
simon_rb on Monday 04 April 2016 1:43, edited 1 time in total.
NickHead
Posts: 83 Joined: Tuesday 29 October 2013 18:30
Target OS: Linux
Domoticz version:
Location: North East Coast of the UK
Contact:
Post
by NickHead » Monday 04 April 2016 1:41
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
A lot of stuff that is doing my head in.
NickHead
Posts: 83 Joined: Tuesday 29 October 2013 18:30
Target OS: Linux
Domoticz version:
Location: North East Coast of the UK
Contact:
Post
by NickHead » Monday 04 April 2016 1:43
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
A lot of stuff that is doing my head in.
simon_rb
Posts: 612 Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:
Post
by simon_rb » Monday 04 April 2016 1:47
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
simon_rb
Posts: 612 Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:
Post
by simon_rb » Monday 04 April 2016 22:11
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 ~ $
Users browsing this forum: No registered users and 1 guest