Skip to content

Instantly share code, notes, and snippets.

@neosarchizo
Last active July 5, 2022 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neosarchizo/a7c0a2dec8e3f99d9046d4bd62c656b5 to your computer and use it in GitHub Desktop.
Save neosarchizo/a7c0a2dec8e3f99d9046d4bd62c656b5 to your computer and use it in GitHub Desktop.
MicroPython - STM32 W5500 이더넷 모듈 소켓 통신
from pyb import SPI, Timer
from network import WIZNET5K
from usocket import socket
nic = WIZNET5K(SPI(2), 'Y5', 'Y4')
nic.active(True)
nic.ifconfig('dhcp')
if nic.isconnected():
config = nic.ifconfig()
print(config)
print('IP : ' + config[0])
print('SUBNET : ' + config[1])
print('GATEWAY : ' + config[2])
print('DNS : ' + config[3])
s = socket()
addr = ('192.168.86.58', 65432)
s.connect(addr)
def timeout(_):
global s
s.send('Hello DeviceMart!')
timer = Timer(1, freq=1)
timer.callback(timeout)
while True:
text = s.recv(128)
if text == '':
pass
else:
print('Server : ' + text.decode('utf-8'))
import socket
HOST = '192.168.86.58'
PORT = 65432
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
s.listen()
conn, addr = s.accept()
with conn:
print(f"Connected by {addr}")
while True:
data = conn.recv(1024)
if not data:
break
conn.sendall(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment