module:micropython:esp32udpclientserver
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| module:micropython:esp32udpclientserver [2021/12/13 11:07] – [Esp32UdpClientServer] omdevelop | module:micropython:esp32udpclientserver [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Esp32UdpClientServer 01V01 ===== | ||
| - | [[http:// | ||
| - | [ | ||
| - | [[http:// | ||
| - | [[http:// | ||
| - | [[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 ===== | ||
| - | {{: | ||
| - | |||
| - | ----- | ||
| - | [[http:// | ||
| - | [ | ||
| - | [[http:// | ||
| - | [[http:// | ||
| - | [[http:// | ||
| - | [[http:// | ||
| - | ] | ||
module/micropython/esp32udpclientserver.1639390044.txt.gz · Last modified: 2021/12/13 12:07 (external edit)