module:micropython:esp32udpclientserver:esp32udpclientserver
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| module:micropython:esp32udpclientserver:esp32udpclientserver [2021/12/13 11:07] – external edit 127.0.0.1 | module:micropython:esp32udpclientserver:esp32udpclientserver [2022/09/13 11:58] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Esp32UdpClientServer | + | ====== Esp32UdpClientServer ===== |
| [[http:// | [[http:// | ||
| [ | [ | ||
| Line 7: | Line 7: | ||
| [[http:// | [[http:// | ||
| ] | ] | ||
| - | |||
| - | ===== Übersicht ===== | ||
| - | * Single MicroPython-Modul **Esp32UdpClient.py** zum Empfangen von UDP-Daten | ||
| - | * Single MicroPython-Modul **Esp32UdpServer.py** zum Senden von UDP-Daten | ||
| - | |||
| - | ===== Benutzung ===== | ||
| - | * Datenaustausch zwischen UdpClient und UdpServer | ||
| - | * UdpClient(Esp32) wartet (nicht blocking!) auf Daten vom UdpServer(Pc) | ||
| - | * UdpClient(Pc) wartet (nicht blocking!) auf Daten vom UdpServer(Esp32) | ||
| - | |||
| - | SourceCode **Esp32UdpClient.py**, | ||
| - | <code python> | ||
| - | # | ||
| - | import time | ||
| - | import network as NTW | ||
| - | import socket as SKT | ||
| - | # | ||
| - | WL_SSID = ' | ||
| - | WL_PW = ' | ||
| - | # | ||
| - | UDP_IPADDRESS = ' | ||
| - | UDP_IPPORT = 5005 | ||
| - | # | ||
| - | # | ||
| - | if (' | ||
| - | # | ||
| - | print(' | ||
| - | # | ||
| - | Wlan = NTW.WLAN(NTW.STA_IF) | ||
| - | Wlan.active(False) | ||
| - | Wlan.active(True) | ||
| - | Wlan.connect(WL_SSID, | ||
| - | while not(Wlan.isconnected()): | ||
| - | pass | ||
| - | print(' | ||
| - | # | ||
| - | Socket = SKT.socket(SKT.AF_INET, | ||
| - | Socket.bind((UDP_IPADDRESS, | ||
| - | Socket.setblocking(0) | ||
| - | Loop = True | ||
| - | while (Loop): | ||
| - | try: | ||
| - | Data, Address = Socket.recvfrom(1024) | ||
| - | if (b' | ||
| - | Loop = False | ||
| - | except SKT.error: | ||
| - | pass | ||
| - | else: | ||
| - | print(Data) | ||
| - | finally: | ||
| - | # debug print(' | ||
| - | time.sleep(0.1) | ||
| - | Socket.close() | ||
| - | # | ||
| - | print(' | ||
| - | # | ||
| - | </ | ||
| - | |||
| - | SourceCode **Esp32UdpServer.py**, | ||
| - | <code python> | ||
| - | # | ||
| - | import time | ||
| - | import network as NTW | ||
| - | import socket as SKT | ||
| - | # | ||
| - | WL_SSID = ' | ||
| - | WL_PW = ' | ||
| - | # | ||
| - | UDP_IPADDRESS = ' | ||
| - | UDP_IPPORT = 5005 | ||
| - | # | ||
| - | # | ||
| - | if (' | ||
| - | # | ||
| - | print(' | ||
| - | # | ||
| - | Wlan = NTW.WLAN(NTW.STA_IF) | ||
| - | Wlan.active(False) | ||
| - | Wlan.active(True) | ||
| - | Wlan.connect(WL_SSID, | ||
| - | while not(Wlan.isconnected()): | ||
| - | pass | ||
| - | print(' | ||
| - | # | ||
| - | Socket = SKT.socket(SKT.AF_INET, | ||
| - | for I in range(0, 10): | ||
| - | print(' | ||
| - | Socket.sendto(b' | ||
| - | time.sleep(1.0) | ||
| - | # | ||
| - | Socket.sendto(b' | ||
| - | Socket.close() | ||
| - | print(' | ||
| - | # | ||
| - | </ | ||
| - | |||
| - | Ausgabe in Terminal: | ||
| - | <code python> | ||
| - | </ | ||
| - | |||
| - | |||
| ===== Version ===== | ===== Version ===== | ||
| - | {{:module:micropython:2112090400_Esp32UdpClientServer_01V01.zip|2112090400_Esp32UdpClientServer_01V01.zip}} | + | * Esp32-Udp-Kommunikation [[:Module:MicroPython:Esp32UdpClientServer: |
| + | * [[: | ||
| + | * [[: | ||
| ----- | ----- | ||
module/micropython/esp32udpclientserver/esp32udpclientserver.1639390044.txt.gz · Last modified: 2021/12/13 12:07 (external edit)