sub RunUserInterface(params As Object)
    if params.contentID <> invalid
        contentID = params.contentID
    else
        contentID = ""
    end if

    if params.options <> invalid
        options = params.options
    else
        options = ""
    end if

    showScreen(contentID, options)
end sub


sub showScreen(contentID As String, options As String)
    screen = CreateObject("roParagraphScreen")
    port = CreateObject("roMessagePort")
    screen.SetMessagePort(port)

    deviceInfo = CreateObject("roDeviceInfo")
    deviceID = deviceInfo.GetDeviceUniqueId()
    aaIPAddrs = deviceInfo.GetIPAddrs()

    screen.SetTitle("IP Tagger")
    for each key in aaIPAddrs
	    ipAddr = aaipAddrs[key]
	    if ipAddr <> invalid and ipAddr.Len() > 0
	        screen.addParagraph(key + " = " + ipAddr)
        end if
    end for

    settings = GetSettings()

    request = CreateObject("roUrlTransfer")
    request.SetCertificatesFile("common:/certs/ca-bundle.crt")
    request.SetPort(port)
    request.SetUrl(settings.url)
    params = deviceID+"="+ipAddr+"&auth="+settings.auth
    screen.addParagraph("Tagging "+ipAddr+" for "+deviceID+"...")
    if request.AsyncPostFromString(params)
        print "Post was sent!"
    endif
    screen.Show()

    while true
        msg = wait(0, port)
        if type(msg) = "roParagraphScreenEvent"
            if msg.isScreenClosed()
              exit while
            end if
        else if type(msg) = "roUrlEvent"
            if msg.GetInt() = 1
                if msg.GetResponseCode() = 200
                    screen.addParagraph("Success! You can get this device's IP address from the following URL:")
                    screen.addParagraph(settings.url+"?k="+deviceID)
                else
                    screen.addParagraph("It didn't work. Got code " + str(msg.GetResponseCode()))
                endif
            endif
        end if
    end while
    screen.Close() ' Wonder if this is needed
end sub
