gecko242
Posts: 9
Joined: Mon Aug 27, 2012 11:53 am
Contact: Website

Android app GPIO?

Sat Feb 02, 2013 12:57 am

I was wondering if it would be possible to have a 3rd-party android app on my HTC wildfire s, switching a relay remotely through the pi. the plan is to be able to switch my pc on and off from my school, and as a fun project I would like to use the pi.
I am not great at python, and no nothing about android :(

Sam
1 raspberry pi, 4gb sd card, running rasbian, been used as a gpio server.
Intel core i3 3220, XFX7770, msi G-43, Corsair CX-600, 2 250gb HDD

User avatar
tonyhughes
Posts: 951
Joined: Wed Dec 26, 2012 3:46 am

Re: Android app GPIO?

Sat Feb 02, 2013 3:47 am

Heres a dirt simple way of doing things:

Set up a shortcut on your Android homescreen to the URL: http://<YourRaspberryPiPublicIPAddress>/androidphonehome.htm

On the Pi, running Raspbian, apt-get apache2 and you have a working webserver.

From there, the world is your oyster - you use a BASH script called from Cron every ten seconds that could monitor the Apache log looking for a particular requested URL, and perform any action based on that.

nano ~/android.sh

Code: Select all

#! /bin/bash
ANDROID=$(tail /var/log/apache2/access.log -n 50 | grep "androidphonehome.htm" )
if [[ $ANDROID ]]
     then
          # This section is run if someone tries to visit the page mentioned above.
          # Perform any action here:
          sudo /home/pi/scripts/MyScriptToActivateRelay.py
     else
          # This section is run if no one visited, so do nothing.
          echo
fi
exit
Then have cron call /home/pi/android.sh every 2 - 60 seconds.

Of course you need a working domain name or static IP address (if you dont have either, DynDNS will work fine).

You also need security and an up to date OS when running servers exposed to the internet - at a bare minimum:

Update system software.
Set up a firewall.
Use port forwarding.
Turn off all unneeded ports and services.

NOTE: Treat the above as a starting point only. With public access to a server like that, anyone, including a search engine, could trigger your little program to run! I just wanted to show you how easy it is to get started.

gecko242
Posts: 9
Joined: Mon Aug 27, 2012 11:53 am
Contact: Website

Re: Android app GPIO?

Sat Feb 02, 2013 9:48 am

Ok, thats very usefull :)
ill have a look...
1 raspberry pi, 4gb sd card, running rasbian, been used as a gpio server.
Intel core i3 3220, XFX7770, msi G-43, Corsair CX-600, 2 250gb HDD

gecko242
Posts: 9
Joined: Mon Aug 27, 2012 11:53 am
Contact: Website

Re: Android app GPIO?

Sat Feb 02, 2013 12:11 pm

When running your script i get the error Synrtax error near unexpected token fi
1 raspberry pi, 4gb sd card, running rasbian, been used as a gpio server.
Intel core i3 3220, XFX7770, msi G-43, Corsair CX-600, 2 250gb HDD

deefunkt
Posts: 9
Joined: Fri Mar 15, 2013 11:19 pm

Re: Android app GPIO?

Tue Apr 09, 2013 12:21 am

gecko242 wrote:When running your script i get the error Synrtax error near unexpected token fi
Hi Gecko, here is a resource to help you with the construction of IF statements in Linux:
http://linux.byexamples.com/archives/107/if-then-fi/

trouch
Posts: 310
Joined: Fri Aug 03, 2012 7:24 pm
Location: France
Contact: Website

Re: Android app GPIO?

Tue Apr 09, 2013 1:46 pm

look on this : https://play.google.com/store/apps/deta ... raspi_gpio
it uses webiopi on the Pi ;)

WebIOPi - Raspberry Pi REST Framework to control your Pi from the web
http://store.raspberrypi.com/projects/webiopi
http://code.google.com/p/webiopi/
http://trouch.com

Return to “Networking and servers”