gboud21
Posts: 1
Joined: Sat Nov 19, 2016 2:30 pm

Raspberry Pi and Android Phone Communication

Sat Nov 19, 2016 2:41 pm

Hi all,

So I am working on a project where I need to be able to upload data from a raspberry pi to a mySQL database. I also need to be able to run scripts on the raspberry pi via an Android App. Thus far I have looked into installing a LAMP server on a pi, using my private desktop PC as a WAMP server as well as potentially using GoDaddy as a LAMP server. However, I wanted to avoid forwarding ports which made me decide against the LAMP server on a pi as well as the WAMP sever on my PC. Is it possible to be able to open a web socket between the Pi and a GoDaddy (or other vps service) which I could run a script on the Pi when the VPS receives a prompt? Just to clarify I'll write a little flow chart below detailing what I'm attempting to do:

Android App button press sends encoded message to VPS to run a particular script on the Pi ->
VPS receives message and deciphers message in php script->
VPS php script sends message to Pi to run program.py->
Pi runs program.py

Another option I have considered is polling the VPS although I am not very familiar with how to implement it. I would imagine that I would do it using php scripts, but I am still learning php. Would it be easier to implement my raspberry pi control using a polling method? Just as further information, I am already going to be transferring a small amount of data from the pi to the VPS about once every 1-5 minutes.
Thank you for any help you guys give!

seitensei
Posts: 3
Joined: Mon Feb 16, 2015 2:57 pm

Re: Raspberry Pi and Android Phone Communication

Mon Nov 21, 2016 5:37 am

Have you looked into writing an application that exposes a HTTP REST API for the Pi and Android device to access?

If you're looking to have the Android trigger the Pi, you can have the Android device send the 'trigger' to the server instead, and the Pi will send a HTTP GET request to the server every X seconds/minutes/hours to see if it has been triggered or not. If triggered, it POSTs the data to the server.

This should be workable with both shared hosting and VPS. The former might require you to write your application on the server in PHP (or anything else on CGI), the latter would let you use any other language you wanted.

paulalexander66
Posts: 1
Joined: Wed Nov 23, 2016 11:09 am

Re: Raspberry Pi and Android Phone Communication

Wed Nov 23, 2016 11:35 am

Hi gboud21 ,

I maybe can't help with all your topics, but I think some problems are already are solved. I've just finished a project where it is possible to communicate with an an Android app to a Raspberry pi via SSL/TLS. An the Raspberry pi there is a Python SSL Server running. This Server can call other scripts/commands. These calls don't have to programmed these only have to be configured in a specific file.
The commands how can call these scripts/commands on the raspberry can also be configured for the Android app.
If you are interested look at http://iot4pi.github.io/SSLPi/.

Return to “Networking and servers”