Add files via upload

This commit is contained in:
LukeSpad 2021-11-25 19:17:50 +00:00 committed by GitHub
parent cc056bca34
commit 82af7d348c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

24
main.py
View file

@ -24,16 +24,16 @@ if __name__ == '__main__':
if len(payload) + 9 < 73: if len(payload) + 9 < 73:
logging.info("\n\t----------------------------------------------------------------------------" + logging.info("\n\t----------------------------------------------------------------------------" +
"\n\t" + name + ": <--Data-received!-<< " + "\n\t" + name + ": <--Data-received!-<< " +
datetime.now().strftime("on %D at %H:%M:%S") + datetime.now().strftime("on %d/%m/%y at %H:%M:%S") +
"\n\t----------------------------------------------------------------------------" + "\n\t----------------------------------------------------------------------------" +
"\n\tHeader: " + header + "\n\tHeader: " + header +
"\n\tPayload: " + payload + "\n\tPayload: " + payload +
"\n\t============================================================================" + "\n\t============================================================================" +
message) message)
elif len(payload) + 9 > 73 and len(payload) + 9 < 132: elif 73 < len(payload) + 9 < 132:
logging.info("\n\t----------------------------------------------------------------------------" + logging.info("\n\t----------------------------------------------------------------------------" +
"\n\t" + name + ": <--Data-received!-<< " + "\n\t" + name + ": <--Data-received!-<< " +
datetime.now().strftime("on %D at %H:%M:%S") + datetime.now().strftime("on %d/%m/%y at %H:%M:%S") +
"\n\t----------------------------------------------------------------------------" + "\n\t----------------------------------------------------------------------------" +
"\n\tHeader: " + header + "\n\tHeader: " + header +
"\n\tPayload: " + payload[:66] + "\n\t\t" + payload[66:132] + "\n\tPayload: " + payload[:66] + "\n\t\t" + payload[66:132] +
@ -42,7 +42,7 @@ if __name__ == '__main__':
else: else:
logging.info("\n\t----------------------------------------------------------------------------" + logging.info("\n\t----------------------------------------------------------------------------" +
"\n\t" + name + ": <--Data-received!-<< " + "\n\t" + name + ": <--Data-received!-<< " +
datetime.now().strftime("on %D at %H:%M:%S") + datetime.now().strftime("on %d/%m/%y at %H:%M:%S") +
"\n\t----------------------------------------------------------------------------" + "\n\t----------------------------------------------------------------------------" +
"\n\tHeader: " + header + "\n\tHeader: " + header +
"\n\tPayload: " + payload[:66] + "\n\t\t" + payload[66:132] + "\n\t\t" + payload[132:] + "\n\tPayload: " + payload[:66] + "\n\t\t" + payload[66:132] + "\n\t\t" + payload[132:] +
@ -54,7 +54,7 @@ if __name__ == '__main__':
logging.debug(self.name + " Protocol Client last received " + str(last) + " seconds ago") logging.debug(self.name + " Protocol Client last received " + str(last) + " seconds ago")
# Recconect if socket has disconnected, or if no response received to last ping # Recconect if socket has disconnected, or if no response received to last ping
if not self.is_connected or last > 60: if not self.is_connected or last > 60:
logging.info("\t" + self.name + ": Reconnecting\n") logging.info("\t" + self.name + ": Reconnecting!")
self.handle_close() self.handle_close()
time.sleep(0.5) time.sleep(0.5)
self.client_connect() self.client_connect()
@ -86,20 +86,26 @@ if __name__ == '__main__':
if mlcli.isBLGW: if mlcli.isBLGW:
logging.info('Creating BLGW Home Integration Protocol Client...') logging.info('Creating BLGW Home Integration Protocol Client...')
blgw = BLHIP.BLHIPClient(host, port[1], user, pwd, 'BLGW Home Integration Protocol', cb) blgw = BLHIP.BLHIPClient(host, port[1], user, pwd, 'BLGW Home Integration Protocol', cb)
mltn = None
else: else:
logging.info('Creating MLGW Home Integration Protocol Client...') logging.info('Creating MLGW Home Integration Protocol Client...')
mltn = MLtn.MLtnClient(host, port[2], user, pwd, 'ML telnet client', cb) mltn = MLtn.MLtnClient(host, port[2], user, pwd, 'ML telnet client', cb)
blgw = None
# Main program loop # Main program loop
while True: while True:
# Ping all connections every 10 minutes to prompt messages on the network # Ping all connections every 10 minutes to prompt messages on the network
asyncore.loop(count=595, timeout=1) asyncore.loop(count=595, timeout=1)
if mlgw.is_connected: mlgw.ping() if mlgw.is_connected:
if mlcli.is_connected: mlcli.ping() mlgw.ping()
if mlcli.is_connected:
mlcli.ping()
if mlcli.isBLGW: if mlcli.isBLGW:
if blgw.is_connected: blgw.ping() if blgw.is_connected:
blgw.ping()
else: else:
if mltn.is_connected: mltn.ping() if mltn.is_connected:
mltn.ping()
# Check the connections approximately every 10 minutes to keep sockets open # Check the connections approximately every 10 minutes to keep sockets open
asyncore.loop(count=5, timeout=1) asyncore.loop(count=5, timeout=1)