import network
import usocket as socket
import badge
import ugfx

badge.vibrator_init()

ugfx.init()
ugfx.set_lut(ugfx.LUT_NORMAL)
ugfx.clear(ugfx.WHITE)

ugfx.string(40, 75, "CampCast Receiver","Roboto_BlackItalic24", ugfx.BLACK)
ugfx.flush()

# Network config
netif = network.WLAN(network.STA_IF)
netif.active(True)
netif.connect("Crazy Belgians")

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(('', 2115))

# Main loop
while True:
    string, address = sock.recvfrom(128)
    print("Received message {}".format(string))
    badge.vibrator_activate(1)
    ugfx.clear(ugfx.WHITE)
    ugfx.string(20, 75, string,"Roboto_BlackItalic24", ugfx.BLACK)
    ugfx.flush()
