commit 612adb4c37976a780947df1b3aeabd5553ade87d
Author: Bharatvaj H <bharatvajph@gmail.com>
Date: Mon, 11 Feb 2019 13:51:26 +0000
Author: Bharatvaj H <bharatvajph@gmail.com>
Date: Mon, 11 Feb 2019 13:51:26 +0000
Initial Commit
2 files changed, 49 insertions(+), 0 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.0) +project(right_initiator) + +add_executable(right_initiator right_initiator.cpp) + +#TODO use find_package, instead of hard linking +target_link_libraries(right_initiator -lbluetooth)
diff --git a/right_initiator.cpp b/right_initiator.cpp @@ -0,0 +1,42 @@ +#include <iostream> +#include <unistd.h> +#include <sys/socket.h> +#include <bluetooth/bluetooth.h> +#include <bluetooth/rfcomm.h> + +using namespace std; + +bdaddr_t inc = ((bdaddr_t) {{0, 0, 0, 0, 0, 0}}); + +int main(int argc, char *argv[]){ + + struct sockaddr_rc addr = { 0 }; + int s, status=0; + char dest[18] = "B8:27:EB:A5:A1:70"; + // allocate a socket + s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); + cout << s << endl; + + // set the connection parameters (who to connect to) + addr.rc_family = AF_BLUETOOTH; + addr.rc_bdaddr = inc; + addr.rc_channel = (uint8_t) 1; + str2ba( dest, &addr.rc_bdaddr ); + + // connect to server + status = connect(s, (struct sockaddr *)&addr, sizeof(addr)); + + // send a message + if( status == 0 ) { + cout << "Receing message" << endl; + char buffer[10]; + status = recv(s, buffer, 6, 0); + } else { + int se=errno; + cout << "Connection failed" <<status<<se<< endl; + + } + close(s); + while(1); + return 0; +}
: bharatvaj/forwarder-initiators