It’s time for the next phase in the project. So far we’ve primarily focused on the “output” side of the story : displaying stuff on the mirror. Now we’re going to focus on the “input” : accepting voice commands from Alexa Voice Services.
In this article I’ll be attempting to send a message from the Java client to the debug hub.
I’ll be very practical on this one, nothing too fancy. I’ll be using one of the buttons on the window of the client to start a request.
I added all of this code to the AVSApp.java file.
First, import some packages I’ll be using in the new code.
After some browsing, I found out that the “createMusicButton” method is responsible for adding the music buttons to the interface. I’ll be using one of those buttons to simulate. Below, you can see I commented out the default handler, and added my own call to the testMethod() method.
This method is fairly simple. It just calls another message to do all the dirty work. I added this level of indirection, because ultimately I want to separate the logic for the mirror interface. There’s just some basic error handling involved here.
Below, you can find the actual message responsible for sending the command.
In the above code extract you can see a new URL object is created pointing to the static IP address of my Mac where the debug server is running . Port 3000 is the port it is listening on. I added the path of the routing, and specified the “GET” method. The rest of the code is basically some plumbing code to read the response from the debug hub. In practice, hardly anything will happen with this response, because the Java client will have no visual feedback, apart from logging to the console.
Of course, the above code is very rudimentary. I will have to refactor the code to be a more robust package in which I can call the get method with multiple parameters in multiple circumstances, and where the connection, for example, is read from the config file. But all in due time.
Below, you can see what happens when I click the button.