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

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

Related

Communication between Raspberry pi and Android studio Application

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! :)

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?

Bluetooth Serial Communication in Android with Ubuntu

I am trying to build an android app that can be controlled by a laptop with ubuntu installed via Bluetooth. What I want is to develop an android app that listens for incoming messages and performs particular actions according to the message. Basically I want the app to listen for Bluetooth signal (message) in the background while camera intent is open in the foreground and snap the picture when a particular message is received.
For that, I started learning about the Bluetooth serial communication and got to know about the following library on Github:
https://github.com/harry1453/android-bluetooth-serial/tree/master/demoApplication
I have replicated the demo application and the application is sending messages successfully, however when I send the message from Linux to the Android app it is not working. Can anyone help me regarding this issue or can suggest me some good tutorial to follow in order to build the app that can communicate with raspberry pi serially?
We know Bluetooth serial configuration is poorly documented (I read many questions here without any clear results.)
I believe it's due to the Raspberry Pi Bluetooth configuration issue based on your description.
With correct Raspberry Bluetooth serial configuration, your program with serial routines (written in Python using PySerial or serial routines written in C, which you can find it in github), your requirements (sending info about camera status via serial port will work.
Please see Bluetooth Serial Configuration (see latest answer) for more details.

Sending a command to Raspberry PI using an Android App

I'm currently working on a small project of simply controlling the lights in my apartment. I have a Raspberry Pi setup to control the lights with a 433 Mhz transmitter. I can send on/off commands to the lights using a "send code " command through the command line on the PI. I'm looking to create an Android App to do this for me, and I'm looking for a way to make this happen.
The Raspberry Pi is always connected to the internet, so I was thinking about hosting an Apache Webserver on it, and then somehow sending it commands from the app. Would anyone know how to go about doing this? I have little knowledge about Apache or webservers to begin with, but my basic google searches have pulled up ideas about using http posts.
Would figuring out how to use an HTTP post be the best course of action, or is there an easier way?
There are many options but probably some Python web framework running on your Raspberry PI will do the job (Twisted, Django or many other).
Python is preinstalled in the PI so it could be the easier choice.
Your Android app will then run HTTP requests (using HttpClient or something more elaborated) to the Python web server that will run in response the bash code.
The real problem comes when you will want to secure your end point (via login or whatever secret sent via Https) to be sure you are the only one switching on/off your lights :)
Personally I'd use an SSH library such as jsch to create a simple android app that sends the desired commands to your raspberry pi, on the press of a button. Of course, if you need to learn how to make an android app, have a look here first.

Getting started with Bluetooth development for Android: Suggestions for test application

I have a task to integrate a Bluetooth device into my application. Now my requirement is very specific. The device has a specific communication protocol which relies on certain ACKs but I figured it would make my development much easier if there was a program that let me test communication with the device.
I was wondering if there was a program for Linux, or perhaps a simple Android program which let me communicate with any Bluetooth device with a series of pings using data I enter and simply log the responses.
EDIT: I might not have been clear enough in my question.
I have a scale that I need to integrate into my application, and the scale has a protocol similar to this:
Get a specific byte string from device
Transfer data
Transfer packet for disconnection
Receive acknowledgement for disconnect packet
Disconnect
Now when I have to issue a POST request from my application, I usually build a test script online so I can test if the POST works properly.
I was wondering if there was something similar I could do with the device.
Thanks
Your question is not clear enough. To communicate with a BT device, you need to know what profile your device supports. Depending on that, you can find a way in Android or Linux or windows to communicate with the device.
The simplest way is to open an RFCOMM channel from android/PC and transfer data to and from the device. For this the device has to support the serial port profile (SPP). If you want to do this in Android, look for the BluetoothChat example from google.
If you want to use a PC/mac/linux look at the Bluez python module. It's really simple to use. There are plenty of other options too..
I was looking for something like SENA BTerm. It lets me connect to any device and send whatever data I wish.
It is an extremely useful tool for testing my code.
http://www.sena.com/download/manual_bterm/overview.html is where you can find it.

Categories

Resources