Bluetooth Connection
응답
17. 3. 30 오전 10:01

Dear XDK community,

I am totally new to Bosch XDK device. Recently, I was trying to connect the XDK direclty to the laptop via bluetooth and exchange sensors data, instead of using the Alpwise application. i have already went through BLE guide and it has quite helped me.

But I am still confused about the alpwise thing. Is it neccesary to use the alpwise mobile application to connect via bluetooth or can I connect the bluetooth directly to the laptop? If yes, what is the function that is resposible of turning the BLE in XDK on and make it appears to other devices?

Any help, example, resource is highly appreciated.

Thanks in advance and kindest regards,

0 (0 투표)
RE: Bluetooth Connection
응답
17. 4. 2 오후 10:47 as a reply to Michael Kneissl.

Hello Michael,

Welcome to the XDK community.

You are not limited to the Alpwise App to receive data from the XDK via BLE. 

You can use any other device with BLE functionality to connect to the XDK and receive data of the specific Bluetooth service.

There is an smartphone application "BLE scanner app" which can be used in the same manner to receive and display the BLE data.

The instantiation of the XDK as peripheral BLE device is responsible for "turning on the BLE" on the XDK. But please note that if you want to receive specific sensor data, this is a functionality that need to be implemented.

Fortunately the example "SendAcceleromerterDataOverBLE that is available via the welcome screen of the XDK workbench implements exactly this use case.

Please tell me if this is helpful and do not hesitate to ask if you have further questions.

Kind regards,
Franjo

0 (0 투표)
RE: Bluetooth Connection
응답
17. 4. 3 오후 12:59 as a reply to Franjo Stjepandic.

Hello Frajno,

 

Thank you very much for answer. The BLE scanner app worked perfectly, unlike the Alpwise app (it has data transmit issues).

 

Moreover, can you please tell me which exact function is responsible of turning the BLE on ? 
 

I tried to do but didn't work. You can have a look on the simple code I wrote for just connecting to XDK_BLE and returning the MAC address, please.

.C FILE


/* system header files */
#include <stdio.h>
#include "BCDS_Basics.h"

/* additional interface header files */
#include "BCDS_Assert.h"
#include "PTD_portDriver_ph.h"
#include "PTD_portDriver_ih.h"
#include "FreeRTOS.h"
#include "timers.h"
#include "task.h"
#include "XdkSensorHandle.h"
#include "BCDS_Accelerometer.h"
#include "BLE_stateHandler_ih.h"
#include "BLE_serialDriver_ih.h"
#include "BleAlpwDataExchange_Server.h"
#include "XdkUsbResetUtility.h"

/* own header files */
#include "XdkApplicationTemplate.h"

/* constant definitions ***************************************************** */

/* local variables ********************************************************** */

/* global variables ********************************************************* */

/* inline functions ********************************************************* */

/* local functions ********************************************************** */

static void notificationCallback(BLE_connectionDetails_t connectionDetails)
{

    switch (connectionDetails.connectionStatus){

		 case BLE_CONNECTED_TO_DEVICE:
			 printf("Device connected: %02x:%02x:%02x:%02x:%02x:%02x \r\n",
			 connectionDetails.remoteAddress.addr[0],
			 connectionDetails.remoteAddress.addr[1],
			 connectionDetails.remoteAddress.addr[2],
			 connectionDetails.remoteAddress.addr[3],
			 connectionDetails.remoteAddress.addr[4],
			 connectionDetails.remoteAddress.addr[5]);
			 break;

		 case BLE_DISCONNECTED_FROM_DEVICE:
			 printf("Device disconnected!\r\n");
			 break;

		 default:
        /* Assertion Reason : "invalid status of Bluetooth Device" */
			assert(false);
			break;
    }
}


static void bleAppHandler(void *pParameters)
{

    BCDS_UNUSED(pParameters); /* to quiet warnings */

    /* return variable for stack receive status from base band */
    BLE_return_t bleTrsprtRetVal;

    /* return variable for BLE state handler */
    uint8_t bleStateHandleRetVal;

    for (;;)
    {

        /* Notify the BLE Stack that some data have been received from the Base band(Chip) or Host */
        bleTrsprtRetVal = BLE_hciReceiveData();

        /* This function is used to run the BLE stack and register a BLE device with the specified role */
        bleStateHandleRetVal = BLE_coreStateMachine();

        UNUSED_PARAMETER(bleTrsprtRetVal);
        UNUSED_PARAMETER(bleStateHandleRetVal);
    }
}


/* global functions ********************************************************* */

void init(void)
{


	 // BLE implementation here
	 BLE_notification_t configParams;
	 BLE_returnStatus_t bleRetStatus;
	 BleStatus appInitReturn = BLESTATUS_FAILED;

	 BLE_setDeviceName((uint8_t *) BLE_DEVICE_NAME, BLE_DEVICE_NAME_LENGTH);

	 // callback function to react accordingly to the connection events
	 configParams.callback = notificationCallback;
	 // configuration to enable connection event notifications
	 configParams.enableNotification = BLE_ENABLE_NOTIFICATION;
	 // set configuration parameters to BLE stack
	 bleRetStatus = BLE_enablenotificationForConnect(configParams);
	 if (bleRetStatus == BLE_INVALID_PARAMETER){
		 // invalid configuration
	 }

	 /* Initialize the whole BLE stack */
		 appInitReturn = BLE_coreStackInit();
		 if (BLESTATUS_FAILED == (appInitReturn))
		 {
			 /* Assertion Reason : BLE Boot up process Failed, */
			 assert(false);
		 }

}



void appInitSystem(xTimerHandle xTimer)
{
	 (void) (xTimer);

	 int taskStackDepth = 1024;
	 int taskPriority = 1;
	 // Create task
	 init();
	 if (pdPASS
	 != xTaskCreate(bleAppHandler,
	 (const char * const) "BLE",
	 taskStackDepth, NULL, taskPriority,0))
	 {
	 //SW timer was not started, due to insufficient heap memory
	 }
}

.h file:

.h FILE





/* header definition ******************************************************** */
#ifndef XDK110_XDKAPPLICATIONTEMPLATE_H_
#define XDK110_XDKAPPLICATIONTEMPLATE_H_
#define ONESECONDDELAY 			      UINT16_C(1000)	               /**< one second is represented by this macro */
#define TIMERBLOCKTIME 			      UINT16_C(0xffff)                 /**< Macro used to define blocktime of a timer*/
#define USEI2CPROTOCOL 			      UINT8_C(0)                       /**< I2c protocol is represented by this macro*/
#define NUMBER_ZERO 			      UINT8_C(0)                       /**< Zero value for BLE variables */
#define NUMBER_ONE 			          UINT8_C(1)                       /**< One value for BLE variables */
#define I2C_ADDRESS 			      UINT8_C(0x18)                    /**< i2c address for BMA280 */
#define STACK_SIZE_FOR_TASK           (configMINIMAL_STACK_SIZE + 10)  /**< TASK stack size for BLE application handler */
#define BLE_TASK_PRIORITY  		      UINT8_C(1)                       /**< TASK Priority value for BLE */
#define BLETRANSMITLENGTH  		      UINT8_C(16)                      /**<Transmit length for BLE */
#define ACCEL_RECEIVELENGTH 	      UINT8_C(30)                      /**< Receive length for BLE */
#define ENABLE_FLAG                   UINT8_C(1)                       /**< macro to represent the "enable" */
#define DISABLE_FLAG                  UINT8_C(0)                       /**< macro to represent the "Disable" */
#define REMOTE_ADDRESS_LENGTH         UINT8_C(6)                       /**< The length of remote device address */
#define MAX_DEVICE_LENGTH             UINT8_C(20)                      /**< The Maximum length of bluetooth device name */
#define SET_IDLE_MODE                 UINT8_C('i')                     /**< command to set the device in idle mode */
#define SET_DISCOVERABLE_MODE         UINT8_C('d')                     /**< command to set the device in discoverable mode */
#define SET_SLEEP_MODE                UINT8_C('s')                     /**< command to set the device in sleep mode */
#define GET_DEVICE_MODE               UINT8_C('g')                     /**< command to get the device current state */
#define TIMER_NO_ERROR                (0L)							   /**<Macro to define no error in timer*/
#define TIMER_NOT_ENOUGH_MEMORY       (-1L)							   /**<Macro to define not enough memory error in timer*/
#define TIMER_AUTORELOAD_ON           UINT32_C(1)            		   /**< Auto reload of timer is enabled*/
#define TIMER_AUTORELOAD_OFF          UINT32_C(0)             		   /**< Auto reload of timer is disabled*/

#define BLE_DEVICE_NAME               "XDK_BLE"              		   /**< Name of the BLE device*/
#define BLE_DEVICE_NAME_LENGTH         UINT8_C(sizeof(BLE_DEVICE_NAME))/**< length of the BLE device name*/

/* local interface declaration ********************************************** */

/* local type and macro definitions */

/* local function prototype declarations */
static void bleAppHandler(void *pParameters);
void bleDataTransmit(void);
/* local module global variable declarations */

/* local inline function definitions */

#endif /* XDK110_XDKAPPLICATIONTEMPLATE_H_ */

Any help is highly appreciated. 

Many thanks in advance and best regards,

0 (0 투표)
RE: Bluetooth Connection
응답
17. 4. 3 오후 3:22 as a reply to Michael Kneissl.

Hello Michael,

as I can see you followed the BLE guide.

The function that "turns on" the BLE is BLE_coreStackInit(). To be more precises it initializes the BLE stack on the XDK and boots up the BLE chip.

Please note that this function has several dependencies and is recommended to be used like described in the BLE guide.

In addition I would ask you to follow exactly the steps described in the guide.

Make sure that you place the important code blocks (4-8) like intended in the function bleAppHandler() below the commend //BLE implementation here.

I would recommend to follow the guide until the end (section 2.4.2) to be able to send data to your BLE scanner app.

Kind regards,
Franjo

+1 (1 투표)
RE: Bluetooth Connection
응답
17. 4. 4 오전 8:05 as a reply to Franjo Stjepandic.

Hello Franjo, 

 

Thank you very much for your support! Highly appreciated. 

I'll let you know how it goes :)

kindest regards,

0 (0 투표)
RE: Bluetooth Connection
응답
17. 4. 4 오전 9:58 as a reply to Michael Kneissl.

Hello Frajno, 

Done!! Thanks again for your support.

 

It has worked perfectly and have sent a "hello world" to the BLE scanner app. But, do you have any idea how to send data through linux shell? I have connected the XDK through Linux shell "Debain" but I wasn't able to see any notifications from XDK (e.x. Hello World). 

 

Many thanks in advance.

Kindest regards,

0 (0 투표)
RE: Bluetooth Connection
응답
17. 4. 4 오후 3:40 as a reply to Michael Kneissl.

Hello Michel,

there are several libraries that are able to do exactly what you are looking for.
To get a basic understanding of BLE on linux I would recommend to work through an appropriate tutorial, something like this.


Some community members tried the same thing as you some time ago, but they had some problems with HCI tools, alhough I am not quite sure if this issue still exists. For more information please see here.


I would really appreciate if you keep me posted about your progress.
Please do not hesitate to ask if anything is unclear.

Kind regards,
Franjo

+1 (1 투표)
RE: Bluetooth Connection
응답
17. 4. 7 오후 2:55 as a reply to Franjo Stjepandic.

Hello Franjo,

 

Thank you very much for your kind response. I have followed BLE on Linux tutorial and had a look on other posts in the community. 

 

I am facing now a problem connecting to the XDK through the gatttool, when I connect first I receive "connection refused (111)" then the after my next attempt to connect I receive "Connection error: too many levels of symbolic links (40)".

although I was able to connect succefully through bluetoothctl, but I wanted to receive data from the XDK, so I wanted to try this way. 

If you have any other suggestions how to transmit data with linux (Raspberry Pi 3 to be more specific). Please let me know ! :)

 

Many thanks in advance for your time and efforts.

Kindest regards,

0 (0 투표)
RE: Bluetooth Connection
응답
17. 4. 10 오후 5:38 as a reply to Michael Kneissl.

Hello Michael,

I am sorry to hear that the issue still exists.

But if you do not excessively rely on BLE, I recommend to use Wi-Fi as an alternative. It is quite simple to setup Wi-Fi on the Raspberry Pi 3 and a lot of protocols which use Wi-Fi are available in the SDK of the XDK. Therefore a small data exchange with the XDK and the Raspberry Pi should be quite simple to establish via Wi-Fi.

Please tell me if this is helpful and do not hesitate to ask if you have further questions.

Kind regards,
Franjo

0 (0 투표)
RE: Bluetooth Connection
응답
17. 4. 11 오전 8:06 as a reply to Franjo Stjepandic.

Hello Franjo,

Thank you very much for following up. Your help is highly appreciated. 

It has eventually worked. I think there are also bugs in the Bluez in linux as well. I am able to show the handles with the UUID's of the XDK, but I am not sure how this can help? 

I have already done this with wireless using udp protocol and built a java listener to receive data form the XDK. But wireless needs internet connection, this is why I want to do with bluetooth.

Many thanks in advance for your time and efforts.

Kindest regards,

0 (0 투표)
RE: Bluetooth Connection
응답
17. 4. 12 오전 11:45 as a reply to Michael Kneissl.

Bluetooth Connection

Hello Michael,

Unfortunately, displaying the XDK's  UUID handles is not very helpful, if you cannot interact with them.

Regarding the suggested Wi-Fi solution, you do not need internet access, but you could build your own small network.
The only thing you need to do is, configure your Raspberry as a hotspot with a DHCP server. Further you can connect the XDK to the hotspot and access the Raspberry with the IP that you assigned while setup.

Please tell me if this is a helpful hint and do not hesitate to ask if you have further questions.

Kind regards,
Franjo

0 (0 투표)
RE: Bluetooth Connection
응답
17. 5. 4 오전 10:40 as a reply to Franjo Stjepandic.

Hello Franjo,

Thank you for your previous support! Eventually I am now at a point where I am sending sensors data to other machines via bluetooth. 

The question for now is: I have sent so far 3 sensor data (accelerometer, Gyroscope, Magnetometer), and all of them is measured by x y z axis, so are there any libraries or something that can give a more clear result for these sensors? for example, compass reading using the magnetometer in degree?

Many thanks in advance and best regrads.

0 (0 투표)
RE: Bluetooth Connection
응답
17. 5. 4 오후 3:47 as a reply to Michael Kneissl.

Hello Michael,

there is no direct way for compass reading. If you want to have a compass reading using the magnetometer, you need to implement it yourself, unfortunately.

There are some additional libraries / virtual sensors, to which you can find instructions in the Sensor Guide. Maybe I can give advice, if I know what use case you want to implement.

Please tell me if this is helpful and do not hesitate to ask if you have further questions.


Kind regards,

Franjo

0 (0 투표)