Creating a GUID?

Hi,

As a way of learning more about the development possibilities I’m playing with a couple of ideas. One of which is ‘Plex (Connect)’. It’s main purpose is aimed at Routine support. As an example I would create a routine ‘Switching to the Bedroom’ upon using would stop what is playing in the living room, turn the TV off and given a determined amount of time turn the Hue lights off. Again upon using it would turn the bedroom Hue rights on and using Plex’s mostly JSON API start playing the same media after 30 seconds or so blah blah.

Plex likes a client ID as a header. So upon install of the Connect app (which will create child devices for servers and clients alike) I’d like to create a GUID as the value for this HTTP header that I’ll store as a setting.

How do I go about this? And (only while I’m at it, haven’t searched yet) how do I base64 encode?

Remember that you’re using Groovy, so pretty much however you do stuff in Groovy, you can do it in a SmartApp. So for Random uiid:

def suuid = UUID.randomUUID().toString() // generate a random uuid

Works fine

For Base64 encode…

def s = 'Argh, Groovy you say, mate?'
def encoded = s.bytes.encodeBase64()
log.debug encoded
2 Likes

Thank you for both answers and the Groovy reminder.