Ditutup

bluez bluetooth RSSI Api for distance calculation code snippet

Hi,

I am using bluez apis for 1 of my projects. I need to calculate distance of my laptop running ubuntu linux on it from another laptop with ubuntu over bluetooth. I got some code but it is not working properly. Can someone please help me?

pasting my code:

#include <bluetooth/bluetooth.h>

#include <bluetooth/hci.h>

#include <bluetooth/hci_lib.h>

#include <stdio.h>

#include <stdlib.h>

#include <stdbool.h>

#include <sys/ioctl.h>

#include <sys/socket.h>

#include <iostream>

#include <bluetooth/hci.h>

using namespace std;

//#define HCI_MAX_DEV 64

#define BLUE_ERROR 2

#define BLUE_NOT_CONNECTED -1

int findConn(int s, int dev_id, long arg) {

struct hci_conn_list_req *cl;

struct hci_conn_info *ci;

if ((cl = (hci_conn_list_req*)malloc(HCI_MAX_DEV * sizeof(*ci) + sizeof(*cl))) == NULL) {

perror("malloc");

error = true;

return 0;

}

cl->dev_id = dev_id;

cl->conn_num = HCI_MAX_DEV;

ci = cl->conn_info;

if (ioctl(s, HCIGETCONNLIST, (void *)cl)) {

perror("Could not get connection list");

error = true;

free(cl);

return 0;

}

int i;

for (i = 0; i < cl->conn_num; i++, ci++) {

if (!bacmp((bdaddr_t *)arg, &ci->bdaddr)) {

free(cl);

return 1;

}

}

free(cl);

return 0;

}

int rssi(char *address) {

struct hci_conn_info_req *cr;

int8_t rssi;

int dd, dev_id;

bdaddr_t bdaddr;

str2ba(address, &bdaddr);

error = false;

dev_id = hci_for_each_dev(HCI_UP, findConn, (long)&bdaddr);

if (dev_id < 0) {

if (error) {

return BLUE_ERROR;

}

else {

return BLUE_NOT_CONNECTED;

}

}

dd = hci_open_dev(dev_id);

if (dd < 0) {

perror("Could not open HCI device");

return BLUE_ERROR;

}

if ((cr = (hci_conn_info_req*)malloc(sizeof(struct hci_conn_info_req) + sizeof(struct hci_conn_info))) == NULL) {

perror("malloc");

hci_close_dev(dd);

return BLUE_ERROR;

}

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

cr->type = ACL_LINK;

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

perror("Could not get connection info");

free(cr);

hci_close_dev(dd);

return BLUE_ERROR;

}

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

perror("Could not read RSSI");

free(cr);

hci_close_dev(dd);

return BLUE_ERROR;

}

free(cr);

hci_close_dev(dd);

return rssi;

}

int main()

{

cout<<"rssi = "<<rssi("80:A5:89:3D:85:3A")<<endl;

cout<<"rssi = "<<rssi("E4:02:9B:84:A4:76")<<endl;

}

when I run this code I get

rssi = -1

rssi = -1

where BLUE_NOT_CONNECTED = -1

Kemahiran: Bluetooth Low Energy (BLE), Pengaturcaraan C, Pengaturcaraan C++, Linux

Lihat lebih lanjut: distance calculation gps code, google maps api javascript great circle distance calculation points driving, excel api google calculation distance, distance calculation api web service, bing maps api distance calculation, maps api distance calculation, php google maps api distance calculation, time distance calculation api, google api driving distance calculation, google map javascript api distance calculation, distance calculation api, driving distance calculation api, use google maps api distance calculator php code, address distance calculation api, texas hold odds calculation code

Tentang Majikan:
( 0 ulasan ) bhubaneswar, India

ID Projek: #14857322

3 pekerja bebas membida secara purata ₹1267 untuk pekerjaan ini

parthitce

RSSI is not the value you want to calculate the distance between two device/controller. We need to get the value from device's RSSI using DBUS interface provided by the device.txt. Relevant Skills and Experience I hav Lagi

₹1250 INR dalam 3 hari
(4 Ulasan)
2.9
Albertaks90

A proposal has not yet been provided

₹1050 INR dalam 2 hari
(0 Ulasan)
0.0
jiandeng

I believe you'll have to connect to the BLE device if you want query RSSI with your code snippet. Relevant Skills and Experience I have an script (not in C++) which can query RSSI without connecting to the device. Pr Lagi

₹1500 INR dalam 3 hari
(0 Ulasan)
0.0