Bläddra i källkod

添加配网功能

wzh 2 år sedan
förälder
incheckning
cb50f168bd
3 ändrade filer med 935 tillägg och 96 borttagningar
  1. 9 16
      pages.json
  2. 781 0
      pages/bluetooth/index/wifi.vue
  3. 145 80
      utils/weitiandi/device/device.js

+ 9 - 16
pages.json

@@ -174,22 +174,15 @@
             }
             
         }
-    ],
-  "tabBar": {
-    "color": "#000000",
-    "selectedColor": "#000000",
-    "borderStyle": "white",
-    "backgroundColor": "#ffffff",
-    "list": [{
-        "pagePath": "pages/index",
-        "iconPath": "static/images/icons/menu-off.png",
-        "selectedIconPath": "static/images/icons/menu-on.png",
-        "text": "%index%"
-      }, {
-        "pagePath": "pages/mine/index",
-        "iconPath": "static/images/icons/mine-off.png",
-        "selectedIconPath": "static/images/icons/mine-on.png",
-        "text": "%mine%"
+        ,{
+            "path" : "pages/bluetooth/index/wifi",
+            "style" :
+            {
+                "navigationBarTitleText": "",
+                "enablePullDownRefresh": false,
+              "navigationStyle": "default"
+            }
+
       }
     ]
   },

+ 781 - 0
pages/bluetooth/index/wifi.vue

@@ -0,0 +1,781 @@
+<template>
+  <view style="height: 100vh">
+    <view v-if="!connected">
+      <scroll-view class="main-container" scroll-y="true"
+                   :refresher-enabled="false">
+        <view v-for="(item, index) in deviceListDataShow" :key="item.id" class="list-item" hover-class="list-item-hover"
+              hover-start-time="0" hover-stay-time="100" @click="listViewTap(item.id)">
+          <image v-if="item.manufacturer==='eciot'" src="/static/img/ecble.png" class="list-item-img"></image>
+          <image v-else src="/static/img/ble.png" class="list-item-img"></image>
+          <text class="list-item-name">{{item.name}}</text>
+          <image v-if="item.rssi >= -41" src="/static/img/s5.png" mode="aspectFit" class="list-item-rssi-img"></image>
+          <image v-else-if="item.rssi >= -55" src="/static/img/s4.png" mode="aspectFit" class="list-item-rssi-img"></image>
+          <image v-else-if="item.rssi >= -65" src="/static/img/s3.png" mode="aspectFit" class="list-item-rssi-img"></image>
+          <image v-else-if="item.rssi >= -75" src="/static/img/s2.png" mode="aspectFit" class="list-item-rssi-img"></image>
+          <image v-else="item.rssi < -75" src="/static/img/s1.png" mode="aspectFit" class="list-item-rssi-img"></image>
+          <text class="list-item-rssi">{{item.rssi}}</text>
+          <view class="list-item-line"></view>
+        </view>
+        <u-popup :show="showSendData"  >
+          <view class="slot-content">
+            <view>
+              <u--input
+                  :placeholder="i18('请输入值')"
+                  border="surround"
+                  v-model="sendData"
+              ></u--input>
+            </view>
+            <view style="margin:10px;text-decoration: underline;margin-bottom: 0px" @click="sendLanyaData">
+              <u-button>发送</u-button>
+            </view>
+          </view>
+        </u-popup>
+        <view v-if="deviceListDataShow.length==0" class="notice"> - {{ $t('buletooth.nodevice') }} -</view>
+        <view class="gap"></view>
+      </scroll-view>
+    </view>
+
+    <view v-if="connected">
+      <view class="text-area">
+        <u--form  v-if="isCompanyUser()" style="width: 100%;"
+                  labelPosition="left"
+                  ref="uForm"
+        >
+          <u-form-item
+              label="WIFI名称:"
+              borderBottom
+              labelWidth="auto"
+              @click="openChooseWifi"
+              ref="item1"
+          >
+            <u--input
+                v-model="SSID"
+                disabled
+                disabledColor="#ffffff"
+                placeholder="请选择wifi:"
+                border="none"
+            ></u--input>
+            <u-icon
+                slot="right"
+                name="arrow-right"
+            ></u-icon>
+          </u-form-item>
+          <u-form-item
+              label="密码:"
+              borderBottom
+              ref="item1"
+          >
+            <u--input
+                v-model="password"
+                border="none"
+            ></u--input>
+          </u-form-item>
+
+        </u--form>
+        <u--form  v-else style="width: 100%;"
+                  labelPosition="left"
+                  ref="uForm"
+        >
+          <u-form-item
+              label="WIFI名称:"
+              borderBottom
+              labelWidth="auto"
+              @click="openChooseWifi"
+              ref="item1"
+          >
+            <u--input
+                v-model="SSID"
+                disabled
+                disabledColor="#ffffff"
+                placeholder="请选择wifi:"
+                border="none"
+            ></u--input>
+            <u-icon
+                slot="right"
+                name="arrow-right"
+            ></u-icon>
+          </u-form-item>
+          <u-form-item
+              label="密码:"
+              borderBottom
+              ref="item1"
+          >
+            <u--input
+                v-model="password"
+                border="none"
+            ></u--input>
+          </u-form-item>
+
+
+          <u-form-item
+              label="二维码ID:"
+              borderBottom
+              ref="item1"
+              labelWidth="auto"
+          >
+            <u--input
+                v-model="qrcodeid"
+                border="none"
+            ></u--input>
+          </u-form-item>
+
+          <u-form-item
+              @click="showProductList = true"
+              label="产品类型:"
+              borderBottom
+              ref="item1"
+              labelWidth="auto"
+          >
+            <u--input disabled
+                      v-model="productName"
+                      border="none"
+            ></u--input>
+          </u-form-item>
+
+        </u--form>
+      </view>
+      <view style="margin:10px">
+        <u-button text="开始配网" v-if="isCompanyUser()" @click="doConnectUser(1)" size="small" type="primary"></u-button>
+
+        <u-button text="开始配网" v-else @click="doConnect(2)" size="small" type="primary"></u-button>
+
+      </view>
+      <u-picker @cancel="showWiftList=false" @confirm="chooseWifi"  :show="showWiftList" :columns="wifiList"></u-picker>
+
+      <u-picker @cancel="showProductList=false" keyName="text" @confirm="chooseProduct"  :show="showProductList" :columns="chooseProductList"></u-picker>
+
+    </view>
+  </view>
+</template>
+
+<script>
+// #ifdef APP
+import ecUI from '@/utils/ecUI.js'
+import ecBLE from '@/utils/ecBLE/ecBLE.js'
+// #endif
+// #ifdef MP
+const ecUI = require('@/utils/ecUI.js')
+const ecBLE = require('@/utils/ecBLE/ecBLE.js')
+// #endif
+import i18 from '@/utils/i18.js'
+import {getDevcieByQrcodeID} from "@/api/device/device";
+import {sendWifi,sendPwd,sendEnd} from "@/utils/weitiandi/device/device.js";
+
+let ctx
+let deviceListData = []
+export default {
+  data() {
+    return {
+      showProductList:false,
+      showPwd:false,
+      rightPwd:"",
+      pwd:"",
+      timer:"",
+      buleid:"",
+      deviceListDataShow: [],
+      showTimer:null,
+      connected:false,
+      uuid:"",
+      showDeviceNo:false,
+      inputDeviceNo:"",
+      commonCode:"",
+      showSendData:false,
+      sendData:"",
+      qrcodeid:"",
+      productName:"",
+      deviceno:"",
+      SSID:"",
+      password:"",
+      showWiftList:false,
+      productId:56,
+      chooseProductList:[[      {
+        id:56,text:"3"
+      },
+        {
+          id:56,text:"4"
+        },
+        {
+          id:57,text:"5"
+        }
+      ]],
+      wifiList: [
+        []
+      ],
+
+    }
+  },
+  onLoad() {
+    uni.setNavigationBarTitle({
+      title: "蓝牙配网"
+    })
+    this.deviceno  = this.generateTimestamp();
+    ecUI.showLoading("正在初始化蓝牙模块")
+    ctx = this
+    clearInterval(this.timer);
+    this.timer = setInterval(() => {
+      ctx.deviceListDataShow = JSON.parse(JSON.stringify(deviceListData))
+    }, 800)
+    console.log(this.commonCode)
+    this.productName = this.chooseProductList[0][0].text;
+  },
+  onUnload(){
+    ecBLE.stopBluetoothDevicesDiscovery();
+    ecBLE.closeBLEConnection()
+  },
+  onShow() {
+    if(this.showTimer!= null){
+      clearTimeout(this.showTimer);
+    }
+    this.showTimer = setTimeout(() => {
+      ctx.openBluetoothAdapter()
+    }, 100)
+  },
+  methods: {
+    isCompanyUser(){
+      return true;
+    },
+    chooseProduct(e){
+      this.productId = e.value[0].id;
+      this.productName = e.value[0].text;
+      this.showProductList= false;
+    },
+    generateTimestamp() {
+      const date = new Date();
+      const year = date.getFullYear().toString().substr(2);
+      const month = date.getMonth() + 1;
+      const day = date.getDate();
+      const hours = date.getHours();
+      const minutes = date.getMinutes();
+
+      // 生成6位随机数字
+      const randomNum = Math.floor(Math.random() * 900000) + 100000;
+
+      // 将数字拼接成字符串
+      const timestamp = `${year}${month < 10 ? '0' + month : month}${day < 10 ? '0' + day : day}${hours}${minutes < 10 ? '0' + minutes : minutes}${randomNum}`;
+
+      return timestamp;
+    },
+    getAuth(){
+      wx.getSetting({
+        success(res) {
+          if (!res.authSetting['scope.userLocation']) {
+            wx.authorize({
+              scope: 'scope.userLocation',
+              success () {
+                // 用户已经同意小程序使用录音功能,后续调用 wx.startRecord 接口不会弹窗询问
+
+              }
+            })
+          }
+        }
+      })
+    },
+    chooseWifi(e){
+      this.SSID = e.value[0];
+      this.showWiftList= false;
+    },
+    openChooseWifi(){
+      if(this.wifiList[0].length == 0){
+        this.getWifiList();
+      }else{
+        this.showWiftList = true;
+      }
+    },
+    openWifi(){
+      let self = this;
+      // #ifdef MP-WEIXIN
+      wx.startWifi({
+        success(res) {
+          console.log(res);
+          // self.getWifiList();
+        },
+        fail(res) {
+          console.log(res)
+          uni.showToast({
+            title: '请打开WIFI',
+            icon: 'none',
+            duration: 3000
+          });
+
+        },
+      })
+      // #endif
+
+    },
+    getWifi(){
+      // #ifdef MP-WEIXIN
+      var that = this
+      wx.getConnectedWifi({
+        success(res) {
+          console.log(res)
+          that.BSSID = res.wifi.BSSID
+          that.WIFIName = res.wifi.SSID
+        },
+        fail(res) {
+          console.log(res)
+          //报错的相关处理
+        },
+      })
+      // #endif
+
+    },
+    getWifiList(){
+      // #ifdef MP-WEIXIN
+      var that = this
+      uni.showLoading();
+      wx.getWifiList({
+        success(res) {
+          console.log(res)
+          wx.onGetWifiList(function(res) {
+            that.showWiftList = true;
+            uni.hideLoading();
+            console.log("获取wifi列表");
+            that.wifiList = [[]];
+            console.log(res.wifiList); //在这里提取列表数据
+            //通过遍历将WIFI名字存入集合,以便下卡框等组件使用
+            for (var i = 0; i < res.wifiList.length; i++) {
+              that.wifiList[0].push(res.wifiList[i].SSID)
+            }
+          })
+        },
+        fail(res) {
+          console.log(res)
+          uni.showToast({
+            title: '获取wifi失败,请检查wifi',
+            icon: 'none',
+            duration: 2000
+          });
+        },
+      })
+      // #endif
+
+    },
+    doConnectUser(){
+      if(this.SSID == ""){
+        uni.showToast({
+          title: '请选择WIFI',
+          icon: 'none',
+          duration: 3000
+        });
+        return;
+      }
+      if(this.password == ""){
+        uni.showToast({
+          title: '请输入wifi密码',
+          icon: 'none',
+          duration: 3000
+        });
+        return;
+      }
+
+      /**
+       * ID:XXX+回车换行(设备编号)
+       * QR:XXXX+回车换行(二维码ID)
+       * ssid:WiFi名字+回车换行
+       * psd:wifi密码+回车换行
+       * 最后+OK
+       */
+      let self = this;
+      let endStr = "$$";
+      ecUI.showLoading("正在配置网络信息")
+
+      setTimeout(function(){
+        sendWifi(self.SSID+endStr);
+      },400);
+
+      setTimeout(function(){
+        sendPwd(self.password+endStr);
+      },600);
+
+
+      setTimeout(function(){
+        sendEnd("OK"+endStr);
+      },800);
+
+
+
+    },
+    doConnect(){
+      if(this.SSID == ""){
+        uni.showToast({
+          title: '请选择WIFI',
+          icon: 'none',
+          duration: 3000
+        });
+        return;
+      }
+      if(this.password == ""){
+        uni.showToast({
+          title: '请输入wifi密码',
+          icon: 'none',
+          duration: 3000
+        });
+        return;
+      }
+
+      if(this.qrcodeid == ""){
+        uni.showToast({
+          title: '请输入二维码ID',
+          icon: 'none',
+          duration: 3000
+        });
+        return;
+      }
+
+
+      if(this.deviceno == ""){
+        uni.showToast({
+          title: '请输入设备编号',
+          icon: 'none',
+          duration: 3000
+        });
+        return;
+      }
+
+
+      /**
+       * ID:XXX+回车换行(设备编号)
+       * QR:XXXX+回车换行(二维码ID)
+       * ssid:WiFi名字+回车换行
+       * psd:wifi密码+回车换行
+       * 最后+OK
+       */
+      let self = this;
+      getDevcieByQrcodeID(this.qrcodeid).then(res=>{
+        if(res.data != null){
+          self.$modal.showToast("当前二维码已经配置设备");
+        }else{
+          let endStr = "$$";
+          ecUI.showLoading("正在配置网络信息")
+          setTimeout(function(){
+            self.sendBlueData("ID:"+self.deviceno+endStr);
+          },200);
+          setTimeout(function(){
+            self.sendBlueData("QR:"+self.qrcodeid+endStr);
+          },400);
+
+          setTimeout(function(){
+            self.sendBlueData("ssid:"+self.SSID+endStr);
+          },600);
+
+          setTimeout(function(){
+            self.sendBlueData("psd:"+self.password+endStr);
+          },800);
+
+          setTimeout(function(){
+            self.sendBlueData("pid:"+self.productId+endStr);
+          },1000);
+
+          setTimeout(function(){
+            self.sendBlueData("OK");
+          },1200);
+        }
+      })
+
+
+
+
+    },
+    stringToHex(str) {
+      let hex = '';
+      for (let i = 0; i < str.length; i++) {
+        const char = str.charCodeAt(i);
+        const hexChar = char.toString(16).padStart(2, '0');
+        hex += hexChar;
+      }
+      return hex;
+    },
+    doByTime(func,time){
+      setTimeout(function (){
+        func();
+      },time);
+    },
+    sendLanyaData(){
+      this.$modal.showToast("正在发送");
+      this.sendBlueData(this.sendData);
+    },
+    i18(text){
+      return text;
+    },
+    cancel(){
+      this.showPwd = false;
+      uni.navigateBack({
+      });
+    },
+    resetPwd(){
+      let self = this;
+      if(!this.inputDeviceNo){
+        self.$modal.showToast("请输入序列号");
+        return;
+      }
+      let uuidRight = false;
+      if(this.inputDeviceNo == this.commonCode || this.uuid == this.inputDeviceNo){
+        uuidRight = true;
+      }
+      if(!uuidRight){
+        self.$modal.showToast("序列号有误");
+        return;
+      }
+      if(uuidRight){
+        this.$modal.confirm("密码将被重置为123456").then(res=>{
+          setPwd("123456")
+          self.$modal.showToast("密码修改成功");
+          this.rightPwd = "123456";
+          self.loginSuccess();
+        });
+      }
+    },
+    getBeijingTime() {
+      const date = new Date();
+      const utcTime = date.getTime() + (date.getTimezoneOffset() * 60 * 1000);
+      const beijingTime = new Date(utcTime + (8 * 60 * 60 * 1000));
+      return beijingTime;
+    },
+    generateUniqueNumber(date) {
+      let dateString = date.toISOString().slice(0, 10).replace(/-/g, '');
+      console.log(dateString)
+      let hash = w_md5.hex_md5_32(dateString);
+      console.log(hash);//32位小写
+      let str = "";
+      for (let i = 0; i < 6; i++) {
+        const c = hash.charCodeAt(i);
+        str  = str+""+c+""
+      }
+      return str.substr(0,6);
+    },
+    goBack(){
+      uni.navigateBack({
+      });
+    },
+    $t(title){
+      return title;
+    },
+    inputPwd(){
+      if(!this.pwd ){
+        this.$modal.showToast(this.$t('buletooth.errpwd'));
+      }else{
+        if(this.rightPwd && this.rightPwd === this.pwd){
+          this.loginSuccess();
+        }else{
+          this.$modal.showToast(this.$t('buletooth.errpwd'));
+        }
+
+      }
+    },
+    loginSuccess(){
+      this.showPwd = false;
+      this.showDeviceNo = false;
+      uni.setStorageSync("pwd",this.rightPwd);
+      uni.setStorageSync('blueid', this.buleid);
+      this.pwd = "";
+      ecBLE.stopBluetoothDevicesDiscovery();
+      uni.navigateTo({
+        url: '/pages/weitiandi/bluetooth/status'
+      });
+    },
+    getLocalPwd(){
+      let pwd = uni.getStorageSync("pwd");
+      return pwd;
+    },
+    sendBlueData(tempSendData){
+      tempSendData = this.stringToHex(tempSendData);
+      let data = tempSendData
+          .replace(/\s*/g, '')
+          .replace(/\n/g, '')
+          .replace(/\r/g, '')
+      data = "55a0"+data;
+      console.log("写入数据:"+data);
+      ecBLE.writeBLECharacteristicValue(data, true)
+    },
+    listViewTap(id){
+      let self = this;
+      ecUI.showLoading("正在连接蓝牙")
+      ecBLE.onBLEConnectionStateChange(res => {
+        console.log(res);
+        if (res.ok) {
+          self.connected = true;
+          self.openWifi();
+          ecUI.hideLoading()
+          self.showSendData = true;
+          ecBLE.stopBluetoothDevicesDiscovery();
+          //
+        } else {
+          ecUI.hideLoading()
+          this.$modal.showToast("请检查是否配置成功");
+        }
+      });
+      //receive data
+      ecBLE.onBLECharacteristicValueChange((str, strHex) => {
+        console.log("数据来了")
+        let isCheckRevHex = true;
+        let data =
+            (isCheckRevHex ? strHex.replace(/[0-9a-fA-F]{2}/g, ' $&') : str)
+        console.log(data)
+        self.$modal.closeLoading();
+
+      })
+      self.connected = false;
+      ecBLE.createBLEConnection(id);
+      setTimeout(function (){
+        if(!self.connected){
+          self.$modal.showToast(i18('连接失败'));
+          self.startBluetoothDevicesDiscovery()
+        }
+      },10000);
+    },
+    showInputPwd(){
+      this.showPwd = true;
+    },
+    messageCallback(data){
+      let self = this;
+      console.log(data);
+      let type = data.type;
+      let real_data = data.real_data;
+      if(type == 253){
+        self.$modal.closeLoading();
+        self.uuid = real_data.substr(0,6);
+      }
+      self.$forceUpdate();
+      console.log('收到服务器内容:' + JSON.stringify(data));
+    },
+    forgetPwd(){
+      this.$modal.loading("正在读取设备ID");
+      getUUID()
+      this.showDeviceNo = true;
+    },
+    openBluetoothAdapter() {
+      let self = this;
+      ecBLE.onBluetoothAdapterStateChange(res => {
+        ecUI.hideLoading()
+        if (res.ok) {
+          ctx.startBluetoothDevicesDiscovery()
+        } else {
+          ecUI.showModal(
+              this.$t('buletooth.tip'),
+              `Bluetooth adapter error | ${res.errCode} | ${res.errMsg}`,
+              () => {
+
+              }
+          )
+        }
+      })
+      ecBLE.openBluetoothAdapter()
+    },
+    startBluetoothDevicesDiscovery() {
+      ecBLE.stopBluetoothDevicesDiscovery();
+      console.log('start search')
+      ecBLE.onBluetoothDeviceFound(res => {
+        let isRight = true;
+        if(res.name.startsWith('BT_') || res.name.startsWith('WGD')){
+          isRight = true;
+        }
+        if(!isRight){
+          return;
+        }
+        for (const item of deviceListData) {
+          if (item.id === res.id) {
+            item.name = res.name
+            item.rssi = res.rssi
+            return
+          }
+        }
+        let manufacturer = ''
+        if (res.name.length === 11 && res.name.startsWith('@')) {
+          manufacturer = 'eciot'
+        }
+        if (res.name.length === 15 && res.name.startsWith('BT_')) {
+          manufacturer = 'eciot'
+        }
+        manufacturer = 'eciot'
+        deviceListData.push({
+          id: res.id,
+          name: res.name,
+          rssi: res.rssi,
+          manufacturer,
+        })
+      })
+      ecBLE.startBluetoothDevicesDiscovery()
+    },
+  }
+}
+</script>
+
+<style>
+.main-container {
+  height: 100vh;
+}
+
+.list-item {
+  height: 57px;
+  position: relative;
+}
+
+.list-item-hover {
+  background-color: #e5e4e9;
+}
+
+.list-item-img {
+  position: absolute;
+  width: 36px;
+  height: 36px;
+  left: 20px;
+  top: 10px;
+}
+
+.list-item-name {
+  position: absolute;
+  font-size: 22px;
+  left: 76px;
+  top: 0px;
+  line-height: 56px;
+}
+
+.list-item-rssi-img {
+  position: absolute;
+  width: 20px;
+  height: 20px;
+  right: 20px;
+  top: 13px;
+}
+
+.list-item-rssi {
+  position: absolute;
+  width: 40px;
+  height: 20px;
+  right: 10px;
+  top: 33px;
+  font-size: 12px;
+  font-weight: bold;
+  display: flex;
+  justify-content: center;
+}
+
+.list-item-line {
+  position: absolute;
+  height: 1px;
+  width: 100vw;
+  left: 20px;
+  top: 56px;
+  background-color: #c6c6c8;
+}
+
+.notice {
+  display: flex;
+  justify-content: center;
+  align-items: center;
+  margin-top: 10px;
+  font-size: 13px;
+  color: #909399;
+}
+
+.gap {
+  height: 57px;
+}
+.text-area {
+  display: flex;
+  justify-content: center;
+  background: white;
+  width: 100%;
+  height: 100%;
+}
+</style>

+ 145 - 80
utils/weitiandi/device/device.js

@@ -103,22 +103,62 @@ const deviceTool = {
         let arr =  [85,253,0,253];
         sendData(arr)
     },
-    sendWifiPwd(wifi,pwd){
-        let arr = buildWifiPwd(wifi,pwd)
+    sendPwd(pwd){
+        let arr = stringToHex(pwd,'a1')
+        arr = changeArrToTen(arr);
+        addLast(arr)
+        sendData(arr)
+    },
+    sendWifi(wifi){
+        let arr = stringToHex(wifi,'a0')
+        arr = changeArrToTen(arr);
+        addLast(arr)
+        sendData(arr)
+    },
+    sendEnd(ok){
+        let arr = stringToHex(ok,'a2')
+        arr = changeArrToTen(arr);
         addLast(arr)
         sendData(arr)
     }
+
 }
-function buildWifiPwd(wifi,pwd){
-    let arr = [85,160,wifi.length+pwd.length+1];
-    for (let i = 0; i < wifi.length; i++) {
-        let c =  wifi.charCodeAt(0);
-        arr.push(c);
+function changeArrToTen(arr){
+    const hexArr = arr.map(str => {
+        let num = parseInt(str,16);
+        return num;
+    });
+    return hexArr;
+}
+function addLast16(arr){
+    let total = 0;
+    for(let i =3;i<arr.length;i++){
+        const data =arr[i];
+        total += parseInt(data,16);
     }
-    arr.push(59)
-
-    for (let i = 0; i < pwd.length; i++) {
-        let c =  pwd.charCodeAt(0);
+    total = total.toString(2);
+    if(total.length>8){
+        let valueStrLen = total.length;
+        total = total.substring(valueStrLen-8,valueStrLen);
+    }
+    total = parseInt(total,2)
+    arr.push(total);
+}
+function   stringToHex(str,key) {
+    let len = str.length;
+    let len16 = len.toString(16).padStart(2, '0');
+    let arr = ['55',key,len16];
+    for (let i = 0; i < str.length; i++) {
+        const char = str.charCodeAt(i);
+        const hexChar = char.toString(16).padStart(2, '0');
+        arr.push(hexChar);
+    }
+    return arr;
+}
+function buildWifiPwd(wifi,key){
+    let arr = [85,key,wifi.length+1];
+    for (let i = 0; i < wifi.length; i++) {
+        let c =  wifi.charCodeAt(i);
         arr.push(c);
     }
     return arr;
@@ -146,7 +186,7 @@ function sendData(arr){
 
 function changeArr(arr){
     const hexArr = arr.map(num => {
-        let str = num.toString(16); // 将每个数字转换为16进制字符串
+       let str = num.toString(16); // 将每个数字转换为16进制字符串
         if(str.length == 1){
             return "0"+str.toUpperCase();
         }else{
@@ -157,10 +197,10 @@ function changeArr(arr){
 }
 
 const dataParser = {
-    /**
-     *     "data":[170,96,33,1,8,244,1,231,3,1,208,32,7,9,5,22,8,0,0,0,5,128,12,0,0,0,0,12,15,18,8,7,8,7,8,7,120]
-     *     "real_data":{"card_avail":1,"peak_price":8,"cost":500,"time_limit":999,"fee_type":1,"max_power":8400,"peak_service_price":7,"volume":9,"bottom_price":5,"botton_end":22,"bottom_start":8,"qr_id_low":0,"qr_id_middle":0,"qr_id_high":0,"bottom_service_price":5,"max_current":3200,"cp_check_off":0,"fee_show_off":0,"time1_end":12,"time2_end":15,"time3_end":18,"time1_price":8,"time1_price_service":7,"time2_price":8,"time2_sercie_price":7,"time3_price":8,"time3_service_price":7},"type":96}
-     */
+/**
+ *     "data":[170,96,33,1,8,244,1,231,3,1,208,32,7,9,5,22,8,0,0,0,5,128,12,0,0,0,0,12,15,18,8,7,8,7,8,7,120]
+ *     "real_data":{"card_avail":1,"peak_price":8,"cost":500,"time_limit":999,"fee_type":1,"max_power":8400,"peak_service_price":7,"volume":9,"bottom_price":5,"botton_end":22,"bottom_start":8,"qr_id_low":0,"qr_id_middle":0,"qr_id_high":0,"bottom_service_price":5,"max_current":3200,"cp_check_off":0,"fee_show_off":0,"time1_end":12,"time2_end":15,"time3_end":18,"time1_price":8,"time1_price_service":7,"time2_price":8,"time2_sercie_price":7,"time3_price":8,"time3_service_price":7},"type":96}
+ */
     mainboard:'CARD_AVAIL\n' +
         'PEAK_PRICE\n' +
         'COST 2\n' +
@@ -242,10 +282,10 @@ function parseData(arr){
     let type = arr[1];
     let str = "";
     if(type == 96){//主板
-        str = dataParser.mainboard;
+         str = dataParser.mainboard;
     }
     if(type == 103){
-        let len =  arr[2];
+      let len =  arr[2];
         if(len == 18){
             str = dataParser.portdetail.double;
         }
@@ -276,7 +316,7 @@ function parseData(arr){
     let obj = parseProp(arr,str);
     data.type = type;
     data.real_data = obj;
-    return data;
+   return data;
 }
 function parseUUID(arr){
     let str = "";
@@ -323,34 +363,34 @@ function parseProp(arr,str){
  * @return
  */
 function cmdToDec(cmds) {
-    if (!cmds) {
-        return -1;
-    }
-    let len = cmds.length;
-    if (len === 1) {
-        return cmds[0];
-    } else if (len === 2) {
-        let first = cmds[0];
-        let second = cmds[1];
-        let firstStr = addZero(first.toString(2));
-        let secondStr = addZero(second.toString(2));
-        let allStr = secondStr + firstStr;
-        let i = parseInt(allStr, 2);
-        return i;
-    } else if (len === 4) {
-        let first = cmds[0];
-        let second = cmds[1];
-        let third = cmds[2];
-        let forth = cmds[3];
-        let firstStr = addZero(first.toString(2));
-        let secondStr = addZero(second.toString(2));
-        let thirdStr = addZero(third.toString(2));
-        let forthStr = addZero(forth.toString(2));
-        let allStr = forthStr + thirdStr + secondStr + firstStr;
-        let i = parseInt(allStr, 2);
-        return i;
-    }
-    return 0;
+  if (!cmds) {
+    return -1;
+  }
+  let len = cmds.length;
+  if (len === 1) {
+    return cmds[0];
+  } else if (len === 2) {
+    let first = cmds[0];
+    let second = cmds[1];
+    let firstStr = addZero(first.toString(2));
+    let secondStr = addZero(second.toString(2));
+    let allStr = secondStr + firstStr;
+    let i = parseInt(allStr, 2);
+    return i;
+  } else if (len === 4) {
+    let first = cmds[0];
+    let second = cmds[1];
+    let third = cmds[2];
+    let forth = cmds[3];
+    let firstStr = addZero(first.toString(2));
+    let secondStr = addZero(second.toString(2));
+    let thirdStr = addZero(third.toString(2));
+    let forthStr = addZero(forth.toString(2));
+    let allStr = forthStr + thirdStr + secondStr + firstStr;
+    let i = parseInt(allStr, 2);
+    return i;
+  }
+  return 0;
 }
 function sendBlueData(tempSendData){
     let data = tempSendData
@@ -369,13 +409,13 @@ function sendBlueData(tempSendData){
  * @return
  */
 function addZero(value) {
-    let len = value.length;
-    if (len < 8) {
-        for (let i = 0; i < 8 - len; i++) {
-            value = "0" + value;
-        }
+  let len = value.length;
+  if (len < 8) {
+    for (let i = 0; i < 8 - len; i++) {
+      value = "0" + value;
     }
-    return value;
+  }
+  return value;
 }
 
 /**
@@ -384,31 +424,31 @@ function addZero(value) {
  * @return
  */
 function decToCmd(value) {
-    let cmds = null;
-    if (value <= 255) { //两位
-        cmds = [value];
-    } else if (value <= 65535) {
-        cmds = new Array(2);
-        let valueStr = value.toString(2);
-        let len = valueStr.length;
-        let lastEight = valueStr.substring(len - 8, len);
-        let firstEight = valueStr.substring(0, len - 8);
-        cmds[0] = parseInt(lastEight, 2);
-        cmds[1] = parseInt(firstEight, 2);
-    } else {
-        cmds = new Array(4);
-        let valueStr = value.toString(2);
-        let len = valueStr.length;
-        let lastEight = valueStr.substring(len - 8, len);
-        let firstEight = valueStr.substring(len - 16, len - 8);
-        let secondEight = valueStr.substring(len - 24, len - 16);
-        let thirdEight = valueStr.substring(0, len - 24);
-        cmds[0] = parseInt(lastEight, 2);
-        cmds[1] = parseInt(firstEight, 2);
-        cmds[2] = parseInt(secondEight, 2);
-        cmds[3] = parseInt(thirdEight, 2);
-    }
-    return cmds;
+  let cmds = null;
+  if (value <= 255) { //两位
+    cmds = [value];
+  } else if (value <= 65535) {
+    cmds = new Array(2);
+    let valueStr = value.toString(2);
+    let len = valueStr.length;
+    let lastEight = valueStr.substring(len - 8, len);
+    let firstEight = valueStr.substring(0, len - 8);
+    cmds[0] = parseInt(lastEight, 2);
+    cmds[1] = parseInt(firstEight, 2);
+  } else {
+    cmds = new Array(4);
+    let valueStr = value.toString(2);
+    let len = valueStr.length;
+    let lastEight = valueStr.substring(len - 8, len);
+    let firstEight = valueStr.substring(len - 16, len - 8);
+    let secondEight = valueStr.substring(len - 24, len - 16);
+    let thirdEight = valueStr.substring(0, len - 24);
+    cmds[0] = parseInt(lastEight, 2);
+    cmds[1] = parseInt(firstEight, 2);
+    cmds[2] = parseInt(secondEight, 2);
+    cmds[3] = parseInt(thirdEight, 2);
+  }
+  return cmds;
 }
 //parseData([170,103,18,1,0,0,54,5,0,0,0,0,2,241,25,67,3,75,0,77,0,159])
 export function sendPortDetailCmd(){
@@ -516,6 +556,27 @@ export function getUUID(){
         resolve()
     });
 }
+export function sendWifi(wifi){
+    deviceTool.sendWifi(wifi);
+    return new Promise(resolve => {
+        resolve()
+    });
+}
+export function sendEnd(end){
+    deviceTool.sendEnd(end);
+    return new Promise(resolve => {
+        resolve()
+    });
+}
+export function sendPwd(wifi){
+    deviceTool.sendPwd(wifi);
+    return new Promise(resolve => {
+        resolve()
+    });
+}
+
+
+
 
 //--------------------------------
 let queue = Promise.resolve();
@@ -569,7 +630,7 @@ function test(){
     }
     arr =[170,103,13,1,0,0,0,0,0,0,0,0,0,23,233,0,117];
     console.log(arr)
-    console.log( parseData(arr))
+   console.log( parseData(arr))
 }
 
 function testQueue(){
@@ -577,5 +638,9 @@ function testQueue(){
         sendBlueData(i+"");
     }
 }
-// test()
+
+function testWifi(){
+deviceTool.sendWifi("MERCURY_D8BC8A$$")
+}
+// testWifi()