Bluetooth RFCOMM example

Posts: 62
Joined: Wed Jan 17, 2018 11:55 pm

Bluetooth RFCOMM example

Postby kbaud1 » Mon Mar 19, 2018 4:50 pm

I found what I think is an older RFCOMM server example but the include file "rfcomm.h " is no longer in the latest IDF.

Code: Select all

#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/rfcomm.h>
int main(int argc, char **argv)
 struct sockaddr_rc loc_addr = { 0 }, rem_addr = { 0 };
 char buf[1024] = { 0 };
 int s, client, bytes_read;
 socklen_t opt = sizeof(rem_addr);
 // allocate socket
 // bind socket to port 1 of the first available
 // local bluetooth adapter
 loc_addr.rc_family = AF_BLUETOOTH;
 loc_addr.rc_bdaddr = *BDADDR_ANY;
 loc_addr.rc_channel = (uint8_t) 1;
 bind(s, (struct sockaddr *)&loc_addr, sizeof(loc_addr));
 // put socket into listening mode
 listen(s, 1);
 // accept one connection
 client = accept(s, (struct sockaddr *)&rem_addr, &opt);
 ba2str(&rem_addr.rc_bdaddr, buf);
 fprintf(stderr, "accepted connection from %s\n", buf);
 memset(buf, 0, sizeof(buf));
 // read data from the client
 bytes_read = read(client, buf, sizeof(buf));
 if (bytes_read > 0) {
 printf("received [%s]\n", buf);
 // close connection
 return 0;
There is a thread dating from June of last year where people could not get it to work with previous IDFs either:

And another thread were people are asking for any help on this...

Another request on github:

This seems to indicate that a UART example might do in a pinch and in fact, there is such an example in the latest IDF: ... art_demo.c
but this is not the bluedroid I am looking for. This seems to interface the UART periperal to a hci connection? HCI is not easy to do in windows like SPP or RFCOMM.


Who is online

Users browsing this forum: amrMike and 39 guests