Skip to content

Commit

Permalink
Crude reconnection attempt after no responce
Browse files Browse the repository at this point in the history
  • Loading branch information
superrob committed Jul 19, 2024
1 parent 2f9d690 commit 6f05183
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/genvexnabto/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
SOCKET_MAXSIZE = 512
DATAPOINT_UPDATEINTERVAL = 10 # Seconds since last datapoint update to trigger new update
SETPOINT_UPDATEINTERVAL = 180 # Seconds since last setpoint update to trigger new update
SECONDS_UNTILRECONNECT = 20 # Seconds with no responce to try reconnecting
DISCOVERY_PORT = 5570
9 changes: 6 additions & 3 deletions src/genvexnabto/genvexnabto.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
GenvexPayloadCP_ID, GenvexPacket, GenvexPacketKeepAlive, GenvexCommandDatapointReadList,
GenvexCommandSetpointReadList, GenvexCommandPing, GenvexCommandSetpointWriteList)

from .const import ( SOCKET_TIMEOUT, SOCKET_MAXSIZE, DATAPOINT_UPDATEINTERVAL, SETPOINT_UPDATEINTERVAL, DISCOVERY_PORT)
from .const import ( SOCKET_TIMEOUT, SOCKET_MAXSIZE, DATAPOINT_UPDATEINTERVAL, SETPOINT_UPDATEINTERVAL, SECONDS_UNTILRECONNECT, DISCOVERY_PORT)

class GenvexNabtoConnectionErrorType:
TIMEOUT = "timeout"
Expand Down Expand Up @@ -221,9 +221,10 @@ def processReceivedMessage(self, message, address):
if (packetType == GenvexPacketType.U_CONNECT):
print("U_CONNECT responce packet")
if (message[20:24] == b'\x00\x00\x00\x01'):
print('Connected, pinging to get model number')
self._server_id = message[24:28]
self.sendPing()
print('Connected, pinging to get model number')
if not self._is_connected:
self.sendPing()
else:
print("Received unsucessfull response")
self._connection_error = GenvexNabtoConnectionErrorType.AUTHENTICATION_ERROR
Expand Down Expand Up @@ -308,4 +309,6 @@ def receiveThread(self):
self.sendDataStateRequest(100)
if time.time() - self._last_setpointupdate > SETPOINT_UPDATEINTERVAL:
self.sendSetpointStateRequest(200)
if time.time() - self._last_responce > SECONDS_UNTILRECONNECT:
self.connectToDevice()

0 comments on commit 6f05183

Please sign in to comment.