from socket import socket,AF_INET,SOCK_DGRAM,SOL_SOCKET,SO_REUSEADDR from network import WLAN,STA_IF from time import sleep,ticks_ms port_notifications=7776 bufSize=100 wifi=socket_notifications=None SSID="ssid" PASSWORD="password" def connect(): global wifi wifi=WLAN(STA_IF) wifi.active(True) wifi.ifconfig(("192.168.0.10","255.255.255.0","192.168.0.1","192.168.0.1")) wifi.connect(SSID, PASSWORD) def setup_socket(): global socket_notifications while not wifi.isconnected(): print("wifi not connected yet") sleep(1) print("wifi connected") socket_notifications=socket(AF_INET, SOCK_DGRAM) socket_notifications.setsockopt(SOL_SOCKET, SO_REUSEADDR, 10) socket_notifications.bind(("0.0.0.0", port_notifications)) def listen_socket(): while(True): message,(ip,port)=socket_notifications.recvfrom(bufSize) message=message.decode() print("message [",ip,":",port,"]:",message) connect() setup_socket() listen_socket()