├── pages ├── index │ ├── index.json │ ├── index.wxss │ ├── index.wxml │ └── index.js └── bluetooth │ ├── bluetooth.json │ ├── bluetooth.wxss │ ├── bluetooth.wxml │ └── bluetooth.js ├── images ├── exam.png ├── home.png ├── mine.png ├── tool.png ├── examselected.png ├── homeselected.png ├── mineselected.png └── toolselected.png ├── app.wxss ├── README.md ├── app.json └── app.js /pages/index/index.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /pages/bluetooth/bluetooth.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /pages/bluetooth/bluetooth.wxss: -------------------------------------------------------------------------------- 1 | /* pages/tool/tool.wxss */ -------------------------------------------------------------------------------- /images/exam.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xwm111/wechatminiprogramforbluetooth/HEAD/images/exam.png -------------------------------------------------------------------------------- /images/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xwm111/wechatminiprogramforbluetooth/HEAD/images/home.png -------------------------------------------------------------------------------- /images/mine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xwm111/wechatminiprogramforbluetooth/HEAD/images/mine.png -------------------------------------------------------------------------------- /images/tool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xwm111/wechatminiprogramforbluetooth/HEAD/images/tool.png -------------------------------------------------------------------------------- /images/examselected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xwm111/wechatminiprogramforbluetooth/HEAD/images/examselected.png -------------------------------------------------------------------------------- /images/homeselected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xwm111/wechatminiprogramforbluetooth/HEAD/images/homeselected.png -------------------------------------------------------------------------------- /images/mineselected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xwm111/wechatminiprogramforbluetooth/HEAD/images/mineselected.png -------------------------------------------------------------------------------- /images/toolselected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xwm111/wechatminiprogramforbluetooth/HEAD/images/toolselected.png -------------------------------------------------------------------------------- /app.wxss: -------------------------------------------------------------------------------- 1 | /**app.wxss**/ 2 | .container { 3 | height: 100%; 4 | display: flex; 5 | flex-direction: column; 6 | align-items: center; 7 | justify-content: space-between; 8 | padding: 200rpx 0; 9 | box-sizing: border-box; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | a demo for how to use bluetooth to connect to BLE 4.0 device. 2 | you can use it to communicate with BLE device 3 | 4 | 一个微信小程序,能够搜索并连接蓝牙4.0设备,还能够和蓝牙设备进行数据交互 5 | 6 | 7 | please modify the serviceId and characteristicId to match your bluetooth device 8 | 9 | 请将index.js文件中的 serviceId和characteristicId 修改成和你蓝牙设备相匹配 10 | 11 | 2017-04-13 12 | 增加通用模块,发现设备之后能够搜索设备的serviceId和搜索在该serviceId下的characteristicId(serviceId目前使用的是第一个,如有需要使用其他的请自行修改) 13 | 14 | 15 | 目前请用安卓手机调试,IOS的接口貌似有些不一样,下个版本改进 16 | 17 | 18 | 19 | Q群:54073007 -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "pages":[ 3 | "pages/index/index", 4 | "pages/bluetooth/bluetooth" 5 | ], 6 | "window":{ 7 | "backgroundTextStyle":"light", 8 | "navigationBarBackgroundColor": "#fff", 9 | "navigationBarTitleText": "蓝牙小程序调试工具", 10 | "navigationBarTextStyle":"black" 11 | }, 12 | "tabBar": { 13 | 14 | "borderStyle": "white", 15 | 16 | "list": [{ 17 | "pagePath": "pages/index/index", 18 | "iconPath": "images/home.png", 19 | "selectedIconPath": "images/homeselected.png", 20 | "text": "简单" 21 | }, { 22 | "pagePath": "pages/bluetooth/bluetooth", 23 | "iconPath": "images/exam.png", 24 | "selectedIconPath": "images/examselected.png", 25 | "text": "通用" 26 | }] 27 | }, 28 | "debug":true 29 | } 30 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | //app.js 2 | App({ 3 | onLaunch: function () { 4 | //调用API从本地缓存中获取数据 5 | var logs = wx.getStorageSync('logs') || [] 6 | logs.unshift(Date.now()) 7 | wx.setStorageSync('logs', logs) 8 | }, 9 | getUserInfo:function(cb){ 10 | var that = this 11 | if(this.globalData.userInfo){ 12 | typeof cb == "function" && cb(this.globalData.userInfo) 13 | }else{ 14 | //调用登录接口 15 | wx.login({ 16 | success: function () { 17 | wx.getUserInfo({ 18 | success: function (res) { 19 | that.globalData.userInfo = res.userInfo 20 | typeof cb == "function" && cb(that.globalData.userInfo) 21 | } 22 | }) 23 | } 24 | }) 25 | } 26 | }, 27 | globalData:{ 28 | userInfo:null 29 | } 30 | }) -------------------------------------------------------------------------------- /pages/index/index.wxss: -------------------------------------------------------------------------------- 1 | view { 2 | display: inline-block; 3 | } 4 | 5 | .container { 6 | padding: 0; 7 | margin: 0; 8 | align-items: flex-start; 9 | } 10 | 11 | .section { 12 | display: inline-block; 13 | width: 100%; 14 | position: relative; 15 | } 16 | 17 | .content { 18 | margin: auto; 19 | padding: auto; 20 | position: absolute; 21 | top: 5px; 22 | left: 10px; 23 | } 24 | 25 | .switch { 26 | position: relative; 27 | float: right; 28 | right: 0px; 29 | } 30 | 31 | button { 32 | background: red\; 33 | } 34 | 35 | .list-item { 36 | margin-top: 20rpx; 37 | margin-bottom: 20rpx; 38 | display: flex; 39 | flex-direction: column; 40 | box-sizing: border-box; 41 | border: 1px dashed #000; 42 | } 43 | 44 | .list-item text { 45 | margin-top: 10rpx; 46 | } 47 | 48 | 49 | .list-item button { 50 | margin-right: 10rpx; 51 | } 52 | 53 | .deviceconnected{ 54 | background-color:sandybrown 55 | } 56 | 57 | .recieve{ 58 | 59 | width: 100% 60 | } 61 | 62 | .recieve textarea{ 63 | border: 1px dashed; 64 | width: 100% 65 | } 66 | 67 | input{ 68 | display: block; 69 | border: 1px dashed; 70 | width: 200px; 71 | } 72 | 73 | -------------------------------------------------------------------------------- /pages/index/index.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 蓝牙初始化: 7 | {{isbluetoothready?"ok":"尚未初始化"}} 8 | 9 | 10 | 11 | 12 | 13 | 16 | 17 | 24 | 25 | 26 | 27 | 数据接收 28 |