refactor: 删除 ESP Config WeChat 项目

This commit is contained in:
duruofu
2025-08-04 19:55:09 +08:00
parent a356de9d73
commit ef991fe9f1
93 changed files with 389 additions and 10656 deletions

View File

@@ -1,2 +0,0 @@
node_modules/
miniprogram_npm/

View File

@@ -1,5 +0,0 @@
# ESP Config WeChat
A WeChat application for provisioning ESP smart devices.
## Implemented modules
[BluFi](https://github.com/espressif/esp-idf/tree/master/examples/bluetooth/blufi)

View File

@@ -1,22 +0,0 @@
//app.js
App({
data: {
service_uuid: "0000FFFF-0000-1000-8000-00805F9B34FB",
characteristic_write_uuid: "0000FF01-0000-1000-8000-00805F9B34FB",
characteristic_read_uuid: "0000FF02-0000-1000-8000-00805F9B34FB",
name: "BLUFI",
mtu: 19,
constMtu: 128,
md5Key: "",
platform: '',
sequenceControl: -1,
sequenceNumber: -1
},
onLaunch: function () {
},
globalData: {
userInfo: null
}
})

View File

@@ -1,15 +0,0 @@
{
"pages": [
"pages/index/index",
"pages/blueDevices/blueDevices",
"pages/blueWifi/blueWifi",
"pages/blueConnect/blueConnect"
],
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#4d9efb",
"navigationBarTitleText": "WeChat",
"navigationBarTextStyle": "white"
},
"sitemapLocation": "sitemap.json"
}

View File

@@ -1,119 +0,0 @@
/**app.wxss**/
.container {
height: 100%;
display: flex;
padding: 0 10px;
flex-direction: column;
align-items: center;
justify-content: space-between;
box-sizing: border-box;
}
.item {
display: flex;
height: 130rpx;
width: 100%;
align-items: center;
border-bottom: 1px solid #eee;
}
.item-img {
flex: 0 0 100rpx;
height: 100rpx;
display: flex;
justify-content: center;
align-items: center;
border-radius: 100%;
}
.bluetooth-img {
height: 80rpx;
width: 80rpx;
}
.item-name {
flex: 1;
padding-left: 10px;
display: flex;
flex-direction: column;
font-size: 32rpx;
}
.text-rssi {
font-size: 28rpx;
color: #999;
}
.btn {
width: 100%;
height: 90rpx;
line-height: 90rpx;
background: #4d9efb;
border: none;
margin-bottom: 30rpx;
font-size: 14px;
color: #fff;
}
.font14 {
font-size: 14px;
}
.font16 {
font-size: 16px;
}
.textcenter {
text-align: center;
}
.width100 {
width: 100%;
}
.margintop20 {
margin-top: 20px;
}
.margintop10 {
margin-top: 10px;
}
.modal-mask{
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
background: rgba(0,0,0,.7);
overflow: hidden;
color: #ffffff;
z-index:900;
}
.modal-dialog{
background-color: #f9f9f9;
/*background: rgba(0,0,0,.7);*/
opacity: 0.95;
position: fixed;
z-index: 999;
top: 20%;
left: 10%;
overflow: hidden;
width: 80%;
color: #000;
border-radius: 26rpx;
}
.modal-dialog input{
margin: 15px 0;
padding: 0 20px;
font-size: 32rpx;
}
.modal-btn-wrapper{
display: flex;
flex-direction: row;
height: 100rpx;
line-height:90rpx;
border-top: 2rpx solid rgba(7,17,27,0.1);
}
.cancel-btn, .confirm-btn{
flex: 1;
height: 100rpx;
line-height: 100rpx;
text-align: center;
font-size: 32rpx;
}
.cancel-btn{
border-right: 2rpx solid rgba(7,17,27,0.1);
}
.modal-title{
text-align: center;
padding-top: 10px;
}

File diff suppressed because one or more lines are too long

View File

@@ -1,42 +0,0 @@
var generatePrime = require('./lib/generatePrime')
var DH = require('./lib/dh')
var Buffer = require('./lib/safe-buffer').Buffer
function getDiffieHellman(mod) {
var prime = new Buffer(primes[mod].prime, 'hex')
var gen = new Buffer(primes[mod].gen, 'hex')
return new DH(prime, gen)
}
var ENCODINGS = {
'binary': true, 'hex': true, 'base64': true
}
function createDiffieHellman(prime, enc, generator, genc) {
if (Buffer.isBuffer(enc) || ENCODINGS[enc] === undefined) {
return createDiffieHellman(prime, 'binary', enc, generator)
}
enc = enc || 'binary'
genc = genc || 'binary'
generator = generator || new Buffer([2])
if (!Buffer.isBuffer(generator)) {
generator = new Buffer(generator, genc)
}
if (typeof prime === 'number') {
return new DH(generatePrime(prime, generator), generator, true)
}
if (!Buffer.isBuffer(prime)) {
prime = new Buffer(prime, enc)
}
return new DH(prime, generator, true)
}
exports.DiffieHellmanGroup = exports.createDiffieHellmanGroup = exports.getDiffieHellman = getDiffieHellman
exports.createDiffieHellman = exports.DiffieHellman = createDiffieHellman

View File

@@ -1,151 +0,0 @@
'use strict'
exports.byteLength = byteLength
exports.toByteArray = toByteArray
exports.fromByteArray = fromByteArray
var lookup = []
var revLookup = []
var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
for (var i = 0, len = code.length; i < len; ++i) {
lookup[i] = code[i]
revLookup[code.charCodeAt(i)] = i
}
// Support decoding URL-safe base64 strings, as Node.js does.
// See: https://en.wikipedia.org/wiki/Base64#URL_applications
revLookup['-'.charCodeAt(0)] = 62
revLookup['_'.charCodeAt(0)] = 63
function getLens (b64) {
var len = b64.length
if (len % 4 > 0) {
throw new Error('Invalid string. Length must be a multiple of 4')
}
// Trim off extra bytes after placeholder bytes are found
// See: https://github.com/beatgammit/base64-js/issues/42
var validLen = b64.indexOf('=')
if (validLen === -1) validLen = len
var placeHoldersLen = validLen === len
? 0
: 4 - (validLen % 4)
return [validLen, placeHoldersLen]
}
// base64 is 4/3 + up to two characters of the original data
function byteLength (b64) {
var lens = getLens(b64)
var validLen = lens[0]
var placeHoldersLen = lens[1]
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
}
function _byteLength (b64, validLen, placeHoldersLen) {
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
}
function toByteArray (b64) {
var tmp
var lens = getLens(b64)
var validLen = lens[0]
var placeHoldersLen = lens[1]
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
var curByte = 0
// if there are placeholders, only get up to the last complete 4 chars
var len = placeHoldersLen > 0
? validLen - 4
: validLen
for (var i = 0; i < len; i += 4) {
tmp =
(revLookup[b64.charCodeAt(i)] << 18) |
(revLookup[b64.charCodeAt(i + 1)] << 12) |
(revLookup[b64.charCodeAt(i + 2)] << 6) |
revLookup[b64.charCodeAt(i + 3)]
arr[curByte++] = (tmp >> 16) & 0xFF
arr[curByte++] = (tmp >> 8) & 0xFF
arr[curByte++] = tmp & 0xFF
}
if (placeHoldersLen === 2) {
tmp =
(revLookup[b64.charCodeAt(i)] << 2) |
(revLookup[b64.charCodeAt(i + 1)] >> 4)
arr[curByte++] = tmp & 0xFF
}
if (placeHoldersLen === 1) {
tmp =
(revLookup[b64.charCodeAt(i)] << 10) |
(revLookup[b64.charCodeAt(i + 1)] << 4) |
(revLookup[b64.charCodeAt(i + 2)] >> 2)
arr[curByte++] = (tmp >> 8) & 0xFF
arr[curByte++] = tmp & 0xFF
}
return arr
}
function tripletToBase64 (num) {
return lookup[num >> 18 & 0x3F] +
lookup[num >> 12 & 0x3F] +
lookup[num >> 6 & 0x3F] +
lookup[num & 0x3F]
}
function encodeChunk (uint8, start, end) {
var tmp
var output = []
for (var i = start; i < end; i += 3) {
tmp =
((uint8[i] << 16) & 0xFF0000) +
((uint8[i + 1] << 8) & 0xFF00) +
(uint8[i + 2] & 0xFF)
output.push(tripletToBase64(tmp))
}
return output.join('')
}
function fromByteArray (uint8) {
var tmp
var len = uint8.length
var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
var parts = []
var maxChunkLength = 16383 // must be multiple of 3
// go through the array every three bytes, we'll deal with trailing stuff later
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
parts.push(encodeChunk(
uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)
))
}
// pad the end with zeros, but make sure to not forget the extra bytes
if (extraBytes === 1) {
tmp = uint8[len - 1]
parts.push(
lookup[tmp >> 2] +
lookup[(tmp << 4) & 0x3F] +
'=='
)
} else if (extraBytes === 2) {
tmp = (uint8[len - 2] << 8) + uint8[len - 1]
parts.push(
lookup[tmp >> 10] +
lookup[(tmp >> 4) & 0x3F] +
lookup[(tmp << 2) & 0x3F] +
'='
)
}
return parts.join('')
}

View File

@@ -1,52 +0,0 @@
var r;
module.exports = function rand(len) {
if (!r)
r = new Rand(null);
return r.generate(len);
};
function Rand(rand) {
this.rand = rand;
}
module.exports.Rand = Rand;
Rand.prototype.generate = function generate(len) {
return this._rand(len);
};
// Emulate crypto API using randy
Rand.prototype._rand = function _rand(n) {
console.log(this);
if (this.rand.getBytes)
return this.rand.getBytes(n);
var res = new Uint8Array(n);
for (var i = 0; i < res.length; i++)
res[i] = this.rand.getByte();
return res;
};
if (typeof self === 'object') {
Rand.prototype._rand = function _rand(n) {
var list = [];
for (var i = 0; i < n; i++) {
list.push(Math.ceil(Math.random() * 255))
}
var arr = new Uint8Array(list);
return arr;
};
} else {
// Node.js or Web worker with no crypto support
try {
var crypto = require('crypto');
if (typeof crypto.randomBytes !== 'function')
throw new Error('Not supported');
Rand.prototype._rand = function _rand(n) {
return crypto.randomBytes(n);
};
} catch (e) {
}
}

View File

@@ -1,165 +0,0 @@
var BN = require('bn');
var MillerRabin = require('miller-rabin');
var millerRabin = new MillerRabin();
var TWENTYFOUR = new BN(24);
var ELEVEN = new BN(11);
var TEN = new BN(10);
var THREE = new BN(3);
var SEVEN = new BN(7);
var Buffer = require('safe-buffer').Buffer
var primes = require('./generatePrime');
var randomBytes = require('randombytes');
module.exports = DH;
function setPublicKey(pub, enc) {
enc = enc || 'utf8';
if (!Buffer.isBuffer(pub)) {
pub = new Buffer(pub, enc);
}
this._pub = new BN(pub);
return this;
}
function setPrivateKey(priv, enc) {
enc = enc || 'utf8';
if (!Buffer.isBuffer(priv)) {
priv = new Buffer(priv, enc);
}
this._priv = new BN(priv);
return this;
}
var primeCache = {};
function checkPrime(prime, generator) {
var gen = generator.toString('hex');
var hex = [gen, prime.toString(16)].join('_');
if (hex in primeCache) {
return primeCache[hex];
}
var error = 0;
if (prime.isEven() ||
!primes.simpleSieve ||
!primes.fermatTest(prime) ||
!millerRabin.test(prime)) {
//not a prime so +1
error += 1;
if (gen === '02' || gen === '05') {
// we'd be able to check the generator
// it would fail so +8
error += 8;
} else {
//we wouldn't be able to test the generator
// so +4
error += 4;
}
primeCache[hex] = error;
return error;
}
if (!millerRabin.test(prime.shrn(1))) {
//not a safe prime
error += 2;
}
var rem;
switch (gen) {
case '02':
if (prime.mod(TWENTYFOUR).cmp(ELEVEN)) {
// unsuidable generator
error += 8;
}
break;
case '05':
rem = prime.mod(TEN);
if (rem.cmp(THREE) && rem.cmp(SEVEN)) {
// prime mod 10 needs to equal 3 or 7
error += 8;
}
break;
default:
error += 4;
}
primeCache[hex] = error;
return error;
}
function DH(prime, generator, malleable) {
this.setGenerator(generator);
this.__prime = new BN(prime);
this._prime = BN.mont(this.__prime);
this._primeLen = 128;
this._pub = undefined;
this._priv = undefined;
this._primeCode = undefined;
if (malleable) {
this.setPublicKey = setPublicKey;
this.setPrivateKey = setPrivateKey;
} else {
this._primeCode = 8;
}
}
Object.defineProperty(DH.prototype, 'verifyError', {
enumerable: true,
get: function () {
if (typeof this._primeCode !== 'number') {
this._primeCode = checkPrime(this.__prime, this.__gen);
}
return this._primeCode;
}
});
DH.prototype.generateKeys = function () {
if (!this._priv) {
this._priv = new BN(randomBytes(this._primeLen));
}
this._pub = this._gen.toRed(this._prime).redPow(this._priv).fromRed();
return this.getPublicKey();
};
DH.prototype.computeSecret = function (other) {
other = new BN(other);
other = other.toRed(this._prime);
var secret = other.redPow(this._priv).fromRed();
var out = new Buffer(secret.toArray());
var prime = this.getPrime();
if (out.length < prime.length) {
var front = new Buffer(prime.length - out.length);
front.fill(0);
out = Buffer.concat([front, out]);
}
return out;
};
DH.prototype.getPublicKey = function getPublicKey(enc) {
return formatReturnValue(this._pub, enc);
};
DH.prototype.getPrivateKey = function getPrivateKey(enc) {
return formatReturnValue(this._priv, enc);
};
DH.prototype.getPrime = function (enc) {
return formatReturnValue(this.__prime, enc);
};
DH.prototype.getGenerator = function (enc) {
return formatReturnValue(this._gen, enc);
};
DH.prototype.setGenerator = function (gen, enc) {
enc = enc || 'utf8';
if (!Buffer.isBuffer(gen)) {
gen = new Buffer(gen, enc);
}
this.__gen = gen;
this._gen = new BN(gen);
return this;
};
function formatReturnValue(bn, enc) {
var buf = new Buffer(bn.toArray());
if (!enc) {
return buf;
} else {
return buf.toString(enc);
}
}

View File

@@ -1,105 +0,0 @@
var randomBytes = require('randombytes');
module.exports = findPrime;
findPrime.simpleSieve = simpleSieve;
findPrime.fermatTest = fermatTest;
var BN = require('bn.js');
var TWENTYFOUR = new BN(24);
var MillerRabin = require('miller-rabin');
var millerRabin = new MillerRabin();
var ONE = new BN(1);
var TWO = new BN(2);
var FIVE = new BN(5);
var SIXTEEN = new BN(16);
var EIGHT = new BN(8);
var TEN = new BN(10);
var THREE = new BN(3);
var SEVEN = new BN(7);
var ELEVEN = new BN(11);
var FOUR = new BN(4);
var TWELVE = new BN(12);
var primes = null;
function _getPrimes() {
if (primes !== null)
return primes;
var limit = 0x100000;
var res = [];
res[0] = 2;
for (var i = 1, k = 3; k < limit; k += 2) {
var sqrt = Math.ceil(Math.sqrt(k));
for (var j = 0; j < i && res[j] <= sqrt; j++)
if (k % res[j] === 0)
break;
if (i !== j && res[j] <= sqrt)
continue;
res[i++] = k;
}
primes = res;
return res;
}
function simpleSieve(p) {
var primes = _getPrimes();
for (var i = 0; i < primes.length; i++)
if (p.modn(primes[i]) === 0) {
if (p.cmpn(primes[i]) === 0) {
return true;
} else {
return false;
}
}
return true;
}
function fermatTest(p) {
var red = BN.mont(p);
return TWO.toRed(red).redPow(p.subn(1)).fromRed().cmpn(1) === 0;
}
function findPrime(bits, gen) {
if (bits < 16) {
// this is what openssl does
if (gen === 2 || gen === 5) {
return new BN([0x8c, 0x7b]);
} else {
return new BN([0x8c, 0x27]);
}
}
gen = new BN(gen);
var num, n2;
while (true) {
num = new BN(randomBytes(Math.ceil(bits / 8)));
while (num.bitLength() > bits) {
num.ishrn(1);
}
if (num.isEven()) {
num.iadd(ONE);
}
if (!num.testn(1)) {
num.iadd(TWO);
}
if (!gen.cmp(TWO)) {
while (num.mod(TWENTYFOUR).cmp(ELEVEN)) {
num.iadd(FOUR);
}
} else if (!gen.cmp(FIVE)) {
while (num.mod(TEN).cmp(THREE)) {
num.iadd(FOUR);
}
}
n2 = num.shrn(1);
if (simpleSieve(n2) && simpleSieve(num) &&
fermatTest(n2) && fermatTest(num) &&
millerRabin.test(n2) && millerRabin.test(num)) {
return num;
}
}
}

View File

@@ -1,84 +0,0 @@
exports.read = function (buffer, offset, isLE, mLen, nBytes) {
var e, m
var eLen = (nBytes * 8) - mLen - 1
var eMax = (1 << eLen) - 1
var eBias = eMax >> 1
var nBits = -7
var i = isLE ? (nBytes - 1) : 0
var d = isLE ? -1 : 1
var s = buffer[offset + i]
i += d
e = s & ((1 << (-nBits)) - 1)
s >>= (-nBits)
nBits += eLen
for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
m = e & ((1 << (-nBits)) - 1)
e >>= (-nBits)
nBits += mLen
for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
if (e === 0) {
e = 1 - eBias
} else if (e === eMax) {
return m ? NaN : ((s ? -1 : 1) * Infinity)
} else {
m = m + Math.pow(2, mLen)
e = e - eBias
}
return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
}
exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
var e, m, c
var eLen = (nBytes * 8) - mLen - 1
var eMax = (1 << eLen) - 1
var eBias = eMax >> 1
var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
var i = isLE ? 0 : (nBytes - 1)
var d = isLE ? 1 : -1
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
value = Math.abs(value)
if (isNaN(value) || value === Infinity) {
m = isNaN(value) ? 1 : 0
e = eMax
} else {
e = Math.floor(Math.log(value) / Math.LN2)
if (value * (c = Math.pow(2, -e)) < 1) {
e--
c *= 2
}
if (e + eBias >= 1) {
value += rt / c
} else {
value += rt * Math.pow(2, 1 - eBias)
}
if (value * c >= 2) {
e++
c /= 2
}
if (e + eBias >= eMax) {
m = 0
e = eMax
} else if (e + eBias >= 1) {
m = ((value * c) - 1) * Math.pow(2, mLen)
e = e + eBias
} else {
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
e = 0
}
}
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
e = (e << mLen) | m
eLen += mLen
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
buffer[offset + i - d] |= s * 128
}

View File

@@ -1,115 +0,0 @@
var bn = require('bn.js');
var brorand = require('brorand');
function MillerRabin(rand) {
this.rand = rand || new brorand.Rand();
}
module.exports = MillerRabin;
MillerRabin.create = function create(rand) {
return new MillerRabin(rand);
};
MillerRabin.prototype._randbelow = function _randbelow(n) {
var len = n.bitLength();
var min_bytes = Math.ceil(len / 8);
// Generage random bytes until a number less than n is found.
// This ensures that 0..n-1 have an equal probability of being selected.
do
var a = new bn(this.rand.generate(min_bytes));
while (a.cmp(n) >= 0);
return a;
};
MillerRabin.prototype._randrange = function _randrange(start, stop) {
// Generate a random number greater than or equal to start and less than stop.
var size = stop.sub(start);
return start.add(this._randbelow(size));
};
MillerRabin.prototype.test = function test(n, k, cb) {
var len = n.bitLength();
var red = bn.mont(n);
var rone = new bn(1).toRed(red);
if (!k)
k = Math.max(1, (len / 48) | 0);
// Find d and s, (n - 1) = (2 ^ s) * d;
var n1 = n.subn(1);
for (var s = 0; !n1.testn(s); s++) {}
var d = n.shrn(s);
var rn1 = n1.toRed(red);
var prime = true;
for (; k > 0; k--) {
var a = this._randrange(new bn(2), n1);
if (cb)
cb(a);
var x = a.toRed(red).redPow(d);
if (x.cmp(rone) === 0 || x.cmp(rn1) === 0)
continue;
for (var i = 1; i < s; i++) {
x = x.redSqr();
if (x.cmp(rone) === 0)
return false;
if (x.cmp(rn1) === 0)
break;
}
if (i === s)
return false;
}
return prime;
};
MillerRabin.prototype.getDivisor = function getDivisor(n, k) {
var len = n.bitLength();
var red = bn.mont(n);
var rone = new bn(1).toRed(red);
if (!k)
k = Math.max(1, (len / 48) | 0);
// Find d and s, (n - 1) = (2 ^ s) * d;
var n1 = n.subn(1);
for (var s = 0; !n1.testn(s); s++) {}
var d = n.shrn(s);
var rn1 = n1.toRed(red);
for (; k > 0; k--) {
var a = this._randrange(new bn(2), n1);
var g = n.gcd(a);
if (g.cmpn(1) !== 0)
return g;
var x = a.toRed(red).redPow(d);
if (x.cmp(rone) === 0 || x.cmp(rn1) === 0)
continue;
for (var i = 1; i < s; i++) {
x = x.redSqr();
if (x.cmp(rone) === 0)
return x.fromRed().subn(1).gcd(n);
if (x.cmp(rn1) === 0)
break;
}
if (i === s) {
x = x.redSqr();
return x.fromRed().subn(1).gcd(n);
}
}
return false;
};

View File

@@ -1,31 +0,0 @@
'use strict'
function oldBrowser() {
throw new Error('Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11')
}
var Buffer = require('safe-buffer').Buffer
module.exports = randomBytes
function randomBytes(size, cb) {
// phantomjs needs to throw
if (size > 65536) throw new Error('requested too many random bytes')
// in case browserify isn't using the Uint8Array version
var arr = [];
for (var i = 0; i < size; i++) {
arr.push(Math.ceil(Math.random() * 255))
}
var rawBytes = new Uint8Array(arr)
// XXX: phantomjs doesn't like a buffer being passed here
var bytes = Buffer.from(rawBytes.buffer)
if (typeof cb === 'function') {
return process.nextTick(function () {
cb(null, bytes)
})
}
return bytes
}

View File

@@ -1,62 +0,0 @@
/* eslint-disable node/no-deprecated-api */
var buffer = require('buffer')
var Buffer = buffer.Buffer
// alternative to using Object.keys for old browsers
function copyProps (src, dst) {
for (var key in src) {
dst[key] = src[key]
}
}
if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
module.exports = buffer
} else {
// Copy properties from require('buffer')
copyProps(buffer, exports)
exports.Buffer = SafeBuffer
}
function SafeBuffer (arg, encodingOrOffset, length) {
return Buffer(arg, encodingOrOffset, length)
}
// Copy static methods from Buffer
copyProps(Buffer, SafeBuffer)
SafeBuffer.from = function (arg, encodingOrOffset, length) {
if (typeof arg === 'number') {
throw new TypeError('Argument must not be a number')
}
return Buffer(arg, encodingOrOffset, length)
}
SafeBuffer.alloc = function (size, fill, encoding) {
if (typeof size !== 'number') {
throw new TypeError('Argument must be a number')
}
var buf = Buffer(size)
if (fill !== undefined) {
if (typeof encoding === 'string') {
buf.fill(fill, encoding)
} else {
buf.fill(fill)
}
} else {
buf.fill(0)
}
return buf
}
SafeBuffer.allocUnsafe = function (size) {
if (typeof size !== 'number') {
throw new TypeError('Argument must be a number')
}
return Buffer(size)
}
SafeBuffer.allocUnsafeSlow = function (size) {
if (typeof size !== 'number') {
throw new TypeError('Argument must be a number')
}
return buffer.SlowBuffer(size)
}

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 259 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

View File

@@ -1,28 +0,0 @@
{
"name": "ESP-Config-WeChat",
"version": "1.0.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "ESP-Config-WeChat",
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"crypto-js": "^4.0.0"
}
},
"node_modules/crypto-js": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.0.0.tgz",
"integrity": "sha512-bzHZN8Pn+gS7DQA6n+iUmBfl0hO5DJq++QP3U6uTucDtk/0iGpXd/Gg7CGR0p8tJhofJyaKoWBuJI4eAO00BBg=="
}
},
"dependencies": {
"crypto-js": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.0.0.tgz",
"integrity": "sha512-bzHZN8Pn+gS7DQA6n+iUmBfl0hO5DJq++QP3U6uTucDtk/0iGpXd/Gg7CGR0p8tJhofJyaKoWBuJI4eAO00BBg=="
}
}
}

View File

@@ -1,23 +0,0 @@
{
"name": "ESP-Config-WeChat",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/EspressifApps/ESP-Config-WeChat.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/EspressifApps/ESP-Config-WeChat/issues"
},
"homepage": "https://github.com/EspressifApps/ESP-Config-WeChat#readme",
"dependencies": {
"crypto-js": "^4.0.0"
}
}

View File

@@ -1,388 +0,0 @@
//获取应用实例
const app = getApp()
const util = require('../../utils/util.js');
const timeOut = 20;//超时时间
var timeId = "";
Page({
data: {
failure: false,
value: 0,
desc: "Device connecting...",
isChecksum: false,
isEncrypt: false,
flagEnd: false,
defaultData: 1,
ssidType: 2,
passwordType: 3,
meshIdType: 3,
deviceId: "",
ssid: "",
uuid: "",
serviceId: "",
password: "",
meshId: "",
processList: [],
result: [],
},
blueConnect: function (event) {
var self = this;
self.setProcess(0, util.descSucList[0]);
self.setProcess(10, util.descSucList[1]);
self.setProcess(20, util.descSucList[2]);
self.setProcess(35, util.descSucList[3]);
self.openNotify(self.data.deviceId, self.data.serviceId, self.data.uuid);
},
// 告知设备数据开始写入
writeDeviceStart: function (deviceId, serviceId, characteristicId, data) {
var self = this, obj = {}, frameControl = 0;
self.setProcess(40, util.descSucList[4]);
app.data.sequenceControl = parseInt(app.data.sequenceControl) + 1;
if (!util._isEmpty(data)) {
obj = util.isSubcontractor(data, self.data.isChecksum, app.data.sequenceControl, self.data.isEncrypt);
frameControl = util.getFrameCTRLValue(self.data.isEncrypt, self.data.isChecksum, util.DIRECTION_OUTPUT, false, obj.flag);
} else {
obj = util.isSubcontractor([self.data.defaultData], self.data.isChecksum, app.data.sequenceControl, true);
frameControl = util.getFrameCTRLValue(self.data.isEncrypt, self.data.isChecksum, util.DIRECTION_OUTPUT, false, obj.flag);
}
// var defaultData = util.encrypt(app.data.sequenceControl, obj.lenData, true);
var value = util.writeData(util.PACKAGE_CONTROL_VALUE, util.SUBTYPE_WIFI_MODEl, frameControl, app.data.sequenceControl, obj.len, obj.lenData);
var typedArray = new Uint8Array(value)
wx.writeBLECharacteristicValue({
deviceId: deviceId,
serviceId: serviceId,
characteristicId: characteristicId,
value: typedArray.buffer,
success: function (res) {
if (obj.flag) {
self.writeDeviceStart(deviceId, serviceId, characteristicId, obj.laveData);
} else {
self.setProcess(60, util.descSucList[5]);
self.writeRouterSsid(deviceId, serviceId, characteristicId, null);
}
},
fail: function (res) {
self.setFailProcess(true, util.descFailList[3]);
}
})
},
//写入路由ssid
writeRouterSsid: function (deviceId, serviceId, characteristicId, data) {
var self = this, obj = {}, frameControl = 0;
app.data.sequenceControl = parseInt(app.data.sequenceControl) + 1;
if (!util._isEmpty(data)) {
obj = util.isSubcontractor(data, self.data.isChecksum, app.data.sequenceControl, self.data.isEncrypt);
frameControl = util.getFrameCTRLValue(self.data.isEncrypt, self.data.isChecksum, util.DIRECTION_OUTPUT, false, obj.flag);
} else {
var ssidData = self.getCharCodeat(self.data.ssid);
obj = util.isSubcontractor(ssidData, self.data.isChecksum, app.data.sequenceControl, self.data.isEncrypt);
frameControl = util.getFrameCTRLValue(self.data.isEncrypt, self.data.isChecksum, util.DIRECTION_OUTPUT, false, obj.flag);
}
// var defaultData = util.encrypt(app.data.sequenceControl, obj.lenData, true);
var value = util.writeData(util.PACKAGE_VALUE, util.SUBTYPE_SET_SSID, frameControl, app.data.sequenceControl, obj.len, obj.lenData);
var typedArray = new Uint8Array(value)
wx.writeBLECharacteristicValue({
deviceId: deviceId,
serviceId: serviceId,
characteristicId: characteristicId,
value: typedArray.buffer,
success: function (res) {
if (obj.flag) {
self.writeRouterSsid(deviceId, serviceId, characteristicId, obj.laveData);
} else {
self.writeDevicePwd(deviceId, serviceId, characteristicId, null);
}
},
fail: function (res) {
self.setFailProcess(true, util.descFailList[4]);
}
})
},
//写入路由密码
writeDevicePwd: function (deviceId, serviceId, characteristicId, data) {
var self = this, obj = {}, frameControl = 0;
app.data.sequenceControl = parseInt(app.data.sequenceControl) + 1;
if (!util._isEmpty(data)) {
obj = util.isSubcontractor(data, self.data.isChecksum, app.data.sequenceControl, self.data.isEncrypt);
frameControl = util.getFrameCTRLValue(self.data.isEncrypt, self.data.isChecksum, util.DIRECTION_OUTPUT, false, obj.flag);
} else {
var pwdData = self.getCharCodeat(self.data.password);
obj = util.isSubcontractor(pwdData, self.data.isChecksum, app.data.sequenceControl, self.data.isEncrypt);
frameControl = util.getFrameCTRLValue(self.data.isEncrypt, self.data.isChecksum, util.DIRECTION_OUTPUT, false, obj.flag);
}
// var defaultData = util.encrypt(app.data.sequenceControl, obj.lenData, true);
var value = util.writeData(util.PACKAGE_VALUE, util.SUBTYPE_SET_PWD, frameControl, app.data.sequenceControl, obj.len, obj.lenData);
var typedArray = new Uint8Array(value)
wx.writeBLECharacteristicValue({
deviceId: deviceId,
serviceId: serviceId,
characteristicId: characteristicId,
value: typedArray.buffer,
success: function (res) {
if (obj.flag) {
self.writeDevicePwd(deviceId, serviceId, characteristicId, obj.laveData);
} else {
self.writeDeviceEnd(deviceId, serviceId, characteristicId);
}
},
fail: function (res) {
self.setFailProcess(true, util.descFailList[4]);
}
})
},
//告知设备写入结束
writeDeviceEnd: function (deviceId, serviceId, characteristicId) {
var self = this;
app.data.sequenceControl = parseInt(app.data.sequenceControl) + 1;
var frameControl = util.getFrameCTRLValue(self.data.isEncrypt, false, util.DIRECTION_OUTPUT, false, false);
var value = util.writeData(self.data.PACKAGE_CONTROL_VALUE, util.SUBTYPE_END, frameControl, app.data.sequenceControl, 0, null);
var typedArray = new Uint8Array(value)
wx.writeBLECharacteristicValue({
deviceId: deviceId,
serviceId: serviceId,
characteristicId: characteristicId,
value: typedArray.buffer,
success: function (res) {
self.onTimeout(0);
},
fail: function (res) {
self.setFailProcess(true, util.descFailList[4]);
}
})
},
//连接超时
onTimeout: function(num) {
const self = this;
timeId = setInterval(function() {
if (num < timeOut) {
num++;
} else {
clearInterval(timeId);
self.setFailProcess(true, util.descFailList[4]);
}
}, 1000)
},
//监听通知
onNotify: function () {
var self = this;
wx.onBLECharacteristicValueChange(function (res) {
self.getResultType(util.ab2hex(res.value));
})
},
//启用通知
openNotify: function (deviceId, serviceId, characteristicId) {
var self = this;
wx.notifyBLECharacteristicValueChange({
state: true, // 启用 notify 功能
deviceId: deviceId,
serviceId: serviceId,
characteristicId: app.data.characteristic_read_uuid,
success: function (res) {
self.writeDeviceStart(deviceId, serviceId, characteristicId);
self.onNotify();
},
fail: function (res) {
}
})
},
getSsids: function (str) {
var list = [],
strs = str.split(":");
for (var i = 0; i < strs.length; i++) {
list.push(parseInt(strs[i], 16));
}
return list;
},
getCharCodeat: function (str) {
var list = [];
for (var i = 0; i < str.length; i++) {
list.push(str.charCodeAt(i));
}
return list;
},
setProcess: function(value, desc) {
var self = this, list = [];
list = self.data.processList;
list.push(desc);
self.setData({
value: value,
processList: list
});
if (value == 100) {
self.closeConnect();
self.setData({
desc: util.descSucList[6]
});
clearInterval(timeId);
app.data.sequenceControl = 0;
setTimeout(function () {
wx.reLaunch({
url: '/pages/index/index'
})
}, 3000)
}
},
setFailProcess: function (flag, desc) {
var self = this, list = [];
list = self.data.processList;
list.push(desc);
self.setFailBg();
self.setData({
failure: flag,
processList: list
});
},
getResultType: function(list) {
var self = this;
var result = self.data.result;
console.log(list)
if (list.length < 4) {
self.setFailProcess(true, util.descFailList[4]);
return false;
}
var val = parseInt(list[0], 16),
type = val & 3,
subType = val >> 2;
console.log(type, subType, self.data.flagEnd)
if (type != parseInt(util.PACKAGE_VALUE)) {
self.setFailProcess(true, util.descFailList[4]);
return false;
}
var sequenceNum = parseInt(list[2], 16);
if (sequenceNum - app.data.sequenceNumber != 1) {
self.setFailProcess(true, util.descFailList[4]);
return false;
}
app.data.sequenceNumber = sequenceNum;
if (app.data.sequenceNumber == 255) {
app.data.sequenceNumber = -1
}
var dataLength = parseInt(list[3], 16);
if (dataLength == 0) {
self.setFailProcess(true, util.descFailList[4]);
return false;
}
var fragNum = util.hexToBinArray(list[1]);
list = util.isEncrypt(self, fragNum, list);
result = result.concat(list);
self.setData({
result: result,
})
if (self.data.flagEnd) {
self.setData({
flagEnd: false,
})
if (type == 1) {
if (subType == 15) {
for (var i = 0; i <= result.length; i++) {
var num = parseInt(result[i], 16) + "";
if (i == 0) {
self.setProcess(85, "Connected: " + util.successList[num]);
} else if (i == 1) {
if (num == 0) {
self.setProcess(100, util.descSucList[6]);
}
}
}
} else if (subType == 18) {
for (var i = 0; i <= result.length; i++) {
var num = parseInt(result[i], 16) + "";
if (i == 0) {
self.setProcess(85, util.successList[num]);
} else if (i == 1) {
self.setFailProcess(true, util.failList[num]);
}
}
} else {
self.setFailProcess(true, util.descFailList[4])
}
} else {
self.setFailProcess(true, util.descFailList[4])
}
}
},
closeConnect: function () {
var self = this;
wx.closeBLEConnection({
deviceId: self.data.deviceId,
success: function (res) {
}
})
wx.closeBluetoothAdapter({
success: function() {
}
});
},
//设置配网失败背景色
setFailBg: function() {
wx.setNavigationBarColor({
frontColor: "#ffffff",
backgroundColor: '#737d89',
})
},
//设置配网成功背景色
setSucBg: function() {
wx.setNavigationBarColor({
frontColor: "#ffffff",
backgroundColor: '#4d9efb',
})
},
onLoad: function (options) {
var self = this;
self.setSucBg();
wx.setNavigationBarTitle({
title: '配网'
});
self.setData({
deviceId: options.deviceId,
ssid: unescape(options.ssid),
password: unescape(options.password),
meshId: options.bssid,
uuid: options.uuid,
serviceId: options.serviceId,
})
self.blueConnect();
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
})

View File

@@ -1,29 +0,0 @@
<!--pages/blueConnect/blueConnect.wxml-->
<view class="container">
<block wx:if="{{!failure}}">
<view class="schedule">
<view class="schedule-result schedule-success">
<image class='schedule-img' mode='aspectFit' src='../../images/round.gif'></image>
<view class="desc-wrapper">
<view class="text-value"><text>{{value}}</text><text class="text-samll">%</text></view>
<view class="text-desc">{{desc}}</view>
</view>
</view>
</view>
</block>
<block wx:else>
<view class="schedule fail">
<view class="schedule-result schedule-fail">
<image class='schedule-img' mode='aspectFit' src='../../images/failure.png'></image>
<view class="desc-wrapper">
<view class="text-sigh"><text>!</text></view>
<view class="text-desc">{{desc}}</view>
</view>
</view>
</view>
</block>
<view class="process-wrapper">
<text class="text-process" wx:for="{{processList}}" wx:key="*this">{{item}}</text>
<text>{{vConsoleV}}</text>
</view>
</view>

View File

@@ -1,68 +0,0 @@
/* pages/blueConnect/blueConnect.wxss */
.container {
padding: 0;
}
.schedule {
background: #4d9efb;
height: 46vh;
width: 100%;
padding: 50rpx;
}
.schedule-result {
position: relative;
display: flex;
justify-content: center;
align-items: center;
border-radius: 100%;
background: transparent;
height: 55vw;
width: 55vw;
margin: 0 auto;
color: #fff;
}
.schedule-img {
height: 55vw;
width: 55vw;
}
.fail{
background: #737d89;
}
.desc-wrapper {
position: absolute;
}
.text-value {
text-align: center;
font-size: 20px;
}
.text-desc {
font-size: 14px;
}
.text-samll {
font-size: 16px;
}
.text-sigh {
height: 80rpx;
width: 80rpx;
background: #fff;
border-radius: 100%;
display: flex;
justify-content: center;
align-items: center;
font-size: 20px;
font-weight: bold;
color: #737d89;
margin: 0 auto 10px;
}
.process-wrapper {
display: flex;
flex-direction: column;
width: 100%;
text-align: left;
margin-top: 20px;
padding-left: 30px;
font-size: 14px;
color: #999;
}
.text-process {
margin: 3px 0;
}

View File

@@ -1,105 +0,0 @@
//获取应用实例
const app = getApp();
const util = require('../../utils/util.js');
Page({
data: {
deviceList: [],
deviceId: "",
},
bindViewConnect: function (event) {
var self = this,
deviceId = event.currentTarget.dataset.value;
self.setData({
deviceId: deviceId
});
wx.navigateTo({
url: '/pages/blueWifi/blueWifi?deviceId=' + deviceId,
})
},
getBluDevice: function () {
var self = this;
wx.getBluetoothDevices({
success: function (res) {
var list = util.filterDevice(res.devices, "name");
if (list.length > 0) {
wx.hideLoading();
}
self.setData({
deviceList: list
})
}
})
wx.onBluetoothDeviceFound(function (res) {
console.log(res.devices[0].name);
var list = util.filterDevice(res.devices, "name");
if (list.length > 0) {
wx.hideLoading();
}
self.setData({
deviceList: self.data.deviceList.concat(list)
})
})
},
onLoad: function () {
var self = this;
wx.setNavigationBarTitle({
title: 'BluFi扫描'
});
wx.showLoading({
title: '设备扫描中...',
})
self.getBluDevice();
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
var self = this,
deviceId = self.data.deviceId;
if (!util._isEmpty(deviceId)) {
wx.closeBLEConnection({
deviceId: deviceId,
})
}
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
})

View File

@@ -1,13 +0,0 @@
<!--index.wxml-->
<view class="container">
<view data-value="{{item.deviceId}}" bindtap="bindViewConnect" wx:for="{{deviceList}}" class="item" wx:key="*this">
<view class="item-img">
<image class='bluetooth-img' mode='aspectFit' src='../../images/bluetooth.png'></image>
</view>
<view class="item-name">
<text class="text-name">{{item.name}}</text>
<text class="text-rssi">Rssi: {{item.RSSI}}</text>
<text class="text-rssi">deviceId: {{item.deviceId}}</text>
</view>
</view>
</view>

View File

@@ -1,11 +0,0 @@
/* pages/blueDevices/blueDevices.wxss */
.prompt-title {
height: 50rpx;
border-top: 1px solid #999;
border-bottom: 1px solid #999;
width: 100%;
}
.item {
height: auto;
padding: 8rpx 0;
}

View File

@@ -1,476 +0,0 @@
// pages/blueWifi/blueWifi.js
//获取应用实例
const app = getApp();
const util = require('../../utils/util.js');
const crypto = require('../../crypto/crypto-dh.js');
const md5 = require('../../crypto/md5.min.js');
var client = "";
Page({
/**
* 页面的初始数据
*/
data: {
deviceId: "",
wifiList: [],
hiddenModal: true,
blueConnectNum: 0,
frag: 16,
flag: false,
flagEnd: false,
fragList: [],
frameControl: 0,
ssid: "",
bssid: "",
serviceId: "",
uuid: "",
password: "",
},
bindViewWifi: function(event) {
var self = this,
ssid = event.currentTarget.dataset.ssid,
bssid = event.currentTarget.dataset.bssid;
self.setData({
hiddenModal: false,
ssid: ssid,
bssid: bssid,
password: ""
})
},
bindViewConfirm: function() {
var self = this;
wx.navigateTo({
url: '/pages/blueConnect/blueConnect?deviceId=' + self.data.deviceId + "&ssid=" + escape(self.data.ssid) + "&bssid=" + self.data.bssid + "&password=" + escape(self.data.password) + "&serviceId=" + self.data.serviceId + "&uuid=" + self.data.uuid,
})
this.setData({
hiddenModal: true,
})
},
bindViewCancel: function(){
this.setData({
hiddenModal: true,
ssid: "",
bssid: "",
password: ""
})
},
bindViewInput: function (e) {
this.setData({ password: e.detail.value })
},
blueConnect: function (event) {
var self = this;
app.data.sequenceControl = -1;
app.data.sequenceNumber = -1;
self.setData({
fragList: [],
wifiList: [],
flagEnd: false,
serviceId: "",
uuid: ""
});
wx.createBLEConnection({
deviceId: self.data.deviceId,
timeout: 10000,
success: function (res) {
console.info("app.data.platform", app.data.platform)
if (app.data.platform == 'android') {
app.data.mtu = app.data.constMtu;
wx.setBLEMTU({
deviceId: self.data.deviceId,
mtu: app.data.constMtu,
success (res) {
console.info('setBLEMTU-suc', res)
},
fail (res) {
console.info('setBLEMTU-fail', res)
}
})
}
self.getDeviceServices(self.data.deviceId);
},
fail: function (res) {
var num = self.data.blueConnectNum;
if (num < 3) {
self.blueConnect();
num++;
self.setData({
blueConnectNum: num
})
} else {
self.showFailToast();
}
}
})
},
getDeviceServices: function (deviceId) {
var self = this;
wx.getBLEDeviceServices({
deviceId: deviceId,
success: function (res) {
var services = res.services;
if (services.length > 0) {
for (var i = 0; i < services.length; i++) {
var uuid = services[i].uuid;
if (uuid == app.data.service_uuid) {
self.getDeviceCharacteristics(deviceId, uuid);
return false;
}
}
}
},
fail: function (res) {
self.showFailToast();
}
})
},
getDeviceCharacteristics: function (deviceId, serviceId) {
var self = this;
wx.getBLEDeviceCharacteristics({
deviceId: deviceId,
serviceId: serviceId,
success: function (res) {
var list = res.characteristics;
if (list.length > 0) {
for (var i = 0; i < list.length; i++) {
var uuid = list[i].uuid;
if (uuid == app.data.characteristic_write_uuid) {
self.openNotify(deviceId, serviceId, uuid);
self.setData({
serviceId: serviceId,
uuid: uuid,
})
return false;
}
}
}
},
fail: function (res) {
self.showFailToast();
}
})
},
//通知设备交互方式(是否加密)
notifyDevice: function (deviceId, serviceId, characteristicId) {
var self = this;
client = util.blueDH(util.DH_P, util.DH_G, crypto);
var kBytes = util.uint8ArrayToArray(client.getPublicKey());
var pBytes = util.hexByInt(util.DH_P);
var gBytes = util.hexByInt(util.DH_G);
var pgkLength = pBytes.length + gBytes.length + kBytes.length + 6;
var pgkLen1 = (pgkLength >> 8) & 0xff;
var pgkLen2 = pgkLength & 0xff;
var data = [];
data.push(util.NEG_SET_SEC_TOTAL_LEN);
data.push(pgkLen1);
data.push(pgkLen2);
var frameControl = util.getFrameCTRLValue(false, false, util.DIRECTION_OUTPUT, false, false);
var value = util.writeData(util.PACKAGE_VALUE, util.SUBTYPE_NEG, frameControl, app.data.sequenceControl, data.length, data);
var typedArray = new Uint8Array(value);
console.log("notifyDevice:", value)
wx.writeBLECharacteristicValue({
deviceId: deviceId,
serviceId: serviceId,
characteristicId: characteristicId,
value: typedArray.buffer,
success: function (res) {
console.log("notifyDevice-suc:", res)
self.getSecret(deviceId, serviceId, characteristicId, client, kBytes, pBytes, gBytes, null);
},
fail: function (res) {
console.log("notifyDevice-fail:", res)
self.showFailToast();
}
})
},
getSecret: function (deviceId, serviceId, characteristicId, client, kBytes, pBytes, gBytes, data) {
var self = this, obj = {}, frameControl = 0;
app.data.sequenceControl = parseInt(app.data.sequenceControl) + 1;
const encrypt = false
const checksum = false
if (!util._isEmpty(data)) {
obj = util.isSubcontractor(data, checksum, app.data.sequenceControl);
frameControl = util.getFrameCTRLValue(encrypt, checksum, util.DIRECTION_OUTPUT, false, obj.flag);
} else {
data = [];
data.push(util.NEG_SET_SEC_ALL_DATA);
var pLength = pBytes.length;
var pLen1 = (pLength >> 8) & 0xff;
var pLen2 = pLength & 0xff;
data.push(pLen1);
data.push(pLen2);
data = data.concat(pBytes);
var gLength = gBytes.length;
var gLen1 = (gLength >> 8) & 0xff;
var gLen2 = gLength & 0xff;
data.push(gLen1);
data.push(gLen2);
data = data.concat(gBytes);
var kLength = kBytes.length;
var kLen1 = (kLength >> 8) & 0xff;
var kLen2 = kLength & 0xff;
data.push(kLen1);
data.push(kLen2);
data = data.concat(kBytes);
obj = util.isSubcontractor(data, checksum, app.data.sequenceControl);
frameControl = util.getFrameCTRLValue(encrypt, checksum, util.DIRECTION_OUTPUT, false, obj.flag);
}
var value = util.writeData(util.PACKAGE_VALUE, util.SUBTYPE_NEG, frameControl, app.data.sequenceControl, obj.len, obj.lenData);
var typedArray = new Uint8Array(value);
wx.writeBLECharacteristicValue({
deviceId: deviceId,
serviceId: serviceId,
characteristicId: characteristicId,
value: typedArray.buffer,
success: function (res) {
console.log('getSecret-suc', res)
if (obj.flag) {
self.getSecret(deviceId, serviceId, characteristicId, client, kBytes, pBytes, gBytes, obj.laveData);
} else {
// setTimeout(function(){
// self.getWifiList(deviceId, serviceId, characteristicId);
// }, 3000)
self.setSecret(deviceId, serviceId, characteristicId);
}
},
fail: function (res) {
console.log('getSecret-error', res)
self.showFailToast();
}
})
},
setSecret (deviceId, serviceId, characteristicId) {
const self = this;
let value = 0;
// value |= 1; // 数据包校验
// value |= 0b10; //数据包加密
let data = [value]
app.data.sequenceControl = parseInt(app.data.sequenceControl) + 1;
let frameControl = util.getFrameCTRLValue(false, false, util.DIRECTION_OUTPUT, false, false);
value = util.writeData(util.PACKAGE_CONTROL_VALUE, util.SUBTYPE_SET_SEC_MODE, frameControl, app.data.sequenceControl, data.length, data);
var typedArray = new Uint8Array(value);
wx.writeBLECharacteristicValue({
deviceId: deviceId,
serviceId: serviceId,
characteristicId: characteristicId,
value: typedArray.buffer,
success: function (res) {
setTimeout(function(){
self.getWifiList(deviceId, serviceId, characteristicId);
}, 3000)
},
fail: function (res) {
self.showFailToast();
}
})
},
getWifiList: function (deviceId, serviceId, characteristicId) {
var self = this;
var frameControl = util.getFrameCTRLValue(false, false, util.DIRECTION_OUTPUT, false, false);
app.data.sequenceControl = parseInt(app.data.sequenceControl) + 1;
var value = util.writeData(util.PACKAGE_CONTROL_VALUE, util.SUBTYPE_WIFI_NEG, frameControl, app.data.sequenceControl, 0, null);
var typedArray = new Uint8Array(value);
wx.writeBLECharacteristicValue({
deviceId: deviceId,
serviceId: serviceId,
characteristicId: characteristicId,
value: typedArray.buffer,
success: function (res) {
},
fail: function (res) {
self.showFailToast();
}
})
},
// 监听特征值变化
onNotify: function () {
var self = this;
wx.onBLECharacteristicValueChange(function (res) {
self.analysisWifi(util.ab2hex(res.value));
})
},
// 启用特征值变化
openNotify: function (deviceId, serviceId, characteristicId) {
var self = this;
wx.notifyBLECharacteristicValueChange({
state: true, // 启用 notify 功能
deviceId: deviceId,
serviceId: serviceId,
characteristicId: app.data.characteristic_read_uuid,
success: function (res) {
//通知设备交互方式(是否加密)
// self.notifyDevice(deviceId, serviceId, characteristicId);
self.onNotify();
self.getWifiList(deviceId, serviceId, characteristicId);
},
fail: function (res) {
self.showFailToast();
}
})
},
analysisWifi: function (list) {
const self = this;
var fragList = self.data.fragList;
if (list.length < 4) {
return false;
}
var val = list[0],
type = val & 3,
subType = val >> 2;
if (type != parseInt(util.PACKAGE_VALUE)) {
wx.hideLoading();
return false;
}
var sequenceNum = parseInt(list[2], 16);
if (sequenceNum - app.data.sequenceNumber != 1) {
wx.hideLoading();
return false;
}
app.data.sequenceNumber = sequenceNum;
if (app.data.sequenceNumber == 255) {
app.data.sequenceNumber = -1
}
var dataLength = parseInt(list[3], 16);
if (dataLength == 0) {
wx.hideLoading();
return false;
}
console.log('fragNum', list)
var fragNum = util.hexToBinArray(list[1]);
list = util.isEncrypt(self, fragNum, list);
fragList = fragList.concat(list);
self.setData({
fragList: fragList,
})
if (self.data.flagEnd) {
if (subType == util.SUBTYPE_WIFI_LIST_NEG) {
self.getList(fragList, fragList.length, 0);
wx.hideLoading();
} else if (subType == util.SUBTYPE_NEGOTIATION_NEG) {
var arr = util.hexByInt(fragList.join(""));
var clientSecret = client.computeSecret(new Uint8Array(arr));
var md5Key = md5.array(clientSecret);
app.data.md5Key = md5Key;
self.setData({
fragList: [],
})
} else {
wx.hideLoading();
}
self.setData({
flagEnd: false,
})
}
},
getList: function (arr, totalLength, curLength) {
var self = this;
if (arr.length > 0) {
var len = parseInt(arr[0], 16);
curLength += (1 + len);
if (len > 0 && curLength < totalLength) {
var rssi = 0, name = "";
let list = []
for (var i = 1; i <= len; i++) {
if (i == 1) {
rssi = parseInt(arr[i], 16);
} else {
list.push(parseInt(arr[i], 16))
}
}
name = decodeURIComponent(encodeURIComponent(String.fromCharCode(...list)))
var wifiList = self.data.wifiList;
wifiList.push({ "rssi": rssi, "SSID": name });
self.setData({
wifiList: wifiList.sort(util.sortBy("rssi", false))
})
arr = arr.splice(len + 1);
this.getList(arr, totalLength, curLength);
}
}
},
showFailToast: function() {
wx.hideLoading();
wx.showToast({
title: 'WiFi信息获取失败',
icon: 'none',
duration: 2000
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var self = this;
wx.setNavigationBarTitle({
title: '选择WiFi'
});
self.setData({
deviceId: options.deviceId,
})
wx.showLoading({
title: 'WiFi获取中...',
})
wx.stopBluetoothDevicesDiscovery({
success: function (res) {
}
})
self.blueConnect();
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
var self = this;
self.setData({
wifiList: [],
fragList: []
});
self.getWifiList(self.data.deviceId, self.data.serviceId, self.data.uuid);
setTimeout(function () {
wx.stopPullDownRefresh();
}, 6000);
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})

View File

@@ -1,4 +0,0 @@
{
"backgroundTextStyle": "dark",
"enablePullDownRefresh": true
}

View File

@@ -1,19 +0,0 @@
<view class="container">
<view data-bssid="" data-ssid="{{item.SSID}}" bindtap="bindViewWifi" wx:for="{{wifiList}}" class="item" wx:key="*this">
<view class="item-name">
<text class="text-name">{{item.SSID}}</text>
</view>
<view class="item-icon">
<image class='wifi-img' mode='aspectFit' src='../../images/wifi.png'></image>
</view>
</view>
<view class='modal-mask' hidden="{{hiddenModal}}"></view>
<view class='modal-dialog' hidden="{{hiddenModal}}">
<view class='modal-title'>{{ssid}}</view>
<input type='text' password='true' bindinput='bindViewInput' placeholder="请输入密码"/>
<view class='modal-btn-wrapper'>
<view class='cancel-btn' style='color:rgba(7,17,27,0.6)' bindtap='bindViewCancel'>取消</view>
<view class='confirm-btn' style='color:#4d9efb' bindtap='bindViewConfirm'>开始配网</view>
</view>
</view>
</view>

View File

@@ -1,12 +0,0 @@
/* pages/blueWifi/blueWifi.wxss */
.item-icon {
flex: 0 0 80rpx;
height: 100%;
display: flex;
justify-items: center;
align-items: center;
}
.wifi-img {
width: 60rpx;
height: 60rpx;
}

View File

@@ -1,57 +0,0 @@
//index.js
//获取应用实例
const app = getApp();
const util = require('../../utils/util.js');
Page({
data: {
},
//事件处理函数
bindViewBlue: function() {
wx.closeBluetoothAdapter({
success: function () {
}
});
wx.openBluetoothAdapter({
success: function (res) {
wx.startBluetoothDevicesDiscovery({
success: function (res) {
wx.navigateTo({
url: '/pages/blueDevices/blueDevices',
})
}
})
},
fail: function (res) {
wx.showToast({
title: '请打开蓝牙',
icon: 'none',
duration: 2000
})
}
})
},
bindViewWifi: function () {
wx.navigateTo({
url: '/pages/wifiDevices/wifiDevices',
})
},
onLoad: function () {
wx.setNavigationBarTitle({
title: '配网方式'
})
wx.getSystemInfo({
success (res) {
try {
app.data.platform = res.platform.toLocaleLowerCase()
} catch(e) {
console.log(e)
}
}
})
},
getUserInfo: function(e) {
}
})

View File

@@ -1,19 +0,0 @@
<!--index.wxml-->
<view class="container">
<view class='header-wrapper'>
<image class="header-image" src="../../images/network.png"></image>
</view>
<view class='content-wrapper'>
<view class="title">配网方式</view>
<view class="btn-info">
<view bindtap="bindViewBlue" class="select-way">
<image class="btn-image" src="../../images/bluetooth-way.png"></image>
<text class="name">BluFi 配网</text>
</view>
<!-- <view bindtap="bindViewWifi" class="select-way">
<image class="btn-image" src="../../images/wifi-way.png"></image>
<text class="name">WiFi配网</text>
</view> -->
</view>
</view>
</view>

View File

@@ -1,60 +0,0 @@
.container {
display: block;
padding: 0;
height: 100vh;
background: #eee;
}
.header-wrapper {
display: flex;
justify-content: center;
align-items: center;
height: 45vh;
width: 100%;
background: #4d9efb;
border-bottom-right-radius: 40px;
border-bottom-left-radius: 40px;
}
.header-image {
width: 29vh;
height: 29vh;
position: relative;
top: -5vh;
}
.content-wrapper {
position: absolute;
top: 38vh;
left: 15px;
height: 50vh;
width: calc(100% - 30px);
padding: 20px;
box-sizing: border-box;
background: #fff;
border-radius: 10px;
box-shadow: 0px 0px 3px #fff;
color: #818181;
}
.title {
margin: 10px 0;
text-align: center;
font-size: 16px;
}
.btn-info {
display: flex;
margin-top: 10vh;
}
.btn-image {
width: 50px;
height: 50px;
}
.select-way {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.name {
margin: 10px 0;
font-size: 14px;
}

View File

@@ -1,72 +0,0 @@
// pages/wifiConfig/wifiConfig.js
Page({
/**
* 页面的初始数据
*/
data: {
},
next: function () {
wx.navigateTo({
url: "/pages/wifiList/wifiList"
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
wx.setNavigationBarTitle({
title: 'WiFi配网'
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})

View File

@@ -1,20 +0,0 @@
<!--pages/wifi3/wifi3.wxml-->
<view class='container'>
<view class='textcenter'>
<view><text class='font14'>第二步</text></view>
<view class="margintop10"><text class='font16'>将手机连接设备,请前往手机设置,进入无线局域网</text></view>
</view>
<!-- wifi -->
<view>
<image class="wifi-img" src="../../images/wifi.jpg"></image>
</view>
<view class="width100 margintop20">
<button class="btn" bindtap='setWifi'>去设置 </button>
</view>
<view class="width100" bindtap='next'>
<button class="btn" > 下一步 </button>
</view>
</view>

View File

@@ -1,9 +0,0 @@
/* pages/wifiConfig/wifiConfig.wxss */
.container{
padding-top: 50rpx;
}
.wifi-img {
width:300px;
height:234px;
margin-top:20px;
}

View File

@@ -1,166 +0,0 @@
// pages/wifiConnect/wifiConnect.js
Page({
/**
* 页面的初始数据
*/
data: {
failStatus: false,
sucStatus: false,
progress: 0,
},
getStatus: function() {
var self = this;
wx.request({
url: 'https://www.alavening.com/wifi/connstatus.cgi',
data: {
},
header: {
'content-type': 'application/json' // 默认值
},
success: function (res) {
console.log(res.data);
var data = res.data;
console.log(data.status);
if (data.status == "success") {
self.setData({
progress: 100,
failStatus: false,
sucStatus: true,
})
self.setResult("success");
} else if (data.status == "fail") {
self.setData({
failStatus: true,
sucStatus: false,
})
self.setResult("fail");
} else {
if (self.data.progress <= 90) {
self.setData({
progress: (self.data.progress + 5),
failStatus: false,
sucStatus: false,
})
}
self.getStatus();
}
},
fail: function (res) {
self.setData({
failStatus: true,
sucStatus: false,
})
}
})
},
setResult: function(result) {
var self = this;
wx.request({
url: 'https://www.alavening.com/wifi/configsuccess.cgi',
method: "post",
data: {
configstatus: result
},
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: function (res) {
},
fail: function () {
}
})
},
setConnect: function(ssid, password) {
var self = this;
wx.request({
url: 'https://alavening.com/wifi/connect.cgi',
method: "post",
data: {
essid: ssid,
password: password
},
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: function (res) {
},
fail: function () {
}
})
self.getStatus();
},
successwifi: function() {
wx.reLaunch({
url: '/pages/index/index'
})
},
failwifi: function() {
wx.navigateBack({
delta: 2
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var self = this;
wx.setNavigationBarTitle({
title: 'WiFi配网'
});
self.setConnect(options.ssid, options.password);
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})

Some files were not shown because too many files have changed in this diff Show More