def start_repl(pebble_id, lightblue, pair): pebble = libpebble.Pebble(pebble_id, using_lightblue=lightblue, pair_first=pair) pebble.install_bridge(httpebble.HTTPebble) readline.set_completer(rlcompleter.Completer(locals()).complete) readline.parse_and_bind('tab:complete') code.interact(local=locals())
def run(self, args): if not args.phone and not args.pebble_id: raise ConfigurationException( "Argument --phone or --pebble_id is required (Or set a PEBBLE_{PHONE,ID} environment variable)" ) self.pebble = libpebble.Pebble() self.pebble.set_print_pbl_logs(args.verbose) if args.phone: self.pebble.connect_via_websocket(args.phone) if args.pebble_id: self.pebble.connect_via_serial(args.pebble_id)
def run(self, args): # Only use the envrionment variables as defaults if no command-line arguments were specified # ...allowing you to leave the envrionment var(s) set at all times if not args.phone and not args.pebble_id: args.phone = os.getenv(PEBBLE_PHONE_ENVVAR) args.pebble_id = os.getenv(PEBBLE_BTID_ENVVAR) if not args.phone and not args.pebble_id: raise ConfigurationException("No method specified to connect to watch\n- To use Developer Connection, argument --phone is required (or set the %s environment variable)\n- To use a direct BT connection, argument --pebble_id is required (or set the %s environment variable)" % (PEBBLE_PHONE_ENVVAR, PEBBLE_BTID_ENVVAR)) if args.phone and args.pebble_id: raise ConfigurationException("You must specify only one method to connect to the watch - either Developer Connection (with --phone/%s) or direct via Bluetooth (with --pebble_id/%s)" % (PEBBLE_PHONE_ENVVAR, PEBBLE_BTID_ENVVAR)) self.pebble = libpebble.Pebble(args.pebble_id) self.pebble.set_print_pbl_logs(args.verbose) if args.phone: self.pebble.connect_via_websocket(args.phone) elif args.pebble_id: self.pebble.connect_via_lightblue(pair_first=args.pair)
def main(): parser = argparse.ArgumentParser( description='a utility belt for pebble development') parser.add_argument( '--pebble_id', type=str, help='the last 4 digits of the target Pebble\'s MAC address. \nNOTE: if \ --lightblue is set, providing a full MAC address (ex: "A0:1B:C0:D3:DC:93") won\'t require the pebble \ to be discoverable and will be faster') parser.add_argument('--lightblue', action="store_true", help='use LightBlue bluetooth API') parser.add_argument( '--pair', action="store_true", help= 'pair to the pebble from LightBlue bluetooth API before connecting.') subparsers = parser.add_subparsers(help='commands', dest='which') ping_parser = subparsers.add_parser('ping', help='send a ping message') ping_parser.set_defaults(func=cmd_ping) launch_parser = subparsers.add_parser( 'launch_app', help='launch an app on the watch by its UUID') launch_parser.add_argument( 'app_uuid', metavar='UUID', type=str, help='a valid UUID in the form of: 54D3008F0E46462C995C0D0B4E01148C') launch_parser.set_defaults(func=cmd_launch_app) load_parser = subparsers.add_parser( 'load', help='load an app onto a connected watch') load_parser.add_argument( '--nolaunch', action="store_false", help='do not launch the application after install') load_parser.add_argument('app_bundle', metavar='FILE', type=str, help='a compiled app bundle') load_parser.set_defaults(func=cmd_load) load_fw_parser = subparsers.add_parser( 'load_fw', help='load new firmware onto a connected watch') load_fw_parser.add_argument('fw_bundle', metavar='FILE', type=str, help='a compiled app bundle') load_fw_parser.set_defaults(func=cmd_load_fw) logcat_parser = subparsers.add_parser( 'logcat', help='view logs sent from a connected watch') logcat_parser.set_defaults(func=cmd_logcat) list_apps_parser = subparsers.add_parser('list', help='list installed apps') list_apps_parser.set_defaults(func=cmd_list_apps) rm_app_parser = subparsers.add_parser('rm', help='remove installed app') rm_app_parser.add_argument( 'app_index_or_hex_uuid', metavar='IDX or UUID in the form of: 54D3008F0E46462C995C0D0B4E01148C', type=str, help='the app index or UUID to delete') rm_app_parser.set_defaults(func=cmd_rm_app) reinstall_app_parser = subparsers.add_parser( 'reinstall', help='reinstall then launch an installed app') reinstall_app_parser.add_argument('app_bundle', metavar='FILE', type=str, help='a compiled app bundle') reinstall_app_parser.add_argument( '--nolaunch', action="store_false", help='do not launch the application after install') reinstall_app_parser.set_defaults(func=cmd_reinstall_app) reset_parser = subparsers.add_parser('reset', help='reset the watch remotely') reset_parser.set_defaults(func=cmd_reset) set_nowplaying_metadata_parser = subparsers.add_parser( 'playing', help='set current music playing') set_nowplaying_metadata_parser.add_argument('track', type=str) set_nowplaying_metadata_parser.add_argument('album', type=str) set_nowplaying_metadata_parser.add_argument('artist', type=str) set_nowplaying_metadata_parser.set_defaults( func=cmd_set_nowplaying_metadata) notification_email_parser = subparsers.add_parser( 'email', help='send an "Email Notification"') notification_email_parser.add_argument('sender', type=str) notification_email_parser.add_argument('subject', type=str) notification_email_parser.add_argument('body', type=str) notification_email_parser.set_defaults(func=cmd_notification_email) notification_sms_parser = subparsers.add_parser( 'sms', help='send an "SMS Notification"') notification_sms_parser.add_argument('sender', type=str) notification_sms_parser.add_argument('body', type=str) notification_sms_parser.set_defaults(func=cmd_notification_sms) get_time_parser = subparsers.add_parser( 'get_time', help='get the time stored on a connected watch') get_time_parser.set_defaults(func=cmd_get_time) set_time_parser = subparsers.add_parser( 'set_time', help='set the time stored on a connected watch') set_time_parser.add_argument('timestamp', type=int, help='time stamp to be sent') set_time_parser.set_defaults(func=cmd_set_time) set_time_now_parser = subparsers.add_parser( 'set_time_now', help='set the time stored on a connected watch to the current time') set_time_now_parser.set_defaults(func=cmd_set_time_now) set_time_mdyhms_parser = subparsers.add_parser( 'set_time_mdyhms', help= 'set the time stored on a connected watch to the time in "mm/dd/yyyy hh:mm:ss"' ) set_time_mdyhms_parser.add_argument('mdyhms', type=str, help='eg. "04/20/2020 10:45:00"') set_time_mdyhms_parser.set_defaults(func=cmd_set_time_mdyhms) remote_parser = subparsers.add_parser( 'remote', help='control a music app on this PC using Pebble') remote_parser.add_argument('app_name', type=str, help='title of application to be controlled') remote_parser.set_defaults(func=cmd_remote) args = parser.parse_args() attempts = 0 while True: if attempts > MAX_ATTEMPTS: raise 'Could not connect to Pebble' try: pebble_id = args.pebble_id if pebble_id is None and "PEBBLE_ID" in os.environ: pebble_id = os.environ["PEBBLE_ID"] pebble = libpebble.Pebble(pebble_id, args.lightblue, args.pair) break except: time.sleep(5) attempts += 1 try: args.func(pebble, args) except Exception as e: pebble.disconnect() raise e return pebble.disconnect()
def connect(self): self.pebble = p.Pebble(self.id)