Author Topic: garagemote with amazon echo  (Read 2972 times)

quesker

  • NewMember
  • *
  • Posts: 13
garagemote with amazon echo
« on: December 25, 2016, 07:57:32 PM »
My garagemote has been up and running for a couple years with mostly no problems.  (I have to tell it twice to open it, but anyway...)

I have amazon echo all set up and sending requests to a node app on my webserver.  I want my app to talk to the garagemote and tell it to open and close the door.  This can be hardcoded since I am not likely adding any motes any time soon.  How can I simply send a message (I'm using node.js) to the garagemote to say open or close?

This is what I have in my nginx.conf on the webserver to pass some requests to the raspberry pi:
   location /socket.io/ {
           proxy_pass http://10.10.10.88:8080;

So there must be some magic POST I can send to 10.10.10.88:8080 to open/close the door right?


« Last Edit: December 26, 2016, 05:17:05 PM by quesker »

quesker

  • NewMember
  • *
  • Posts: 13
Re: garagemote with amazon echo
« Reply #1 on: December 26, 2016, 07:27:09 PM »
this seems like it should do it, but doesn't...


Code: [Select]
const socket = require('socket.io-client')('http://10.10.10.88:8080');
socket.emit('GRGOPN');

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: garagemote with amazon echo
« Reply #2 on: December 26, 2016, 07:34:30 PM »
You have a Pi + Moteino at one end and the garagemote at the other end? Node running on the Pi?
Can you give more detail about your hardware setup?

quesker

  • NewMember
  • *
  • Posts: 13
Re: garagemote with amazon echo
« Reply #3 on: December 26, 2016, 07:51:01 PM »
Unfortunately I can't remember how I set it all up.  It looks to me like the php part is on my webserver and the gateway.js is on the pi talking to the garagemote.  I can't remember the password to the pi so I can't go look at the logs.  Now that I know more about things I see it was silly to split it up like that.

From a browser using your index.php everything works fine to see the door status and to open and close it.  I am just trying to figure out the magic to talk to gateway.js to tell it to open the door or close it, so this new node app can control it (so the amazon echo can talk to it).


I think maybe this is the php that does it:
Code: [Select]
socket.emit("NODEACTION", {nodeId:event.data.nodeId, action:event.data.action})

Now if I can figure out the nodeId I bet I can make it work.


quesker

  • NewMember
  • *
  • Posts: 13
Re: garagemote with amazon echo
« Reply #4 on: December 26, 2016, 07:58:26 PM »
I tried this in node, didn't open the door  :(

Code: [Select]
const socket = require('socket.io-client')('http://10.10.10.88:8080');
socket.emit("NODEACTION", {nodeId:"54", action:"GRGOPN"});

I also tried without quotes around 54.

quesker

  • NewMember
  • *
  • Posts: 13
Re: garagemote with amazon echo
« Reply #5 on: December 26, 2016, 08:18:30 PM »
I figured out the pi user/pass so now I can troubleshoot from that end.

quesker

  • NewMember
  • *
  • Posts: 13
Re: garagemote with amazon echo
« Reply #6 on: December 26, 2016, 08:59:41 PM »
AUTHORIZING CONNECTION FROM undefined:undefined

that seems weird.  but even if I disable that auth, I still haven't figured out the right magic to socket.emit()

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: garagemote with amazon echo
« Reply #7 on: December 27, 2016, 12:23:48 PM »
Oh you're using the old old version of the gateway.js script which just allowed hardcoded nodes like the garagemote and switchmotes...
Well the fundamental problem is you cannot send requests from unauthorized clients. That's one of the main points behind this architecture, not allowing random unauthorized requests to open your garage or turn lights on.
If you disable HTTP_AUTH then you might be able to do it, I am not really sure how you can on that old version of the code.
Try watching what happens when you click the button in your browser, if there's any wrappers around the request, I think it will be a websocket request.

mhaggerty

  • NewMember
  • *
  • Posts: 14
Re: garagemote with amazon echo
« Reply #8 on: January 16, 2017, 08:59:22 PM »
I am exploring the same issue!! Integrating Amazon Echo "Alexa" voice into this environment would be awesome! ..."Alexa, ask Moteino to open garage door"... Unfortunately I have not gotten too far into it yet!  I have found that the Echo will respond to GPIO requests using ngrok (see http://www.instructables.com/id/Control-Raspberry-Pi-GPIO-With-Amazon-Echo-and-Pyt/?ALLSTEPS ) - while I have been able to replicate turning a LED on/off with this, I have not yet been able to get responses from the Moteino Gateway.  I'd think it should be possible to link to it!  Additional instructables like http://www.instructables.com/id/Hacking-the-Amazon-Echo/?ALLSTEPS look promising... Something to explore when I get a bit of free time <definition: free time - noun.  a rare occurrence that allows focus on personal hobbies such as programming home automation :-)>. 

mhaggerty

  • NewMember
  • *
  • Posts: 14
Re: garagemote with amazon echo
« Reply #9 on: January 24, 2017, 10:20:28 PM »
I was able to use Python to communicate via pySerial to the piGateway by sending <nodeID>:<command> (10:STS) and tie that into the Amazon Echo environment using ngrok.  The challenge I have now is that the Python script competes with gateway.js on reading the output from serial resulting in inconsistent responses (when I stop gateway it works great!).  My code is a bit rough looking right now, but I'd be willing to share what I've got if anyone is interested.  Before releasing it I'd like to be able to add mutex to both Python and gateway.js so both can run simultaneously. 
Does anyone have experience/ideas to lock the serial port when in use?  Of course race conditions/deadlocks are a factors to avoid here!   Basically a check/lock command for both Python and gateway.js would be necessary (don't forget to unlock!).
Thoughts???? 

mhaggerty

  • NewMember
  • *
  • Posts: 14
Re: garagemote with amazon echo
« Reply #10 on: May 26, 2019, 11:13:27 AM »
I finally was able to find the time to work on integrating Alexa with IoT Gateway.  Please visit: https://github.com/mikehagg/garagemote.alexa for the code.  Contributions welcome!