Bluetooth communication
TobiasTi opened this issue · 1 comments
Hi,
I'm using the eclipse plugin as described in: http://c4ev3.github.io/.
In my project I want to controll the EV3 via bluetooth (Android).
Here is a code snipped, what I'm currently trying to do on EV3 side.
Includes & definitions:
#include "stdio.h"
#include "string.h"
#include "ctype.h"
#include "unistd.h"
#include "stdlib.h"
#include "bluetooth/bluetooth.h"
#include "bluetooth/sdp.h"
#include "bluetooth/sdp_lib.h"
#define DEV_ADDR "E4:12:1D:96:10:EF" // MAC address of service device
#define BYTE uint8_t
#define UUID uuid_t
#define LIST sdp_list_t
#define SESSION sdp_session_t
#define RECORD sdp_record_t
#define DATA sdp_data_t
Code:
...
// Server UUID: "d8308c4e-9469-4051-8adc-7a2663e415e2"
static BYTE uuid[16] = { // UUID as byte array
0xd8, 0x30, 0x8c, 0x4e, 0x94, 0x69, 0x40, 0x51,
0x8a, 0xdc, 0x7a, 0x26, 0x63, 0xe4, 0x15, 0xe2
};
int chan;
chan = GetServiceChannel( uuid );
if( chan > 0 ) {
printf( "specified service is on channel %d\n", chan );
}
...
int GetServiceChannel( BYTE *uuid) // uuid of service as 16 bytes
{
SESSION *s;
UUID svc_uuid;
LIST *response_list,*search_list,*attrid_list,*r;
RECORD *rec;
int range;
int n;
BYTE addr[6]; // define my own addr type
int chan=0;
// CONNECT TO SDP SERVER
// (Note: device must be ON but server need not be running)
str2ba( DEV_ADDR, (bdaddr_t *)&addr );
s = sdp_connect( BDADDR_ANY, (bdaddr_t *)&addr, SDP_RETRY_IF_BUSY );
if( !s ) {
fprintf( stderr, "can't connect to sdp server\n" );
return( 0 );
}
...
The function sdp_connect is not connecting to the rfcomm socket on my android device.
Is there a better way to access the bluetooth functionalities of the EV3 Brick? I didn't find any information in the official EV3 documentation. I was hoping you'd have some experience in using EV3 bluetooth. Thank you.
I've replied to Prof. Abke's email. Did the message not arrive? I'll reproduce my answer below:
I didn't look at this in particular. The EV3 firmware is available on https://github.com/mindboards/ev3sources though. One could look there, how the firmware realizes Bluetooth communication. My guess is that you get a rfcomm character device under /dev, which is usable in the same manner as a normal /dev/ttyX.