Physical Button Instead of GUI Button #14

Closed
chrismo16 opened this Issue Mar 26, 2016 · 35 comments

Comments

Projects
None yet

I would like to use a physical button to hold while issuing voice commands. I'm new to the build scene so if anyone has any ideas or can point me to another project that could help please let me know.

I am looking for this too. Currently I am considering using Amazon dash since there is an existing hack to make that button work with pi but haven't had a chance to code anything yet.

Yes this would be way better than using the GUI.

This is the only thing preventing me from building it and showing it off to friends.

Somehow assumed that the java client would be thin. Looks like it has a good deal of functionality. I haven't dabbled with Java that much. Is there a way to quickly convert the UI entry point of this java client into a service that a python script could call? The Dash button click could be registered easily in a python script.

That would be a cool way yeah, if you can somehow debug on what happens in the terminal when you press some key in the gui that would be golden then :D

lemire commented Mar 27, 2016

How hard would it be to emulate the actual Echo and have it record continuously, triggering a query when a specific phrase is uttered? Seems like we have some building blocks already : https://github.com/StevenHickson/PiAUISuite

This was neat and I got it up and running quickly, but in total agreement that having a way to toggle the listening mode with a physical button, specifically the sweet giant red arcade button I bought for a different project, would be great. I will dig around but as others have pointed out the Java client appears rather cumbersome. A Python API enabling us to write a script to act when the GPIO pin changes would be so much more impressive.

I used to do stuff w/ Java but it's been a while (and everyday I am grateful for that, haha)...

//and everyday I am grateful for that// - you could say that again :)

I took a peek at the iOS code and that seems pretty lightweight. It would be nice if the contributors could add a line or two about what each sample is capable of and what's the division of labor between companionService and javaClient. Of course, I am going to get this info after I spend a bit more time with the code, but this seems like useful info to be mentioned in the Readme.

cc: @ajotwani

I haven't done it yet, but looks to me like just a couple things are needed to make this work (and I haven't touched Java in quite a number of years either)

  • Here's a sample button listener using Pi4J: http://pi4j.com/example/listener.html
  • In this file: alexa-avs-raspberry-pi/samples/javaclient/src/main/java/com/amazon/alexa/avs/AVSApp.java

Basically, include all of the includes, pull the guts out of the Pi4j sample main method and throw it into AVSApp and use this in the handleGPIO.....stateChangeEvent method,

`
RequestListener requestListener = new RequestListener() {

                    @Override
                    public void onRequestSuccess() {
                        finishProcessing();
                    }

                    @Override
                    public void onRequestError(Throwable e) {
                        log.error("An error occured creating speech request", e);
                        JOptionPane.showMessageDialog(getContentPane(), e.getMessage(), "Error",
                                JOptionPane.ERROR_MESSAGE);
                        actionButton.doClick();
                        finishProcessing();
                    }
                };`

If anyone tries it, let me know if it works. I'll probably try this at some point over the next few weeks

That is very cool, @halwebguy. Thanks! Will try it out over the weekend.

Thanks for the tip. I'm going to 'hack night' at my local library tonight,
so I will take a stab at this, if I don't get drawn into answering too many
questions or trying to help people get up and running.

I'll report back...at the latest should have something by this weekend.

S

On Tue, Mar 29, 2016 at 7:57 AM, halwebguy notifications@github.com wrote:

I haven't done it yet, but looks to me like just a couple things are
needed to make this work (and I haven't touched Java in quite a number of
years either)

Here's a sample button listener using Pi4J:
http://pi4j.com/example/listener.html

In this file:
alexa-avs-raspberry-pi/samples/javaclient/src/main/java/com/amazon/alexa/avs/AVSApp.java

Basically, include all of the includes, pull the guts out of the Pi4j
sample main method and throw it into AVSApp and use this in the
handleGPIO.....stateChangeEvent method,

`RequestListener requestListener = new RequestListener() {

                @Override
                public void onRequestSuccess() {
                    finishProcessing();
                }

                @Override
                public void onRequestError(Throwable e) {
                    log.error("An error occured creating speech request", e);
                    JOptionPane.showMessageDialog(getContentPane(), e.getMessage(), "Error",
                            JOptionPane.ERROR_MESSAGE);
                    actionButton.doClick();
                    finishProcessing();
                }
            };`

If anyone tries it, let me know if it works. I'll probably try this at
some point over the next few weeks


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
amzn#14 (comment)

Here's a Python-based Alexa project that uses a button to trigger the listener. https://github.com/novaspirit/AlexaPi, forked from https://github.com/sammachin/AlexaPi. I've used Sam Machin's version, and it seems to work pretty well.

Woah, that's pretty sweet! And here I was digging through all that (but
ultimately, not particulary complicated, just verbose) code...

On Wed, Mar 30, 2016 at 3:06 PM, Nelson Butterworth <
notifications@github.com> wrote:

Here's a Python-based Alexa project that uses a button to trigger the
listener. https://github.com/novaspirit/AlexaPi, forked from
https://github.com/sammachin/AlexaPi. I've used Sam Machin's version, and
it seems to work pretty well.


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
amzn#14 (comment)

Oh yeah, check that out. Time to try a fresh mSD card.

@halwebguy I had a similar idea and tried to do it. I get a runtime error though. I'd appreciate it if you could help. #109

Hey there. I just wanted to say that I currently have this working with a physical button. I did use pi4j and will update this with steps on how to get it working. There were a lot of people who helped me and a lot of learning involved. Great project. :) My steps are updated and everything should be working. Let me know if you have any issues. @shankararunachalam

That is awesome, @Eddie-Hartman. Please let us know here or in the fork once you have had a chance to write it up.

Contributor

ajot commented Apr 8, 2016

@Eddie-Hartman That's awesome. Mind sending a PR, so we can review and update the ReadMe here?

@ajotwani What is a PR? A public repository? It's available here.
Edit: Ah a Pull Request. (This is my first github project. Still learning.)

@Eddie-Hartman a PR is a pull request. Github provides a help page about how to create one.

I believe I did it properly here @dougharris @ajotwani let me know if I messed up. :)

@Eddie-Hartman You've nailed the process for the PR. I'll leave the review of the code and the merge to @ajotwani

hankp46 commented Jun 22, 2016

I have the AVS service working. However, when I add the pushbutton code I can ask questions but cannot get flash update or radio stations. I understand flash and radio is handled via VLC but cannot find anything wrong. Also AVS thinks it is playing the flash since it start with "here's your flash update" and if you let it run will finally come back with "flash update ended". Any clues?

hankp46 commented Jun 29, 2016

Just wanted everyone to know that the new Pi4J package now let's you utilize GPIO without running sudo. I made changes and all is now working. This web site;
http://pi4j.com/download.html
Tells you what you need to download and what changes you need to make to your Pom.xml file.
You also need to add some imports and code to AVSApp.java
import com.pi4j.io.gpio.*;
import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent;
import com.pi4j.io.gpio.event.GpioPinListenerDigital;
import com.pi4j.wiringpi.GpioUtil;
and add the following line of code
GpioUtil.enableNonPrivilegedAccess();

    // create gpio controller

final GpioController gpio = GpioFactory.getInstance();

I will try to use the new Pi4J package and as long and everything goes well, I'll make the changes to my fork. Thanks. I have thought multiple times about the issues you were having as well, but just didn't have any good answers. Sorry. It's works fine on pi 3s and a b+ that I've tested. I don't really know why you wouldn't get flash updates or radio if you get it before. Maybe compare your dependencies with mine? Good luck and thanks again for the update.

@hankp46 I'm trying to update everything now. I was unable to find the method GpioUtil.enableNonPrivilegedAccess(); in snapshot 1.0.1 or 1.1. Also, I'm unable to build now because it says that Maven can't find the Pi4J package even though I changed pom.xml file properly. Any ideas on what's going on?

hankp46 commented Jul 17, 2016

I'm out of the country until 28 July so won't be able to research now.

Hank Poletto
hpoletto@cfl.rr.com

On Jul 17, 2016, at 10:59 AM, Elton (Eddie) Hartman notifications@github.com wrote:

@hankp46 I'm trying to update everything now. I was unable to find the method GpioUtil.enableNonPrivilegedAccess(); in snapshot 1.0.1 or 1.1. Also, I'm unable to build now because it says that Maven can't find the Pi4J package even though I changed pom.xml file properly. Any ideas on what's going on?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

I fixed it. They were silly spelling mistakes. I just had to go over everything again twice lol. Now I'm having this problem though. Thanks for the update though since everything compiles and SEEMS to work I'll update my fork when I can get everything working again.

I guess I missed something:

[ERROR] Failed to execute goal on project sample-java-client: Could not resolve dependencies for project com.amazon.alexa.avs:sample-java-client:jar:20160207.0: Could not find artifact com.pi4j:pi4j-core:jar:1.1-SNAPSHOT -> [Help 1]

I installed pi4j, it's and the jar is in /opt/pi4j/lib

man install -e shows this error:

Caused by: org.apache.maven.project.DependencyResolutionException: Could not resolve dependencies for project com.amazon.alexa.avs:sample-java-client:jar:20160207.0: Could not find artifact com.pi4j:pi4j-core:jar:1.1-SNAPSHOT in oss-snapshots-repo (https://oss.sonatype.org/content/groups/public)

Any ideas?

Yeah it's not a snapshot anymore. The version in the maven dependency may no longer exist. Pi4j no longer needs an install if it's listed in the dependencies. I will fix this tomorrow. :)

Actually, I just fixed it. Let me know if you have any more trouble.

hankp46 commented Aug 6, 2016

Eddie
Just got back from vacation and tried Alexa. No longer getting any responses. Listening and processing with no errors but no response. Any ideas of changes that could cause this? I made the pom.xml change.

Eddie-Hartman commented Aug 7, 2016

@hankp46 I just made the changes and I'm getting no responses either. I'll take a look at it soon. We have a good idea of what would have caused this (the new update) but I don't know why.

Edit: I guess that you're already aware, but the issue seems to be with all amazon alexa services and not necessarily the code changes I made. Hopefully the servers will be back on soon.

@ajot ajot added the dev-request label Aug 31, 2016

I made a few changes to the POM.xml ad the AVSApp.java files to handle both a physical button and RGB light. This code is build on top of the latest version of the alexa pi code (that supports wake words) Code here: https://github.com/darianbjohnson/Mystic_Mirror_Project/tree/master/AVS

Note: a diagram of how I wired the pins is here: https://camo.githubusercontent.com/6cc0b98e9f15cc02863eee0fc130264de51ebbde/68747470733a2f2f6861636b737465722e696d6769782e6e65742f75706c6f6164732f6174746163686d656e74732f3138313736392f776972696e672e706e67

@dskidmor dskidmor added Feature Request and removed dev-request labels Dec 8, 2016

@keleric keleric closed this Jan 26, 2017

Zacki84 commented May 27, 2017

@darianbjohnson
I want to build a physical button and RGB light with your code, but I can´t find the AVSApp.java file on my pi, do you know what I did wrong?
Does your code work with wake word and button? I would like to have both ways working.
can you help me, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment