Communication between Raspberry pi and Android studio Application - android

I've created a mobile application using android studio to control some leds and sensors, so I'd want to connect my mobile application to my raspberry pi to send and receive data, is that possible? i.e. I want to write a code in the raspberry pi (ex:connect.py) and my mobile application that connects the two together.

Congrats on stepping into IoT!
The best way to get this done is by connecting your mobile application to a database and the same database to your raspberry pi as well.
The raspberry pi will be listening to the changes made on the database and trigger the functions like sending an email or moving a robo arm accordingly. The database is only responsible to act as a bridge between the app and the microcontroller.
And how do you connect to the database you may ask? You use APIs for that on both the client sides.
The mobile app can be used to send instructions like switch on the motor or receive data logs from the MCU. Again, the database is where each is connected.
You can check out one of my video demos on this at https://www.linkedin.com/feed/update/urn:li:activity:6731591459058839552/
Happy coding! :)

Related

Communicate between two (and more) Flutter applications using flutter_bluetooth_serial

I'm developing Flutter app for Android, where I want to exchange some data between few instances of my app on different devices via Bluetooth. I'm using flutter_bluetooth_serial package (this is the only package I found which supports Bluetooth Classic, not Bluetooth Low Energy). I'm able to make connection
between device 1 and device 2 using BluetoothConnection.toAddress(device.address); (but even there was a problem, I had to modify the plugin and apply this workaround to make connection work).
Now I want to run my app on device 2 (which is connected with device 1) and send or receive some data, but I have no idea how I can do that using flutter_bluetooth_serial. In device 1 where I create connection I can use result of BluetoothConnection.toAddress(device.address) to send or listen for some data, but on device 2 I can't use it, because connection is already established by device 1 and I can't see another API for communication.
To simplify: let's say I want to achieve something more or less like Bluetooth chat functionality in this example application, but between multiple Flutter applications, not Flutter app and raspberry pi.
Is there any way of solving it with use of flutter_bluetooth_serial or any other package? Or I have to write some native Android code?

How to authenticate bluetooth communication between Raspberry and Android

I created an application on the Raspberry (using QT bluetooth module) that publishes a service with a specific UUID and waits on a rfcomm socket. I was able from my Android application to pair with the Raspberry, to find the service and exchange data using sockets. The Android application simply asks to the user if he wants to pair with the Raspberry, without pin confirmation. Now I would like to add an authentication step, a simple pin or passkey, to allow the connection only to those who know it. I can change the Android application to show a dialog allowing the user to insert the pin, in such a way the application on Raspberry can verify the correctness of the pin and eventually close the socket, but this solution is obviously valid only for the devices with my application. Is there a way to implement a similar solution during the pairing process, in order to make it available to every devices? I tried among the QT functions but I didn't find anything that could help me. Thank you
There is a flaw in your design which is if you plan on authenticating with a pin the raspberry pi needs some way to tell the user what the pin should be. If you don't have a screen or output of some kind on the raspberry pi then the pin would be useless because you have no way to generate a random pin and then tell the user what it should be.
Depending on the application you are usually fine not having an authentication pin ect. Think about most Bluetooth devices you use, none of them have any authentication you can just click pair.
Here are some other options I can think of:
1) Detect when you have already connected to a device on the raspberry pi and not broadcast the service so once you are connected to a device another device cant also connect and cause issues.
2) Have a button on the raspberry pi and only broadcast the publish service for 1 min after pressing the button
3) get a screen or someway of outputting information to the user from the raspberry pi to show them the pin to enter on their phone

send string variable from raspberry pi 2 to android app over bluetooth

I am developing an android app using android studio to receive string(results) from raspberry pi after image processing code .
I am using python 2.7.3, opencv 3.1, numpy 1.8.
bluetooth chip RN42XVP connected to the raspberry pi 2
I read this question
Receiving data from raspberry pi in android via bluetooth
I tried it but it gave too many errors and undefined variable!
anyway I think it is not specifically what am searching for.
what i need is simply to send the content of string from a python code on raspberry pi to android application.
when a button clicked in android app it will receive and display the content
The following is the general approach: read the manual
Read the data sheet, it has all the information on how to connect and talk to the device. You need to figure out the following:
How do you want to connect to the device (the product page mentions UART or USB).
depending on your choice you figure out what hardware this module needs in order to run (Capacitors, Voltage supply, etc.).
After that you connect the device to USB- or UART-capable pins on your Raspberry Pi.
Then you want to open a device file descriptor on you raspberry pi, which talks to those pins. (Normally a open(file, "w") should be sufficient). (If you are not sure, refer to the Raspberry Pi documentation or google it.)
Everything you write into this file descriptor gets sent to the wireless module.
Figure out how to communicate with the module (what commands you need to send, how to set it up, etc.).
Write your python code.
After Googling it, it seems, that this is a very popular module and has already been used with Arduinos, maybe you can find a tutorial on how to connect it, I'm pretty sure that there also are some libraries already written, which spares you the hassle of writing everything yourself.
The following link describes how to connect the module with an Arduino, but it should be easy to do the same with your Raspberry Pi: http://dduino.blogspot.co.at/2012/03/arduino-rn-42-bluetooth-module.html

How to interract android applications with a raspberry PI ...?

I can program my Raspberry PI to control its GPIOs using Python or Wiring-PI C library.
I can control it with web interfaces like webiopi or web2py.
What I intend to do is write my own android app (layouts created by me only) and want this app to remotely acces the PI and run the code stored for the GPIOs control.
I want my Java code to control my C code remotely or something like that.
I have no idea what kind of libraries I need for this kind of interaction and I would appreciate any ideas.
As you can control your Raspberry Pi with web interfaces like webiopi or web2py, why not use REST API from your Android application.
REST API Client Library for Android
Restful API service
If you are looking for more ideas you may consider Bluetooth client server application with an Android client (on device) and Java/Python server (running on the pi)
Initializing bluetooth connection android(client) to python(server) on pc
you'll need to setup a server on your raspeberry pi to receive GET or POST calls.
Then from your Android app use all the normal, standard Java to call this web service and get a suitable response, e.g. GPIO status.
for example android App use a GET request to http://192.168.0.10:8080/GPIO/Toggle/3 your raspberry Pi server, listening to port 8080, will toggle GPIO 3 and reply back to Android 00001000 (meaning that GPIO 3 is On).
But that's just one possible idea, you could use a library like Kryonet to communicate over traditional sockets.

I want to be able to send data from a kinect to an android app

I am working on a dual application on android sdk and kinect sdk. I want to be able to have the kinect send data to a smartphone application. The smartphone application will then give notifications to the user based on the kinect data. The smartphone should be able (hopefully) to turn the kinect on/off and maybe a few other basic commands. How can I get the kinect and smartphone application communicate?
Cool concept, I'm a huge fan of the Kinect (when used on Windows; I think it's a gimmick for the Xbox).
For starters, you can't directly interface with the Kinect from a smartphone. Kinect needs a USB connection, external power, and a Windows 7 machine with a 2.6 GHz dual core processor. So now it becomes a question of connecting a server application running on the Windows 7 machine and a client application on the Android phone. There's a few ways you could do this (USB, WiFi, TCP), but all of them suffer somewhere. USB would tether you to the computer, making the smartphone app redundant (just use the computer since you're already connected to it). WiFi is probably the best choice if you intend to send serious amounts of data, but would only work in your house. TCP (or UDP) could work for some applications, but if you start trying to stream video your phone will hate you.
I'm going to assume you're not going for a data-heavy application (video streaming to phone). If you're just looking to send off notifications from the Kinect to the Android (for example, use the Kinect as a motion detector and send messages to the Android when someone enters the room), similar to a text message update, you could certainly pull off the TCP/IP solution, and probably quite easily. You'd set up a simple TCP server on the Windows 7 computer with the Kinect, and then connect to it with a TCP request (look at the Client side code). Once you've got that set up, it's easy to send messages between the Kinect and the smartphone app. For starters, just try to get a few quick messages sent over. Server says "HI THERE", Android replies "I HATE YOU WINDOWS", etc, and make sure the messages are making it to their destination (TCP pretty much guarantees they will). After you have that running, just build your apps up around it.
If you're willing to eschew the use of the official Microsoft SDK, the Point Cloud Library (built on top of OpenNI) has a framework and tutorial in place for streaming.

Categories

Resources