Ejemplo n.º 1
0
def on_disconnect(client, userdata, rc):
    global angle_thread, gndtime_thread, height_thread
    global broker, port

    # Stops hoist and stops publishing angle
    HOIST.stop()
    try:
        angle_thread.cancel()
        gndtime_thread.cancel()
        height_thread.cancel()
    except NameError:
        pass
    print("client disconnected. Reason code", rc)

    # Attempts to reconnect to broker (self)
    time.sleep(3)
    client.connect(broker, port, keepalive=5)
Ejemplo n.º 2
0
def accel_disconnect(recourse="now"):
    global angle_error_count, angle_thread, acc_err_thread

    # This to reattempt taking + publishing angle for 2 sec before
    # reporting disconnect to UI
    if recourse == "retry":
        angle_error_count += 1

        # Stops publishing accel data if disconnected for over 2sec
        if angle_error_count == 8:
            HOIST.stop()
            try:
                angle_thread.cancel()
            except:
                pass
            print("accelerometer disconnect - 2s")
            client.publish("accelerometer/status", "Backup disconnected")

    # Immediately reports accel disconnected to UI
    else:
        client.publish("accelerometer/status", "Backup disconnected")
Ejemplo n.º 3
0
client.on_disconnect = on_disconnect
client.will_set("status", "Backup Pi client disconnectetd", retain=False)

# Subscribes to "hoist" first time connected

client.connect(broker, port, keepalive=5)

try:
    while True:
        client.loop_start()

        # Enters with either Scenario 1 or 2
        if backup_listen:
            if (last_msg_timer.countup() >= 1):
                # timer starts in on_message received
                HOIST.stop()

            elif topic == "hoist":
                print(msg)

                if msg == "Off":
                    HOIST.stop()

                elif msg == "Disable leveling":
                    ignore_angle = True
                    try:
                        acc_err_thread.cancel()
                    except NameError:
                        pass

                elif msg == "Make level":