Raspberry pi android bluetooth

Raspberry Pi Bluetooth Data Transfer to the Smartphone

In addition to some wireless connections such as 433Mhz, infrared and NFC, Bluetooth is probably the most common and popular mode of data transmission between smartphones, which is why the Raspberry Pi Bluetooth data transfer is interesting. Meanwhile, pretty much all devices support Bluetooth and can not only be paired with it but of course, you can also transfer data, which is interesting for projects such as a Car PC.

This tutorial will show you how to exchange files between Raspberry Pi and a Bluetooth-enabled mobile phone/smartphone.

Required Hardware Parts

The Bluetooth adapter can have a significant impact on the range. Cheap devices often do not recognize the connection after a few meters or obstacles, whereas higher-quality dongles also work up to a distance of 30 meters (outdoors).

Setting up the Software

First, some packages have to be installed:

sudo apt-get install bluez-utils libopenobex1 obexftp obexpushd --yes

After the USB Bluetooth dongle is connected, we check if it has been recognized correctly:

If a device has been detected, it will look like this:

raspberry pi bluetooth console

Now we check if the Bluetooth service has already been started (it is automatically loaded every time you restart).

sudo service bluetooth status

For the device to be connected, it (smart phone) must be searched for. It starts a scan, which should find all devices in the immediate vicinity.

The mobile phone should be found directly. If not, wait a few seconds as the last result is cached. If it’s detected, it will look like this:

pi@raspberrypi ~ $ hcitool scan Scanning . C4:42:02:41:B2:06 SM-G901F

This address of the device is important and will continuously be needed. In the following step, it must be changed according to your device address.

Читайте также:  Передача файлов через блютуз приложение

In order to connect the Pi and your mobile phone, this address must be specified (adjust it!):

sudo bluez-simple-agent hci0 C4:42:02:41:B2:06 yes

Then you will be asked for a code which you also have to enter on the mobile phone (for example 1234).
After that, the devices should be connected.

Send Files with the Raspberry Pi Bluetooth Module

Files can be sent on different channels. To find out which OBEX channel your smartphone uses, you can use the following command:

browse C4:42:02:41:B2:06 | egrep "Service Name:|Channel:"

Now you have to see which channel is under “OBEX Object Push”. For me, that is Channel 12.

To transfer a file (here ~/TEST.txt ) you have to specify the following command (do not forget to change it):

obexftp --nopath --noconn --uuid none --bluetooth C4:42:02:41:B2:06 --channel 12 -p ~/TEST.txt

Subsequently, a request will pop up on the smartphone, which must be confirmed.

A number of other examples of obexftp can be found here.

Receive Files using Raspberry Pi Bluetooth

To receive files, we start an FTP server on the Raspberry Pi, which is waiting for files. With screen, the server can also be run in the background.

Now you can select the file to be sent on the smartphone and send it to the connected Pi. Of course, depending on the size, it can take a bit. The file is created in the directory from which the server was started.

Finally, it should be said that the connected devices remain stored and no reconnecting is necessary, as long as both devices (Raspberry Pi Bluetooth Module and a terminal device such as a smartphone) are within reach of each other.

Control all GPIOs with the Raspberry Pi REST API via Python

Using TensorFlow Lite with Google Coral TPU on Raspberry Pi 4

How-To: Bluetooth Connection between ESP32’s and Raspberry Pi’s

Raspberry Pi Samba Server: Share Files in the Local Network

6 Comments

pi@raspberrypi:~ $ sudo apt-get install bluez-utils libopenobex1 obexftp obexpushd –yes
Reading package lists… Done
Building dependency tree
Reading state information… Done
Package bluez-utils is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
bluez

Package libopenobex1 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Читайте также:  Bluetooth наушники ac robin echo

E: Package ‘bluez-utils’ has no installation candidate
E: Package ‘libopenobex1’ has no installation candidate

My data:
Static hostname: raspberrypi
Icon name: computer
Machine ID:
Boot ID:
Operating System: Raspbian GNU/Linux 10 (buster)
Kernel: Linux 4.19.75-v7+
Architecture: arm

Try
sudo apt-get update
then
sudo apt-get upgrade

Try
sudo apt-get update
then
sudo apt-get upgrade
NO effect, same problem as Timon Yoder

Transfer from LT to RPi, where does it save?

In this example, it will be in whatever folder you were running the command from. Other examples on the web tell you to create a folder, and then specify the file transfer location using the -o option. Here’s what I was using on my old setup. sudo obexpushd -B -o /home/pi/Documents/file_transfer -n

How can I transfer data , movie, songs etc from my Android phone to raspberry Pi 4

Источник

Управление контактами ввода/вывода (GPIO) Raspberry Pi через Bluetooth и Android приложение

Плата Raspberry Pi находит широкое применение в различных проектах, относящихся к тематике интернета вещей (Internet of Things, IoT), во многом благодаря тому что у нее есть встроенные Wi-Fi и Bluetooth, в настоящее время являющиеся самыми популярными протоколами беспроводной связи. В данной статье мы рассмотрим управление контактами ввода/вывода (GPIO) платы Raspberry Pi через Bluetooth и Android приложение. Ранее на нашем сайте мы рассматривали аналогичный проект для платы Arduino.

Внешний вид проекта управления контактами ввода/вывода (GPIO) Raspberry Pi через Bluetooth и Android приложение

В данном проекте мы использовали плату Raspberry 2 Pi Model B, у которой нет встроенного модуля Bluetooth, поэтому для использования в ней возможностей данного протокола мы использовали простой USB Bluetooth адаптера. Для демонстрации возможностей данного проекта мы использовали светодиод, подключенный к плате Raspberry Pi через резистор 220 Ом. В данном проекте для беспроводной связи между смартфоном и платой Raspberry Pi мы использовали протокол RFCOMM Bluetooth.

Программирование Bluetooth в языке Python основано на концепции программирования сокетов (socket programming) и взаимодействие между Bluetooth устройствами в данном случае осуществляется через RFCOMM сокет. RFCOMM (Radio Frequency Communication) представляет собой Bluetooth протокол, который обеспечивает эмуляцию последовательного порта RS-232 и также известен под именем Serial Port Emulation. Профиль последовательного порта Bluetooth основан на этом протоколе. RFCOMM является достаточно популярным приложением Bluetooth поскольку он обеспечивается хорошей поддержкой и имеет свободно доступные инструменты API

Для работы с данным протоколом в нашем проекте мы будем использовать Bluetooth модуль HC-06, на нашем сайте вы можете посмотреть все проекты, в которых он был использован.

Читайте также:  Bluetooth гарнитура hbh 610

Установка необходимых пакетов для работы с Bluetooth в Raspberry Pi

Первым делом нам необходимо установить последние обновления для операционной системы Raspberry Pi OS:

Источник

How to connect to Raspberry pi with an android app over bluetooth

I’m having trouble connecting my smartphone to my raspberry pi over bluetooth using an app. My situation: I’m developing a bluetooth controllable application based on a raspberry pi. I’m able to connect to the raspberry pi over bluetooth and send and receive data over an RFCOMM socket using the app «bluetooth terminal». The raspberry pi is constantly listening for RFCOMM connection. My goal: I want to develop an app in which the user can connect with the raspberry pi over bluetooth. The app should open the RFCOMM socket so it can communicate with the pi. My problem: My app is not able to connect to the raspberry pi and since i don’t know the UUID of the raspberry pi, i think that might be the problem. My code: I’m quite new to java programming so correct me if you see anything strange. This is the method which i’m trying to connect with.

 public void BTConnect() < final UUID MY_UUID = UUID.fromString("0000110E-0000-1000-8000-00805F9B34FB"); BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); BluetoothSocket socket = null; String RPi_MAC = "XX:XX:XX:XX:XX:XX"; SetpairedDevices = mBluetoothAdapter.getBondedDevices(); // If there are paired devices if (pairedDevices.size() > 0) < // Loop through paired devices for (BluetoothDevice device : pairedDevices) < if (device.getAddress().equals(RPi_MAC)) < try < socket = device.createInsecureRfcommSocketToServiceRecord(MY_UUID); >catch (IOException e0) < Log.d("BT_TEST", "Cannot create socket"); e0.printStackTrace(); >try < socket.connect(); >catch (IOException e1) < try < socket.close(); Log.d("BT_TEST", "Cannot connect"); e1.printStackTrace(); >catch (IOException e2) < Log.d("BT_TEST", "Socket not closed"); e2.printStackTrace(); >> > > > > 
 W/BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback D/BT_TEST: Cannot connect W/System.err: java.io.IOException: read failed, socket might closed or timeout, read ret: -1 W/System.err: at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:599) W/System.err: at android.bluetooth.BluetoothSocket.readInt(BluetoothSocket.java:610) W/System.err: at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:333) W/System.err: at com.example.gebruiker.soundslikepi.MainActivity.BTConnect(MainActivity.java:80) W/System.err: at com.example.gebruiker.soundslikepi.MainActivity$1.onClick(MainActivity.java:39) W/System.err: at android.view.View.performClick(View.java:4856) W/System.err: at android.view.View$PerformClick.run(View.java:19956) W/System.err: at android.os.Handler.handleCallback(Handler.java:739) W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95) W/System.err: at android.os.Looper.loop(Looper.java:211) W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5373) W/System.err: at java.lang.reflect.Method.invoke(Native Method) W/System.err: at java.lang.reflect.Method.invoke(Method.java:372) W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020) W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815) 
  • Need to know what the UUID of the raspberry pi is, if so, how do i find out?
  • Need to use a different approach in my android app?

I would really like to know how to fix this problem, so any help would be appreciated.

Источник

Оцените статью
Adblock
detector