How to debug tmux session disconnecting mqtt connection

Running Hass.io with lovelace interface on rpi2 with IP .117. HA v0.103.5.

It has 2 scripts that run on startup from the rc.local file:

  1. makes a python script run called tsrb430.py which runs continuously in order to check if needs to run py scripts that turn my lights on and off via a ble relay board it controls by running those scripts.

  2. mqttReceive.py which takes commands from the hassio interface switch that toggle one of the relays on that board that controls a specific patio light.

Lets say I restart my hassio today. Itll run fine for about 2-3 days. Then ill try to toggle the switch for the patio lights (which uses mqtt to connect to another rpi3 which is the one that controls the relay board via ble, but the light wont switch on. I list my tmux sessions and the mqttListen session which runs the mqttReceive.py shows an error that its been disconnected. Then I usually solve it by restarting my hassio rpi2.

Here is the mqttReceive.py:

import paho.mqtt.client as mqtt
from failedPythonBLE import turn1ON,turn1OFF,turn2ON,turn2OFF,turn3ON,turn3OFF

MQTT_SERVER = "192.168.1.113"
MQTT_PATH = "test_channel"

# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
    print("Connected with result code "+str(rc))

    # Subscribing in on_connect() means that if we lose the connection and
    # reconnect then subscriptions will be renewed.
    client.subscribe(MQTT_PATH)

# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
    print(msg.topic+" "+str(msg.payload))
    # more callbacks, etc

    if str(msg.payload)=='01':
        print "letsGoBaby! Turn On Relay 1"
        turn1ON.letsgobaby()
    elif str(msg.payload)=='02':
        print "Turn Off Relay 1"
        turn1OFF.letsgobaby()
    elif str(msg.payload)=="komp-on":
        print "Turn On Relay 2"
        turn2ON.letsgobaby()
    elif str(msg.payload)=="komp-off":
        print "Turn Off Relay 2"
        turn2OFF.letsgobaby()
    elif str(msg.payload)=="sole-on":
        print "Turn On Relay 3"
        turn3ON.letsgobaby()
    elif str(msg.payload)=="sole-off":
        print "Turn Off Relay 3"
        turn3OFF.letsgobaby()
    elif str(msg.payload)=='07':
        print "Turn On Relay 4"
        turn4ON.letsgobaby()
    elif str(msg.payload)=='08':
        print "Turn Off Relay 4"
        turn4OFF.letsgobaby()

client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message

client.connect(MQTT_SERVER, 1883, 60)
client.loop_forever()

Just to clear up, this is my setup: