Ejemplo n.º 1
0
 def _show_verification_text(self, username, verification_text,
                             expire_minutes):
     text = "Hi {}!\nAuthentication Code: {}".format(
         username, verification_text)
     console.big_image('images/pair_pending.png')
     console.big_status(text)
     print_all(text + "\n")
Ejemplo n.º 2
0
 def _show_verification_failed(self, reason):
     reason = re.sub(r'\<.*?\>', '', reason)
     text = "Error:\n{}".format(reason)
     console.big_image('images/pair_error.png')
     console.big_status("Error:\nTry again.")
     print_all(text + "\n")
     time.sleep(5)  # <-- TODO Remove this hack. Do something that's async.
     console.big_clear()
Ejemplo n.º 3
0
 def _show_verification_success(self, username):
     text = "Congrats {}!\nYou are paired with this device.".format(
         username)
     console.big_image('images/pair_success.png')
     console.big_status(text)
     print_all(text + "\n")
     time.sleep(5)  # <-- TODO Remove this hack. Do something that's async.
     console.big_clear()
Ejemplo n.º 4
0
def ensure_token():
    token = STORE.get('DEVICE_TOKEN', None)

    if token is not None:
        # We have a token. All is well.
        return

    console.big_image('images/token_error.png')
    console.big_status('Ready to receive login token.')

    camera = CameraRGB()

    system_password = None

    for i, frame in enumerate(camera.stream()):
        frame = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
        stream_frame(frame)
        qrcodes = myzbarlight.qr_scan(frame)

        if len(qrcodes) > 0:
            qr_data = qrcodes[0]
            try:
                qr_data = json.loads(qr_data.decode('utf-8'))
                token = qr_data['t']
                if 'p' in qr_data:
                    # This allows us to override the default system_password for special-purpose devices.
                    # The default is just... a default. No matter what is set here, it can be changed later.
                    system_password = qr_data['p']
                break
            except:
                pass

    console.big_image('images/token_success.png')
    console.big_status('Success. Token: {}...'.format(token[:5]))

    camera.close()

    STORE.put('DEVICE_TOKEN', token)
    print_all("Stored Device token: {}...".format(token[:5]))

    jupyter_password = util.token_to_jupyter_password(token)
    STORE.put('DEVICE_JUPYTER_PASSWORD', jupyter_password)
    print_all("Stored Jupyter password: {}...".format(jupyter_password[:2]))

    if system_password is None:
        # If a particular default system_password was not specified, we will generate a good
        # default system_password from the token. This is a good thing, since it ensures that
        # each device is given a strong, unique default system_password.
        system_password = util.token_to_system_password(token)

    util.change_system_password(system_priv_user, system_password)
    print_all("Successfully changed {}'s password!".format(system_priv_user))

    time.sleep(5)

    console.big_clear()
    console.clear_image()
Ejemplo n.º 5
0
# Repeat forever: Check to see if we are connected to WiFi. If not, wait 10 seconds
#                 to see if anything changes. If after 10 seconds we still don't have
#                 WiFi, initiate the WiFi connection screen. If we _do_ have WiFi, then
#                 we'll repeat this whole process after 5 seconds.
while True:
    current = wireless.current()
    log.info("Current WiFi network: {}".format(current))

    if current is None:
        log.info("No WiFi!")
        time.sleep(10)
        if wireless.current() is None:
            log.info(
                "Still no WiFi after 10 seconds... will ask user to connect.")
            console.big_image('images/wifi_error.png')
            console.big_status('https://labs.autoauto.ai/wifi')
            while wireless.current() is None:
                ssid, password = get_wifi_info_from_user()
                if ssid is None:
                    log.info("WiFi magically came back before user input.")
                    break
                log.info("Will try to connect to SSID: {}".format(ssid))
                console.big_image('images/wifi_pending.png')
                console.big_status('Trying to connect...')
                did_connect = wireless.connect(ssid, password)
                has_internet = has_internet_access() if did_connect else False
                if not did_connect or not has_internet:
                    if did_connect and not has_internet:
                        msg = 'Connected to WiFi...\nbut no internet detected.\nPress BUTTON #1 to connect.\nPress BUTTON #2 to disconnect.'
                        log.info(msg)
Ejemplo n.º 6
0
###############################################################################
#
# Copyright (c) 2017-2018 AutoAuto, LLC
# ALL RIGHTS RESERVED
#
# Use of this library, in source or binary form, is prohibited without written
# approval from AutoAuto, LLC.
#
###############################################################################

from auto import console as c
import time


# Put up a big full-screen image by passing an image-path.
c.big_image('images/wifi_success.png')
time.sleep(2)


# Put up some big text!
for i in range(1, 5):
    text = "All is good... {}".format(i)
    c.big_status(text)
    time.sleep(1)


# Clear the big text.
c.big_status('')
time.sleep(2)