Newbi to Domoticz TCPIP plugin

Moderator: leecollings

Post Reply
JonF
Posts: 4
Joined: Wednesday 23 January 2019 23:04
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Newbi to Domoticz TCPIP plugin

Post by JonF »

I have good experience of many programming languages.
I currently use Proximix Girder for home automation, but this has been discontinued so I'm looking for an alternative.
Keeping LUA as an option is appealing.
I have an extensive array of sensors and output via many protocols. Most however are serial.
As such I am trying to set up a proof of principle plugin that should be able to poll a defined TCPIP on my local network (address:port), and parse the string response into devices so I can do something with it.
These could be switches, analogue values, sensor states, and output requests.
I consider myself to be capable of picking up most programming languages to a high level, but for the life of me I just can not get my head round making this work.
I'm convinced once I get a proof of concept for some basic building block protocols (none out of the box seem to suit), I'll be on my way.

So, I've cobbled together the following from a mixture of other examples, and I can add it as an item of hardware.
It is located in:
/home/pi/domoticz/plugins/TCPIP and the filename is plugin.py

Code: Select all

"""
<plugin key="TCPIPSerial2" name="TCP IP Serial Driver2" author="JPF" version="1.0.0" >
    <description>
    <h2>TCP IP Serial Driver</h2><br/>
    Test TCPIP Serial driver
    </description>
    <params>
        <param field="Address" label="IP Address" width="200px" required="true" default="192.168.1.000"/>
    <param field="Port" label="Port" width="200px" required="true" default="0000"/>
        <param field="Mode6" label="Debug" width="150px">
            <options>
                <option label="None" value="0"  default="true" />
                <option label="Python Only" value="2"/>
                <option label="Basic Debugging" value="62"/>
                <option label="Basic+Messages" value="126"/>
                <option label="Connections Only" value="16"/>
                <option label="Connections+Python" value="18"/>
                <option label="Connections+Queue" value="144"/>
                <option label="All" value="-1"/>
            </options>
        </param>
    </params>
</plugin>
"""
import Domoticz

class BasePlugin:
    enabled = False
    lastPolled = 0
    lastResponse = 0
    TCPIPConn = None

def __init__(self):
    return

def onStart(self):
    if Parameters["Mode6"] != "0":
        Domoticz.Debugging(int(Parameters["Mode6"]))
        DumpConfigToLog()
    
    self.TCPIPConn=Domoticz.Connection(Name="TCPIP Connection", Transport="TCP/IP", Protocol="None", Address=Parameters["Address"], Port=Parameters["Port"])
    self.TCPIPConn.Listen()

    for Device in Devices:
        UpdateDevice(Device, Devices[Device].nValue, Devices[Device].sValue, 1)
    

def onStop(self):
    Domoticz.Log("onStop called")

def onConnect(self, Connection, Status, Description):
    if (Connection == self.TCPIPConn):
        if (Status == 0):
            Domoticz.Log("Connected successfully to: "+Connection.Address+":"+Connection.Port)
            self.TCPIPConn.Send("PollDevice\r")
        else:
            #nothing
            self.TCPIPConn = None

def onMessage(self, Connection, Data):
    strData = Data.decode("utf-8", "ignore")
    self.lastResponse = 0
    Domoticz.Debug("Received Data: '"+strData)

def onCommand(self, Unit, Command, Level, Hue):
    Domoticz.Log("onCommand called for Unit " + str(Unit) + ": Parameter '" + str(Command) + "', Level: " + str(Level))

def onDisconnect(self, Connection):
    Domoticz.Log("Hardware has disconnected.")
    self.TCPIPConn = None
    for Device in Devices:
        UpdateDevice(Device, Devices[Device].nValue, Devices[Device].sValue, 1)
    return
    
def onHeartbeat(self):
    #nothing
    global TCPIPConn
    TCPIPConn = BasePlugin()

def onStart():
    global TCPIPConn
    TCPIPConn.onStart()

def onStop():
    global TCPIPConn
    TCPIPConn.onStop()

def onConnect(Connection, Status, Description):
    global TCPIPConn
    TCPIPConn.onConnect(Connection, Status, Description)

def onMessage(Connection, Data):
    global TCPIPConn
    TCPIPConn.onMessage(Connection, Data)

def onCommand(Unit, Command, Level, Hue):
    global TCPIPConn
    TCPIPConn.onCommand(Unit, Command, Level, Hue)

def onDisconnect(Connection):
    global TCPIPConn
    TCPIPConn.onDisconnect(Connection)

def onHeartbeat():
    global TCPIPConn
    TCPIPConn.onHeartbeat()

    # Generic helper functions
def DumpConfigToLog():
    for x in Parameters:
        if Parameters[x] != "":
            Domoticz.Debug( "'" + x + "':'" + str(Parameters[x]) + "'")
    Domoticz.Debug("Device count: " + str(len(Devices)))
    for x in Devices:
        Domoticz.Debug("Device:           " + str(x) + " - " + str(Devices[x]))
        Domoticz.Debug("Device ID:       '" + str(Devices[x].ID) + "'")
        Domoticz.Debug("Device Name:     '" + Devices[x].Name + "'")
        Domoticz.Debug("Device nValue:    " + str(Devices[x].nValue))
        Domoticz.Debug("Device sValue:   '" + Devices[x].sValue + "'")
        Domoticz.Debug("Device LastLevel: " + str(Devices[x].LastLevel))
    return
    
def UpdateDevice(Unit, nValue, sValue, TimedOut):
    # Make sure that the Domoticz device still exists (they can be deleted) before updating it 
    if (Unit in Devices):
        if (Devices[Unit].nValue != nValue) or (Devices[Unit].sValue != sValue) or (Devices[Unit].TimedOut != TimedOut):
            Devices[Unit].Update(nValue=nValue, sValue=str(sValue), TimedOut=TimedOut)
            Domoticz.Log("Update "+str(nValue)+":'"+str(sValue)+"' ("+Devices[Unit].Name+")")
    return

def DecodeDDDMessage(Message):
    # Sample discovery message
    # AMXB<-SDKClass=Receiver><-Make=DENON><-Model=AVR-4306>
    strChunks = Message.strip()
    strChunks = strChunks[4:len(strChunks)-1].replace("<-","")
    dirChunks = dict(item.split("=") for item in strChunks.split(">"))
    return dirChunks
I can see that tabbing as a concept is important in python, which is a new language to me.

However, I'm stuck on these errors in the log:
2019-01-23 22:46:12.229 Status: (TEST1) Started.
2019-01-23 22:46:12.403 Status: (TEST1) Entering work loop.
2019-01-23 22:46:12.403 Status: (TEST1) Initialized version 1.0.0, author 'JPF'
2019-01-23 22:46:12.405 Error: (TEST1) 'onStart' failed 'NameError':'name 'TCPIPConn' is not defined'.
2019-01-23 22:46:12.405 Error: (TEST1) ----> Line 82 in /home/pi/domoticz/plugins/TCPIP/plugin.py, function onStart
2019-01-23 22:46:21.922 Error: (TEST1) 'onHeartbeat' failed 'NameError':'name 'TCPIPConn' is not defined'.
2019-01-23 22:46:21.922 Error: (TEST1) ----> Line 106 in /home/pi/domoticz/plugins/TCPIP/plugin.py, function onHeartbeat
2019-01-23 22:46:31.940 Error: (TEST1) 'onHeartbeat' failed 'NameError':'name 'TCPIPConn' is not defined'.
2019-01-23 22:46:31.940 Error: (TEST1) ----> Line 106 in /home/pi/domoticz/plugins/TCPIP/plugin.py, function onHeartbeat
I can see there is a variable not defined, but I just can't understand the concept of what is going on in this plugin.

Can anyone point me in the right direction and/or assist with getting me up an running.

I have Domoticz:
Version: 4.9741
Build Hash: 195d46ab
Compile Date: 2018-07-03 09:28:39
dzVents Version: 2.4.6
Python Version: 3.4.4 (default, Apr 17 2016, 16:02:33) [GCC 5.3.1 20160409]
User avatar
Dnpwwo
Posts: 819
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Newbi to Domoticz TCPIP plugin

Post by Dnpwwo »

@JonF,

If you programmed other languages then Python is going to really annoy you. Not since Fortran have I seen a language where indentation has actual meaning.

By removing the indentation from the BasePlugin 'defs' they are no longer part of the BasePlugin class which means that the callbacks are now defined multiple times because they are at the same indent :o

I would recommend going back to one of the examples and copying the indentation from that. FYI tabs only count as one space to Python so use an editor like Notepad++ where you can convert tabs to spaces.

I feel your pain...
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
JonF
Posts: 4
Joined: Wednesday 23 January 2019 23:04
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Newbi to Domoticz TCPIP plugin

Post by JonF »

Ok thanks.
I'll brush up on python.
So it may just be a formatting issue instead of actual coding errors.
JonF
Posts: 4
Joined: Wednesday 23 January 2019 23:04
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Newbi to Domoticz TCPIP plugin - working, kind of

Post by JonF »

Well I have a result, after a bit of reading up on python

I have a TCPIP connection though to a terminal program for proof of concept.
It also sends data every heartbeat (intended to send the poll command to ask for data).
I can get 8 switches (devices) set up and given an 8 bit string I can set the status of lamps given some string manipulation.
i just need to work out the opposite direction, but I look to be on my way.
I'm also stuck on the refresh rate, which is quite slow. I can;t see where to make this faster (currently 1 - 2 seconds)
For info, I used scite as a python editor, but it needed properties set to use 4 x spaces when the tab was pressed.

below, code working, but still in progress
I also did not realise you can just click 'Update' in the hardware page if you make a change to the plugin.py code and it all refreshes.
I found https://www.domoticz.com/wiki/Developin ... hon_plugin to be very useful, as were some of the examples once the concept was understood.

Code: Select all

"""
<plugin key="TCPIPSerial2" name="TCP IP Serial Driver" author="JPF" version="1.0.0" >
    <description>
    <h2>TCP IP Serial Driver</h2><br/>
    Test TCPIP Serial driver
    </description>
    <params>
        <param field="Address" label="IP Address" width="200px" required="true" default="192.168.1.000"/>
    <param field="Port" label="Port" width="200px" required="true" default="0000"/>
        <param field="Mode6" label="Debug" width="150px">
            <options>
                <option label="None" value="0"  default="true" />
                <option label="Python Only" value="2"/>
                <option label="Basic Debugging" value="62"/>
                <option label="Basic+Messages" value="126"/>
                <option label="Connections Only" value="16"/>
                <option label="Connections+Python" value="18"/>
                <option label="Connections+Queue" value="144"/>
                <option label="All" value="-1"/>
            </options>
        </param>
    </params>
</plugin>
"""
import Domoticz

class BasePlugin:
    enabled = False
    lastPolled = 0
    lastResponse = 0
    TCPIPConn = None

    def __init__(self):
        return

    def onStart(self):
        if Parameters["Mode6"] == "Debug":
            Domoticz.Debugging(1)
            
        if(len(Devices)==0):
            for n in range(1,8):
                Domoticz.Log("Creating device: "+str(n))
                Domoticz.Device(Name="Test_"+str(n), Unit=n, TypeName="Switch",  Image=5).Create()
        
        DumpConfigToLog()
        
        self.handleConnect()
        return

    def onStop(self):
        Domoticz.Log("onStop called")

    def onConnect(self, Connection, Status, Description):
        if (Connection == self.TCPIPConn):
            if (Status == 0):
                Domoticz.Log("Connected successfully to: "+Connection.Address+":"+Connection.Port)
                self.TCPIPConn.Send("New Connection\r")
            else:
                #nothing
                Domoticz.Log("Failed to connect ("+str(Status)+") to: "+Connection.Address+":"+Connection.Port+" with error: "+Description)
                self.TCPIPConn = None

    def onMessage(self, Connection, Data):
        strData = Data.decode("utf-8", "ignore")
        self.lastResponse = 0
        Domoticz.Log("Received Data: "+strData)
        #strip whitespace
        strData = strData.strip()
        #assuming for testing this is a bit list, loop through it
        n=0
        for x in strData:
            n=n+1
            #Domoticz.Log(x)
            if (x=='0'):
                x_status="On"
            else:
                x_status="Off"
            UpdateDevice(n, int(x), x_status, 1)

    def onCommand(self, Unit, Command, Level, Hue):
        Domoticz.Log("onCommand called for Unit " + str(Unit) + ": Parameter '" + str(Command) + "', Level: " + str(Level))

    def onDisconnect(self, Connection):
        Domoticz.Log("Hardware has disconnected.")
        self.TCPIPConn = None
        for Device in Devices:
            UpdateDevice(Device, Devices[Device].nValue, Devices[Device].sValue, 1)
        return
        
    def onHeartbeat(self):
        #nothing
        global TCPIPConn
        #TCPIPConn = BasePlugin()
        self.TCPIPConn.Send('ABC?\r')

    def handleConnect(self):
        self.TCPIPConn = None
        self.TCPIPConn=Domoticz.Connection(Name="TCPIP Connection", Transport="TCP/IP", Protocol="None", Address=Parameters["Address"], Port=Parameters["Port"])
        self.TCPIPConn.Connect()

global _plugin
_plugin = BasePlugin()

def onStart():
    global _plugin
    _plugin.onStart()

def onStop():
    global _plugin
    _plugin.onStop()

def onConnect(Connection, Status, Description):
    global _plugin
    _plugin.onConnect(Connection, Status, Description)

def onMessage(Connection, Data):
    global _plugin
    _plugin.onMessage(Connection, Data)

def onCommand(Unit, Command, Level, Hue):
    global _plugin
    _plugin.onCommand(Unit, Command, Level, Hue)

def onDisconnect(Connection):
    global _plugin
    _plugin.onDisconnect(Connection)

def onHeartbeat():
    global _plugin
    _plugin.onHeartbeat()

    # Generic helper functions
def DumpConfigToLog():
    for x in Parameters:
        if Parameters[x] != "":
            Domoticz.Debug( "'" + x + "':'" + str(Parameters[x]) + "'")
    Domoticz.Debug("Device count: " + str(len(Devices)))
    for x in Devices:
        Domoticz.Debug("Device:           " + str(x) + " - " + str(Devices[x]))
        Domoticz.Debug("Device ID:       '" + str(Devices[x].ID) + "'")
        Domoticz.Debug("Device Name:     '" + Devices[x].Name + "'")
        Domoticz.Debug("Device nValue:    " + str(Devices[x].nValue))
        Domoticz.Debug("Device sValue:   '" + Devices[x].sValue + "'")
        Domoticz.Debug("Device LastLevel: " + str(Devices[x].LastLevel))
    return
    
def UpdateDevice(Unit, nValue, sValue, TimedOut):
    # Make sure that the Domoticz device still exists (they can be deleted) before updating it 
    if (Unit in Devices):
        if (Devices[Unit].nValue != nValue) or (Devices[Unit].sValue != sValue) or (Devices[Unit].TimedOut != TimedOut):
            Devices[Unit].Update(nValue=nValue, sValue=str(sValue), TimedOut=TimedOut)
            Domoticz.Log("Update "+str(nValue)+":'"+str(sValue)+"' ("+Devices[Unit].Name+")")
    return

def DecodeDDDMessage(Message):
    # Sample discovery message
    # AMXB<-SDKClass=Receiver><-Make=DENON><-Model=AVR-4306>
    strChunks = Message.strip()
    strChunks = strChunks[4:len(strChunks)-1].replace("<-","")
    dirChunks = dict(item.split("=") for item in strChunks.split(">"))
    return dirChunks
Flopp
Posts: 279
Joined: Sunday 03 January 2016 14:55
Target OS: -
Domoticz version:
Location: Sweden
Contact:

Re: Newbi to Domoticz TCPIP plugin

Post by Flopp »

Old topic but maybe you can help me.
I get respond if I turn on Debug 64, but with nodebug I dont get any data. How do I listen to it so I can use the responded data?
I tried to use self.httpServerConn as a Listner but it doesnt help

This is my plugin.py

Code: Select all

# Basic Python Listener Example
#
# Author: Dnpwwo, 2017
#
"""
<plugin key="HTTPListen" name="Listener Sample Plugin" author="dnpwwo" version="1.0.0">
    <params>
        <param field="Port" label="Port" width="30px" required="true" default="8008"/>
        <param field="Mode6" label="Debug" width="100px">
            <options>
                <option label="True" value="Debug"/>
                <option label="False" value="Normal"  default="true" />
                <option label="Logging" value="File"/>
            </options>
        </param>
    </params>
</plugin>
"""
import Domoticz
class BasePlugin:
    enabled = False
    httpServerConn = None
    httpServerConns = {}
    httpClientConn = None
    heartbeats = 0

    def __init__(self):
        return

    def onStart(self):
        Domoticz.Debugging(64)
        DumpConfigToLog()
        self.httpServerConn = Domoticz.Connection(Name="Server Connection", Transport="TCP/IP", Protocol="HTTPS", Address="api.home-connect.com", Port="443")
        self.httpServerConn.Listen()
        Domoticz.Log("Leaving on start")

    def onConnect(self, Connection, Status, Description):
        if (Status == 0):
            Domoticz.Log("Connected successfully to: "+Connection.Address+":"+Connection.Port)
        else:
            Domoticz.Log("Failed to connect ("+str(Status)+") to: "+Connection.Address+":"+Connection.Port+" with error: "+Description)
        Domoticz.Log(str(Connection))

        if (Connection != self.httpClientConn):
            self.httpServerConns[Connection.Name] = Connection

    def onMessage(self, Connection, Data):
        Domoticz.Log("onMessage called for connection: "+Connection.Address+":"+Connection.Port)
        DumpHTTPResponseToLog(Data)
        Domoticz.Log(str(Data))

    def onDisconnect(self, Connection):
        Domoticz.Log("onDisconnect called for connection '"+Connection.Name+"'.")
        Domoticz.Log("Server Connections:")
        for x in self.httpServerConns:
            Domoticz.Log("--> "+str(x)+"'.")
        if Connection.Name in self.httpServerConns:
            del self.httpServerConns[Connection.Name]

    def onHeartbeat(self):
        if (self.httpClientConn == None or self.httpClientConn.Connected() != True):
            self.httpClientConn = Domoticz.Connection(Name="Client Connection", Transport="TCP/IP", Protocol="HTTPS", Address="api.home-connect.com", Port="443")
            self.httpClientConn.Connect()
            self.heartbeats = 0
        else:
            if self.heartbeats == 0:
                headers = { 'Host': 'api.home-connect.com', 'Authorization': 'Bearer TYv8TVWTrVoorp7RyjlByMMcbkw6fKfz3IMjNYq5z97S8qiivOkPax4GNUgJA'}
                self.httpClientConn.Send({'Verb':'GET', 'URL': '/api/homeappliances/xxxx9038xxx700xxxx/events', 'Headers': headers})
                self.heartbeats += 1

global _plugin
_plugin = BasePlugin()

def onStart():
    global _plugin
    _plugin.onStart()

def onConnect(Connection, Status, Description):
    global _plugin
    _plugin.onConnect(Connection, Status, Description)

def onMessage(Connection, Data):
    global _plugin
    _plugin.onMessage(Connection, Data)

def onDisconnect(Connection):
    global _plugin
    _plugin.onDisconnect(Connection)

def onHeartbeat():
    global _plugin
    _plugin.onHeartbeat()

# Generic helper functions
def LogMessage(Message):
    if Parameters["Mode6"] != "Normal":
        Domoticz.Log(Message)
    elif Parameters["Mode6"] != "Debug":
        Domoticz.Debug(Message)
    else:
        f = open("http.html","w")
        f.write(Message)
        f.close()

def DumpConfigToLog():
    for x in Parameters:
        if Parameters[x] != "":
            Domoticz.Debug( "'" + x + "':'" + str(Parameters[x]) + "'")
    Domoticz.Debug("Device count: " + str(len(Devices)))
    for x in Devices:
        Domoticz.Debug("Device:           " + str(x) + " - " + str(Devices[x]))
        Domoticz.Debug("Device ID:       '" + str(Devices[x].ID) + "'")
        Domoticz.Debug("Device Name:     '" + Devices[x].Name + "'")
        Domoticz.Debug("Device nValue:    " + str(Devices[x].nValue))
        Domoticz.Debug("Device sValue:   '" + Devices[x].sValue + "'")
        Domoticz.Debug("Device LastLevel: " + str(Devices[x].LastLevel))
    return

def DumpHTTPResponseToLog(httpDict):
    if isinstance(httpDict, dict):
        Domoticz.Log("HTTP Details ("+str(len(httpDict))+"):")
        for x in httpDict:
            if isinstance(httpDict[x], dict):
                Domoticz.Log("--->'"+x+" ("+str(len(httpDict[x]))+"):")
                for y in httpDict[x]:
                    Domoticz.Log("------->'" + y + "':'" + str(httpDict[x][y]) + "'")
            else:
                Domoticz.Log("--->'" + x + "':'" + str(httpDict[x]) + "'")
debian@NUC:~/domoticz/plugins/AliveTest$
and this is what I get in DZ log

Code: Select all

2021-04-22 21:27:45.326 Status: (AliveTest) Started.
2021-04-22 21:27:45.370 Status: (AliveTest) Entering work loop.
2021-04-22 21:27:45.370 Status: (AliveTest) Initialized version 1.0.0, author 'dnpwwo'
2021-04-22 21:27:45.370 (AliveTest) Debug logging mask set to: MESSAGE
2021-04-22 21:27:45.371 (AliveTest) Leaving on start
2021-04-22 21:27:55.508 (AliveTest) Connected successfully to: api.home-connect.com:443
2021-04-22 21:27:55.508 (AliveTest) Name: 'Client Connection', Transport: 'TCP/IP', Protocol: 'HTTPS', Address: 'api.home-connect.com', Port: '443', Baud: -1, Bytes: 0, Connected: True, Last Seen: 2021-04-22 21:27:55, Parent: 'None'
2021-04-22 21:28:05.394 (AliveTest) Sending 1045 bytes of data
2021-04-22 21:28:05.394 (AliveTest)  GET./api/homeapplian
2021-04-22 21:28:05.394 (AliveTest) 63  ces/xxxx9038xxx700xx
2021-04-22 21:28:05.394 (AliveTest) xx/events.HTTP/1.1..
2021-04-22 21:28:05.394 (AliveTest) User-Agent:.Domoticz
2021-04-22 21:28:05.394 (AliveTest) /1.0..Host:.api.home
2021-04-22 21:28:05.394 (AliveTest) -connect.com..Author
2021-04-22 21:28:05.394 (AliveTest) ization:.Bearer.eyJ4
2021-04-22 21:28:05.394 (AliveTest) LWVudiI6IlBSRCIsImFs
2021-04-22 21:28:05.394 (AliveTest) ZyI6IlJTMjU2IiwieC1y
2021-04-22 21:28:05.394 (AliveTest) ZWciOiJFVSIsImtpZCI6
2021-04-22 21:28:05.394 (AliveTest) IlMxIn0.eyJmZ3JwIjpb
2021-04-22 21:28:05.394 (AliveTest) XSwiY2x0eSI6InByaXZh
2021-04-22 21:28:05.394 (AliveTest) dGUiLCJzdWIiOiIwNTRi
2021-04-22 21:28:05.394 (AliveTest) NTJlZC02YxY3LTRmMjgt
2021-04-22 21:28:05.394 (AliveTest) OWI1Ni1jNjBkZDNmNThl
2021-04-22 21:28:05.394 (AliveTest) z97S8qiivOkPax4GNUgJ
2021-04-22 21:28:05.394 (AliveTest) A....
2021-04-22 21:28:05.495 (AliveTest) Received 586 bytes of data
2021-04-22 21:28:05.495 (AliveTest) 48 54 54 50 2f 31 2e 31 20 32 30 30 20 4f 4b 0d 0a 44 61 74 HTTP/1.1.200.OK..Dat
2021-04-22 21:28:05.495 (AliveTest) 65 3a 20 54 68 75 2c 20 32 32 20 41 70 72 20 32 30 32 31 20 e:.Thu,.22.Apr.2021.
2021-04-22 21:28:05.495 (AliveTest) 31 39 3a 32 38 3a 30 35 20 47 4d 54 0d 0a 43 6f 6e 74 65 6e 19:28:05.GMT..Conten
2021-04-22 21:28:05.495 (AliveTest) 74 2d 54 79 70 65 3a 20 74 65 78 74 2f 65 76 65 6e 74 2d 73 t-Type:.text/event-s
2021-04-22 21:28:05.495 (AliveTest) 74 72 65 61 6d 0d 0a 54 72 61 6e 73 66 65 72 2d 45 6e 63 6f tream..Transfer-Enco
2021-04-22 21:28:05.495 (AliveTest) 64 69 6e 67 3a 20 63 68 75 6e 6b 65 64 0d 0a 43 6f 6e 6e 65 ding:.chunked..Conne
2021-04-22 21:28:05.495 (AliveTest) 63 74 69 6f 6e 3a 20 6b 65 65 70 2d 61 6c 69 76 65 0d 0a 61 ction:.keep-alive..a
2021-04-22 21:28:05.495 (AliveTest) 63 63 65 73 73 2d 63 6f 6e 74 72 6f 6c 2d 61 6c 6c 6f 77 2d ccess-control-allow-
2021-04-22 21:28:05.495 (AliveTest) 6f 72 69 67 69 6e 3a 20 2a 0d 0a 61 63 63 65 73 73 2d 63 6f origin:.*..access-co
2021-04-22 21:28:05.495 (AliveTest) 6e 74 72 6f 6c 2d 61 6c 6c 6f 77 2d 6d 65 74 68 6f 64 73 3a ntrol-allow-methods:
2021-04-22 21:28:05.495 (AliveTest) 20 47 45 54 2c 50 4f 53 54 2c 4f 50 54 49 4f 4e 53 2c 50 55 .GET,POST,OPTIONS,PU
2021-04-22 21:28:05.495 (AliveTest) 54 2c 44 45 4c 45 54 45 0d 0a 61 63 63 65 73 73 2d 63 6f 6e T,DELETE..access-con
2021-04-22 21:28:05.495 (AliveTest) 74 72 6f 6c 2d 61 6c 6c 6f 77 2d 63 72 65 64 65 6e 74 69 61 trol-allow-credentia
2021-04-22 21:28:05.495 (AliveTest) 6c 73 3a 20 74 72 75 65 0d 0a 61 63 63 65 73 73 2d 63 6f 6e ls:.true..access-con
2021-04-22 21:28:05.495 (AliveTest) 74 72 6f 6c 2d 61 6c 6c 6f 77 2d 68 65 61 64 65 72 73 3a 20 trol-allow-headers:.
2021-04-22 21:28:05.495 (AliveTest) 41 75 74 68 6f 72 69 7a 61 74 69 6f 6e 2c 43 6f 6e 74 65 6e Authorization,Conten
2021-04-22 21:28:05.495 (AliveTest) 74 2d 54 79 70 65 2c 41 63 63 65 70 74 2c 43 61 63 68 65 2d t-Type,Accept,Cache-
2021-04-22 21:28:05.495 (AliveTest) 43 6f 6e 74 72 6f 6c 2c 4c 61 73 74 2d 45 76 65 6e 74 2d 49 Control,Last-Event-I
2021-04-22 21:28:05.495 (AliveTest) 44 2c 49 66 2d 4d 6f 64 69 66 69 65 64 2d 53 69 6e 63 65 2c D,If-Modified-Since,
2021-04-22 21:28:05.495 (AliveTest) 58 2d 52 65 71 75 65 73 74 65 64 2d 57 69 74 68 2c 58 2d 45 X-Requested-With,X-E
2021-04-22 21:28:05.495 (AliveTest) 76 65 6e 74 73 2d 46 61 63 61 64 65 0d 0a 72 65 66 65 72 72 vents-Facade..referr
2021-04-22 21:28:05.495 (AliveTest) 65 72 2d 70 6f 6c 69 63 79 3a 20 6f 72 69 67 69 6e 0d 0a 78 er-policy:.origin..x
2021-04-22 21:28:05.495 (AliveTest) 2d 66 72 61 6d 65 2d 6f 70 74 69 6f 6e 73 3a 20 73 61 6d 65 -frame-options:.same
2021-04-22 21:28:05.495 (AliveTest) 6f 72 69 67 69 6e 0d 0a 78 2d 63 6f 6e 74 65 6e 74 2d 74 79 origin..x-content-ty
2021-04-22 21:28:05.495 (AliveTest) 70 65 2d 6f 70 74 69 6f 6e 73 3a 20 6e 6f 73 6e 69 66 66 0d pe-options:.nosniff.
2021-04-22 21:28:05.495 (AliveTest) 0a 78 2d 78 73 73 2d 70 72 6f 74 65 63 74 69 6f 6e 3a 20 31 .x-xss-protection:.1
2021-04-22 21:28:05.495 (AliveTest) 3b 20 6d 6f 64 65 3d 62 6c 6f 63 6b 0d 0a 61 70 69 2d 67 61 ;.mode=block..api-ga
2021-04-22 21:28:05.495 (AliveTest) 74 65 77 61 79 2d 73 65 72 76 69 63 65 3a 20 61 70 69 2d 67 teway-service:.api-g
2021-04-22 21:28:05.495 (AliveTest) 61 74 65 77 61 79 0d 0a 68 63 2d 65 6e 76 3a 20 45 55 2d 50 ateway..hc-env:.EU-P
2021-04-22 21:28:05.495 (AliveTest) 52 44 0d 0a 0d 0a .. .. .. .. .. .. .. .. .. .. .. .. .. .. RD....
2021-04-22 21:26:11.819 (AliveTest) Received 52 bytes of data
2021-04-22 21:26:11.819 (AliveTest) 2e..data:.event:KEEP
2021-04-22 21:26:11.819 (AliveTest) -ALIVE.id:xx009038xx
2021-04-22 21:26:11.819 (AliveTest) x700xxxx....
2021-04-22 21:26:11.819 (AliveTest) 603,"handling":"none
2021-04-22 21:26:11.819 (AliveTest) ","uri":"/api/homeap
2021-04-22 21:26:11.819 (AliveTest) pliances/xx009038xxx
2021-04-22 21:26:11.819 (AliveTest) 700xxxx/programs/sel
2021-04-22 21:26:11.819 (AliveTest) ected","key":"BSH.Co
2021-04-22 21:26:11.819 (AliveTest) mmon.Root.SelectedPr
2021-04-22 21:26:11.819 (AliveTest) ogram","value":"Dish
2021-04-22 21:26:11.819 (AliveTest) care.Dishwasher.Prog
2021-04-22 21:26:11.819 (AliveTest) ram.Eco50","level":"
2021-04-22 21:26:11.819 (AliveTest) hint"},{"timestamp":
2021-04-22 21:26:11.819 (AliveTest) 1619119603,"handling
2021-04-22 21:26:11.819 (AliveTest) /:"none","uri":"/api
2021-04-22 21:26:11.819 (AliveTest) /homeappliances/xxxx
2021-04-22 21:26:11.819 (AliveTest) 9038xxx700xxxx/progr
2021-04-22 21:26:11.819 (AliveTest) ams/selected/options
2021-04-22 21:26:11.819 (AliveTest) /BSH.Common.Option.P
2021-04-22 21:26:11.819 (AliveTest) rogramProgress","key
2021-04-22 21:26:11.819 (AliveTest) ":"BSH.Common.Option
2021-04-22 21:26:11.819 (AliveTest) .ProgramProgress","u
2021-04-22 21:26:11.819 (AliveTest) nit":"%","value":0,"
2021-04-22 21:26:11.819 (AliveTest) level":"hint"}],"haI
2021-04-22 21:26:11.819 (AliveTest) d":"xxxx9038xxx700xx
2021-04-22 21:26:11.819 (AliveTest) xx"}.event:NOTIFY.id
2021-04-22 21:26:11.819 (AliveTest) :xxxx9038xxx700xxxx.
2021-04-22 21:26:43.948 (AliveTest) 0a 0d 0a .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ...
2021-04-22 21:26:43.998 (AliveTest) Received 237 bytes of data
2021-04-22 21:26:43.998 (AliveTest) e7..data:{"items":[{
2021-04-22 21:26:43.998 (AliveTest) "timestamp":16191196
2021-04-22 21:26:43.998 (AliveTest) 03,"handling":"none"
2021-04-22 21:26:43.998 (AliveTest) ,"key":"BSH.Common.E
2021-04-22 21:26:43.998 (AliveTest) vent.ProgramFinished
2021-04-22 21:26:43.998 (AliveTest) ","value":"BSH.Commo
2021-04-22 21:26:43.998 (AliveTest) n.EnumType.EventPres
2021-04-22 21:26:43.998 (AliveTest) entState.Off","level
2021-04-22 21:26:43.998 (AliveTest) ":"hint"}],"haId":"0
2021-04-22 21:26:43.999 (AliveTest) xxxx9038xxx700xxxx"}.
2021-04-22 21:26:43.999 (AliveTest) event:EVENT.id:xxxx9
2021-04-22 21:26:43.999 (AliveTest) xxxxx700xxxx....
2021-04-22 21:26:43.999 (AliveTest) Received 336 bytes of data
2021-04-22 21:26:43.999 (AliveTest) 31 34 39 0d 0a 64 61 74 61 3a 7b 22 69 74 65 6d 73 22 3a 5b 149..data:{"items":[
2021-04-22 21:26:43.999 (AliveTest) 7b 22 74 69 6d 65 73 74 61 6d 70 22 3a 31 36 31 39 31 31 39 {"timestamp":1619119
2021-04-22 21:26:43.999 (AliveTest) 36 30 33 2c 22 68 61 6e 64 6c 69 6e 67 22 3a 22 6e 6f 6e 65 603,"handling":"none
2021-04-22 21:26:43.999 (AliveTest) 22 2c 22 75 72 69 22 3a 22 2f 61 70 69 2f 68 6f 6d 65 61 70 ","uri":"/api/homeap
2021-04-22 21:26:43.999 (AliveTest) pliances/xxxx9038xxx
2021-04-22 21:26:43.999 (AliveTest) 700xxxx/programs/sel
2021-04-22 21:26:43.999 (AliveTest) 65 63 74 65 64 2f 6f 70 74 69 6f 6e 73 2f 42 53 48 2e 43 6f ected/options/BSH.Co
2021-04-22 21:26:43.999 (AliveTest) 6d 6d 6f 6e 2e 4f 70 74 69 6f 6e 2e 52 65 6d 61 69 6e 69 6e mmon.Option.Remainin
2021-04-22 21:26:43.999 (AliveTest) 67 50 72 6f 67 72 61 6d 54 69 6d 65 22 2c 22 6b 65 79 22 3a gProgramTime","key":
2021-04-22 21:26:43.999 (AliveTest) 22 42 53 48 2e 43 6f 6d 6d 6f 6e 2e 4f 70 74 69 6f 6e 2e 52 "BSH.Common.Option.R
2021-04-22 21:26:43.999 (AliveTest) 65 6d 61 69 6e 69 6e 67 50 72 6f 67 72 61 6d 54 69 6d 65 22 emainingProgramTime"
2021-04-22 21:26:43.999 (AliveTest) 2c 22 75 6e 69 74 22 3a 22 73 65 63 6f 6e 64 73 22 2c 22 76 ,"unit":"seconds","v
2021-04-22 21:26:43.999 (AliveTest) 61 6c 75 65 22 3a 31 34 34 30 30 2c 22 6c 65 76 65 6c 22 3a alue":14400,"level":
2021-04-22 21:26:43.999 (AliveTest) "hint"}],"haId":"xxx
2021-04-22 21:26:43.999 (AliveTest) x9038xxx700xxxx"}.ev
2021-04-22 21:26:43.999 (AliveTest) ent:NOTIFY.id:xxxx90
2021-04-22 21:26:43.999 (AliveTest) 38xxx700xxxx....
2021-04-22 21:26:44.151 (AliveTest) Received 325 bytes of data
2021-04-22 21:26:44.151 (AliveTest) 31 33 65 0d 0a 64 61 74 61 3a 7b 22 69 74 65 6d 73 22 3a 5b 13e..data:{"items":[
2021-04-22 21:26:44.151 (AliveTest) 7b 22 74 69 6d 65 73 74 61 6d 70 22 3a 31 36 31 39 31 31 39 {"timestamp":1619119
2021-04-22 21:26:44.151 (AliveTest) 36 30 34 2c 22 68 61 6e 64 6c 69 6e 67 22 3a 22 6e 6f 6e 65 604,"handling":"none
2021-04-22 21:26:44.151 (AliveTest) 22 2c 22 75 72 69 22 3a 22 2f 61 70 69 2f 68 6f 6d 65 61 70 ","uri":"/api/homeap
2021-04-22 21:26:44.151 (AliveTest) pliances/xxxx9038xxx
2021-04-22 21:26:44.151 (AliveTest) 700xxxx/status/BSH.C
2021-04-22 21:26:44.151 (AliveTest) ommon.Status.Operati
2021-04-22 21:26:44.151 (AliveTest) onState","key":"BSH.
2021-04-22 21:26:44.151 (AliveTest) Common.Status.Operat
2021-04-22 21:26:44.151 (AliveTest) ionState","value":"B
2021-04-22 21:26:44.151 (AliveTest) SH.Common.EnumType.O
2021-04-22 21:26:44.151 (AliveTest) perationState.Ready"
2021-04-22 21:26:44.151 (AliveTest) ,"level":"hint"}],"h
2021-04-22 21:26:44.151 (AliveTest) aId":"xxxx9038xxx700
2021-04-22 21:26:44.151 (AliveTest) xxxx"}.event:STATUS.
2021-04-22 21:26:44.151 (AliveTest) id:xxxx9038700
2021-04-22 21:26:44.151 (AliveTest) xx..
User avatar
Dnpwwo
Posts: 819
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Newbi to Domoticz TCPIP plugin

Post by Dnpwwo »

Hi Flopp,

You have set the connection protocol to HTTPS but I suspect that whatever you are connecting to is not sending a valid HTTP response. I've seen this before with some embedded webservers.

The debug messages are showing the device is returning data but onMessage is never called because the connection code does not believe it has a 'complete' message yet. This is the same with debug on or off.

If you set the protocol to 'None' the plugin will get to see the data as it arrives and you can decode the HTTP yourself
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
Flopp
Posts: 279
Joined: Sunday 03 January 2016 14:55
Target OS: -
Domoticz version:
Location: Sweden
Contact:

Re: Newbi to Domoticz TCPIP plugin

Post by Flopp »

Thanks for your reply, I tried everything, I think, but no success.

For ListenConnection I removed Protocol, set Protocol to None(string), set port to 80(string).

Can it be that the response is not coming from same address as the request is sent to?

any other test I can do?
Flopp
Posts: 279
Joined: Sunday 03 January 2016 14:55
Target OS: -
Domoticz version:
Location: Sweden
Contact:

Re: Newbi to Domoticz TCPIP plugin

Post by Flopp »

when I run it as curl I can at least see that it is TCP and port 443

Maybe this doesn't help to solve :(

curl 13175 debian 3u IPv4 19307268 0t0 TCP 192.168.100.14:44502->52.29.215.214:443 (ESTABLISHED)
User avatar
Dnpwwo
Posts: 819
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Newbi to Domoticz TCPIP plugin

Post by Dnpwwo »

@Flopp,

Had another look at you code and I think you've made it much harder than it needs to be. Which example did you start from? I would recommend the HTTP.py example because I don't believe you need to 'Listen'.

When you ask the framework to open a connection to an address (as you do with your httpClientConn) it will automatically call onMessage for any messages that arrive depending on the protocol selected. All your httpServerConn(s) related code is not required an is just confusing things.

api.home-connect.com is only returning a single response (to the GET request) although with Debug set it looks like more than one because it is a chunked response. onMessage never gets called because the final chunk never arrives so technically the response never completes (unless you didn't post the whole debug trace).

Could you remove the Listen code and set debug to All and repost?
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
Flopp
Posts: 279
Joined: Sunday 03 January 2016 14:55
Target OS: -
Domoticz version:
Location: Sweden
Contact:

Re: Newbi to Domoticz TCPIP plugin

Post by Flopp »

Thanks a lot for helping me :)

i have now disable ServerConn.Listen
Dnpwwo wrote: Saturday 24 April 2021 4:54 @Flopp,

Had another look at you code and I think you've made it much harder than it needs to be. Which example did you start from? I would recommend the HTTP.py example because I don't believe you need to 'Listen'.
Used HTTP Listen
Dnpwwo wrote: Saturday 24 April 2021 4:54 @Flopp,

api.home-connect.com is only returning a single response (to the GET request) although with Debug set it looks like more than one because it is a chunked response. onMessage never gets called because the final chunk never arrives so technically the response never completes (unless you didn't post the whole debug trace).
I post the whole debug
Dnpwwo wrote: Saturday 24 April 2021 4:54 @Flopp,

Could you remove the Listen code and set debug to All and repost?
here it comes
2021-04-24 09:05:34.139 (AliveTest) Debug logging mask set to: PYTHON PLUGIN QUEUE IMAGE DEVICE CONNECTION MESSAGE ALL
2021-04-24 09:05:34.139 (AliveTest) 'HardwareID':'21'
2021-04-24 09:05:34.139 (AliveTest) 'HomeFolder':'/home/debian/domoticz/plugins/AliveTest/'
2021-04-24 09:05:34.139 (AliveTest) 'StartupFolder':'/home/debian/domoticz/'
2021-04-24 09:05:34.139 (AliveTest) 'UserDataFolder':'/home/debian/domoticz/'
2021-04-24 09:05:34.139 (AliveTest) 'Database':'/home/debian/domoticz/domoticz.db'
2021-04-24 09:05:34.139 (AliveTest) 'Language':'en'
2021-04-24 09:05:34.139 (AliveTest) 'Version':'1.0.0'
2021-04-24 09:05:34.139 (AliveTest) 'Author':'dnpwwo'
2021-04-24 09:05:34.139 (AliveTest) 'Name':'AliveTest'
2021-04-24 09:05:34.139 (AliveTest) 'Port':'443'
2021-04-24 09:05:34.139 (AliveTest) 'Key':'HTTPListen'
2021-04-24 09:05:34.139 (AliveTest) 'Mode6':'Normal'
2021-04-24 09:05:34.139 (AliveTest) 'DomoticzVersion':'2020.2'
2021-04-24 09:05:34.139 (AliveTest) 'DomoticzHash':'b63341bc0'
2021-04-24 09:05:34.139 (AliveTest) 'DomoticzBuildTime':'2020-04-26 13:47:55'
2021-04-24 09:05:34.139 (AliveTest) Device count: 0
2021-04-24 09:05:34.139 (AliveTest) Leaving on start
2021-04-24 09:05:34.071 Status: (AliveTest) Started.
2021-04-24 09:05:34.139 Status: (AliveTest) Entering work loop.
2021-04-24 09:05:34.139 Status: (AliveTest) Initialized version 1.0.0, author 'dnpwwo'
2021-04-24 09:05:44.141 (AliveTest) Pushing 'onHeartbeatCallback' on to queue
2021-04-24 09:05:44.163 (AliveTest) Processing 'onHeartbeatCallback' message
2021-04-24 09:05:44.163 (AliveTest) Calling message handler 'onHeartbeat'.
2021-04-24 09:05:44.163 (AliveTest) Pushing 'ProtocolDirective' on to queue
2021-04-24 09:05:44.163 (AliveTest) Pushing 'ConnectDirective' on to queue
2021-04-24 09:05:44.163 (AliveTest) Processing 'ProtocolDirective' message
2021-04-24 09:05:44.163 (AliveTest) Protocol set to: 'HTTPS'.
2021-04-24 09:05:44.163 (AliveTest) Processing 'ConnectDirective' message
2021-04-24 09:05:44.163 (AliveTest) Transport set to: 'TCP/IP', api.home-connect.com:443.
2021-04-24 09:05:44.169 (AliveTest) Connect directive received, action initiated successfully.
2021-04-24 09:05:44.223 (AliveTest) Pushing 'onConnectCallback' on to queue
2021-04-24 09:05:44.269 (AliveTest) Processing 'onConnectCallback' message
2021-04-24 09:05:44.269 (AliveTest) Calling message handler 'onConnect'.
2021-04-24 09:05:44.269 (AliveTest) Connected successfully to: api.home-connect.com:443
2021-04-24 09:05:44.269 (AliveTest) Name: 'Client Connection', Transport: 'TCP/IP', Protocol: 'HTTPS', Address: 'api.home-connect.com', Port: '443', Baud: -1, Bytes: 0, Connected: True, Last Seen: 2021-04-24 09:05:44, Parent: 'None'
2021-04-24 09:05:44.269 (AliveTest) Connected successfully to: api.home-connect.com:443
2021-04-24 09:05:44.269 (AliveTest) Connected successfully to: api.home-connect.com:443
2021-04-24 09:05:54.192 (AliveTest) 64 47 6b 69 4f 69 4a 69 4d 47 4e 69 59 7a 6c 69 4f 53 30 44 dGkiOiJiMGNiYzliOS0a
2021-04-24 09:05:54.192 (AliveTest) 4e 7a 4d 33 4c 54 51 79 4d 6a 4d 74 59 54 4a 6d 59 53 30 44 NzM3LTQyMjMtYTJmYS01
2021-04-24 09:05:54.192 (AliveTest) 4d 57 49 30 4f 47 49 78 4e 54 42 6d 59 54 45 69 66 51 2e 44 MWI0OGIxNTBmYTEifQ.y
2021-04-24 09:05:54.192 (AliveTest) 31 58 46 2d 72 4c 33 31 68 36 6b 54 43 4d 6b 58 61 4f 48 67 1XF-rL31h6kTCMkXaOHg
2021-04-24 09:05:54.192 (AliveTest) 5a 78 43 79 71 63 68 59 41 4c 30 6b 45 50 73 63 72 71 62 4e ZxCyqchYAL0kEPscrqbN
2021-04-24 09:05:54.192 (AliveTest) 38 52 5f 34 37 6a 70 52 4a 58 36 45 43 64 30 47 46 7a 65 59 8R_47jpRJX6ECd0GFzeY
2021-04-24 09:05:54.192 (AliveTest) 4c 52 4e 75 67 75 6e 4d 55 7a 55 74 59 41 48 4e 6b 5f 74 70 LRNugunMUzUtYAHNk_tp
2021-04-24 09:05:54.192 (AliveTest) 41 45 35 79 48 7a 73 6c 55 49 37 70 4f 76 65 36 4b 4b 35 54 AE5yHzslUI7pOve6KK5s
2021-04-24 09:05:54.192 (AliveTest) 34 47 37 34 4e 47 79 53 4b 4b 53 62 57 6d 6b 59 30 57 79 33 4G74NGySKKSbWmkY0Wy3
2021-04-24 09:05:54.192 (AliveTest) 67 35 76 54 4d 63 67 68 46 78 46 63 77 78 49 57 31 66 74 6a g5vTMcghFxFcwxIW1ftj
2021-04-24 09:05:54.192 (AliveTest) 49 31 2d 52 43 38 4e 72 41 6f 4c 42 62 65 4c 37 41 4f 79 50 I1-RC8NrAoLBbeL7AOyP
2021-04-24 09:05:54.192 (AliveTest) 7a 78 38 68 31 67 52 33 51 2d 6c 56 34 6e 78 57 58 56 50 52 zx8h1gR3Q-lV4nxWXVPR
2021-04-24 09:05:54.192 (AliveTest) 30 64 33 33 66 34 72 65 48 6f 48 74 65 54 5f 72 33 6a 6e 4e 0d33f4reHoHteT_r3jnN
2021-04-24 09:05:54.192 (AliveTest) 39 2d 74 46 6b 4a 4f 37 53 64 71 67 6b 68 77 48 67 62 44 6a 9-tFkJO7SdqgkhwHgbDj
2021-04-24 09:05:54.192 (AliveTest) 79 57 51 64 4a 54 4c 6b 73 61 36 2d 4b 4b 31 5f 6f 66 5a 73 yWQdJTLksa6-KK1_ofZs
2021-04-24 09:05:54.192 (AliveTest) 6f 6a 58 47 44 44 5f 75 30 36 58 41 76 4e 63 67 49 72 7a 49 ojXGDD_u06XAvNcgIrzI
2021-04-24 09:05:54.192 (AliveTest) 66 71 75 31 31 4b 67 73 52 74 42 62 44 64 76 75 43 2d 72 47 fqu11KgsRtBbDdvuC-rG
2021-04-24 09:05:54.192 (AliveTest) 41 74 74 38 68 52 70 4a 6c 43 77 6e 6a 4b 72 73 53 59 4a 65 Att8hRpJlCwnjKrsSYJe
2021-04-24 09:05:54.193 (AliveTest) 53 34 61 4f 69 4b 55 54 79 70 4d 53 34 77 70 62 59 32 4b 34 S4aOiKUTypMS4wpbY2K4
2021-04-24 09:05:54.193 (AliveTest) 51 65 72 75 4a 48 4c 50 34 47 71 66 63 41 43 70 39 69 35 77 QeruJHLP4GqfcACp9i5w
2021-04-24 09:05:54.193 (AliveTest) 51 0d 0a 0d 0a .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. Q....
2021-04-24 09:05:54.276 (AliveTest) Pushing 'ReadEvent' on to queue
2021-04-24 09:05:54.293 (AliveTest) Processing 'ReadEvent' message
2021-04-24 09:05:54.293 (AliveTest) Received 586 bytes of data
2021-04-24 09:05:54.293 (AliveTest) 48 54 54 50 2f 31 2e 31 20 32 30 30 20 4f 4b 0d 0a 44 61 74 HTTP/1.1.200.OK..Dat
2021-04-24 09:05:54.293 (AliveTest) 65 3a 20 53 61 74 2c 20 32 34 20 41 70 72 20 32 30 32 31 20 e:.Sat,.24.Apr.2021.
2021-04-24 09:05:54.293 (AliveTest) 30 37 3a 30 35 3a 35 34 20 47 4d 54 0d 0a 43 6f 6e 74 65 6e 07:05:54.GMT..Conten
2021-04-24 09:05:54.293 (AliveTest) 74 2d 54 79 70 65 3a 20 74 65 78 74 2f 65 76 65 6e 74 2d 73 t-Type:.text/event-s
2021-04-24 09:05:54.293 (AliveTest) 74 72 65 61 6d 0d 0a 54 72 61 6e 73 66 65 72 2d 45 6e 63 6f tream..Transfer-Enco
2021-04-24 09:05:54.293 (AliveTest) 64 69 6e 67 3a 20 63 68 75 6e 6b 65 64 0d 0a 43 6f 6e 6e 65 ding:.chunked..Conne
2021-04-24 09:05:54.293 (AliveTest) 63 74 69 6f 6e 3a 20 6b 65 65 70 2d 61 6c 69 76 65 0d 0a 61 ction:.keep-alive..a
2021-04-24 09:05:54.293 (AliveTest) 63 63 65 73 73 2d 63 6f 6e 74 72 6f 6c 2d 61 6c 6c 6f 77 2d ccess-control-allow-
2021-04-24 09:05:54.293 (AliveTest) 6f 72 69 67 69 6e 3a 20 2a 0d 0a 61 63 63 65 73 73 2d 63 6f origin:.*..access-co
2021-04-24 09:05:54.293 (AliveTest) 6e 74 72 6f 6c 2d 61 6c 6c 6f 77 2d 6d 65 74 68 6f 64 73 3a ntrol-allow-methods:
2021-04-24 09:05:54.293 (AliveTest) 20 47 45 54 2c 50 4f 53 54 2c 4f 50 54 49 4f 4e 53 2c 50 55 .GET,POST,OPTIONS,PU
2021-04-24 09:05:54.293 (AliveTest) 54 2c 44 45 4c 45 54 45 0d 0a 61 63 63 65 73 73 2d 63 6f 6e T,DELETE..access-con
2021-04-24 09:05:54.293 (AliveTest) 74 72 6f 6c 2d 61 6c 6c 6f 77 2d 63 72 65 64 65 6e 74 69 61 trol-allow-credentia
2021-04-24 09:05:54.293 (AliveTest) 6c 73 3a 20 74 72 75 65 0d 0a 61 63 63 65 73 73 2d 63 6f 6e ls:.true..access-con
2021-04-24 09:05:54.293 (AliveTest) 74 72 6f 6c 2d 61 6c 6c 6f 77 2d 68 65 61 64 65 72 73 3a 20 trol-allow-headers:.
2021-04-24 09:05:54.293 (AliveTest) 41 75 74 68 6f 72 69 7a 61 74 69 6f 6e 2c 43 6f 6e 74 65 6e Authorization,Conten
2021-04-24 09:05:54.293 (AliveTest) 74 2d 54 79 70 65 2c 41 63 63 65 70 74 2c 43 61 63 68 65 2d t-Type,Accept,Cache-
2021-04-24 09:05:54.293 (AliveTest) 43 6f 6e 74 72 6f 6c 2c 4c 61 73 74 2d 45 76 65 6e 74 2d 49 Control,Last-Event-I
2021-04-24 09:05:54.293 (AliveTest) 44 2c 49 66 2d 4d 6f 64 69 66 69 65 64 2d 53 69 6e 63 65 2c D,If-Modified-Since,
2021-04-24 09:05:54.293 (AliveTest) 58 2d 52 65 71 75 65 73 74 65 64 2d 57 69 74 68 2c 58 2d 45 X-Requested-With,X-E
2021-04-24 09:05:54.293 (AliveTest) 76 65 6e 74 73 2d 46 61 63 61 64 65 0d 0a 72 65 66 65 72 72 vents-Facade..referr
2021-04-24 09:05:54.293 (AliveTest) 65 72 2d 70 6f 6c 69 63 79 3a 20 6f 72 69 67 69 6e 0d 0a 78 er-policy:.origin..x
2021-04-24 09:05:54.293 (AliveTest) 2d 66 72 61 6d 65 2d 6f 70 74 69 6f 6e 73 3a 20 73 61 6d 65 -frame-options:.same
2021-04-24 09:05:54.293 (AliveTest) 6f 72 69 67 69 6e 0d 0a 78 2d 63 6f 6e 74 65 6e 74 2d 74 79 origin..x-content-ty
2021-04-24 09:05:54.293 (AliveTest) 70 65 2d 6f 70 74 69 6f 6e 73 3a 20 6e 6f 73 6e 69 66 66 0d pe-options:.nosniff.
2021-04-24 09:05:54.293 (AliveTest) 0a 78 2d 78 73 73 2d 70 72 6f 74 65 63 74 69 6f 6e 3a 20 31 .x-xss-protection:.1
2021-04-24 09:05:54.293 (AliveTest) 3b 20 6d 6f 64 65 3d 62 6c 6f 63 6b 0d 0a 61 70 69 2d 67 61 ;.mode=block..api-ga
2021-04-24 09:05:54.293 (AliveTest) 74 65 77 61 79 2d 73 65 72 76 69 63 65 3a 20 61 70 69 2d 67 teway-service:.api-g
2021-04-24 09:05:54.293 (AliveTest) 61 74 65 77 61 79 0d 0a 68 63 2d 65 6e 76 3a 20 45 55 2d 50 ateway..hc-env:.EU-P
2021-04-24 09:05:54.293 (AliveTest) 52 44 0d 0a 0d 0a .. .. .. .. .. .. .. .. .. .. .. .. .. .. RD....
2021-04-24 09:05:56.039 (AliveTest) Pushing 'ReadEvent' on to queue
2021-04-24 09:05:56.052 (AliveTest) Processing 'ReadEvent' message
2021-04-24 09:05:56.052 (AliveTest) Received 241 bytes of data
2021-04-24 09:05:56.052 (AliveTest) 65 62 0d 0a 64 61 74 61 3a 7b 22 69 74 65 6d 73 22 3a 5b 7b eb..data:{"items":[{
2021-04-24 09:05:56.052 (AliveTest) 22 74 69 6d 65 73 74 61 6d 70 22 3a 31 36 31 39 32 34 37 39 "timestamp":16192479
2021-04-24 09:05:56.052 (AliveTest) 35 36 2c 22 68 61 6e 64 6c 69 6e 67 22 3a 22 6e 6f 6e 65 22 56,"handling":"none"
2021-04-24 09:05:56.052 (AliveTest) 2c 22 6b 65 79 22 3a 22 42 53 48 2e 43 6f 6d 6d 6f 6e 2e 45 ,"key":"BSH.Common.E
2021-04-24 09:05:56.052 (AliveTest) 76 65 6e 74 2e 50 72 6f 67 72 61 6d 46 69 6e 69 73 68 65 64 vent.ProgramFinished
2021-04-24 09:05:56.052 (AliveTest) 22 2c 22 76 61 6c 75 65 22 3a 22 42 53 48 2e 43 6f 6d 6d 6f ","value":"BSH.Commo
2021-04-24 09:05:56.052 (AliveTest) 6e 2e 45 6e 75 6d 54 79 70 65 2e 45 76 65 6e 74 50 72 65 73 n.EnumType.EventPres
2021-04-24 09:05:56.052 (AliveTest) 65 6e 74 53 74 61 74 65 2e 50 72 65 73 65 6e 74 22 2c 22 6c entState.Present","l
2021-04-24 09:05:56.052 (AliveTest) 65 76 65 6c 22 3a 22 68 69 6e 74 22 7d 5d 2c 22 68 61 49 64 evel":"hint"}],"haId
2021-04-24 09:05:56.052 (AliveTest) 22 3a 22 30 31 30 30 39 30 33 38 36 34 38 37 30 30 31 38 35 ":"01009038648700185
2021-04-24 09:05:56.052 (AliveTest) 36 22 7d 0a 65 76 65 6e 74 3a 45 56 45 4e 54 0a 69 64 3a 30 6"}.event:EVENT.id:0
2021-04-24 09:05:56.052 (AliveTest) 30 34 30 39 30 33 38 36 34 34 37 30 30 31 38 35 36 0a 0a 00 20090386487001852...
2021-04-24 09:05:56.052 (AliveTest) 0a .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .
2021-04-24 09:06:04.145 (AliveTest) Pushing 'onHeartbeatCallback' on to queue
2021-04-24 09:06:04.170 (AliveTest) Processing 'onHeartbeatCallback' message
2021-04-24 09:06:04.170 (AliveTest) Calling message handler 'onHeartbeat'.
2021-04-24 09:06:51.057 (AliveTest) Pushing 'ReadEvent' on to queue
2021-04-24 09:06:51.078 (AliveTest) Processing 'ReadEvent' message
2021-04-24 09:06:51.078 (AliveTest) Received 52 bytes of data
2021-04-24 09:06:51.078 (AliveTest) 32 65 0d 0a 64 61 74 61 3a 0a 65 76 65 6e 74 3a 4b 45 45 50 2e..data:.event:KEEP
2021-04-24 09:06:51.079 (AliveTest) 2d 41 4c 49 56 45 0a 69 64 3a 30 30 34 30 39 30 33 38 36 34 -ALIVE.id:0200903864
2021-04-24 09:06:51.079 (AliveTest) 38 37 30 30 31 38 35 36 0a 0a 0d 02 .. .. .. .. .. .. .. .. 87001852....
2021-04-24 09:06:54.224 (AliveTest) Pushing 'onHeartbeatCallback' on to queue
2021-04-24 09:06:54.236 (AliveTest) Processing 'onHeartbeatCallback' message
2021-04-24 09:06:54.236 (AliveTest) Calling message handler 'onHeartbeat'.
Flopp
Posts: 279
Joined: Sunday 03 January 2016 14:55
Target OS: -
Domoticz version:
Location: Sweden
Contact:

Re: Newbi to Domoticz TCPIP plugin

Post by Flopp »

this is my code, I have removed default code

Code: Select all

class BasePlugin:
    enabled = False
    httpServerConn = None
    httpServerConns = {}
    httpClientConn = None
    heartbeats = 0

    def __init__(self):
        return

    def onStart(self):

        Domoticz.Debugging(1)
        DumpConfigToLog()

        Domoticz.Log("Leaving on start")

    def onConnect(self, Connection, Status, Description):
        if (Status == 0):
            Domoticz.Log("Connected successfully to: "+Connection.Address+":"+Connection.Port)
        else:
            Domoticz.Log("Failed to connect ("+str(Status)+") to: "+Connection.Address+":"+Connection.Port+" with error: "+Description)
        Domoticz.Log(str(Connection))
        Domoticz.Log("Connected successfully to: "+Connection.Address+":"+Connection.Port)

        if (Connection != self.httpClientConn):
            self.httpServerConns[Connection.Name] = Connection

    def onMessage(self, Connection, Data):
        Domoticz.Log("onMessage called for connection: "+Connection.Name)
        DumpHTTPResponseToLog(Data)
        Domoticz.Log(str(Data))


    def onDisconnect(self, Connection):
        Domoticz.Log("onDisconnect called for connection '"+Connection.Name+"'.")
        Domoticz.Log("Server Connections:")
        for x in self.httpServerConns:
            Domoticz.Log("--> "+str(x)+"'.")
        if Connection.Name in self.httpServerConns:
            del self.httpServerConns[Connection.Name]

    def onHeartbeat(self):
        if (self.httpClientConn == None or self.httpClientConn.Connected() != True):
            self.httpClientConn = Domoticz.Connection(Name="Client Connection", Transport="TCP/IP", Protocol="HTTPS", Address="api.home-connect.com", Port="443")
            self.httpClientConn.Connect()
            self.heartbeats = 0
        else:
            if self.heartbeats == 0:
                headers = { 'Host': 'api.home-connect.com', 'Authorization': 'Bearer OGIxNTBmYTEifQ.d1XF-9i5wQ'}
                self.httpClientConn.Send({'Verb':'GET', 'URL': '/api/homeappliances/02009031001851/events', 'Headers': headers})

                self.heartbeats += 1

Flopp
Posts: 279
Joined: Sunday 03 January 2016 14:55
Target OS: -
Domoticz version:
Location: Sweden
Contact:

Re: Newbi to Domoticz TCPIP plugin

Post by Flopp »

Anyone know how to solve this?
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests