当前位置:网站首页>Use of WiFi module based on wechat applet
Use of WiFi module based on wechat applet
2022-04-23 14:04:00 【one billion twenty-nine million one hundred and seventy-nine th】
This article is mainly written based on wechat applet wifi Module USES , Mainly write 4 Features ,wifi The initialization 、 Get the surrounding wifi list 、 Connect wifi And get a connection wifi Basic information of .
1、wifi The initialization ,wifi Before using the module , Must be initialized .
2、 Get the surrounding wifi list , Get... Near you wifi Basic information of the list ,wifi name ,mac Address , Basic information such as signal strength , Through these, we can locate .
3、 Connect wifi, know wifi Account and password can connect .
4、 Get the connection wifi Basic information of , You don't need an account and password to get , And the connection above wifi It doesn't matter. . What you get is that the mobile phone is connected wifi.
Here is the specific code
(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}} month {
{day}} Japan {
{week}}</text>
</view>
</view>
<view class="footer">
<button class="to-clock" hover-class="hover-to-clock" bindtap="toClock"> initialization wifi</button>
<button class="to-clock" hover-class="hover-to-clock" bindtap="toClock1">WiFi The list of data </button>
<button class="to-clock" hover-class="hover-to-clock" bindtap="toClock2"> Connect wifi</button>
<button class="to-clock" hover-class="hover-to-clock" bindtap="toClock3"> Get connected wifi Information </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 Code
1)wifi initialization
// initialization wifi
toClock(){
wx.startWifi({
success (res) {
console.log(" initialization wifi Module success "+res.errMsg)
}
})
},
2) Get the surrounding wifi list
//wifi Data list Get the surrounding wifi list
toClock1(){
wx.getWifiList({
success:function(res){
// console.log(" To obtain a list of "+res);
// console.log(" To obtain a list of "+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])// Other business codes
})
},
complete: (res) => {
},
})
},
3) Connect wifi
// Connect wifi
toClock2(){
var pass="Xys147258369."
var zh="XYS1"
wx.connectWifi({
SSID:zh,
password:pass,
success (res) {
console.log(" Connect wifi success ")
},
fail(res){
console.log(" The connection fails "+res.errCode+" "+res.errMsg);
}
})
},
4) Get the connection wifi essential information ( account number 、 Password and signal strength )
// Get connected wifi Information
toClock3(){
var that = this;
wx.getConnectedWifi({
success(res){
console.log(" Successfully get connected wifi Information ")
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(" Getting information ")
},
})
},
Search for WeChat official account : The small white XBIT
Reply key :wifi
Other keywords :ibeacon、 QR code access control
版权声明
本文为[one billion twenty-nine million one hundred and seventy-nine th]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231401298212.html
边栏推荐
猜你喜欢

STM32学习记录0007——新建工程(基于寄存器版)

Call wechat customer service applet

Taobao released the baby prompt "your consumer protection deposit is insufficient, and the expiration protection has been started"

联想产品经理林林:天津当地网络运营商网络故障 ZUI系统后台服务器暂时无法正常工作

Quartus Prime硬件实验开发(DE2-115板)实验一CPU指令运算器设计

基于Ocelot的gRpc网关

微信小程序的订阅号开发(消息推送)

基于CM管理的CDH6.3.2集群集成Atlas2.1.0

Nacos+AspnetCore+Ocelot实战编码

基于ibeacons三点定位(微信小程序)
随机推荐
Crontab timing task output generates a large number of mail and runs out of file system inode problem processing
金蝶云星空API调用实践
JS force deduction brush question 103 Zigzag sequence traversal of binary tree
多线程 @Async 线程池
多重继承虚基类习题
JS brain burning interview question reward
专题测试05·二重积分【李艳芳全程班】
Mock测试
微信小程序 input隐藏和不可操作的设置
Oracle告警日志alert.log和跟踪trace文件中文乱码显示
About note 1
Spark入门基本操作
Intégration de Clusters CDH Phoenix basée sur la gestion cm
leetcode--380. O (1) time insertion, deletion and acquisition of random elements
scikit-learn构建模型的万能模板
1256: bouquet for algenon
Jacob print word
China creates vast research infrastructure to support ambitious climate goals
Wechat applet
CentOS mysql多实例部署