Community
cancel
Showing results for 
Search instead for 
Did you mean: 
IBanc
New Contributor I
1,648 Views

Bluetooth Problem

Hi,

 

I was trying to connect from an android app to Edison via bluetooth, just like Arduino and send some text. But when i am trying to connect edison disconnects me right away (android says connection lost).

bluetoothctl output:

  1. [CHG] Device C0:EE:FB:43:9D:73 Connected: yes
  2. [CHG] Device C0:EE:FB:43:9D:73 Connected: no

Android BT Service:

package com.itbstudios.indoorscale.bluetooth;

import android.app.Service;

import android.bluetooth.BluetoothAdapter;

import android.bluetooth.BluetoothDevice;

import android.bluetooth.BluetoothSocket;

import android.content.Intent;

import android.os.Binder;

import android.os.Bundle;

import android.os.Handler;

import android.os.IBinder;

import android.os.Message;

import android.util.Log;

import android.widget.Toast;

import com.itbstudios.indoorscale.GlobalActivity;

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

import java.util.ArrayList;

import java.util.UUID;

/**

* Created by iosif on 10/14/2015.

*/

public class BluetoothService extends Service {

public static final String SPP_UUID = "00001101-0000-1000-8000-00805F9B34FB";

public static int mState = GlobalActivity.STATE_NONE;

public static String deviceName;

public static BluetoothDevice device = null;

private static ConnectedThread mConnectedThread;

private static Handler mHandler = null;

private static Object obj = new Object();

private final IBinder mBinder = new LocalBinder();

private BluetoothAdapter mBluetoothAdapter;

private ConnectThread mConnectThread;

private Handler handler = new Handler() {

@Override

public void handleMessage(Message msg) {//

if (!Thread.currentThread().isInterrupted()) {

switch (msg.what) {

case 3:

break;

case 4:

break;

case 5:

break;

case -1:

break;

}

}

super.handleMessage(msg);

}

};

public static void write(byte[] out) {

// Create temporary object

ConnectedThread r;

// Synchronize a copy of the ConnectedThread

synchronized (obj) {

if (mState != GlobalActivity.STATE_CONNECTED)

return;

r = mConnectedThread;

}

// Perform the write unsynchronized

r.write(out);

}

@Override

public void onCreate() {

Log.d("BluetoothService", "Service started");

super.onCreate();

}

@Override

public IBinder onBind(Intent intent) {

mHandler = ((BluetoothApplication) getApplication()).getHandler();

return mBinder;

}

@Override

public int onStartCommand(Intent intent, int flags, int startId) {

Log.d("BluetoothService", "Onstart Command");

mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

if (mBluetoothAdapter != null) {

device = intent.getParcelableExtra(GlobalActivity.BT_DEVICE);

deviceName = device.getName();

String macAddress = device.getAddress();

if (macAddress != null && macAddress.length() > 0) {

connectToDevice(macAddress);

} else {

stopSelf();

return 0;

}

}

String stopservice = intent.getStringExtra("stopservice");

if (stopservice != null && stopservice.length() > 0) {

stop();

}

return START_STICKY;

}

private synchronized void connectToDevice(String macAddress) {

BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(macAddress);

if (mState == GlobalActivity.STATE_CONNECTING) {

if (mConnectThread != null) {

mConnectThread.cancel();

mConnectThread = null;

}

}

// Cancel any thread currently running a connection

if (mConnectedThread != null) {

mConnectedThread.cancel();

mConnectedThread = null;

}

mConnectThread = new ConnectThread(device);

mConnectThread.start();

setState(GlobalActivity.STATE_CONNECTING);

GlobalActivity.BluetoothConnectionStatus = GlobalActivity.STATE_CONNECTING;

}

private void setState(int state) {

BluetoothService.mState = state;

if (mHandler != null) {

mHandler.obtainMessage(GlobalActivity.MESSAGE_STATE_CHANGE, state, -1).sendToTarget();

}

}

public synchronized void stop() {

setState(GlobalActivity.STATE_NONE);

GlobalActivity.Blu...

12 Replies
idata
Community Manager
186 Views

Hello Iosif,

 

 

When you get the output:

 

 

1. [CHG] Device C0:EE:FB:43:9D:73 Connected: yes

 

2. [CHG] Device C0:EE:FB:43:9D:73 Connected: no

 

 

What steps did you take? What exactly did you do both on the Edison and the Android device?

 

 

Peter.
IBanc
New Contributor I
186 Views

I followed exactly those steps.

 

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® Developer Zone

The error is visible in bluetoothctl when trying to connect from Android. Bluetooth Advanced Tools SPP app used in the tutorial is not able to see the device at all. So i have my own app which is working with HC-05 on Arduino. Also i tried many apps on Android with the same result. I also created a com port on my Windows PC and tried to open the Arduino IDE console and monitor the port. When trying to connect i get Unable to open communication PORT.

Managed to connect from my windows machine on the same port to Arduino HC-05 also.

Thanks!

idata
Community Manager
186 Views

Could try the steps found in https://communities.intel.com/docs/DOC-100754 https://communities.intel.com/docs/DOC-100754? What happens? Does the Edison still have issues connecting?

 

 

Peter.
IBanc
New Contributor I
186 Views

The same... Already tried

idata
Community Manager
186 Views

These are the steps I took to connect my Edison to a Nexus 5:

rfkill unblock bluetooth

 

bluetoothctl

 

scan on

 

# Found device

 

scan off

 

pair XX:XX:XX:XX:XX:XX:XX

 

trust XX:XX:XX:XX:XX:XX:XX

 

connect XX:XX:XX:XX:XX:XX:XX

As you can see in the screenshot bellow the connection was successful:

Peter.

IBanc
New Contributor I
186 Views

try to connect from Nexus 5 to Edison and please tell me if it works....

so don't type connect MAC, try to connect from your smartphone using an app like SPP Pro https://play.google.com/store/apps/details?id=mobi.dzs.android.BLE_SPP_PRO Bluetooth spp tools pro - Android Apps on Google Play - the one intel uses in theyr bluetooth video tutorials and not only.

idata
Community Manager
186 Views

These are the steps I took:

On Edison:

rfkill unblock bluetooth

 

bluetoothctl

 

agent DisplayYesNo

 

default-agent

 

pairable on

 

discoverable on

 

*Say yes to the permission requests

On Nexus 5:

Find phone, pair and connect.

Peter.

IBanc
New Contributor I
186 Views

Hi,

Like this it is working on mine to (connecting from settings) but please try from any Serial Profile App, like in this video

 

https://software.intel.com/en-us/videos/connecting-bluetooth-devices-to-your-intel-edison https://software.intel.com/en-us/videos/connecting-bluetooth-devices-to-your-intel-edison

Also attached the log bellow

Ps. Peter can I have your Skype in a PM? Maybe we can do a share screen to show you! Also is it possible that my Edison is faulty (a better way to say it, is it possible mine to have a faulty BT module)?

Thanks!

Br

 

Iosif
IBanc
New Contributor I
186 Views

I found the BIG PROBLEM, and it is a big one!

It's a software image 3.0 bug. Flashed 2.1 "edison-iotdk-image-280915" and worked using tutorial.

Please try what i told you and tell me if you have the bug that i had in 1.7.3.

EDIT: Managed to port the SPP Protocol from prev build to the latest and with some code changes regarding the way bluez and kernel are opening port for serial com and closing it. In my case it was more about a handshake error. Because the handshakeing was not completed successfully, kernel and bluez were closing the port (service and connection also) doing to TIMEOUT on the connection.

 

Thank You!
idata
Community Manager
186 Views

Hi losif,

 

 

I just tested it on both the current image and the previous image, and I believe I'm seeing the same behavior as you. I can establish the SPP connection on the previous version (159.devkit) but not on the current one (3.0).

 

Let me see what I can find out about this, in the meantime I'd suggest you to go back to the previous image to continue with your project.

 

 

Peter.
IBanc
New Contributor I
186 Views

Already back on prev. build. Also i played with bluez and changed few things. It's working perfectly on this build. Of course I would like to see it fixed in next builds.

If you want, you can mark it as answered.

 

Thank You!
idata
Community Manager
186 Views

Hello losif,

 

 

I have an update for this issue. You can try the following workaround to fix it on the latest image:

 

 

On the latest image (Yocto 3.5), enter the command:

 

opkg install --force-reinstall http://iotdk.intel.com/repos/3.5/iotdk/edison/core2-32/bluez5_5.37-r0_core2-32.ipk

 

 

Also, I've been informed that this issue is in consideration for a future release of Edison software, so hopefully it will be fixed soon.

 

 

Let me know how it goes.

 

-Peter.
Reply