Exemple #1
0
def view_earnings():
    """Main screen"""
    last_update = datetime.datetime.utcnow()
    current_price = get_our_price()
    price_step = 5
    while True:
        if LCD.is_pressed(lcd.UP):
            (current_price, price_step) = price_up(current_price, price_step)
        elif LCD.is_pressed(lcd.DOWN):
            (current_price, price_step) = price_down(current_price, price_step)
        elif LCD.is_pressed(lcd.LEFT):
            message_both("{}\n{}".format(MESH_IP, HOSTNAME), LCD)
            time.sleep(2)
        elif LCD.is_pressed(lcd.RIGHT):
            message_both("Name:\n{}".format(NAME), LCD)
            time.sleep(2)
        else:
            now = datetime.datetime.utcnow()
            if now - last_update > datetime.timedelta(seconds=1):
                current_bytes = get_current_bytes()

                if current_bytes > 0:
                    current_earnings = to_cash(current_bytes, get_our_price())
                    message = active_earnings_message(current_bytes,
                                                      current_earnings)
                    GLOBAL_VARS["total_earnings"] = GLOBAL_VARS["total_earnings"] + \
                        current_earnings
                else:
                    message = inactive_earnings_message()

                update_earnings_info(message, current_price)
                last_update = datetime.datetime.utcnow()
Exemple #2
0
def update_earnings_info(message, current_price):
    """send and display earnings update"""
    message_both(message, LCD)
    cmd = json_post_cmd(
        {
            "id": NAME,
            "message": message,
            "price": current_price,
            "total": GLOBAL_VARS["total_earnings"]
        }, STAT_SERVER)
    run_cmd_nowait(cmd)
    return datetime.datetime.utcnow(), message
Exemple #3
0
def price_up(current_price, price_step):
    current_price = max(current_price + int(1 * (price_step)), 0)
    set_our_price(current_price)
    message_both("Cents per GB:\n{}".format(current_price), LCD)

    for i in range(10):
        if LCD.is_pressed(lcd.UP):
            return price_up(current_price, price_step)
        if LCD.is_pressed(lcd.DOWN):
            return price_down(current_price, price_step)
        time.sleep(0.1)

    current_price = get_our_price()
    return current_price, price_step
Exemple #4
0
def view_traffic():
    """Display traffic interface"""
    last_update = datetime.datetime.utcnow()
    last_total_sent = get_total_sent()
    last_total_received = get_total_received()
    while True:
        now = datetime.datetime.utcnow()
        if LCD.is_pressed(lcd.LEFT):
            message_both("{}\n{}".format(MESH_IP, HOSTNAME), LCD)
            time.sleep(2)
        elif LCD.is_pressed(lcd.RIGHT):
            message_both("Name:\n{}".format(NAME), LCD)
            time.sleep(2)
        elif now - last_update > datetime.timedelta(seconds=1):
            total_sent = get_total_sent()
            total_received = get_total_received()
            current_sent = total_sent - last_total_sent
            current_received = total_received - last_total_received
            message = traffic_message(current_sent, current_received)
            update_traffic_info(message)
            last_update = datetime.datetime.utcnow()
            last_total_sent = total_sent
            last_total_received = total_received
Exemple #5
0
def update_traffic_info(message):
    """send and display traffic update"""
    message_both(message, LCD)
    return datetime.datetime.utcnow(), message
Exemple #6
0
            message_both("Name:\n{}".format(NAME), LCD)
            time.sleep(2)
        else:
            now = datetime.datetime.utcnow()
            if now - last_update > datetime.timedelta(seconds=1):
                current_bytes = get_current_bytes()

                if current_bytes > 0:
                    current_earnings = to_cash(current_bytes, get_our_price())
                    message = active_earnings_message(current_bytes,
                                                      current_earnings)
                    GLOBAL_VARS["total_earnings"] = GLOBAL_VARS["total_earnings"] + \
                        current_earnings
                else:
                    message = inactive_earnings_message()

                update_earnings_info(message, current_price)
                last_update = datetime.datetime.utcnow()


LCD = lcd.Adafruit_CharLCDPlate()

BABEL_SOCKET = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
message_both('Connecting to\nBabel...', LCD)
BABEL_SOCKET.connect((BABEL_IP, BABEL_PORT))
print BABEL_SOCKET.recv(BABEL_BUFF)
message_both('Connected to\nBabel!', LCD)

message_both('intermediary', LCD)
view_earnings()