Raspberry Pi IFTTT DO Button - linux

I recently put together a Raspberry Pi garage door opener and it seems to be working well at this point. I used this as a reference and used his scripts and webpage with slight fixes/modifications. I can now log into the site I'm hosting from the pi with Apache2 and open and close my door and view my webcam stream. I am using DuckDNS and port forwarding port 80 to my pi currently.
What I would like to do next is set up IFTTT Maker Channel integration with the goal of using a DO Button to control the door from my Android Wear watch. The problem is I don't know how to set up the pi to receive an HTTP request from IFTTT.
Essentially what I need to learn how to do is have the pi listen for this request and run a script (setting GPIO pin 17 to high for a half second). Presumably once I figure this out I would also be able to use Tasker/AutoVoice for Google Now integration.
Thanks in advance for any help.

So I figured it out and want to post my limited knowledge answer for anyone looking to do the same, it was actually easier than I was making it.
I had a couple of problems from the start
My whole html root folder requires a password
I didn't understand what a GET request was doing in this instance
My script files weren't working properly
Here's how I was able to correct these issues and get it working
Send the username/password in the GET request, not extremely secure, but oh well:http://user:password#address.org/file.php
With the basic GET request it appears to just basically "load" the URL given as if you typed it in a browser address bar and hit enter, this means that if my script file is working correctly it should run the script
I corrected my script files

Related

How to setup action on Google API on local server?

I am new for action for Google, and I want a help. I want to create a chatbot and wanna use actions on Google API for this, I came across certain blogs but I can not understand how to setup this thing and local and make use of actions on Google API's in a productive way. I have read the documentation but nothing seems to be work in a desired manner. Please help me with initial steps where I could begin with.
I think you should read the documents properly. Here's the correct address for developing actions :- https://developers.google.com/actions/apiai/
This is the perfect document, if you will use API.ai. If you want to learn faster then you have to watch videos. Here is the link for the basic video.
This is the basic video you need to watch :- https://youtu.be/5Al0bfCF-xA
I think this video will help you alot. If still you need some more help for building apps, do reply we will help !
You can test it on your local server by opening up a port on your wifi router and and forward that port to you server ip and port. However, you still https call from api.ai to your local server.

How to access NodeJS data through cakePHP?

Dummy question here but I haven't found any answer on the web for now.
I'm working on a cakephp website, installed on a Raspberry Pi, which is supposed to be able to connect wireless-ly through a local network to an Arduino YUN, get its components list.
For example :
"A LED is connected on ports :
Input : 2,
Output : 6;
and is currently on"
And change the input value :
"turn the LED off"
I'm not supposed to reload the webpage to see the change occurring.
So I figured out I needed NodeJS to send/receive the informations with websockets but I don't know how to connect NodeJS -running on its own webserver- to cakephp.
I'm a complete rookie with NodeJS, just did a few tutorials earlier, so I'm stuck here.
Does anyone know how to deal with this ?
Thanks in advance,
There are a few different libraries you can use to connect to the node server.
http://elephant.io/
https://github.com/bergie/dnode-php
You can, of course, just fall back to sending http requests (curl) from your cakephp app to the node server.
I have a few discoveries to add that may help some people.
While searching more deeply on DNode and elephant.io I found a cakePHP plugin called cake_websocket which make use of socket.io.
Seems to me that it is an equivalent to elephant.io specialized in cakePHP (while elephant.io is 'just' PHP).
I hope it can help someone !
Instead of using any library.
You can try iframe tag with src to your 'node.js' view.html.
So, listen for events on view.html which are triggered from your 'cakephp' view.html
So, you will have cakephp->view.html talking to node.js->view.html which is connected to node.js->index.js(server)

Using Chromecast Android API to push a URL to the "ChromeCast" App

So far I've been able to write a webpage that pushes a url to the (what I'm calling) native app in the chromecast device. Through this API I can open a "video_playback" app that sends the URL and some other info, just like in this webpage http://googlecast.github.io/cast-chrome/ to my device and my video plays just fine...
Now I want to do that with the Android API, but it treats that receiver "app" as if it doesn't exist. With some more poking around I found that the actual name of the app is ChromeCast, but all I've been able to do is get a blank screen or a 404 to show up. Is this not supported on the Android app? (ie I'm forced to write my own receiver) or am I doing something wrong?
I perfectly able to open a YouTube app through the Android API and load a video, so most of my code is fine. It seems I just need to figure out what application name and arguments to use in the ApplicationSession.startSession() function.
Any help would be appreciated.-
How are you starting your session (which version of startSession() are you using?)
It sounds like you are starting your session ok but then you need to send the url of the video via the MediaProtocolMessageStream.loadMedia().
https://developers.google.com/cast/reference/android/javadoc/reference/com/google/cast/MediaProtocolMessageStream#loadMedia(java.lang.String, com.google.cast.ContentMetadata, boolean)

WebSockets noob working with Railo

I am admittedly a complete noob in all things server, Linux, and websockets. I finally managed to set up a VM running Apache, Tomcat, and Railo that I could connect to and serve up CFM pages, all the while learning UNIX command line navigation, server theory, etc, etc...
Here's my problem -- there is only one Railo websocket extension and it is super rinky-dink (I had to modify the CFC just to get the service to start) but I can't get a websocket connection up (I keep getting "unexpected code 200" in Google Chrome). There is minimal documentation, which is not helpful at all.
Basically, I am trying to do some prototyping for a future project that will use websockets. I like Railo for its speed, security, and excellent ability for very database heavy operations. I am interested in Node, but don't know how to get the same security and DB functionality out of Javascript as I can with CFML.
So I have a couple questions: what are my best options for WebSocket servers? Should I be trying to use Apache and/or Tomcat? People keep saying it's totally not worthwhile to have something like Node.js running the websockets portion and something else doing the heavy lifting behind it -- why is this? I'm more than happy writing WS handlers in whatever language if I can just get a nudge in the right direction, some excellent tutorials (I can't seem to find much in this department), or good feedback on how to, from the ground up, set up my Linux box to handle websockets -- and preferably how to handle both websockets and a robust language like Railo.
The Railo extension works fine for me.
What about submitting some test code so that we can debug it? Of course the websockets projects is very young and in full deployment. So feel free to fork and submit patches or suggestions.
You have plenty of options:
Railo Google Group
https://groups.google.com/forum/?fromgroups#!forum/railo
Github Extension Repository
submit a but in the Railo Jira bugtracker
The main problem of node.js is that it's mono-thread : you won't be able to do background tasks using it and local IO will block your server.
A solution I use is Go. It's very fast, has very good concurrency features and has integrated websocket and json libraries (sample : http://gary.beagledreams.com/page/go-websocket-chat.html). An efficient web application server is made in a few dozens lines of Go. You'll find that there is still much less documentation on internet than for java or even node.js through.
There are a few implementations of websockets in java but as I'm in the process of switching everything I had in java to Go I hadn't tested them. I know I use Google gson for the json encoding in java and it's very good.
The "unexpected code 200" is caused by Railo's web socket server sending an outdated response. They changed the web socket spec and Chrome uses the newer spec.
The problem seems to be caused by chrome & co implementing the new spec, "draft-ietf-hybi-thewebsocketprotocol-17". It requires the server to respond with "HTTP/1.1 101 Switching Protocols" rather than 200 OK.
The solution here would be to either update the Railo web socket extension yourself or use some other solution:
Here is a complete demo of a web socket chat server written in PHP.
http://www.flynsarmy.com/2012/02/php-websocket-chat-application-2-0/
I have used this myself to implement a real-time HTML chat served from an Arch Linux machine that I had lying around. Configuration consisted of simply setting up Apache and PHP then changing the IP address in index.html and in server.php to the external ip address of the server machine.
This flynsarmy demo includes a recent version of PHPWebSocket which is an open source web socket server written entirely in PHP and contained in a single file. The demo hooks into three callbacks: connect, message recieved, and disconnect.
The important thing to note, for me, was that the web socket protocol supports text only, not binary so while extending it for my own chat app I had to implement my own commands to help control the server. Commands in my case looked like this:
!kickusers: username, another_username, a_third_username
My server code would check the first character of all messages for a '!' and if present would treat it as a command. Then I slice up the string to get the command "kickusers" and a list of users to kick. Then I call the appropriate kick function and pass it the array of usernames.
Since my scenario was a chat client this meant that the user could literally type this command into chat and the server would accept and respond to it.
The way all this is deployed on my server is like so:
I have Apache serve the index.html page when the user goes to that location on my server in their browser. The only purpose Apache plays here is to give index.html to the client who requested it.
The index.html page contains html to display the chat and javascript to send and recieve chat to/from the server. Basically, index.html is simply a chat client written in HTML and Javascript and it runs in the browser.
I run server.php via ssh on the server to start up the WEB SOCKET server (totally separate from Apache) which just sits there and handles chat stuff like echoing text to the other connected clients etc.
Though the Arch wiki on installing Apache and PHP is specific to Arch in the way that you install the Apache and PHP packages the sections on configuring Apache and PHP apply to all. I'll save you the google query and give you the link here if you like: https://wiki.archlinux.org/index.php/LAMP
As for prototyping, the reason I gave the link to Flynsarmy's chat demo is because his comments are helpful, he wrote a blog about it, and it comes as a very simple yet complete example of how to do something with web sockets in php.

Pitfalls of accessing a webserver on 127.0.0.1 from js with a public site

I'm thinking about exploring the idea of having our client software run as a service on a high port and listen for simple http GET requests from 127.0.0.1. The theory is that I would be able to access this service via js from a web page that is served from my site.
1) User installs client software that installs itself as a service and waits for authenticated requests on 127.0.0.1:8080
2) When the user hits my home page js on the page makes an xhtml request to 127.0.0.1:8080 and asks for the status
3) The home page then makes another js request back to my web server sending the status that it received.
This would allow my users to upload/download and edit files on a USB attached device in real-time from a browser. Polling could be the fallback method which is close to what we do today.
Has anyone done this and what potential pitfalls are there? Will this even work?
I can't see any potential pitfalls. I do have a couple of points however.
1/ You probably want to make sure your service only accepts incoming connection from the local machine (127.0.0.1). Otherwise, anyone could look at your JavaScript and figure out that it's talking to [your-ip]:8080. They could then try that themselves from a remote site (security hole).
2/ I wouldn't use port 8080 as it's commonly used for other things (alternate HTTP servers, etc.). Make it configurable and choose a nice high random-type value.
3/ I'm not sure what you're trying to do with point 3 but I think you're trying to send the status back to the user. In which case, why wouldn't the JavaScript on your home page just get the status in a single session and output/update the HTML to be presented to the user? Your "another js request back to my web server" doesn't make sense to me.
You may not be able to do a xml http request to 127.0.0.1 as XMLHTTPRequest is usually limited to the same domain as the main content is being served from. I'm not sure if this restriction applies if the server is on the client's machine. That being said, you could still create a <script> tag that had the src pointing to 127.0.0.1, and have the web server return some Javascript to run. If you only need a simple response, this could work well.
I think it is much better for you to avoid implementation of application logic in JavaScript and html. Once user clicks button on a web page JavaScript should send request to your service and allow it do the rest of the work.
You could have problems with step 1 (Client installs itself) depending on your target user base.
You will need a customised install for each supported environment (Win2K, Vista, Linux, MAC OS 9.0/10.0 etc.).
If your user is on a locked down at work PC this simply wont be allowed.
To some users this might look distressingly similar to a trojan unless you explicitly point out you will be installing software that runs as a service.
You didnt mention an unistall procedure. Users resent "Adobe" like software which installs itself and provides no sensible un-install options
Ohterwise the approach is sound, and, there are are couple of commercial products out there that use exactly this approach!

Resources