千赢娱乐手机登录_ qy8com千赢手机版_千赢网页手机版
做最好的网站

千赢娱乐手机登录

当前位置:千赢娱乐手机登录 > 千赢娱乐手机登录 > 使能notify蓝牙低功耗设备,CentOS7版本基础使用

使能notify蓝牙低功耗设备,CentOS7版本基础使用

来源:http://www.modeLspro.net 作者:千赢娱乐手机登录 时间:2019-11-04 02:39

第1章 CentOS7的使用

一、简单的多级菜单

[root@web129 ~]# cat menu.sh 
#!/bin/bash
#shell菜单演示
function menu()
{
echo -e `date`
cat <<EOF
-----------------------------------
>>>菜单主页:
`echo -e "\033[35m 1)系统状态\033[0m"`
`echo -e "\033[35m 2)服务管理\033[0m"`
`echo -e "\033[35m 3)主菜单\033[0m"`
`echo -e "\033[35m Q)退出\033[0m"`
EOF
read -p "请输入对应序列号:" num1
case $num1 in
    1)
    echo -e "\033[32m >>>系统状态-> \033[0m"
    system_menu
    ;;
    2)
    echo -e "\033[32m >>>服务管理-> \033[0m"
    server_menu
    ;;
    3)
    echo -e "\033[32m >>>返回主菜单-> \033[0m"
    menu
    ;;
    Q|q)
    echo -e "\033[32m--------退出--------- \033[0m"
    exit 0
    ;;
    *)
    echo -e "\033[31m err:请输入正确的编号\033[0m"
    menu
esac
}
function system_menu()
{
cat<<EOF
------------------------
********系统状态********
------------------------
1)nginx 状态
2)http 状态
3)tomcat 状态
X)返回上一级目录
------------------------
EOF
read -p "请输入编号:" num2
case $num2 in
    1)
    `echo -e "systemctl status nginx.service"`
    system_menu
    ;;
    2)
     `echo -e "systemctl status httpd.service"`
    system_menu
    ;;
    3)
     `echo -e "systemctl status tomcat.service"`
    system_menu
    ;;
    x|X)
    echo -e "\033[32m---------返回上一级目录------->\033[0m"
    menu
    ;;
    *)
    echo -e "请输入正确编号"
    system_menu
esac
}
function server_menu()
{
cat<<EOF
------------------------
1)开启服务
2)停止服务
X)返回上一级目录
------------------------
EOF
read -p "请输入编号:" num3
case $num3 in
        1)
        op_menu
        ;;
        2)
        op_menu1
        ;;
        x|X)
        echo -e "\033[32m-- -----返回上一级目录---------> \033[0m"
        menu
        ;;
        *)
        echo -e "请输入正确编号"
        system_menu
esac
}

function op_menu()
{
cat<<EOF
------------------------
1)开启nginx服务
2)开启http服务
3)开启tomcat服务
X)返回上一级目录
------------------------
EOF
read -p "请输入编号:" num4
case $num4 in
        1)
    `echo -e "systemctl start nginx.service"`
    op_menu
        ;;
        2)
    `echo -e "systemctl start httpd.service"`
        op_menu
    ;;
    3)
    `echo -e "systemctl start tomcat.service"`
        op_menu
        ;;
        x|X)
        echo -e "\033[32m--------返回上一级目录------->\033[0m"
        server_menu
        ;;
        *)
        echo -e "请输入正确编号"
    op_menu
esac
}
function op_menu1()
{
cat<<EOF
------------------------
1)停止nginx服务
2)停止http服务
3)停止tomcat服务
X)返回上一级目录
------------------------
EOF
read -p "请输入编号:" num5
case $num5 in
        1)
        `echo -e "systemctl stop nginx.service"`
        op_menu1
        ;;
        2)
        `echo -e "systemctl stop httpd.service"`
        op_menu1
        ;;
        3)
        `echo -e "systemctl stop tomcat.service"`
        op_menu1
        ;;
        x|X)
        `echo -e "\033[32m >>>返回上一级目录---> \033[0m"`
        server_menu
        ;;
        *)
        echo -e "请输入正确编号"
        op_menu1
esac
}
menu
[root@web129 ~]# 

 

显示效果如下:

图片 1

图片 2

 

星期三, 05. 九月 2018 02:03上午 - beautifulzzzz

1.1 为什么要使用CentOS7版本

CentOS7是在CentOS6基础上发布的新版本,与之前的版本相比,主要的更新包括:

1、内核更新到3.10.0

2、支持Linux容器

3、LVM快照支持ext4和XFS

4、转用systemd、firewalld和GRUB2

5、XFS作为缺省文件系统

6、支持PTPv2

7、支持40G 以太网卡

8、在兼容的硬件上支持以UEFI安全启动模式安装

这其中最令人瞩目的新特性就是支持Docker技术。作为目前流行的应用虚拟化技术之一,Docker能够将应用程序与系统完全隔离,让其在系统之间实现迁移而不需要停机,提高了应用程序的移动性和灵活性。CentOS7在内核层面支持Docker容器技术,可以提高Docker稳定性和可靠性。

综上,我们会选择CentOS7来作为服务器的操作系统。

图片 3

第2章 CentOS7与CentOS6版本的区别

1、前言

上一篇讲了如何编译安装BlueZ-5,本篇主要在于玩BlueZ,用命令行去操作BLE设备:

  • [BlueZ] 1、Download install and use the BlueZ and hcitool on PI 3B

图片 4

2.1 系统基础服务变化

操作

Centos6

Centos7

对比

自动补全

只支持命令、文件名

支持命令、选项、文件名

 

文件系统

ext4       

xfs                

随机读写更快

repo仓库

yum

yum-config-manager  

添加仓库便捷

修改主机名

/etc/sysconfig/network

/etc/hostname            

hostnamectl

修改时区    

/etc/sysconfig/clock

timedatectl set-timezone   

更方便

修改字符集

/etc/sysconfig/il8n    

/etc/locale.conf           

localectl

防火墙

iptables

firewalld

 

服务管理

System V init

systemd

 

时间同步服务

ntp

chrony 

 

 

2、gatttool —— 老工具趟坑

刚开始跟着 Get Started with Bluetooth Low Energy on Linux 操作gatttool,发现坑太多(主要原因是工具老了):

采用sudo gatttool -b 4D:69:98:0E:91:5E -I去连接
发现会报错:Error: connect error: Connection refused (111)
最终参考LINK-11发现需要加random选项([#1](https://stackoverflow.com/questions/32947807/cannot-connect-to-ble-device-on-raspberry-pi))

➜  ~  sudo gatttool -b 4D:69:98:0E:91:5E -I
[4D:69:98:0E:91:5E][LE]> connect
Attempting to connect to 4D:69:98:0E:91:5E
Error: connect error: Connection refused (111)
[4D:69:98:0E:91:5E][LE]> exit
➜  ~  sudo gatttool  -t random  -b 4D:69:98:0E:91:5E -I
[4D:69:98:0E:91:5E][LE]> connect
Attempting to connect to 4D:69:98:0E:91:5E
Connection successful
[4D:69:98:0E:91:5E][LE]> 
(gatttool:3104): GLib-WARNING **: Invalid file descriptor.

过一回会10S自动断开,网上说这个工具老了,不建议用了([#2](https://www.spinics.net/lists/linux-bluetooth/msg67617.html)):

There are new tools to use with GATT, bluetoothctl/bluetoothd is the preferred since with that you have GAP, etc, 
but if want to use a stand alone tool then I suggest you use btgatt-client.

图片 5

2.2 系统文件目录结构

centos6

cetos7

bin 

usr/bin

sbin

usr/sbin

lib

usr/lib

3、bluetoothctl——NB的新工具

命令行进入bluetoothctl操作环境([#6](https://mcuoneclipse.com/2016/12/19/tutorial-ble-pairing-the-raspberry-pi-3-model-b-with-hexiwear/))

bluetoothctl

我在手机上用lightblue模拟一个BLE设备ty_prod,之后对其service进行修改,调用scan on进行搜索还是老的,
最终发现要先用remove移除之前的设备,之后再scan就会出现[NEW] Device 72:3B:E1:81:4E:4F ty_prod设备
注: 用lightblue模拟的设备的MAC不是固定的
注: 我发现在lightblue中无论怎么模拟BLE设备,一旦被连上搜索到的service都是IPone的

[bluetooth]# devices
Device 28:ED:6A:A0:26:B7 ty_prod
Device 58:71:33:00:00:24 Bluetooth Keyboard
Device 00:1A:7D:DA:71:0A SHEN-PC
Device 94:87:E0:B3:AC:6F Mi Phone
[bluetooth]# remove 28:ED:6A:A0:26:B7 
...
[bluetooth]# scan on
Discovery started
[NEW] Device 72:3B:E1:81:4E:4F ty_prod
[bluetooth]# scan off
...
Discovery stopped
[bluetooth]# connect 72:3B:E1:81:4E:4F
Attempting to connect to 72:3B:E1:81:4E:4F
[CHG] Device 72:3B:E1:81:4E:4F Connected: yes
Connection successful
[ty_prod]

索性就用IPhone自带的服务做测试了~

[ty_prod]# info
Device 28:ED:6A:A0:26:B7 (public)
    Name: tuya_mdev_test
    Alias: tuya_mdev_test
    Appearance: 0x0040
    Icon: phone
    Paired: yes
    Trusted: no
    Blocked: no
    Connected: yes
    LegacyPairing: no
    UUID: Fax                       (00001111-0000-1000-8000-00805f9b34fb)
    UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
    UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
    UUID: Current Time Service      (00001805-0000-1000-8000-00805f9b34fb)
    UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
    UUID: Battery Service           (0000180f-0000-1000-8000-00805f9b34fb)
    UUID: Vendor specific           (7905f431-b5ce-4e99-a40f-4b1e122d00d0)
    UUID: Vendor specific           (89d3502b-0f36-433a-8ef4-c502ad55f8dc)
    UUID: Vendor specific           (9fa480e0-4967-4542-9390-d343dc5d04ae)
    UUID: Vendor specific           (d0611e78-bbb4-4591-a5f8-487910ae4366)
[CHG] Device 28:ED:6A:A0:26:B7 ServicesResolved: no
[CHG] Device 28:ED:6A:A0:26:B7 Connected: no

我们用Current Time Service,列出所有attributes操作如下:

[tuya_mdev_test]# menu gatt
[tuya_mdev_test]# list-attributes 28:ED:6A:A0:26:B7
...
Primary Service
    /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0041
    00001805-0000-1000-8000-00805f9b34fb
    Current Time Service
Characteristic
    /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0041/char0045
    00002a0f-0000-1000-8000-00805f9b34fb
    Local Time Information
Characteristic
    /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0041/char0042
    00002a2b-0000-1000-8000-00805f9b34fb
    Current Time
Descriptor
    /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0041/char0042/desc0044
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
...

上面Current Time Service对应的服务如下图:

图片 6

我们选择Current Time进行操作UUID:0x2A2B

[ty_prod]# select-attribute /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0041/char0042
[tuya_mdev_test:/service0041/char0042]# read
Attempting to read /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0041/char0042
[CHG] Attribute /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0041/char0042 Value:
  e2 07 09 05 01 24 11 03 f1 02                    .....$....      
  e2 07 09 05 01 24 11 03 f1 02                    .....$.... 
[tuya_mdev_test:/service0041/char0042]# attribute-info
Characteristic - Current Time
    UUID: 00002a2b-0000-1000-8000-00805f9b34fb
    Service: /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0041
    Value:
  e2 07 09 05 01 2e 01 03 f5 02                    ..........      
    Notifying: yes
    Flags: read
    Flags: notify

读出结果大致意思应该是:2018-9/5-1:36:17 周三

读取一下0x180A的Device Information:

[tuya_mdev_test:/service0006/char0007]# select-attribute /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0047/char004a
[tuya_mdev_test:/service0047/char004a]# attribute-info
Characteristic - Model Number String
    UUID: 00002a24-0000-1000-8000-00805f9b34fb
    Service: /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0047
    Flags: read
[tuya_mdev_test:/service0047/char004a]# read
Attempting to read /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0047/char004a
[CHG] Attribute /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0047/char004a Value:
  69 50 68 6f 6e 65 36 2c 32                       iPhone6,2       
  69 50 68 6f 6e 65 36 2c 32                       iPhone6,2    

当然写、使能notify也很简单,看help即可。最后断开连接、并退出!!!

[tuya_mdev_test:/service0047/char004a]# disconnect 28:ED:6A:A0:26:B7
Attempting to disconnect from 28:ED:6A:A0:26:B7
[CHG] Device 28:ED:6A:A0:26:B7 ServicesResolved: no
Successful disconnected
[CHG] Device 28:ED:6A:A0:26:B7 Connected: no
[bluetooth]# quit

图片 7

2.3 修改主机名

LINKS

[1].Cannot connect to BLE device on Raspberry Pi
[2].Invalid file descriptor gatttool of bluez 5.32
[3].Get Started with Bluetooth Low Energy on Linux
[4].Reverse Engineering a Bluetooth Low Energy Light Bulb
[5].Doing Bluetooth Low Energy on Linux
[6].Tutorial: BLE Pairing the Raspberry Pi 3 Model B with Hexiwear

图片 8

@beautifulzzzz
智能硬件、物联网,热爱技术,关注产品
博客:http://blog.beautifulzzzz.com
园友交流群:414948975

2.3.1 centos6实现方式

临时修改主机名

[root@zeq ~]# hostname zeq_temp

[root@zeq ~]# bash

[root@zeq_temp ~]#

永久修改主机名

[root@zeq_temp ~]# sed -i '/^HOSTNAME=/c HOSTNAME=zeq' /etc/sysconfig/network

[root@zeq_temp ~]# cat /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=zeq

2.3.2 centos7实现方式

临时修改主机名

[root@zeq ~]# hostname zeq-c7

[root@zeq ~]# bash

永久修改主机名

[root@zeq-c7 ~]# hostnamectl set-hostname zeq-cc7

[root@zeq-c7 ~]# cat /etc/hostname

zeq-cc7

2.4 时区修改

2.4.1 查看时区

[root@zeq ~]# timedatectl list-timezones

2.4.2 修改时区

[root@zeq ~]#timedatectl set-timezone "America/Punta_Arenas" 

[root@zeq ~]# timedatectl set-timezone "Asia/Shanghai"

2.5 网络接口变化

net.ifnames 基于固件、拓扑、进行自动分配网卡名称,缺点比eth0、更难读,如ens32

biosdevname 根据戴尔服务器系统的BIOS提供的信息对网络接口进行重命名,如em1

默认命名规则 eth0 eth1 eth2

biosdevname em1 em2 em3

net.ifnames ens33 ens34 ens35

本文由千赢娱乐手机登录发布于千赢娱乐手机登录,转载请注明出处:使能notify蓝牙低功耗设备,CentOS7版本基础使用

关键词: 千赢国际娱乐

上一篇:进程命令,C语言文件操作

下一篇:没有了