当前位置:网站首页>利用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地址■ 相关文献链接:
● 相关图表链接:
边栏推荐
- How to realize the frame selection of objects in canvas (6)
- [Flutter] Detailed explanation of the use of the Flutter inspector tool, viewing the Flutter layout, widget tree, debugging interface, etc.
- Ubuntu中使用SQLite
- Fabric 私有数据案例
- 更换可执行文件glibc版本的某一次挣扎
- npm ERR! code ENOTSUP npm ERR! notsup Unsupported engine for [email protected]: wanted: {“n
- Replace the executable file glibc version of the one
- Nacos micro service ~ Nacos 】 【 configuration of the center
- Navicat如何连接MySQL
- [Microservice~Nacos] Nacos service provider and service consumer
猜你喜欢

Nacos配置中心用法详细介绍

go语言解决自定义header的跨域问题

Ubuntu中使用SQLite

【VMWARE--共享文件】

【LeetCode每日一题】——637.二叉树的层平均值

Fabric 私有数据案例

自学HarmonyOS应用开发(47)- 自定义switch组件
![2022-07-29:一共有n个人,从左到右排列,依次编号0~n-1, h[i]是第i个人的身高, v[i]是第i个人的分数, 要求从左到右选出一个子序列,在这个子序列中的人,从左到右身高是不下降的。](/img/a0/998fb7edca5ebe5d9b1d1e8b705faa.png)
2022-07-29:一共有n个人,从左到右排列,依次编号0~n-1, h[i]是第i个人的身高, v[i]是第i个人的分数, 要求从左到右选出一个子序列,在这个子序列中的人,从左到右身高是不下降的。

什么专业越老越吃香?

How to realize the frame selection of objects in canvas (6)
随机推荐
MySQL高级篇(高阳)建表sql语句大全
npm ERR! code ENOTSUPnpm ERR! notsup Unsupported engine for [email protected]: wanted: {“n
How to realize the frame selection of objects in canvas (6)
1.2Recyclerview实现Item点击事件
【MySQL必知必会】 范式 | ER模型
[Best training DAY16] KC's Can [Dynamic programming]
泰克Tektronix示波器软件TDS2012|TDS2014|TDS2022上位机软件NS-Scope
Replace the executable file glibc version of the one
Performance Testing Theory 1 | Sorting out difficult problems in performance testing
Running a Fabric Application
【LeetCode每日一题】——637.二叉树的层平均值
二叉排序树(C语言)
遇到bug的解决办法,测试再也不背锅了
Reconstruction of binary tree
Ubuntu中使用SQLite
Navicat for mysql破解版安装
[Flutter] Flutter preloading of mixed development solves the problem of slow page loading for the first time
Self-study HarmonyOS application development (56) - Use Service to ensure that the application runs continuously in the background
MATLAB被禁下一个会是LABVIEW吗?国产测试软件ATECLOUD崛起发力
泰克Tektronix示波器软件TDS210|TDS220|TDS224上位机软件NS-Scope