Shop OBEX P1 Docs P2 Docs Learn Events
Spinneret Web Sercer to Opening a door via text message — Parallax Forums

Spinneret Web Sercer to Opening a door via text message

Tony11Tony11 Posts: 41
edited 2012-02-13 21:59 in Accessories
Source here http://bit.ly/hHUH5p




Opening a door via text message. On my iphone, under the text, what do I have to type in (To: ########)

to get the Spinneret Web Server to read the text, sent to it......... something like this (HTTP/1.1 200 OK)

I guess I don't know that's why I am asking people that know


Tony

Comments

  • Mike GMike G Posts: 2,702
    edited 2011-07-10 05:45
    Start by contacting your SMS provider and see if they offer an API or web service that executes custom logic when a text message is received.
    http://www.twilio.com/api/
  • David CarrierDavid Carrier Posts: 294
    edited 2011-07-11 10:27
    Tony,
    You can get a free number from Google Voice and set it to automatically forward all text messages to an email address. You could the use Post Office Protocol to retrieve the emails.

    — David Carrier
    Parallax Inc.
  • Mike GMike G Posts: 2,702
    edited 2011-07-11 13:26
    David, how do you use POP to send an HTTP GET to the Spinneret? I believe that's what the OP is asking.
  • David CarrierDavid Carrier Posts: 294
    edited 2011-07-11 14:53
    Mike,
    I was explaining a method "to get the Spinneret Web Server to read the text"; I was not saying that it would use HTTP. If he needs something that can occur over HTTP protocol, then he could set up a server that receives the Google Voice text messages and use something like WebDAV to communicate them to the Spinneret Web Server. In the end, it would take less work to program the Spinneret Web Server to fetch the email messages directly. IMAP would also work, and it lets you keep a socket open for an extended period of time for a push-type connection.

    — David Carrier
    Parallax Inc.
  • Tony11Tony11 Posts: 41
    edited 2011-07-11 15:41
    Thanks for your help its working
  • Mike GMike G Posts: 2,702
    edited 2011-07-11 17:50
    David, the project that the OP referenced uses twilio (and Python) to execute an HTTP GET when an text message is received from a "White Listed" number. I'm not sure how to implement a WebDAV solution with the Spinneret. The twilio solution is fairly painless.
  • michaelmonsomichaelmonso Posts: 19
    edited 2012-01-07 17:33
    tony how did you get it to work?im trying to do the same thing from that youtube video. i want to get it to work with the servo just like the video then customize it to run relays so it would trigger my automatic gate to open. i cant get the sms part to work. i can manually put in the address with the open and close to work but i cant send my twilio number an "open" and have it send it to the spinneret. please help
  • michaelmonsomichaelmonso Posts: 19
    edited 2012-01-07 17:38
    he used a file called door.py...this is where im stuck at...1st i dont know where he put this file door.py? on the spinneret?on a web host somewhere?did he host the file himself? and 2nd is that the only file needed?ie i tried putting it on some web space i have and pointing the twilio app url to that hopeing that when i sent a message "open" to twilio that it would send the message to the file on my webspace to the door.py file....that file would run and see if im authorized to open or close and if so send the command to the spinneret to open or close.
  • michaelmonsomichaelmonso Posts: 19
    edited 2012-01-07 17:41
    im trying to do the same thing....i have the same source files changed for my need... i dont know how to get twilio to respond to the spinneret....or what or how i need to set up twilio to use the python file supplied to communicate between twilio and the spinneret please help. off and on ive been working on this and pulling out my hair
  • Mike GMike G Posts: 2,702
    edited 2012-01-07 19:46
    im trying to do the same thing....i have the same source files changed for my need... i dont know how to get twilio to respond to the spinneret....or what or how i need to set up twilio to use the python file supplied to communicate between twilio and the spinneret please help. off and on ive been working on this and pulling out my hair

    Twilio has excellent documentation, APIs for just about every language, and detailed getting started tutorials with example source code. The door.py is very similar to Twilio's getting started code. I'm sure if you spent some time on in the Twilio tutorials you can copy and paste your project.
  • michaelmonsomichaelmonso Posts: 19
    edited 2012-01-08 09:16
    i have no direction to go in. the spinneret i can manipulate his code to do what i want. in a browser if i put my global ip in plus the port ie 76.168.124.160:5001 then at manually to it the on or off ie /?1=o or /?1=c i can manually control the servo ( i will later change it just to turn on and off relays)...however i know nothing of php or python to get the twilio to intereact with the spinneret and parse the message to add the on or off commants to the global ip as billy does in his video for the spinneret sms door openerer....mike you gave me help changing his door.py code before and wrote it in curl this was your code....
    .
    <?php require "Services/Twilio.php";
    	// Members
    	$whilelist = array("+18183248995", "+18188126120");
    	$authenticated = false;
    	
    	//HTTP POST check
    	if($_POST)
    	{
    		// Get the POST data
    		$from = $_POST["from"];
    		$body = $_POST["body"];
    		
    		//Enumerate the phone list and auth
    		if(in_array($from, $whilelist)) {
    			$authenticated = true;
    		} 
    
    
    		// Setup querystring variable
    		switch($body) {
    			case "open":
    				$qdata = "?l=o";
    				break;
    			case "close":
    				$qdata = "?l=c";
    				break;
    			case "status":
    				$qdata = "?l=";
    				break;
    			default:
    				$qdata = "?l=";
    				break;	
    		}
    		
    		// Execute HTTP GET if authenticated	
    		if($authenticated)
    		{
    			$url = "76.160.141.191:5001" . $qdata;
    			$ch = curl_init();
    			curl_setopt($ch, CURLOPT_URL, $url);
    			curl_setopt($ch, CURLOPT_HEADER, 0);
    			curl_exec($ch);
    			curl_close($ch);
    		}
    		
    	}//$_POST
    	
    ?>
    



    i can not get that to work...i dont know what to do with your code or his to make this operate..please help
  • Mike GMike G Posts: 2,702
    edited 2012-01-08 09:53
    michaelmonso, first http://76.160.141.191:5001/ is not available on the internet.
    however i know nothing of php or python to get the twilio to intereact with the spinneret and parse the message to add the on or off commants to the global ip as billy does in his video for the spinneret sms door openerer....mike you gave me help changing his door.py code before and wrote it in curl this was your code....
    Reading this tells me have not tried the Twilio tutorial. First read tutorial in my previous post. Follow the instructions and you should be able to send an SMS message to the Twilio service and receive a response on your cell phone. It's literally copy and paste. Once that's working, all you have to do is make an HTTP GET request to your Spinneret.
    mike you gave me help changing his door.py code before and wrote it in curl this was your code....
    cURL is a library. IIRC, you did not have Python installed on your hosted server.
    http://php.net/manual/en/book.curl.php

    You'll have to consult your hosting provider to figure out if cURL is installed. Then write your PHP script and verify connectivity to the Spinneret.

    Once you verify the SMS to PHP and PHP to Spinneret is working, all that's left is integrating the code.
  • michaelmonsomichaelmonso Posts: 19
    edited 2012-01-08 10:14
    i changed the ip address im at my sisters house and she wouldnt like her ip broadcasted one of the paranoid people that thinks she will get hacked. i have done the tutorials they work fine for me i just dont know what to do with his code.
  • Mike GMike G Posts: 2,702
    edited 2012-01-08 10:31
    i have done the tutorials they work fine for me i just dont know what to do with his code.
    [Scratching my head] You actually did the tutorial?


    This is the code snippet from the tutorial that you should have on your web server. It's looks a lot like door.py eh?
    <?php
    // make an associative array of senders we know, indexed by phone number
    $people = array(
    "+14158675309"=>"Curious George",
    "+14158675310"=>"Boots",
    "+14158675311"=>"Virgil",
    );
    // if the sender is known, then greet them by name
    // otherwise, consider them just another monkey
    if(!$name = $people[$_REQUEST['From']]) {
    $name = "Monkey";
    }
    // now greet the sender
    header("content-type: text/xml");
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    ?>
    <Response>
    <Sms><?php echo $name ?>, thanks for the message!</Sms>
    </Response>
    

    Anyway, right after $name = "Monkey"; is where you would place the HTTP GET to the Spinneret.
  • michaelmonsomichaelmonso Posts: 19
    edited 2012-01-08 11:22
    so what would the http get look like. if i use the above code what would it need to be so that when anyone send a text to the twilio number it responds back with the thanks for the message but allso tells the spinneret at my global ip to add /?1=c after my ip:port
  • michaelmonsomichaelmonso Posts: 19
    edited 2012-01-08 12:46
    [h=2]icon1.png Re: Spinneret Web Sercer to Opening a door via text message[/h]
    so what would the http get look like. if i use the above code what would it need to be so that when anyone send a text to the twilio number it responds back with the thanks for the message but allso tells the spinneret at my global ip to add /?1=c after my ip:port
  • Mike GMike G Posts: 2,702
    edited 2012-01-08 12:54
    so what would the http get look like. if i use the above code what would it need to be so that when anyone send a text to the twilio number it responds back with the thanks for the message but allso tells the spinneret at my global ip to add /?1=c after my ip:port

    This is a modified version of your "copied code" but essentially the same logic. I removed the authenticated logic for testing purposes. I'll leave the Spinneret up for a while so you can see the results.
    http://www.mikegebhard.com/spinneret/httpget.php
    <?php 
    	$body = $_POST["body"];
    
    		// Setup querystring variable
    		switch($body) {
    			case "open":
    				$qdata = "open";
    				break;
    			case "close":
    				$qdata = "close";
    				break;
    			case "status":
    				$qdata = "status";
    				break;
    			default:
    				$qdata = "status";
    				break;	
    		}
    		
    		// Execute HTTP GET if authenticated
    		if($_POST["body"])
    		{
    			$authenticated = true;
    		}	
    		
    		if($authenticated)
    		{
    			$url = "http://spinneret.servehttp.com/door/" . $qdata;
    			$ch = curl_init();
    			curl_setopt($ch, CURLOPT_URL, $url);
    			curl_setopt($ch, CURLOPT_HEADER, 0);
    			curl_exec($ch);
    			curl_close($ch);
    		}
    ?>
    

    This is the entire web page I used to test the HTTP GET. You should have a similar page on your web server.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>PHP GET To Spinneret</title>
    <?php 
    	$body = $_POST["body"];
    
    		// Setup querystring variable
    		switch($body) {
    			case "open":
    				$qdata = "open";
    				break;
    			case "close":
    				$qdata = "close";
    				break;
    			case "status":
    				$qdata = "status";
    				break;
    			default:
    				$qdata = "status";
    				break;	
    		}
    		
    		// Execute HTTP GET if authenticated
    		if($_POST["body"])
    		{
    			$authenticated = true;
    		}	
    		
    		if($authenticated)
    		{
    			$url = "http://spinneret.servehttp.com/door/" . $qdata;
    			$ch = curl_init();
    			curl_setopt($ch, CURLOPT_URL, $url);
    			curl_setopt($ch, CURLOPT_HEADER, 0);
    			curl_exec($ch);
    			curl_close($ch);
    		}
    ?>
    
    <?php echo $body ?>
    
    </head>
    <body>
    <h1>GET to Spinneret</h1>
    <form id="doorlogic" method="post" name="doorlogic">
      <select name="body">
        <option value="open" selected="selected">open</option>
        <option value="close">close</option>
        <option value="status">status</option>
      </select>
     <input id="submit" name="submit" type="submit" value="Submit" />
    </form>
    <?php echo $url ?>
    </body>
    </html>
    

    The return XML is what Twilio expects.
    <Response>
      <Sms>open</Sms>
    </Response>
    

    The rest is up to you.
  • michaelmonsomichaelmonso Posts: 19
    edited 2012-02-11 19:50
    can anyone help me change the same file door.py into a .cgi compatible file....
    this is the door.py code.
    [COLOR=#333333][FONT=Bitstream Vera Sans Mono][B]import[/B][/FONT][/COLOR][COLOR=#333333][FONT=Bitstream Vera Sans Mono] [/FONT][/COLOR][COLOR=#555555][FONT=Bitstream Vera Sans Mono]urllib2[/FONT][/COLOR]
    
    
    
    
    [B]def[/B] [COLOR=#990000][B]door[/B][/COLOR](request):
        [COLOR=#DD1144]'''[/COLOR]
    [COLOR=#DD1144]      This is plugged into a django env, but can really be used with anything.[/COLOR]
    [COLOR=#DD1144]      Twilio hits this URL, which pings the door and returns the response[/COLOR]
    [COLOR=#DD1144]    '''[/COLOR]
    
    
        doorurl [B]=[/B] [COLOR=#DD1144]'http://url-to-parallax-server/'[/COLOR]
    
    
        whitelist [B]=[/B] [ [COLOR=#DD1144]"+19175551212"[/COLOR],
                      [COLOR=#DD1144]"+19175557383"[/COLOR],
                      ]
    
    
        fromnum [B]=[/B] request[B].[/B]POST[B].[/B]get([COLOR=#DD1144]"From"[/COLOR])
        body [B]=[/B] request[B].[/B]POST[B].[/B]get([COLOR=#DD1144]"Body"[/COLOR])
    
    
        [B]if[/B] fromnum [B]and[/B] body [B]and[/B] fromnum [B]in[/B] whitelist:
            [B]if[/B] body [B]==[/B] [COLOR=#DD1144]"open"[/COLOR]:
                doorurl [B]=[/B] doorurl [B]+[/B] [COLOR=#DD1144]'?1=o'[/COLOR]
            [B]elif[/B] body [B]==[/B] [COLOR=#DD1144]"close"[/COLOR]:
                doorurl [B]=[/B] doorurl [B]+[/B] [COLOR=#DD1144]'?1=c'[/COLOR]
            [B]elif[/B] body [B]==[/B] [COLOR=#DD1144]"status"[/COLOR]:
                [B]pass[/B]
    
    
            [B]try[/B]:
                doorres [B]=[/B] urllib2[B].[/B]urlopen(doorurl, timeout [B]=[/B] [COLOR=#009999]10[/COLOR])[B].[/B]read()[B].[/B]strip()
            [B]except[/B]:
                doorres [B]=[/B] [COLOR=#DD1144]"door unresponsive"[/COLOR]
    
    
            [B]return[/B] HttpResponse([COLOR=#DD1144]'<Response><Sms>'[/COLOR] [B]+[/B] doorres [B]+[/B] [COLOR=#DD1144]'</Sms></Response>'[/COLOR], content_type[B]=[/B][COLOR=#DD1144]"text/xml"[/COLOR])
    
    
        [B]raise[/B] Http404
    
  • michaelmonsomichaelmonso Posts: 19
    edited 2012-02-13 21:59
    disregard got code working....ty mike g for your preivious help....you and twilio cust serv made it happen.
Sign In or Register to comment.