Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
New Contributor I
2,608 Views

Using the Intel Edison to send data to an Android app with BLE?

Greetings.

I found https://github.com/devunwired/accessory-samples/blob/master/BluetoothGatt/src/com/example/bluetoothg... here some sample code how to read bluetooth data in an Android app that is being received, but I need to be able to send some data through my Edison module. For instance, how would I send a "signal" to my Android app, maybe a JSON file or just string that is JSON?

The goal is to let the Edison module discover bluetooth sensors/beacons (iBeacons/Eddystone) and then report this to the Android app. I have successfully paired the devices (Edison runs Yocto and it has BlueZ so I used the command "bluetoothctl") but I am not sure how I should send data. I know I can use OBEX or maybe SPP as a profile, but then how do I send the data through the profile from the Edison module to the Android app? Do I need to use RFCOMM sockets (https://software.intel.com/en-us/forums/internet-of-things/topic/542726 this had some information regarding it)?

I have looked at these guides but none tell how to actually send data:

 

https://software.intel.com/en-us/articles/connecting-the-intel-edison-board-to-your-android-phone-wi... IoT - Connecting the Intel® Edison board to your Android* Phone with Serial Port Profile (SPP) | Intel® Software

https://software.intel.com/en-us/forums/internet-of-things/topic/542726 Send Data From Edison to Android App?

https://software.intel.com/en-us/articles/intel-edison-board-getting-started-with-bluetooth IoT - Intel® Edison Board Getting Started with Bluetooth* | Intel® Software

This https://software.intel.com/en-us/articles/connecting-to-intel-edison-from-android-with-bluetooth-le-... guide though did tell me how to send some data using the Grove starter kit, but I could not get it to work as all the values were hard coded for this network card. Maybe it would work if I can get the right values for the Edison.

All information is highly appreciated! Thanks.

13 Replies
Highlighted
Community Manager
23 Views

Hi,

 

 

It seems that you have done a good research about this. I haven't tested something similar to what you are trying to do, however, I found another guide that you might find useful. I'm not sure if you have checked it already, but I share the guide anyways: https://software.intel.com/en-us/blogs/2015/05/19/communicate-to-arduino-code-with-your-android-phon... https://software.intel.com/en-us/blogs/2015/05/19/communicate-to-arduino-code-with-your-android-phon...

 

 

I'll keep looking for additional information about this. In the meantime, please let us know if you have ran additional tests about this so we can try to help you.

 

 

-Sergio

 

0 Kudos
Highlighted
New Contributor I
23 Views

That is a good guide I have missed. I have read it through but I cannot do the last step: the BLE_SPP_PRO app cannot find my device. I have successfully paired my phone to my Edison module, scan on and discoverable is on, but the app cannot find my module.

Even if this worked then I am not sure how my Edison module can speak back to my phone. Through the app I can, following the guide, send some data to it. But I need to be able to do the other way around.

Do you know how I can achieve this?

Thank you.

0 Kudos
Highlighted
New Contributor I
23 Views

Whenever I try the bluetooth service I get an error:

root@jayway-edison:~# systemctl status -l bluetooth-spp-pin

● bluetooth-spp-pin.service - Bluetooth SPP and PIN service

Loaded: loaded (/lib/systemd/system/bluetooth-spp-pin.service; enabled)

Active: active (exited) since Fri 2016-08-05 11:08:37 UTC; 19s ago

Process: 285 ExecStart=/home/root/bluetooth/bluetooth-spp-pin.sh (code=exited, status=0/SUCCESS)

Main PID: 285 (code=exited, status=0/SUCCESS)

Aug 05 11:08:38 jayway-edison systemd[1]: Started Bluetooth SPP and PIN service.

Aug 05 11:08:41 jayway-edison bluetooth-spp-pin.sh[285]: Can't get device info: No such device

Not sure if this is supposed to be, if the script should not be able to find the device. I cannot however still find my Edison module through the app.

0 Kudos
Highlighted
Community Manager
23 Views

Have you already checked the Bluetooth guide http://download.intel.com/support/edison/sb/edisonbluetooth_331704007.pdf http://download.intel.com/support/edison/sb/edisonbluetooth_331704007.pdf ? It contains useful information that might help you configure Bluetooth.

 

 

Let us know your results.

 

 

-Sergio

 

0 Kudos
Highlighted
New Contributor I
23 Views

Yes, I have looked at it.

The section 6.7.1 SPP verification using DBUS APIs only shows how to receive data:

"And on the Intel® Edison side, you can see the data received and retransmitted back:

root@edison:~# python ./SPP-loopback.py –C 22

NewConnection(/org/bluez/hci0/dev_98_0D_2E_C8_BD_2C, 10)

received: cmd line mode testing SPP test

received: byte mode testing SPP profile in Edison"

How do I send data BACK to the Android device?

0 Kudos
Highlighted
Community Manager
23 Views

Hi,

 

 

You can try to send/receive files with Obex. Obex is explained in section 6.13. You can see the guide here http://www.intel.com/content/www/us/en/support/boards-and-kits/000005743.html http://www.intel.com/content/www/us/en/support/boards-and-kits/000005743.html .

 

 

There's some interesting information about obex and transferring data with Bluetooth in these threads:Let us know your results.

 

 

-Sergio

 

0 Kudos
Highlighted
New Contributor I
23 Views

So the OBEX profile really is an FTP operation? Then I would need an FTP client in my Android app or build on myself? And I do not want to send files between them, just some strings. For instance if I have an id then I want to send only this, not put that in a file and send that file.

Is there any way of sending data back to the app from the module? Sending data from the app to the module seems to work throughout the mentioned tutorials, but I only want to do the same but with the module to the app. I want the module to trigger the app, so it really is just one way the data has to go, from the module to the app. Later it will also be app to module but for now only module to app.

0 Kudos
Highlighted
New Contributor I
23 Views

Hi zettez,

If you want just to send strings, try the SPP profile. I have a simple python code that a share some strings with a Android app.

On the Edison you should configure some things:

- Install Bluez, by download the source (wget this http://www.kernel.org/pub/linux/bluetooth/bluez-5.41.tar.xz link) and make install inside the folder. (you will need setuptools installed first)

- Enable the compatibility mode for rfcomm /thread/76926 see my post

- Enable the bluetooth:

rfkill unblock bluetooth

if it is the fist time, https://software.intel.com/en-us/articles/intel-edison-board-getting-started-with-bluetooth paring the Edison with your device using:

bluetoothctl

Then, Use this python code:

from bluetooth import *

import time

import subprocess

import socket

server = BluetoothSocket(RFCOMM)

server.bind(("",PORT_ANY))

server.listen(1)

port = server.getsockname()[1]

print 'port: ',port

uuid = "1101"

advertise_service( server, "SPP Service",

service_id=uuid,

service_classes = [uuid, SERIAL_PORT_CLASS],

profiles = [SERIAL_PORT_PROFILE])

data = 's'

while data != 'q':

cli, addr = server.accept()

print "accepted", addr

data = 's'

while data != 'q' and data != 'e':

try:

data = cli.recv(1024)

except btcommon.BluetoothError as error:

print 'Recv: ',error

data = 'e'

else:

print "data: ",data

if data == 't':

print 'send test string'

cli.send('test')

cli.close()

server.close()

Regards,

Rogerio

Highlighted
Community Manager
23 Views

Hi zettez,

 

 

Do you still need help with this thread, were you able to send data to an Android following rbulha's suggestion?

 

 

-Sergio

 

0 Kudos
Highlighted
New Contributor I
23 Views

Thank you for your reply. I cannot get this to work however. I followed what you wrote but I get this error:

root@edison:/home/bluetooth# python test.py

Traceback (most recent call last):

File "test.py", line 1, in

from bluetooth import *

ImportError: No module named bluetooth

Do you know why I cannot find the bluetooth module? I wget the bluez and installed it, there were no problems there. Maybe this module is somewhere else?

Searching for this issue, https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=45511 this came up: it said the problem was that python-bluez was not installed. Do I also need this dependency? I thought that was what the link was that you gave me. I found some github repos with this, but I am not sure which one to try.

Thanks!

0 Kudos
Highlighted
New Contributor I
23 Views

Hi zettez,

I forgot to say about install PyBluez!

You could do this using pip...

Fist get you board online..

Then I suggest checking the date, and adjust to the current date:

date --set="22 aug 2016 09:48:00"

Then, install pip

opkg update

pip install --upgrade pip

Then, install PyBluez

pip install --upgrade pybluez

This should solve the "ImportError: No module named bluetooth"

Regards,

Rogério

0 Kudos
Highlighted
New Contributor I
23 Views

Thanks, this made it all work. I had to restart the script a couple of times and also restart my app, but then it worked. I will update you or create a new thread if something else comes in.

0 Kudos
Highlighted
Community Manager
23 Views

Thank you for letting us know rbulha's suggestion resolved your issue. If you have any other questions don't hesitate to post in the community, we'd be happy to help.

 

 

-Sergio

 

0 Kudos