当前位置:网站首页>Wechat applet communicates with esp8266 based on UDP protocol
Wechat applet communicates with esp8266 based on UDP protocol
2022-04-23 14:05:00 【one billion twenty-nine million one hundred and seventy-nine th】
1、 summary
Wechat applet is about UDP Agreed API, The specific contents can be viewed on the official website ; The idea of the overall implementation is to use the routing group to build a LAN , mobile phone 、 Routers and esp8266, Mobile phones and esp8266 Connect the router , Log in to the router to view esp8266 Of ip, Wechat applets use udp The agreement can go to esp8266 send data , Then realize wechat applet and esp8266 signal communication , It also realizes the communication with MCU .
2、 Hardware preparation
Router 、 mobile phone 、esp8266
3、 Realize the idea
(1) Group lan
Router 、 Mobile phones and esp8266 Group lan ; Mobile phones and esp8266 Connect the router
(2) see ip
Log in to the background view of routing esp8266 Of ip, Wechat applet udp For agreement ip( Here's just a look at esp8266 that will do )
4、 Wechat applet sends commands to esp8266
Let's take light control as an example
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>
<view class="section">
<view class="section-title"> The lamp 1</view>
<view class="section-form">
<view class="form-group">
<label> The lamp 1 The control of </label>
<switch color="#007aff" checked bindchange="light" ></switch>
</view>
</view>
</view>
<view class="section">
<view class="section-title"> The lamp 2</view>
<view class="section-form">
<view class="form-group">
<label> The lamp 2 The control of </label>
<switch color="#007aff" checked bindchange="wind" ></switch>
</view>
</view>
</view>
<view class="section">
<view class="section-title"> The lamp 3</view>
<view class="section-form">
<view class="form-group">
<label> The lamp 3 The control of </label>
<switch color="#007aff" checked bindchange="buzzer" ></switch>
</view>
</view>
</view>
wxss
/* 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: 60rpx;
}
.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;
}
.main-body {
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
}
.section {
width: 100%;
padding: 20rpx;
}
.section-title {
font-size: 35rpx;
width: 300rpx;
height: 80rpx;
line-height: 80rpx;
padding-left: 20rpx;
border-bottom: 4rpx solid #000;
}
.section-form {
display: flex;
flex-direction: column;
padding: 10rpx 20rpx;
}
.form-group {
display: flex;
flex-direction: row;
width: 100%;
height: 80rpx;
line-height: 80rpx;
font-size: 32rpx;
}
.form-group label {
width: 75%;
}
.form-group input,
.form-group switch {
height: 80rpx;
width: 60rpx;
line-height: 80rpx;
text-align: center;
}
.form-group input {
border-bottom: 2rpx solid #000;
height: 60rpx;
line-height: 60rpx;
}
js
With lamp 1 Column , Core code
// The lamp 26 high1 low1
light(e){
var iip=wx.getStorageSync('ip')// Here is the manual input binding ip Access to the cache You can also write dead here
console.log("iip"+iip)
var that=this
var status=e.detail.value
if(status==true){
console.log(" turn on the light ")
var mess="on"
var ip1 = iip;
var port = "";
const udp = wx.createUDPSocket();
udp.bind();
udp.send({
address: ip1,
port: port,
message: mess
});
}else{
console.log(" Turn off the lights ")
var mess="off"
var ip2 = iip;
var port = "";
const udp = wx.createUDPSocket();
udp.bind();
udp.send({
address: ip2,
port: port,
message: mess
});
}
},
5、esp8266 Accept the data transmitted by wechat applet
版权声明
本文为[one billion twenty-nine million one hundred and seventy-nine th]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231401297638.html
边栏推荐
- 烟雾传感器(mq-2)使用详细教程(基于树莓派3b+实现)
- 联想产品经理林林:天津当地网络运营商网络故障 ZUI系统后台服务器暂时无法正常工作
- Mysql个人学习总结
- JS 力扣刷题 103. 二叉树的锯齿形层序遍历
- Chrome插件 之 Selenium IDE、XPath 安装
- Elmo (bilstm-crf + Elmo) (conll-2003 named entity recognition NER)
- Interesting talk about network protocol
- JS force deduction brush question 103 Zigzag sequence traversal of binary tree
- Detailed tutorial on the use of smoke sensor (mq-2) (based on raspberry pie 3B +)
- 1256:献给阿尔吉侬的花束
猜你喜欢
Programming travel function
1256:献给阿尔吉侬的花束
org.apache.parquet.schema.InvalidSchemaException: A group type can not be empty. Parquet does not su
关于密匙传递的安全性和数字签名
Special test 05 · double integral [Li Yanfang's whole class]
Indoor and outdoor map switching (indoor three-point positioning based on ibeacons)
STM32学习记录0007——新建工程(基于寄存器版)
Quartus prime hardware experimental development (de2-115 board) experiment 1 CPU instruction calculator design
浅谈基于openssl的多级证书,Multi-level CA的签发和管理,以及双向认证
Qt Designer怎样加入资源文件
随机推荐
Introduction to spark basic operation
JDBC入门
jacob打印word
基于微信小程序的wifi模块使用
New关键字的学习和总结
Interesting talk about network protocol
visio安装报错 1:1935 2:{XXXXXXXX...
L2-024 tribe (25 points)
websocket
金蝶云星空API调用实践
程序编译调试学习记录
STM32学习记录0007——新建工程(基于寄存器版)
Android篇:2019初中级Android开发社招面试解答(中
The latest development of fed digital currency
PATH环境变量
网站_收藏
centOS下mysql主从配置
基于CM管理的CDH集群集成Phoenix
mysql新表,自增id长达20位,原因竟是......
Nacos+AspnetCore+Ocelot实战编码