当前位置:网站首页>Lianshengde W801 series 5-WeChat applet and W801 Bluetooth communication routine (read notes)
Lianshengde W801 series 5-WeChat applet and W801 Bluetooth communication routine (read notes)
2022-08-11 01:41:00 【hwd00001】
文章目录
To test withW801Bluetooth communication,I found the Bluetooth routine of the WeChat applet to read,作为一个没有 JavaScript基础的人,Reading the source code of the applet is confusing.Then saw a freshman“前端小刘不怕牛牛”Write a small program introduction article,清晰易懂.微 信小程序(黑马)专栏
Now make a note to record it.
网友cwlgoodman作品 微信小程序源码这个仓库有4个工程,我们用的是第一个:
1.bluetooth_demo
2.bluetooth_lock
3.glucometer
4.wechat_api
Modified source code.
This article can be read in conjunction with another:《From the perspective of WeChat appletW801Bluetooth communication source code(indicate方式)》
1.Import the first interface of the applet(Development tool interface)
It is assumed that the reader has already installed it《微信开发者工具》,And will import the existing project instance.
直接上图:
The resource manager on the left is the project file structure,This project has2个界面,One is the search interface;The second is the device interface.The search interface contains a list of searched device information;After clicking Device Information,to enter the device interface.操作流程如下图:
小程序控制LED视频:
微信小程序控制LED
2.Code analysis of the search interface
Every page is inpages中以单独的子文件夹存在,A file in a folder consists of four parts
js类型文件,构建页面的逻辑
wxml类型文件,类似html文件,设计页面结构
json类型文件,设置该页面的配置
wxss类型文件,类型css文件,设置页面的样式
Here we only focus on two files:《search.wxml》《search.js》.
《search.wxml》:
<view class="container">
<scroll-view scroll-y style="width:690rpx;height:{
{
list_height}}rpx">
<block wx:for="{
{devicesList}}" wx:key="deviceId">
<!-- Contents of the searched device list,Click a list item,绑定函数 “Connect” -->
<view class="list-item" id="{
{item.deviceId}}" bindtap="Connect">
<view style="display:flex;flex-direction:column;width:80%">
<text style="font-size:medium;word-break:break-all">设备名称: {
{item.name}}</text>
<text style="font-size:x-small;color:gray;word-break:break-all">设备ID: {
{item.deviceId}}</text>
<text style="font-size:x-small;color:gray;word-break:break-all">信号强度RSSI: {
{item.RSSI}}</text>
</view>
<image style="width:36px;height:36px" mode="aspectFit" src="/images/bluetooth.png"></image>
</view>
</block>
</scroll-view>
<!-- 按键 绑定函数 “Search”,根据变量 searching value displays different content -->
<button type="primary" class="button" loading="{
{searching}}" bindtap="Search">{
{searching?"搜索中...":"搜索蓝牙设备"}}</button>
</view>
《search.js》 内容过多,Do not release source code,Just look at the list of functions:
- 打开小程序,首先加载 搜索页面,Call back at this time onLoad函数.
- 点击 搜索蓝牙设备按键,调用search函数.
- Bluetooth devices have been searched,At this point, the interface will display the relevant information of the device,点击设备信息,将调用Connect函数,开始连接设备;Only after connecting to bluetooth successfully,to navigate to设备页面.
3.Device page code analysis
The device page has the same file structure as the search page,由4个文件组成,Here we also only focus on two files:《device.wxml》《device.js》.
《device.wxml》:(The corresponding page effect is shown in the second picture-Right side of the operation flowchart)
<view class="container">
<text style="font-size:medium;word-break:break-all">设备名称:{
{name}}</text>
<text style="font-size:x-small;color:gray;word-break:break-all">设备ID:{
{connectedDeviceId}}</text>
<text style="font-size:x-small;color:gray">状态:{
{connected?"已连接":"已断开"}}</text>
<text style="font-size:medium;margin-top:10px">发送内容:</text>
<input class="input" value="{
{inputText}}" bindinput="bindInput"/>
<text style="font-size:medium;margin-top:10px">接收内容:</text>
<input class="input" disabled value="{
{receiveText}}"/>
<button type="primary" class="button" bindtap="Send">发送</button>
<!-- 下面6A key is added by me,用于控制3个LED的亮灭 -->
<button type="primary" style="width: 193rpx; height: 108rpx; display: block; box-sizing: border-box; left: -249rpx; top: 19rpx; position: relative; color: crimson" class="button" bindtap="onLed1on">Led1on</button>
<button type="primary" style="width: 193rpx; height: 108rpx; display: block; box-sizing: border-box; left: -249rpx; top: 54rpx; position: relative" class="button" bindtap="onLed1off">Led1off</button>
<button type="primary" style="width: 193rpx; height: 108rpx; display: block; box-sizing: border-box; left: -12rpx; top: -199rpx; position: relative; color: crimson" class="button" bindtap="onLed2on">Led2on</button>
<button type="primary" style="width: 193rpx; height: 108rpx; display: block; box-sizing: border-box; left: -12rpx; top: -162rpx; position: relative" class="button" bindtap="onLed2off">Led2off</button>
<button type="primary" style="width: 193rpx; height: 108rpx; display: block; box-sizing: border-box; left: 235rpx; top: -415rpx; position: relative; color: crimson" class="button" bindtap="onLed3on">Led3on</button>
<button type="primary" style="width: 193rpx; height: 108rpx; display: block; box-sizing: border-box; left: 235rpx; top: -378rpx; position: relative" class="button" bindtap="onLed3off">Led3off</button>
</view>
《device.js》 函数列表:
The prerequisite for entering the device interface is that the device is successfully connected.从搜索界面进入设备界面,首先调用onLoead函数.
- onLoad函数,To query eigenvalues(Characteristic)的属性,If yes has write(write)的属性,Then writing a binary value to this eigenvalue is sent to W801;if instructed(indicate)的属性,Then listen to the value change of this feature value and read itW801发过来的信息.
- 读取W801The data sent over is through monitoringindicate自动完成.
- The keys are bound to the corresponding functions respectively.
4.蓝牙API使用示意图
边栏推荐
- C # - delegate detailed usage
- The concept of services
- Use mysql statement to operate data table (table)
- 21、阿里云oss
- 21. Aliyun oss
- 迭代器和生成器
- 单面PCB布线阻抗的工程设计
- php 判断数组是否为多维数组
- 单片机人机交互--矩阵按键
- J9 Digital Theory: DAO governance is more like an ecological process: governance is native to the network and continues to evolve
猜你喜欢
随机推荐
单面PCB布线阻抗的工程设计
联盛德W801系列6-从微信小程序的角度来分析W801的蓝牙通信源码(indicate方式)
Apache Commons Configuration远程代码执行漏洞(CVE-2022-33980)分析&复现
络达开发---自定义BLE服务(二):功能实现
88Q2110 通过C22方式访问C45 phy地址
MySQL中的DDL常规操作总结
Experiment record of Shengxin (part3)--scipy.spatial.distance_matrix
版本号大小的判断方法
Mysql database installation and configuration detailed tutorial
分库分表ShardingSphere-JDBC笔记整理
软件测试面试题:对 RUP,CMM,CMMI,XP,PSP,TSP 的认识?
C#使用计时器
【21天学习挑战赛】折半插入排序
C# WebBrower1控件可编辑模式保存时会提示“该文档已被修改,是否保存修改结果”
WinForm(五)控件和它的成员
SystemVerilog: Verifying knowledge bits and pieces
最新国产电源厂家及具体型号pin-to-pin替代手册发布
uni-app实现app和H5调用手机拨号功能
what is an array
word 设置标题前分页