Skip to content

Commit

Permalink
Merge pull request #173 from Luos-io/rc_2.2.8
Browse files Browse the repository at this point in the history
Pyluos Release 2.2.8
  • Loading branch information
JeromeGalan authored Nov 4, 2022
2 parents a349582 + f92bbc8 commit 2ea7dd5
Show file tree
Hide file tree
Showing 3 changed files with 218 additions and 135 deletions.
13 changes: 6 additions & 7 deletions pyluos/io/ws.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import socket
import websocket
import struct

import sys
if sys.version_info >= (3, 0):
Expand All @@ -16,7 +17,6 @@ def resolve_hostname(hostname, port):
# to enforce we only search for IPV4 address
# and avoid a 5s timeout in the websocket on the ESP
# See https://github.com/esp8266/Arduino/issues/2110

addrinfo = socket.getaddrinfo(hostname, port,
socket.AF_INET, 0,
socket.SOL_TCP)
Expand All @@ -32,7 +32,7 @@ def is_host_compatible(cls, host):
socket.inet_pton(socket.AF_INET, host)
return True
except socket.error:
return host.endswith('.local')
return host.endswith('.local') or (host == "localhost")

@classmethod
def available_hosts(cls):
Expand All @@ -47,8 +47,8 @@ def available_hosts(cls):
def __init__(self, host, port=9342):
host = resolve_hostname(host, port)

self._ws = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._ws.connect((host, port))
self._ws = websocket.WebSocket()
self._ws.connect("ws://" + str(host) + ":" + str(port)+"/ws")

self._msg = queue.Queue(500)
self._running = True
Expand All @@ -68,7 +68,7 @@ def recv(self):
return data

def write(self, data):
self._ws.send(data + '\r'.encode() + '\n'.encode())
self._ws.send(data)

def close(self):
self._running = False
Expand All @@ -92,8 +92,7 @@ def extract_line(s):
buff = b''

while self._running:
s = self._ws.recv(4096)

s = self._ws.recv()
buff = buff + s
while self._running:
line, buff = extract_line(buff)
Expand Down
Loading

0 comments on commit 2ea7dd5

Please sign in to comment.