Emblem

Alexa and Emlalock

EarRing

Emlalock has a simple API that allows a session to be remotely modified. They're mostly focused around the time aspect of the session. For a wearer most of the commands are ones to make the session worse (e.g. add time, increase minimum/maximum). A holder can also reduce times.

For a wearer you need to know your UserID and your API key. Both of these can be obtained/changed from the web site.

Then you make simple GET requests of the service. For example
  https://www.emlalock.com/api/info/?userid=YOURUSERID&apikey=YOURAPIKEY
will return status information.

The Amazon Echo "Alexa" software allows people to create their own skills. If you put the skill in "test" mode then you can basically anything for personal use and it never needs to be signed off or published.

It then becomes possible to glue Alexa and Emlalock together.


The basics

I won't go into details on how to build an Amazon skill. But, basically, you need a web service that does all the backend work and an Alexa skill configuration that talks to the service. It's possible to write services in Lamba or host them yourself. The Alexa Skills can be created via the Alexa Skill Developer site

In my case I host the software on my home machine and configure my router to allow incoming connections to be forwarded to the software. Along with a dynamic DNS setup it means I can point the Alexa skill at http://my.home.dynamic.dns.address:9876/echo/emla and Alexa will work.

I'm not going to go into those details because each home router is different, they may support different dynamic DNS providers, and so on. Getting this connectivity working may be the hardest part! You may already have an internet facing server (e.g. Amazon Lightsail, at $5/month) which you can use for this. If you use Lambda then there may be a charge for number of calls made. The skill development is free. Since I have internet facing equipment I run the code on my own machine. This makes the Alexa interaction free.


The software

In case other people also want to use this software, I decided to write it in Go; now Linux, Windows, Mac and other users could run it on their machines.

So, here it is. This is the simple Go source code. It has some dependencies, which you may need to go get for compilation to complete

github.com/mikeflynn/go-alexa
github.com/tkanos/gonfig
github.com/channelmeter/iso8601duration
github.com/codegangsta/negroni
github.com/gorilla/mux
(gorilla/mux and codegangsta/negroni are dependencies for go-alexa)

Once the dependencies are met, you can just go build emlalock.go.

Set up

There are no default values. You need a configuration file. If you run the code without a configuration then it will tell you the file it's looking for:
% ./emlalock 
Using configuration file /home/bdsm/.emlalock_id
Skill ID is not defined.  Aborted

On Windows it will look for %HOMEDIR%%HOMEPATH% or %USERPROFILE. On Linux/MacOS it will look in $HOME. Examples may be:

    C:\Documents and Settings\bdsm\.emlalock.cfg
    C:\Users\bdsm\.emlalock.cfg
    /Users/bdsm/.emlalock.cfg
    /home/bdsm/.emlalock.cfg
This file is a JSON format file.
    {
      "SkillID":"Your_Skill_ID_From_Amazon_Developer_Site",
      "EmlaUser":"your_emla_user_code",
      "EmlaAPI":"your_emla_API_code",
      "Name":"Wearer"
    }
Each line is required. The SkillID is used to verify that the requests have come from Amazon Alexa; when you create a skill with the online developer kit it will generate the ID; you need to copy it here.

The EmlaUser is not your login name; it's your ID code. You can see this, and the API key, on the settings pages.

Once you've correctly configured the software, the startup would look something like:

  Using configuration file /home/bdsm/.emlalock_id
  [negroni] listening on :9876
The connection to Emlalock can be tested with a command such as:
    % emlalock status
    Using configuration file /home/bdsm/.emlalock_id
    Calling info 
    Wearer is now locked for 15 hours 13 minutes 26 seconds 


The Alexa Skill

I called the skill "emla lock" (with a space), which should make voice recognition better. You can call skill anything you like, of course.

Once you've created the blank skill and defined the endpoints in the Alexa Skill Developer we need to define the interaction model. This contains the "utterances" (words) to invoke the functions, and the "intents" (actions) to take.

The easiest way is to switch to the JSON editing mode and cut'n'paste this file to replace what was already there. This defines two intents; "status" and "add".

The "status" command can be invoked by "status" or "information" or "time left".

The "add" command can be invoked with "add" or "increase time by" or "punish wearer by" or "punish wearer for". It requires a time period, such as "3 hours".

You can customise the name used in the skill; e.g if your name is Fred then you can use "punish fred for" as one of the phrases.

A successful invocation might look like "Alexa tell emlalock to punish wearer for 3 hours". If everything works then the service code will log output:

2018/05/12 21:08:43 Got Alexa event add
Calling add value=H1
2018/05/12 21:08:44 Got response Time added.  Wearer is now locked for 14 hours 48 minutes 23 seconds
[negroni] 2018-05-12T21:08:43-04:00 | 200 |      531.801426ms | bdsm.spuddy.org:9876 | POST /echo/emla

The "status" call currently reports on time left (or "time's up") along with any remaining pillory time; "Wearer is now locked for 5 hours 47 minutes 57 seconds . Wearer is in the pillory for 47 minutes and 57 seconds"


Be careful

There is no "access control" on this. If you're in a shared household then _anyone_ could add time. Which might be fun at parties...