Using ESP32 to construct a ZIGBEE network transmission and transfer

Introduction: Using the networking function of ESP32, a serial port module of WiFi UDP to Zigbee is constructed. This module only sends UDP instructions to Zigbee's network, which replaces the original function. Note that the network address of ESP32 is 192.168.0.114. How can I get the IP address of ESP32? You can intervene in the 192.168.0.1 WiFi gateway and check the IP address of the epressif in the client list of the DHCP server.

Keywords: ESP32, Zigbee

 

§ 01 ZIGBEE gateway

1, Background introduction

  in The third hand in the laboratory: slide rail parameters and control interface The control parameters of the slide platform in the laboratory are given. These platforms are interconnected through zigbee communication modules connected to "COM2". Because the serial port setting used by the platform now encounters problems, it is planned to use ESP32 as the bridge and the conversion bridge from UDP to COM port, so that the original laboratory equipment can continue to be used.

2, Production module

1. ESP32 module

   ESP32 module uses Intelligent vehicle competition referee system based on ESP32 This is produced and sold by Longqiu company. You can send information to ZIGBEE through TXD2 and RXD2.

▲, serial port in ESP32 referee system

2. ZIGBEE module

   the following figure shows the interface of ZIGBEE, which is connected with ESP32 referee system module through four core flat cable.

▲ figure 1.2.2 interface between ZigBee interface and ESP32

3, Software programming

1. Test serial port

   reference in Software modification of the 17th smart car competition system - time delay of multiple vehicle groups For the code in the software modification of ESP32 referee system in the blog, write serial port test software. The code is as follows:

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)

   the waveform of testing TX2 pin is:

▲ figure 1.3.1 TX waveform of sending 0x55 data

2. Send ZIGBEE command

   connect ESP32 to ZIGBEE module.

▲ figure 1.3.2 connecting ZIGBEE module

   send a relay click command every 500ms through the following procedure. After verification, the action is normal. This proves that the whole ZIGBEE sending process is normal.

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. Connect WiFi interface

  according to Basic experiment of MicroPython of ESP32 module For the general experiment of ESP32 networking, connect ESP32 to the WiFi hotspot in the laboratory and establish a UDP interface connection.

   the following is the complete ESP32 program. Use thorny ide to write the following program into ESP32 internal FLASH and start it.

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()

   after testing, sending the following command can cause the relay in ZIGBEE in the laboratory to act.

solenoidrelay pulse 4 50

   this verifies that the function of the WiFi to Zigbee module is normal.

 

※ general    conclusion ※

   using the networking function of ESP32, a serial port module of WiFi UDP to Zigbee is built. This module only sends UDP instructions to Zigbee's network, which replaces the original function.

   note that the network address of ESP32 is 192.168.0.114.

  how can I get the IP address of ESP32? You can intervene in the 192.168.0.1 WiFi gateway and check the IP address of the epressif in the client list of the DHCP server.

▲ figure 2.1 ESPressif IP address

■ links to relevant literature:

● links to relevant charts:

Tags: network Network Protocol udp

Posted by roninblade on Tue, 09 Aug 2022 12:20:46 +0300