当前位置:网站首页>基于微信小程序的wifi模块使用
基于微信小程序的wifi模块使用
2022-04-23 14:02:00 【1029179954】
本文章主要写基于微信小程序的wifi模块使用,主要写4个功能,wifi的初始化、获取周围的wifi列表、连接wifi和获取连接wifi的基本信息。
1、wifi的初始化,wifi模块使用前,必须初始化。
2、获取周围的wifi列表,获取你附近的wifi列表的基本信息,wifi名,mac地址,信号强度等基本信息,通过这些就可进行定位。
3、连接wifi,知道wifi账号和密码就可以连接。
4、获取连接wifi的基本信息,获取不需要账号和密码,和上边的连接wifi没有关系。获取的是手机已经连接wifi。
下面是具体代码
(1)wxml
<view class="scan">
<view class="time-section">
<view class="time">
<view class="hourminuts">
<text>{
{hours}}:{
{minutes}}</text>
</view>
<view class="seconds">
<text>{
{seconds}}</text>
</view>
</view>
<view class="date">
<text>{
{month}}月{
{day}}日 {
{week}}</text>
</view>
</view>
<view class="footer">
<button class="to-clock" hover-class="hover-to-clock" bindtap="toClock">初始化wifi</button>
<button class="to-clock" hover-class="hover-to-clock" bindtap="toClock1">WiFi列表数据</button>
<button class="to-clock" hover-class="hover-to-clock" bindtap="toClock2">连接wifi</button>
<button class="to-clock" hover-class="hover-to-clock" bindtap="toClock3">获取已连接wifi信息</button>
</view>
<view class="date">
<text>{
{count4}}</text>
</view>
</view>
(2)css
/* pages/scan/scan.wxss */
page {
background-color: #fafafa;
}
.name {
margin-top: 20rpx;
margin-bottom: 40rpx;
line-height: 32px;
font-size: 17.25pt;
color: #000000;
}
.time-section {
margin-top: 110rpx;
}
.time {
display: flex;
flex-direction: row;
justify-content: center;
}
.hourminuts {
line-height: 154rpx;
font-size: 41.25pt;
color: rgba(0, 0, 0, 0.87);
}
.seconds {
line-height: 72rpx;
font-size: 18.75pt;
color: #f5a623;
margin: auto 0rpx 20rpx 0rpx;
}
.date {
margin-top: 12rpx;
text-align: center;
font-weight: 500;
line-height: 22px;
font-size: 12pt;
color: rgba(0, 0, 0, 0.54);
margin-bottom: 120rpx;
}
.footer {
/*display: flex;
flex-direction: column;
justify-content: center;*/
/*align-items: center;*/
margin: 0 auto;
width: 80%;
}
.to-clock {
background-color: #22a1e0;
color: #ffffff;
margin-bottom: 40rpx;
}
.hover-to-clock {
opacity: 0.7;
}
.to-list {
color: rgba(0, 0, 0, 0.54);
margin-bottom: 40rpx;
}
.hover-to-list {
opacity: 0.7;
}
(3)js代码
1)wifi初始化
//初始化wifi
toClock(){
wx.startWifi({
success (res) {
console.log("初始化wifi模块成功"+res.errMsg)
}
})
},
2)获取周围的wifi列表
//wifi数据列表 获取周围的wifi列表
toClock1(){
wx.getWifiList({
success:function(res){
// console.log("获取列表"+res);
// console.log("获取列表"+res.wifi);
wx.onGetWifiList(function (res) {
var len=res.wifiList.length
for(var i=0;i<len;i++){
console.log(res.wifiList[i])
}
console.log(res.wifiList[0])//其他一些业务代码
})
},
complete: (res) => {
},
})
},
3)连接wifi
//连接wifi
toClock2(){
var pass="Xys147258369."
var zh="XYS1"
wx.connectWifi({
SSID:zh,
password:pass,
success (res) {
console.log("连接wifi成功")
},
fail(res){
console.log("连接失败"+res.errCode+" "+res.errMsg);
}
})
},
4)获取连接wifi基本信息(账号、密码和信号强度)
//获取已经连接的wifi信息
toClock3(){
var that = this;
wx.getConnectedWifi({
success(res){
console.log("成功获取到已连接wifi信息")
console.log(res.wifi.SSID+" "+res.wifi.BSSID+" "+res.wifi.secure+" "+res.wifi.signalStrength);
var wifi = res.wifi;
that.setData({
mySSID:wifi.SSID,
myBSSID:wifi.BSSID,
mysecure:wifi.secure,
mysignalStrength:wifi.signalStrength,
})
},
complete: (res) => {
console.log("正在获取信息")
},
})
},
具体实现效果搜索微信公众号:小白XBIT
回复关键字:wifi
其他关键字:ibeacon、二维码门禁
版权声明
本文为[1029179954]所创,转载请带上原文链接,感谢
https://blog.csdn.net/baidu_38978508/article/details/115873044
边栏推荐
- nodejs通过require读取本地json文件出现Unexpected token / in JSON at position
- [code analysis (2)] communication efficient learning of deep networks from decentralized data
- Introduction to spark basic operation
- Special test 05 · double integral [Li Yanfang's whole class]
- Restful WebService和gSoap WebService的本质区别
- Jenkins construction and use
- Decentralized Collaborative Learning Framework for Next POI Recommendation
- 微信小程序基于udp协议与esp8266进行通信
- 分库分表 & ShardingSphere
- crontab定时任务输出产生大量邮件耗尽文件系统inode问题处理
猜你喜欢
Lin Lin, product manager of Lenovo: network failure of local network operator in Tianjin. The background server of Zui system can't work normally for the time being
Question bank and answer analysis of the 2022 simulated examination of the latest eight members of Jiangxi construction (quality control)
[VMware] address of VMware Tools
groutine
Un modèle universel pour la construction d'un modèle d'apprentissage scikit
Express ② (routage)
visio安装报错 1:1935 2:{XXXXXXXX...
Express middleware ③ (custom Middleware)
Record a strange bug: component copy after cache component jump
Port occupied 1
随机推荐
关于pthread多线程一些好文章
JMeter pressure test tool
Qt Designer怎样加入资源文件
金蝶云星空API调用实践
记录一个奇怪的bug:缓存组件跳转之后出现组件复制
About note 1
联想产品经理林林:天津当地网络运营商网络故障 ZUI系统后台服务器暂时无法正常工作
Program compilation and debugging learning record
SPC简介
The art of automation
3300万IOPS、39微秒延迟、碳足迹认证,谁在认真搞事情?
微信小程序基于udp协议与esp8266进行通信
SQL数据库
Quartus prime hardware experimental development (de2-115 board) experiment 1 CPU instruction calculator design
快捷键(多行)
趣谈网络协议
多线程 @Async 线程池
Android: answers to the recruitment and interview of intermediate Android Development Agency in early 2019 (medium)
编程旅行之函数
分库分表 & ShardingSphere