sidsst
Posts: 4
Joined: Mon Jun 18, 2018 6:57 am

Trigger RaspberryPi events from Android App

Mon Jun 18, 2018 7:07 am

Hi ,
I am developing a project in which I want my raspberry Pi 3 and the android app to interact over wifi. I want them both to be in client mode. (Already know how to implement from pi's AP mode) . I want to have a utility where on pressing a button on the App I can control the bluetooth of pi and receive a list of devices that pi finds. Is it possible to do this ?

Any help will be appreciated. Been trying and searching for a lot of days now.
Thanks.

hippy
Posts: 7911
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Trigger RaspberryPi events from Android App

Mon Jun 18, 2018 11:04 am

It should be possible. MIT App Inventor 2 is simple to use to create Android Apps and can be used to read a file from a server, parse that, handle and display the returned data. All you would need is a server on a Pi which can handle requests, check what Bluetooth devices are found, and returns that data. It is quite easy to create or extend servers on a Pi using Python and other languages.

I am doing something very similar to keep my Android phone DVD collection list App updated from my PC. That PC could easily be a Pi.

sidsst
Posts: 4
Joined: Mon Jun 18, 2018 6:57 am

Re: Trigger RaspberryPi events from Android App

Mon Jun 18, 2018 11:12 am

In my case both my Pi and my android phone will be connected to a single wifi. I want to communicate between the two devices over this wifi. If you are talking about pi being an AP standalone server , I unfortunately do not need that. If it is something else , could you please suggest me how to do it. Thanks. Been stuck on it for 2 months now :|

hippy
Posts: 7911
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Trigger RaspberryPi events from Android App

Mon Jun 18, 2018 11:24 am

sidsst wrote:
Mon Jun 18, 2018 11:12 am
In my case both my Pi and my android phone will be connected to a single wifi. I want to communicate between the two devices over this wifi. If you are talking about pi being an AP standalone server , I unfortunately do not need that. If it is something else , could you please suggest me how to do it. Thanks. Been stuck on it for 2 months now :|
My set-up is Android to WiFi router, PC to WiFi router, that could be Pi to WiFi router. No AP except for that router itself acting as one.

If you can access your Pi when it's an AP, it should be just the same to access it when the Pi is connected to a WiFi router. The Pi might get a different IP address and you would have to change that on the Android App but that should be all you need to do.

It should 'just work', everything connected to the WiFi router should be on the same network, the local LAN, though you might have to tweak the router settings to allow it to work.

Perhaps describe what you have done, what doesn't work, what errors messages or problems you are getting.
Last edited by hippy on Mon Jun 18, 2018 11:27 am, edited 1 time in total.

sidsst
Posts: 4
Joined: Mon Jun 18, 2018 6:57 am

Re: Trigger RaspberryPi events from Android App

Mon Jun 18, 2018 11:26 am

My set-up is Android to WiFi router, PC to WiFi router, that could be Pi to WiFi router. No AP except for that router itself acting as one.
Can you please share the code of how you do it. The client and server part that is. Not for the app. Thanks a lot.

hippy
Posts: 7911
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Trigger RaspberryPi events from Android App

Mon Jun 18, 2018 11:36 am

This is a simple Python 2.7 server -

Code: Select all

#!/usr/bin/python

import BaseHTTPServer

class HttpHandler(BaseHTTPServer.BaseHTTPRequestHandler):
  def do_GET(self):
    self.send_response( 200 )
    self.send_header("Content-type", "text/html")
    self.end_headers()
    self.wfile.write("<html><body>Hello!</body><html>")

BaseHTTPServer.HTTPServer(("", 80), HttpHandler).serve_forever()
Run that on your Pi with 'python filename.py', point your phone's browser to the Pi's IP address and it should show the "Hello!" page response.

Return to “Networking and servers”