3 Replies Latest reply on Mar 25, 2016 6:35 PM by HC

    Connect to Edison was cancelled while launching project in Eclipse IDE

    HC

      Hello,

       

      whenever I tried to run the code in the eclipse IDE, I am facing following  intermittent errors. I have tried following options:

      1. Flashing the Edison mini breakout board with latest image

      2. Running integrated installer.

      3. Ensured Edison board is connected over wifi.

      4. Synchronizing libraries when asked to do.

       

      I have shared the code below which I am currently using. Please let me if am missing anything. Your inputs will be highly valued.

      Screen Shot 2016-03-21 at 1.38.21 PM.png

       

      Screen Shot 2016-03-21 at 1.33.55 PM.png

       

      Screen Shot 2016-03-21 at 1.31.22 PM.png

       

      Screen Shot 2016-03-20 at 1.56.03 PM.png

       

      CODE:

       

       

       

      #include <stdio.h>

      #include <stdlib.h>

      #include <unistd.h>

      #include <sys/socket.h>

      #include <bluetooth/bluetooth.h>

      #include <bluetooth/hci.h>

      #include <bluetooth/hci_lib.h>

      #include <sys/ioctl.h>

      #include <bluetooth/rfcomm.h>

       

      void connectusingRF(int *sock,char *addr);

       

      int main(int argc, char **argv)

      {

          inquiry_info *ii = NULL;

          struct hci_conn_info_req *cr;

          bdaddr_t bdaddr;

          int8_t rssi;

          int max_rsp, num_rsp;

          int dev_id, sock, len, flags;

          int i;

       

          char addr[19] = { 0 };

          char name[248] = { 0 };

       

          //hema declaration

       

          //char command[50];

          char command1[50];

          //strcpy(command, "btmon &" );

         // system(command);*/

          strcpy(command1, "hcitool lescan" );

          system(command1);

          // end of dec

       

          dev_id = hci_get_route(NULL);

          printf("device Id %x \n", dev_id);

          sock = hci_open_dev( dev_id );

          if (dev_id < 0 || sock < 0) {

          perror("opening socket");

          exit(1);

          }

          len  = 8;

          max_rsp = 255;

          flags = IREQ_CACHE_FLUSH;

          ii = (inquiry_info*)malloc(max_rsp * sizeof(inquiry_info));

          cr = malloc(sizeof(*cr) + sizeof(struct hci_conn_info));

       

          num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);

       

          if( num_rsp < 0 ) perror("hci_inquiry");

          printf("we are here %d \n",num_rsp);

          for (i = 0; i < num_rsp; i++) {

              ba2str(&(ii+i)->bdaddr, addr);

              memset(name, 0, sizeof(name));

              if (hci_read_remote_name(sock, &(ii+i)->bdaddr, sizeof(name),name, 0) < 0)

              strcpy(name, "[unknown]");

              printf("%s  %s\n", addr, name);

          }

      /////

          str2ba(addr,&bdaddr);

          bacpy(&cr->bdaddr, &bdaddr);

          cr->type = ACL_LINK;

         if (ioctl(sock, HCIGETCONNINFO, (unsigned long) cr) < 0) {

         perror("Get connection info failed");

         exit(1);

        }

       

         if (hci_read_rssi(sock, htobs(cr->conn_info->handle), &rssi, 100) < 0) {

         perror("Read RSSI failed");

         exit(1);

        }

       

        connectusingRF(&sock,addr);

         printf("RSSI return value: %d\n", rssi);

       

         free( cr );

         close( sock );

         return 0;

        }

       

        void connectusingRF(int *sock,char *addr)

        {

        char dest[18] = "A8:86:DD:8F:6D:5D";

        struct sockaddr_rc rcaddr = {0};

        int newsock = socket(AF_BLUETOOTH,SOCK_STREAM,BTPROTO_RFCOMM);

       

        rcaddr.rc_family = AF_BLUETOOTH;

        rcaddr.rc_channel = (uint8_t)1;

        str2ba(dest,&rcaddr.rc_bdaddr);

       

        int stat = connect(newsock,(struct sockaddr *)&rcaddr,sizeof(rcaddr));

        // send a message

        if( stat == 0 ) {

        printf("workinf\n");

              stat = write(newsock, "hello!", 6);

        } else {

        printf("problem %d\n",stat);

        }

        if(stat < 0) {

        perror("Error in connection");

        }

        close(newsock);

      }

       

      Thanks,

      HC