@Dnpwwo thanks for the suggestions. I am still stuck with this:
Seismicportal requires a long-lived websocket connection. Whenever a new message arrives, the server just sends it in a JSON format. You have to keep the connection open to get new events. I tried 2 ways:
1. websocket-client module:
Everything works OK, i got the messages, the websocket-client send pings to the server in a timely manner, since if the server is not pinged, it has a timeout of 1 min. and it kicks the client out. The problem with this approach is that you have to use "ws.run_forever()" to keep the connection open, but since the Domoticz Plugin Framework doesn't support threading, the plugin thread just stucks in that line; event tough i close the domoticz server down, i have to kill the domoticz server process seperately, there's no way to use ws.close() since the ws.run_forever() keeps the plugin occupied.
2. Native HTTP method:
I tried to make an upgrade to the native plugin HTTP connection with:
Code: Select all
onstart()
self.socketConn = Domoticz.Connection(Name="EmscConn", Transport="TCP/IP", Protocol="HTTP", Address="www.seismicportal.eu", Port="80")
onconnect()
Headers = { 'Content-Type': 'text/xml; charset=utf-8', \
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', \
'Host': "www.seismicportal.eu", \
'User-Agent':'Domoticz/1.0', \
'Upgrade': 'websocket', \
'Connection':'keep-alive, Upgrade', \
'Sec-Websocket-Key': 'fv9RzjCDxpJj4FUXmUo7ZA==', \
'Sec-Websocket-Version': '13', \
'Sec-Websocket-Extensons':'permessage-deflate'}
Connection.Send({"Verb":"GET", "URL":"/standing_order/websocket", "Headers": Headers})
It looks like it is connected, but since i couldn't send a ping frame the connection drops out after 1 minute. Connection.send() only supports 'Verb' and 'Status', it doesn't support to send a raw frame. And also for the JSON:
Code: Select all
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]) + "'")
does not solve the incoming JSON, since the incoming message is not http defined i guess. I tried to make a JSON connection but this time the GET Verb for the elevated websocket connection creates an error.
Do you have any suggestions? I basically prefer to solve it in a native way but as i see there're not any examples, only the samsung tv plugin with Short-lived one-off send-receive connections using websocket-client module which doesn't help me much. Thanks...