Пример #1
0
def get_wifi_info_from_user():
    camera = CameraRGB()

    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'))
                ssid = qr_data['s']
                password = qr_data['p']
                break
            except:
                # We got invalid data from the QR code, which is
                # fine, we'll just move on with life and try again.
                pass

        if (i % 100) == 99:
            # Every 100 frames, we'll check to see if WiFi magically came back.
            if wireless.current() is not None:
                ssid = None
                password = None
                break

    camera.close()

    return ssid, password
Пример #2
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()
Пример #3
0
 def run():
     camera = CameraRGB()
     frame = camera.capture()
     base64_img = base64_encode_image(frame)
     send_func({
         'type': 'query_response_async',
         'query_id': query_id,
         'async_guid': guid,
         'response': {'base64_img': base64_img},
         'to_user_session': user_session,
     })
     camera.close()
Пример #4
0
def global_camera(verbose=False):
    """
    Creates (for the first call) or retrieves (for later calls) the
    global camera object. This is a convenience function to facilitate
    quickly and easily building a camera singleton.
    """
    global GLOBAL_CAMERA
    try:
        return GLOBAL_CAMERA
    except NameError:
        GLOBAL_CAMERA = wrap_frame_index_decorator(CameraRGB())
        if verbose:
            auto.print_all("Instantiated a global camera object!")
        return GLOBAL_CAMERA
Пример #5
0
 def run():
     camera = wrap_frame_index_decorator(CameraRGB())
     while True:
         frame = camera.capture()
         base64_img = base64_encode_image(frame)
         send_func({
             'type': 'command_response_async',
             'command_id': command_id,
             'async_guid': guid,
             'response': {'base64_img': base64_img},
             'to_user_session': user_session,
         })
         try:
             g = queue.get(timeout=0.1)
             if g is False:
                 break
         except Empty:
             pass
     camera.close()