add logging to the UDP broadcast discovery path
This commit is contained in:
@@ -72,6 +72,7 @@ class SaturnPrinter:
|
|||||||
with sock:
|
with sock:
|
||||||
sock.settimeout(timeout)
|
sock.settimeout(timeout)
|
||||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, timeout)
|
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, timeout)
|
||||||
|
logging.debug(f"sending M99999 to {broadcast}:{SATURN_UDP_PORT}")
|
||||||
sock.sendto(b'M99999', (broadcast, SATURN_UDP_PORT))
|
sock.sendto(b'M99999', (broadcast, SATURN_UDP_PORT))
|
||||||
|
|
||||||
now = time.time()
|
now = time.time()
|
||||||
@@ -85,6 +86,7 @@ class SaturnPrinter:
|
|||||||
else:
|
else:
|
||||||
#logging.debug(f'Found printer at {addr}')
|
#logging.debug(f'Found printer at {addr}')
|
||||||
pdata = json.loads(data.decode('utf-8'))
|
pdata = json.loads(data.decode('utf-8'))
|
||||||
|
logging.debug(f"received: {pdata}")
|
||||||
printers.append(SaturnPrinter(addr, pdata))
|
printers.append(SaturnPrinter(addr, pdata))
|
||||||
return printers
|
return printers
|
||||||
|
|
||||||
@@ -101,6 +103,7 @@ class SaturnPrinter:
|
|||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
with sock:
|
with sock:
|
||||||
sock.settimeout(timeout)
|
sock.settimeout(timeout)
|
||||||
|
logging.debug(f"sending M99999 to {broadcast}:{SATURN_UDP_PORT}")
|
||||||
sock.sendto(b'M99999', (self.addr, SATURN_UDP_PORT))
|
sock.sendto(b'M99999', (self.addr, SATURN_UDP_PORT))
|
||||||
try:
|
try:
|
||||||
data, addr = sock.recvfrom(1024)
|
data, addr = sock.recvfrom(1024)
|
||||||
@@ -108,6 +111,7 @@ class SaturnPrinter:
|
|||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
pdata = json.loads(data.decode('utf-8'))
|
pdata = json.loads(data.decode('utf-8'))
|
||||||
|
logging.debug(f"received: {pdata}")
|
||||||
self.set_desc(pdata)
|
self.set_desc(pdata)
|
||||||
|
|
||||||
def set_desc(self, desc):
|
def set_desc(self, desc):
|
||||||
@@ -127,6 +131,7 @@ class SaturnPrinter:
|
|||||||
# Tell the printer to connect
|
# Tell the printer to connect
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
with sock:
|
with sock:
|
||||||
|
logging.debug(f"sending M66666 to {self.addr}")
|
||||||
sock.sendto(b'M66666 ' + str(mqtt.port).encode('utf-8'), self.addr)
|
sock.sendto(b'M66666 ' + str(mqtt.port).encode('utf-8'), self.addr)
|
||||||
|
|
||||||
# wait for the connection
|
# wait for the connection
|
||||||
|
Reference in New Issue
Block a user