收藏
回答

wifi API 连接指定wifi 总是超时错误

问题模块 框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
API和组件 小程序 Bug wx.connectWifi 客户端 V 7.0.3 2.6.4

- 当前 Bug 的表现(可附上截图)


- 预期表现 连接成功或者连接失败 使用mpvue 搭建的环境


- 复现路径   mpvue  搭建环境即可


- 提供一个最简复现 Demo

<template>
  <div>
    <button @click="startLocalServiceDiscovery">开始搜索</button>
    <button @click="stopLocalServiceDiscovery">停止搜索</button>
 
    <button @click="startWifi">开启Wifi 获取</button>
    <button @click="getWifiList">获取Wifi 列表</button>
    <!-- <input v-model="pass" type="text" value="请输入密码"> -->
    <input class="i-input" v-model="pass" placeholder="请输入密码">
    <ul v-if="wifiLists.length >0">
      <li class="item" v-for="(item, index) in wifiList" :key="index">
        wifi名称 :{{ item.SSID}}
        <button @click="selecedItem(index)" style="width=20px">选择</button>
      </li>
    </ul>
  </div>
</template>
 
<script>
export default {
  components: {},
 
  data() {
    return {
      pass: "1234-Hsl",
      logs: [],
      wifiLists: []
    };
  },
  computed: {
    wifiList() {
      return this.wifiLists;
  
    }
  },
  methods: {
    
    selecedItem(id) {
      console.log(typeof id);
      wx.connectWifi({
        SSID: toString(id),
        password: toString(this.pass),
        success(res) {
          console.log(res);
        },
        complete(complete) {
          console.log("complete", complete);
        }
      });
    },
    startWifi() {
      wx.startWifi({
        success(res) {
          console.log(res.errMsg);
        },
        complete(complete) {
          console.log("complete", complete);
        }
      });
    },
    getWifiList() {
      wx.getWifiList({
        success(res) {
          console.log(res);
        },
        complete(complete) {
          console.log("complete", complete);
        }
      });
 
   
    },
    startLocalServiceDiscovery() {
      wx.startLocalServiceDiscovery({
        // 当前手机所连的局域网下有一个 _http._tcp. 类型的服务
        serviceType: "_http._tcp.",
        success: res => {
          console.log("开始搜索成功", res);
        },
        fail: err => {
          console.log("开始搜索失败", err);
        }
      });
    },
    stopLocalServiceDiscovery() {
      wx.stopLocalServiceDiscovery({
        success: res => {
          console.log("停止搜索成功", res);
        },
        fail: err => {
          console.log("停止搜索失败", err);
        }
      });
    }
  },
  created() {
    // this.wifi();
    wx.onWifiConnected(wifi => {
      console.log("wifi", wifi);
    });
    wx.onGetWifiList(list => {
      this.wifiLists = list.wifiList;
      console.log("this.wifiListh获取到列表", this.wifiLists);
    });
    wx.onLocalServiceResolveFail((serviceType, serviceName) => {
      console.log("serviceType", serviceType);
      console.log("serviceName", serviceName);
    });
    wx.onLocalServiceFound((serviceType, serviceName, ip, port) => {
      console.log("serviceType", serviceType);
      console.log("serviceName", serviceName);
      console.log("ip", ip);
      console.log("port", port);
    });
  }
};
</script>
 
<style>
.i-input {
  padding: 7px 15px;
  color: #495060;
}
.item {
  font-size: 16px;
  line-height: 16px;
  text-align: center;
  color: black;
  padding: 5px;
}
.log-list {
  display: flex;
  flex-direction: column;
  padding: 40rpx;
}
.log-item {
  margin: 10rpx;
}
</style>


回答关注问题邀请回答
收藏

1 个回答

  • 伽蓝
    伽蓝
    2019-04-02

    各位大佬们 没人遇到过吗?

    2019-04-02
    赞同
    回复
登录 后发表内容