Example #1
0
def on_message_wemos(client, userdata, msg):
    global loops
    global num

    print(msg.topic + " " + str(msg.payload) + " received on mqtt bus")
    #print "randint: %d" % num
    #print "loops: %d" % loops

    _msg = str(msg.payload)
    print(_msg)

    if _msg == "NODE-%d-OFF" % num:
        log_split_times("NODE-%d-OFF" % num, "a")
        num = random.randint(1, num_nodes)

        time.sleep(1)

        if loops >= total_loops:
            client.disconnect()
            print("")
            print("Round finished!")
            print("")
            times2.print_split_times()
            times2.print_total_time()
            exit()
        else:
            print("Sending message to: NODE %d") % num
            client.publish("wemos", "NODE-%d-ON" % num)
            log_split_times("NODE-%d-ON" % num, "a")
            loops += 1
Example #2
0
def on_message_program_2(client, userdata, msg):
    """
    Program 2 - TEST 10 meter sprint
    """
    global loops
    global distance

    print(msg.topic + " " + str(msg.payload) + " received on mqtt bus")
    _msg = str(msg.payload)
    print(_msg)
    x = _msg.find("b")

    if _msg[x + 1:] == "'NODE-1-OFF'":
        #time.sleep(3)
        #client.publish("wemos","NODE-1-OFF")
        client.publish("wemos", "NODE-2-ON;%d" % distance)
        log_split_times("NODE-2-ON", "w")
        loops += 1

    if _msg[x + 1:] == "'NODE-2-OFF'":
        log_split_times("NODE-2-OFF", "a")
        client.publish("wemos", "FINISHED")
        times2.print_split_times()
        times2.print_total_time()
        client.disconnect()
        display.display_time()
        loops = 0
        return
Example #3
0
def on_message_program_1(client, userdata, msg):
    """
    Program 1 - TEST 5-10-5
    """
    global loops
    global program_1_state
    global distance

    print(msg.topic + " " + str(msg.payload) + " received on mqtt bus")
    _msg = str(msg.payload)
    print(_msg)
    x = _msg.find("b")

    if _msg[x + 1:] == "'NODE-1-OFF'" and program_1_state == "step1":
        #time.sleep(3)
        #client.publish("wemos","NODE-1-OFF")
        client.publish("wemos", "NODE-2-ON;%d" % distance)
        log_split_times("NODE-2-ON", "w")
        loops += 1
        program_1_state = "step2"

    elif _msg[x + 1:] == "'NODE-2-OFF'" and program_1_state == "step2":
        log_split_times("NODE-2-OFF", "a")
        client.publish("wemos", "NODE-3-ON;%d" % distance)
        log_split_times("NODE-3-ON", "a")
        program_1_state = "step3"

    elif _msg[x + 1:] == "'NODE-3-OFF'" and program_1_state == "step3":
        log_split_times("NODE-3-OFF", "a")
        client.publish("wemos", "NODE-1-ON;%d" % distance)
        log_split_times("NODE-1-ON", "a")
        program_1_state = "step4"

    elif _msg[x + 1:] == "'NODE-1-OFF'" and program_1_state == "step4":
        log_split_times("NODE-1-OFF", "a")
        client.publish("wemos", "FINISHED")
        times2.print_split_times()
        times2.print_total_time()
        program_1_state = ""
        client.disconnect()
        display.display_time()
        loops = 0
        return
Example #4
0
def on_message_random(client, userdata, msg):
    """
    Program Random - Training random
    """
    global total_loops
    global loops
    global num
    global distance

    print(msg.topic + " " + str(msg.payload) + " received on mqtt bus")
    #print "randint: %d" % num
    #print "loops: %d" % loops

    _msg = str(msg.payload)
    print(_msg)
    x = _msg.find("b")

    #if _msg == "NODE-%d-OFF" % num:
    if _msg[x + 1:] == "'NODE-%d-OFF'" % num:
        log_split_times("NODE-%d-OFF" % num, "a")
        num = random.randint(1, num_nodes)

        time.sleep(delay_time / 1000)

        if loops >= total_loops:
            print("")
            print("Round finished!")
            client.publish("wemos", "FINISHED")
            print("")
            times2.print_split_times()
            times2.print_total_time()
            loops = 0
            client.disconnect()
            display.display_time()
            #exit()
            return
        else:
            print("Sending message to: NODE %d" % num)
            client.publish("wemos", "NODE-%d-ON;%d" % (num, distance))
            log_split_times("NODE-%d-ON" % num, "a")
            loops += 1
Example #5
0
def display_time():
    tid = times2.print_total_time()
    print(tid)

    t1 = int(tid[0])
    t2 = int(tid[1])
    t3 = int(tid[3])
    t4 = int(tid[4])

    display = [t1, t2, t3, t4]
    Display.Show(display)
    Display.ShowDoublepoint(1)
Example #6
0
def home():
    form = LoginForm()
    if current_user.is_authenticated:
        home_active = True
        start = False
        start_2 = False
        player = None
        nodes = None
        rounds = None
        distance = None
        delay = None
        node_1 = True
        node_2 = True
        node_3 = True
        node_4 = True
        node_5 = True
        """
        split_time = times2.print_split_times()
        split_time_len = (len(split_time))

        labels = []	
        labels_2 = settings2.get_times()
        labels_2 = labels_2[1]
        #for i in range(0,labels_2):
        for i in range(0,split_time_len):
            labels.append(i+1)

        values_2 = settings2.get_times()
        values_2 = values_2[3:split_time_len+3]
        values = []
        for i in values_2:
            if i != "":
                values.append(i) 
        """
        nodes_list = []
        nodes = settings2.get_values_int("nodes")
        rounds = settings2.get_values_int("rounds")
        delay = settings2.get_values_int("delay")
        distance = settings2.get_values_int("distance")
        if request.method == 'POST':
            player = request.form['player']
            nodes = request.form['nodes']
            rounds = request.form['duration']
            delay = request.form['time_sleep']
            distance = request.form['sensitivity']
            program = request.form['program']

            settings2.update_values("nodes", int(nodes))
            settings2.update_values("rounds", int(rounds))
            settings2.update_values("delay", int(delay))
            settings2.update_values("distance", int(distance))

            split_time = times2.print_split_times()
            split_time_len = (len(split_time))

            labels = []
            labels_2 = settings2.get_times()
            labels_2 = labels_2[1]
            for i in range(0, split_time_len):
                #for i in range(0,labels_2):
                labels.append(i + 1)
            values_2 = settings2.get_times()
            values_2 = values_2[3:split_time_len + 3]
            values = []
            for i in values_2:
                if i != "":
                    values.append(i)
            ish = "hejsan"
            for x in range(1, int(nodes) + 1):
                nodes_list.append(x)

            if player != "":
                start = True
                trainer2.read_settings()
                t1 = threading.Thread(target=trainer2.main(program))
                t1.daemon = True
                t1.start()
                t1.join()
                split_time = times2.print_split_times()
                settings2.update_times(split_time)
                flash("Total time: %s " % times2.print_total_time())
                if program == "program_1":
                    settings2.update_score(player, times2.print_total_time(),
                                           split_time[0], split_time[1],
                                           split_time[2])
            else:
                start_2 = True
                flash("Incomplete form")

        split_time = times2.print_split_times()
        split_time_len = (len(split_time))

        labels = []
        labels_2 = settings2.get_times()
        labels_2 = labels_2[1]
        #for i in range(0,labels_2):
        for i in range(0, split_time_len):
            labels.append(i + 1)

        values_2 = settings2.get_times()
        values_2 = values_2[3:split_time_len + 3]
        values = []
        for i in values_2:
            if i != "":
                values.append(i)
        program_value = False
        if request.form.get("program") == "Random":
            program_value = True

        settings2.update_times(split_time)
        nodes = settings2.get_values_int("nodes")
        rounds = settings2.get_values_int("rounds")
        delay = settings2.get_values_int("delay")
        distance = settings2.get_values_int("distance")
        total_time = times2.print_total_time()

        #return flask.render_template('makkan.html', form=form,start_2=start_2, start=start, nodes_list=nodes_list, player=player, nodes=nodes, time_sleep=delay, duration=rounds, sensitivity=distance\
        #, node_1=node_1, node_2=node_2, node_3=node_3, node_4=node_4, node_5=node_5)

        return flask.render_template('makkan.html',home_active=home_active, program_value=program_value,values=values, labels=labels, form=form,start_2=start_2, start=start, nodes_list=nodes_list, player=player, nodes=nodes, delay=delay, rounds=rounds, distance=distance\
            , node_1=node_1, node_2=node_2, node_3=node_3, node_4=node_4, node_5=node_5, total_time=total_time,split_time_len = split_time_len)