plamoni / SiriProxy

A (tampering) proxy server for Apple's Siri
GNU General Public License v3.0
2.12k stars 343 forks source link

SiriProxy Plugin (PHP func.) works stand alone, not when implement in plugin. #469

Closed robinbolscher closed 11 years ago

robinbolscher commented 11 years ago

Hi guys!

First of all thanks a lot for the effort you put in to this project, is just amazing. I am a creative technology student at a university in holland, and I want to enhance my skills in home automation, and I'd love to implement the siriproxy. Now, after struggling for many weeks, I turn myself to you.

The problem is as follows, siriproxy server is up and running, as is my siriproxy-php plugin. It sends back the answers that I have put in. Now, I want to execute some small (php like) code to edit a .txt file on a webserver. I can put a 1 or a 0 in the text file by either browsing to domain.com/led.php?state=1 or domain.com/led.php?state=0. Now I want my siriproxy-php plugin to put these links, so that I can use siriproxy to alter the content of the .txt file, and therefore do some cool stuff with Arduino.

So I wrote some ruby code, my first btw, and it works when I run that code on my windows computer in cmd. So it should work. But when I implement that exact same code in the plugin, it gives back the correct feedback, but it does not put the /led.php?state=0/1 online.

Here an example of my plugin:

listen_for /turn on water boiler/i do say "Your water boiler is on!" #say something to the user! result = Net::HTTP.get(URI.parse('domain.com/led.php?state=1')) request_completed #always complete your request! Otherwise the phone will "spin" at the user! end listen_for /turn off water boiler/i do say "Your water boiler is turned off!" #say something to the user! result = Net::HTTP.get(URI.parse('domain.com/led.php?state=0')) request_completed #always complete your request! Otherwise the phone will "spin" at the user! end

If someone could look at my code, and help me along, it would me really appreciated!

Best regards, Robin Bolscher

plamoni commented 11 years ago

Fun stuff, as it so happens, SiriProxy was my first Ruby code, also! :-)

I don't see anything really wrong with your code, though I'm not familiar with Net::HTTP and how it should be used. I think you might get something from checking out the SiriProxy-Thermostat plugin, which does basically what you want to do. It uses an HTTP interface to interact with a thermostat.

First, I used HTTParty for the thermostat plugin. You might consider doing the same. Here's the code I used:

https://github.com/plamoni/SiriProxy-Thermostat/blob/master/lib/siriproxy-thermostat.rb#L62-L65

Your code will probably be something like:

result = HTTParty.get("http://domain.com/led.php", :query => { :state => 1 });

One other thing you might consider is that while the HTTP task might take a second or two, Siri likes to get a response as quickly as possible. So you might note that in my Thermostat plugin, I spawn off a thread for the HTTP request then send a response right back to the user telling them that the action is in progress. This is a better user experience, but adds a couple lines of code.

Good luck on your project, hope that all helps!

robinbolscher commented 11 years ago

Thank you for your answer and insights! I will definitely implement the 'in progress' function, good tip. Because of your answer, and my thoughts that I was doing everything correctly, I started looking elsewhere. What turned out to be the problem for so long, at university campus you have to register every computer to make use of the local network, if you don't, you have a connection, but you can't browse the web. I did this of course for the pc where the VM was running on, but forgot to do this for the Ubuntu VM... So this was basically the fix to all of this!

So now I am really happy with everything working, and looking forward to make more (complicated) plugins in the future!

Keep up the good work:)

plamoni commented 11 years ago

Thanks for your interest!