Skip to content

Commit

Permalink
OTA_SDK2.0.0
Browse files Browse the repository at this point in the history
Optimize SDK interface
  • Loading branch information
coffee1boy committed Feb 6, 2023
1 parent 7eade0b commit fbaeecd
Show file tree
Hide file tree
Showing 108 changed files with 39,429 additions and 7 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
====使用前请先阅读本文====
#压缩包文件结构说明
code -- 演示程序源码
doc -- 开发文档
libs -- 核心库
ReadMe.txt
README.md


## 小程序使用说明
1.打开微信APP,搜索小程序【杰理OTA】(初次打开小程序,需要授予对应权限)
2.选择升级文件(目前只支持选择微信聊天中的文件,其他方式需开发者自己开发)
2.选择升级文件(目前只支持选择微信聊天中的文件,其他方式需开发者自己开发。iOS加载较大文件时,需要加载一段时间
3.扫描设备
4.连接设备
4.连接设备(调整MTU,请在连接设备前设置,仅Android支持)
5.开始升级(!!!升级过程中请不要离开小程序,微信会把小程序挂起导致接收蓝牙数据失败)


Expand All @@ -29,5 +28,11 @@
1.需要把小程序id变更至自己的小程序测试号id

**sdk使用说明:**
目前必须使用该库做蓝牙连接才可以OTA升级。
1.当设备端打开设备认证时,小程序端也需要打开认证(关闭认证时,同理)。

2.若打开认证时,单备份回连也需要认证。

## 开发文档

sdk使用文档请查看[杰理文档系统-杰理OTA (zh-jieli.com)](https://doc.zh-jieli.com/vue/#/docs/ota)

1 change: 1 addition & 0 deletions code/JLOTA/.cloudbase/container/debug.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"containers":[]}
31 changes: 31 additions & 0 deletions code/JLOTA/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Eslint config file
* Documentation: https://eslint.org/docs/user-guide/configuring/
* Install the Eslint extension before using this feature.
*/
module.exports = {
env: {
es6: true,
browser: true,
node: true,
},
ecmaFeatures: {
modules: true,
},
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
globals: {
wx: true,
App: true,
Page: true,
getCurrentPages: true,
getApp: true,
Component: true,
requirePlugin: true,
requireMiniProgram: true,
},
// extends: 'eslint:recommended',
rules: {},
}
56 changes: 56 additions & 0 deletions code/JLOTA/docs/readMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
整个OTA项目的架构: OTA流程库基于RCSP协议库实现,所以需要先实现RCSP协议库


**当前微信api【基础库版本:2.24.6】的bug:***

1. wx.setBLEMTU函数的fail属性并不会将最终协商mtu返回。解决方法:fail的时候调用wx.getBLEMTU方法获取最终协商mtu
2. wx.onBLEMTUChange函数不会触发(不确定是不是使用方式不对)
3. 目前发现bug:iOS端微信有些版本会不支持获取MTU,会直接性导致mtu发数只能以每包20Byte地发,最终影响手表设备升级失败。
可参考的处理方案:通过自定义命令的方式,从设备端获取到MTU





## 常见问题:

### 1.MTU引起的发送数据异常问题

常见现象一:小机在OTA时频繁请求同一段数据

**引发错误的原因:**

一.小程序中 MTU 为 ATT_MTU,包含 Op-Code 和 Attribute Handle 的长度,实际可以传输的数据长度为 ATT_MTU - 3。
iOS 系统中 MTU 为固定值;安卓系统中,MTU 会在系统协商成功之后发生改变,建议使用 wx.onBLEMTUChange 监听

二. MTU大小不足,并且没有做分包发送,导致发送出去的数据丢数据。举例子:MTU只有23,实际可用mtu大小:23-3=20,发送数据有40byte,那么小机真正接收到的数据只有最前面的20byte。

### 2.小程序调整MTU失败问题

常见现象一:调用wx.setBLEMTU,会回调fail函数

**引发错误的原因:**

一. 小程序调整MTU时,可调节的MTU大小要小于设备端设置的mtu。否则会调整失败,而且fail中也不会携带最终协商mtu(当前微信api的bug)

[mtu值大于设备端的mtu大小]: https://developers.weixin.qq.com/community/develop/doc/0002c25cca071050f93ae0b5856800?highLine=wx.setBLEMTU

二.iOS手机是不支持调整MTU的,需要通过wx.getBLEMTU()获取,要指明writeType为writeNoResponse

### 3.小程序提审代码时,wx.getLocation暂未开通问题

先到「设置」- 「基本设置」-「服务类目」将小程序的类目设置成对应的类目,再到「开发」-「开发管理」-「接口设置」中自助开通该接口(wx.getLocation)权限。

只有部分类目可以开通该接口,具体请查阅官方介绍[wx.getLocation(Object object) ](https://developers.weixin.qq.com/miniprogram/dev/api/location/wx.getLocation.html)


### 4.旧JS项目使用TS出现白屏现象(部分ui显示不正常)
在 project.config.json 文件中,修改 setting 下的 uglifyFileName 字段为 false(关闭上传时代码保护)[如何解决基于typescript、less开发的小程序,真机预览页面空白,babel报错? ](https://developers.weixin.qq.com/community/develop/doc/00046a8e9f4ff0b2115e8711f56000?highLine=TypeScript%25E7%25BC%2596%25E8%25AF%2591%25E4%25B8%258D%25E6%25AD%25A3%25E5%25B8%25B8)

### 5.OTA升级失败,等待回复命令超时
可能原因一:mtu太小,频繁调用wx.writeBLECharacteristicValue,会偶现写入成功回调延时很严重。处理方法:当wx.writeBLECharacteristicValue回调complete的时候,再调用下一次。
可能原因二:mtu太小,一个协议包数据太大,导致完整发出去的时候,设备端已经超时。处理方法:调大mtu。

### 6.出现认证失败
可能原因一:上一次通过认证的蓝牙连接断开和这一次蓝牙连接时间间隔很短,蓝牙底层并没有断开。处理办法:1.做一下处理,不要频繁断连设备。2.如果非要频繁断连设备,推荐小程序端不走认证,且关闭设备端的认证。

38 changes: 38 additions & 0 deletions code/JLOTA/miniprogram/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"pages": [
"pages/pageConnect/pageConnect",
"pages/pageUpdate/pageUpdate",
"pages/pageSetting/pageSetting"
],
"tabBar": {
"custom": true,
"color": "#808080",
"selectedColor": "#398BFF",
"list": [{
"pagePath": "pages/pageConnect/pageConnect",
"text": "连接",
"iconPath": "/images/[email protected]",
"selectedIconPath": "/images/[email protected]"
},
{
"pagePath": "pages/pageUpdate/pageUpdate",
"text": "升级",
"iconPath": "/images/[email protected]",
"selectedIconPath": "/images/[email protected]"
},
{
"pagePath": "pages/pageSetting/pageSetting",
"text": "设置",
"iconPath": "/images/[email protected]",
"selectedIconPath": "/images/[email protected]"
}]
},
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "杰理OTA升级",
"navigationBarTextStyle": "black"
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}
10 changes: 10 additions & 0 deletions code/JLOTA/miniprogram/app.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**app.wxss**/
// .container {
// height: 100%;
// display: flex;
// flex-direction: column;
// align-items: center;
// justify-content: space-between;
// padding: 200rpx 0;
// box-sizing: border-box;
// }
57 changes: 57 additions & 0 deletions code/JLOTA/miniprogram/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// app.ts

import { IAppOption } from "../typings/index";
import { BluetoothManager, BluetoothConfigure } from "./lib/bluetoothManager";


App<IAppOption>({
globalData: {
gbIsHandshake: true,
gbIsAutoTest: false,
gbTestNum: 1,
gbMtuNum: 23,
bluetoothManager: <any>null,
},
onLaunch() {
const cacheIsHandshake = wx.getStorageSync("IsHandshake")
if (cacheIsHandshake != "") {
this.globalData.gbIsHandshake = cacheIsHandshake
}
const cacheIsAutoTest = wx.getStorageSync("IsAutoTest")
if (cacheIsAutoTest != "") {
this.globalData.gbIsAutoTest = cacheIsAutoTest
}
const cacheTestNum = wx.getStorageSync("TestNum")
if (cacheTestNum != "") {
this.globalData.gbTestNum = cacheTestNum
}
const cacheMtuNum = wx.getStorageSync("MtuNum")
if (cacheMtuNum != "") {
this.globalData.gbMtuNum = cacheMtuNum
}

const sysinfo = wx.getSystemInfoSync()
this.globalData.bluetoothManager = new BluetoothManager(sysinfo.platform);
const configure = new BluetoothConfigure()
configure.isUseAuth = this.globalData.gbIsHandshake
configure.changeMTU = this.globalData.gbMtuNum
//todo 目前未实现自动化测试OTA
configure.isAutoTestOTA = false;
configure.autoTestOTACount = 20;
this.globalData.bluetoothManager.setConfigure(configure)

// 展示本地存储能力
const logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)

// 登录
wx.login({
success: res => {
console.log(res.code)
// 发送 res.code 到后台换取 openId, sessionKey, unionId
},
})

},
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"component": true,
"usingComponents": {}
}
Loading

0 comments on commit fbaeecd

Please sign in to comment.