bluetooth/bluetooth-client.c
changeset 165 f551b78c3eee
equal deleted inserted replaced
164:e1f4bba1097a 165:f551b78c3eee
       
     1 /**
       
     2  * bluetooth.c
       
     3  * Copyright (C) 2010 Markus Bröker
       
     4  */
       
     5 
       
     6 #include <stdio.h>
       
     7 #include <stdlib.h>
       
     8 #include <unistd.h>
       
     9 #include <sys/socket.h>
       
    10 #include <bluetooth/bluetooth.h>
       
    11 #include <bluetooth/rfcomm.h>
       
    12 
       
    13 int main (int argc, char **argv)
       
    14 {
       
    15     struct sockaddr_rc addr = { 0 };
       
    16     int s, status;
       
    17     // Hard-coded for simplicity
       
    18     char dest[18] = "58:17:0C:FF:36:D7";    // E10i
       
    19 
       
    20     // allocate a socket
       
    21     s = socket (AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
       
    22 
       
    23     // set the connection parameters (who to connect to)
       
    24     addr.rc_family = AF_BLUETOOTH;
       
    25     addr.rc_channel = (uint8_t) 1;
       
    26     str2ba (dest, &addr.rc_bdaddr);
       
    27 
       
    28     // connect to server
       
    29     status = connect (s, (struct sockaddr *)&addr, sizeof (addr));
       
    30 
       
    31     // send a message
       
    32     if (status == 0) {
       
    33         status = write (s, "hello!", 6);
       
    34     }
       
    35 
       
    36     if (status < 0)
       
    37         perror ("uh oh");
       
    38 
       
    39     close (s);
       
    40 
       
    41     return EXIT_SUCCESS;
       
    42 }