UIFlow Guide
Create a UDP Server to listen for data reception, and send back the same data content. Through the network-related APIs can get the current IP address of the local machine, used to provide other Client data sending.
from m5stack import *
from m5ui import *
from uiflow import *
import network
import socket
setScreenColor(0x222222)
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect('SSID', 'PASSWORD')
print(wlan.ifconfig())
udpsocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udpsocket.bind(('0.0.0.0', 5000))
while True:
print(udpsocket.recv(1024))
wait_ms(2)
udpsocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udpsocket.bind(('0.0.0.0', 5000))
udpsocket.sendto('Hello', ('192.168.31.11', 5000))
udpsocket.close()
data = udpsocket.recv(1024)
data = udpsocket.read(10)
Create a UDP Client to send data to the specified server.
from m5stack import *
from m5ui import *
from uiflow import *
import socket
import time
setScreenColor(0x222222)
udpsocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udpsocket.connect(('192.168.31.10', 5000))
while True:
udpsocket.send('Hello World')
wait(1)
wait_ms(2)
udpsocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udpsocket.connect(('192.168.31.10', 5000))
udpsocket.send('Hello World')
udpsocket.write('')
udpsocket.sendto('Hello World', ('192.168.31.10', 5000))
udpsocket.close()
data = udpsocket.recv(1024)
data = udpsocket.read(10)