当前位置:网站首页>利用ESP32构造一个ZIGBEE的网络发送转接
利用ESP32构造一个ZIGBEE的网络发送转接
2022-07-30 01:24:00 【卓晴】

简 介: 利用 ESP32的联网功能,构建了一个 WiFi UDP 转 Zigbee的串口模块。这个模块仅仅是将 UDP的指令发送到Zigbee的网络中,便替代了原来的功能。注意,ESP32的网络地址为: 192.168.0.114。如何能够获得 ESP32的IP地址呢? 可以介入 192.168.0.1 WiFi网关,在DHCP服务器的客户列表中检查到 Espressif的IP地址。
关键词:ESP32,Zigbee
§01ZIGBEE网关
一、背景介绍
在 实验室中的第三只手:滑轨参数以及控制接口 给出了实验室中的滑轨平台控制参数。这些平台都是通过连接在 “COM2” 上的 zigbee 通讯模块相互连接的。由于现在平台所使用到的串口设置遇到问题,因此计划使用ESP32作为网桥,作为UDP转成COM口的转换网桥,这样可以使得原来实验室的设备能够继续使用。
二、制作模块
1、ESP32模块
ESP32模块使用了基于ESP32的智能车竞赛裁判系统 ,这是由龙邱公司生产出售的。 可以通过其中的TXD2,RXD2完成向ZIGBEE 发送信息。

▲ , ESP32裁判系统中的串口2、ZIGBEE模块
下图给出了ZIGBEE的接口,通过四芯的扁平电缆与ESP32裁判系统模块相连。

▲ 图1.2.2 ZIGBEE接口与ESP32之间的接口三、软件编程
1、测试串口
参考在 第十七届智能车竞赛比赛系统软件修改-多车组时间延迟 博文中对于ESP32裁判系统软件修改中的代码,编写串口测试软件。代码如下:
from machine import Pin,UART
import time
import machine
machine.freq(240000000)
uart1 = UART(2, baudrate=115200, rx=16, tx=17, timeout=10)
bz1 = Pin(21, Pin.OUT)
bz1.off
while True:
uart1.write(bytes([0x55]))
time.sleep_ms(10)
测试 TX2 管脚的波形为为:

▲ 图1.3.1 发送0x55数据TX波形2、发送ZIGBEE命令
将ESP32连接到 ZIGBEE模块。

▲ 图1.3.2 连接ZIGBEE模块通过如下程序,每隔 500ms 发送一个relay click 指令,经过验证,动作正常。由此证明整个ZIGBEE发送过程是正常的。
from machine import Pin,UART
import time
import machine
machine.freq(240000000)
uart1 = UART(2, baudrate=115200, rx=16, tx=17, timeout=10)
bz1 = Pin(21, Pin.OUT)
bz1.off
while True:
uart1.write(b'solenoidrelay pulse 4 50\r')
time.sleep_ms(500)
print("SEND.")
3、连接WiFi接口
根据 ESP32模块的MicroPython的基本实验 对于ESP32联网的一般实验,将ESP32接入实验室中的 WiFi 热点,并建立UDP接口连接。
如下是完整的 ESP32程序。使用 Thonny IDE 将 下面的程序写入ESP32内部FLASH,并启动。
from machine import Pin,UART
import machine,time, network, usocket
machine.freq(240000000)
uart1 = UART(2, baudrate=115200, rx=16, tx=17, timeout=10)
bz1 = Pin(21, Pin.OUT)
bz1.off()
wlan = network.WLAN(network.STA_IF)
wlan.active(False)
wlan.active(True)
time.sleep_ms(100)
wlan.connect('TENDA626A', 'gniqouhz')
bz1.on()
while not wlan.isconnected():
time.sleep_ms(100)
wlan.ifconfig()
bz1.off()
us = usocket.socket(usocket.AF_INET, usocket.SOCK_DGRAM)
sockaddr = usocket.getaddrinfo('0.0.0.0', 4567)[0][-1]
us.bind(sockaddr)
while True:
data,addr = us.recvfrom(1024)
if len(data) > 0:
bz1.on()
uart1.write(data)
bz1.off()
经过测试,发送一下指令,可以引起实验室中ZIGBEE中的继电器动作。
solenoidrelay pulse 4 50
这也就验证了这个WiFi 转 Zigbee的模块功能正常了。
※ 总 结 ※
利用 ESP32的联网功能,构建了一个 WiFi UDP 转 Zigbee的串口模块。这个模块仅仅是将 UDP的指令发送到Zigbee的网络中,便替代了原来的功能。
注意,ESP32的网络地址为: 192.168.0.114。
如何能够获得 ESP32的IP地址呢? 可以介入 192.168.0.1 WiFi网关,在DHCP服务器的客户列表中检查到 Espressif的IP地址。

▲ 图2.1 ESPressif IP地址■ 相关文献链接:
● 相关图表链接:
边栏推荐
- 泰克Tektronix示波器软件TDS520|TDS1001|TDS1002上位机软件NS-Scope
- 初级测试人员如何快速成长
- Nacos micro service ~ Nacos 】 【 configuration of the center
- Selenium上传文件有多少种方式?不信你有我全
- ufw 设置防火墙规则
- How many ways does Selenium upload files?I don't believe you have me
- 遇到bug的解决办法,测试再也不背锅了
- 【Vmware NSX-V基本架构及组件安装】
- 十一、uni-app生成弹窗及换行
- 【MySQL系列】MySQL数据库基础
猜你喜欢

【VMWARE--共享文件】
![[Training DAY16] ALFA [convex hull] [computational geometry]](/img/26/ecc77dabdf468b3a8ad3888b292496.png)
[Training DAY16] ALFA [convex hull] [computational geometry]

新型LaaS协议Elephant Swap给ePLATO提供可持续溢价空间

CMake Tutorial Tour (1)_Basic starting point

【Flutter】Flutter inspector 工具使用详解,查看Flutter布局,widget树,调试界面等

高德地图jsapi不生效 INVALID_USER_SCODE

Fabric Writing Case Chaincode

Vmtouch - under Linux file cache management artifact
![[MySQL series] MySQL database foundation](/img/50/cc75b2cdf6e52714c1d492fa1ae2c4.png)
[MySQL series] MySQL database foundation

Google Chrome (google) is set to translate Chinese, the translation option does not take effect or the translation option does not pop up
随机推荐
What majors become more popular the older they get?
Detailed introduction to the usage of Nacos configuration center
SSM integration case
Fabric 编写案例 链码
Fabric 私有数据案例
Leetcode69. x 的平方根
Huawei's "genius boy" Zhihui Jun has made a new work, creating a "customized" smart keyboard from scratch
会议OA之待开会议&&所有会议
ufw 设置防火墙规则
How to realize the frame selection of objects in canvas (6)
Running a Fabric Application
exness: U.S. GDP shrinks, yen bounces back
泰克Tektronix示波器软件TDS520|TDS1001|TDS1002上位机软件NS-Scope
Nacos micro service ~ Nacos 】 【 configuration of the center
转发和重定向的区别及使用场景
聊聊性能测试环境搭建
Print linked list from end to beginning
LeetCode/Scala - without the firstborn of the string of characters, the longest text string back
9 common mistakes testers fall into
【MySQL系列】MySQL数据库基础