python bluetooth蓝牙信息获取蓝牙设备类型的方法

yipeiwu_com5年前Python基础

python 获取蓝牙设备类型

扫描蓝牙设备获取到的信息中,无法判断扫描到的蓝牙设备属于什么类型的设备。

扫描蓝牙信息使用的是python 里面的bluetooth模块。

首先扫描出来的是这样的信息

('74:60:FA:FD:FC:49','HUAWEI P30',5898764)

可根据5898764来判断是什么蓝牙设备。

收集了一些设备,可以成功的转化为设备类型

def bt_device_type(device_type):
  if device_type == 5898764 or device_type == 'Android':
    return 'Android'
  if device_type == 7078144 or device_type == 'computer_ubuntu14':
    return 'computer_ubuntu14'
  if device_type == 786700 or device_type == 'computer_ubuntu16':
    return 'computer_ubuntu16'
  if device_type == 655620 or device_type == 'computer_windows':
    return 'computer_windows'
  if device_type == 2360324 or device_type == 'headset':
    return 'headset' #耳机
  if device_type == 2360328 or device_type =='speaker':
    return 'speaker' # 扩音器
  if device_type == 263208 or device_type == 'SV':
    return 'SV' #蓝牙音响
  if device_type == 7995916 or device_type == 'phone':
    return 'phone' #苹果设备
  if device_type == 3670284 or device_type == 'MACBook':
    return 'MACBook'
  if device_type == 7936 or device_type == 2752780 or device_type == 'PC':
    return 'PC'
  if device_type == 6947088 or device_type == 'iPad':
    return 'iPad'
  return 'unknown'

最终是这样的,想显示成中文,那就改为中文的。有帮助请点一下赞

相关文章

Python中获取网页状态码的两个方法

第一种是用urllib模块,下面是例示代码: 复制代码 代码如下: import urllib status=urllib.urlopen("//www.jb51.net").code...

django如何通过类视图使用装饰器

需求:当我们想禁止ip黑名单访问我们的某些页面时,例如注册页面。应该怎么操作呢? 解决方案:这时候我们可以设计一个装饰器,过滤ip黑名单。 装饰器的写法如下: from functo...

python给指定csv表格中的联系人群发邮件(带附件的邮件)

以下为使用python给指定路径的csv表格中的联系人群发带附件的邮件(csv表格的第一列为联系人姓名,第二列为联系人邮箱账号)的代码,详情见注释。 import time impo...

python中使用xlrd读excel使用xlwt写excel的实例代码

python中使用xlrd读excel使用xlwt写excel的实例代码

在数据分析和运营的过程中,有非常多的时候需要提供给别人使用,提供的形式有很多种,最经常使用的是Excel, 而 数据的统计和分析采用的是 python, 使用 python 把数据存在E...

python实现图像检索的三种(直方图/OpenCV/哈希法)

python实现图像检索的三种(直方图/OpenCV/哈希法)

简介: 本文介绍了图像检索的三种实现方式,均用python完成,其中前两种基于直方图比较,哈希法基于像素分布。 检索方式是:提前导入图片库作为检索范围,给出待检索的图片,将其与图片库...