weliem / bluez_inc

A C library for Bluez (BLE) that hides all DBus communication. It doesn't get easier than this. This library can also be used in C++.
MIT License
84 stars 19 forks source link

Request for Humidity & Temperature sensor detail. #7

Closed rajpancha1 closed 1 year ago

rajpancha1 commented 1 year ago

Martijn:

Thank you for the bluetooth library bluez_inc and the central/peripheral examples.

I am trying it with Sensirion SHT31 sensor with the primaries and charesteristics/descriptors information using gatttool output shown below. I'm not sure if I am using the UUIDs and CUD correctly. Below are my replacements $defines derived using gatttool: Greatly appreciate your help to correct my mappings. Alternatively, I should try it with the same sensor you used.

Deriving the #defines for central/main.c replacing the original #defines: **#define HTS_SERVICE_UUID "00001809-0000-1000-8000-00805f9b34fb"

define TEMPERATURE_CHAR_UUID "00002a1c-0000-1000-8000-00805f9b34fb"**

    #define DIS_SERVICE "0000180a-0000-1000-8000-00805f9b34fb"
    #define DIS_MANUFACTURER_CHAR "00002a29-0000-1000-8000-00805f9b34fb"
   #define DIS_MODEL_CHAR "00002a24-0000-1000-8000-00805f9b34fb"

#define CUD_CHAR "00002901-0000-1000-8000-00805f9b34fb"

WITH the following:

define SHT31_UUID "88307D2F-6E54-3962-D2E5-42C8803180A5"

define GAP "00001800-0000-1000-8000-00805f9b34fb"

define GATT "00001801-0000-1000-8000-00805f9b34fb"

define DIS_SERVICE "0000180a-0000-1000-8000-00805f9b34fb"

define BATTERY_SERVICE "0000180f-0000-1000-8000-00805f9b34fb"

define SHT31_MGT_SERVICE_UUID "0000f234-b38d-4985-720e-0f993a68ee41"

define SHT31_HUMI_SERVICE_UUID "00001234-b38d-4985-720e-0f993a68ee41"

define SHT31_TEMP_SERVICE_UUID "00002234-b38d-4985-720e-0f993a68ee41"

define BATTERY_LEVEL "00002a19-0000-1000-8000-00805f9b34fb"

define DIS_MODEL_CHAR "00002234-b38d-4985-720e-0f993a68ee41"

define CUD_CHAR "0000f234-b38d-4985-720e-0f993a68ee41"

/ To read Temperature in Degree C (use uuid 00002235). /

define TEMPERATURE_CHAR_UUID "00002235-b38d-4985-720e-0f993a68ee41"

/ To read Relative Humidity in %RH (use uuid 00001235). /

define HUMIDITY_CHAR_UUID "00001235-b38d-4985-720e-0f993a68ee41"

define DIS_MANUFACTURER_CHAR "00002a29-0000-1000-8000-00805f9b34fb"

/ #define DIS_MODEL_CHAR "00002a24-0000-1000-8000-00805f9b34fb" / / #define CUD_CHAR "00002901-0000-1000-8000-00805f9b34fb" /

-----X--------------- $ gatttool -t random -b CB:D9:A4:93:23:FB -I [CB:D9:A4:93:23:FB][LE]> connect Attempting to connect to CB:D9:A4:93:23:FB Connection successful [CB:D9:A4:93:23:FB][LE]> primary attr handle: 0x0030, end grp handle: 0x0034 uuid: 00001234-b38d-4985-720e-0f993a68ee41 attr handle: 0x0035, end grp handle: 0xffff uuid: 00002234-b38d-4985-720e-0f993a68ee41

attr handle: 0x0001, end grp handle: 0x0007 uuid: 00001800-0000-1000-8000-00805f9b34fb #GAP attr handle: 0x0008, end grp handle: 0x000b uuid: 00001801-0000-1000-8000-00805f9b34fb #GATT attr handle: 0x000c, end grp handle: 0x001a uuid: 0000180a-0000-1000-8000-00805f9b34fb Device Info attr handle: 0x001b, end grp handle: 0x001e uuid: 0000180f-0000-1000-8000-00805f9b34fb Battery Service attr handle: 0x001f, end grp handle: 0x002f uuid: 0000f234-b38d-4985-720e-0f993a68ee41 To access Sync Time MS (0xf235 to 0xf239 char properties) attr handle: 0x0030, end grp handle: 0x0034 uuid: 00001234-b38d-4985-720e-0f993a68ee41 To read Relative Humidity in %RH (use uuid 00001235). attr handle: 0x0035, end grp handle: 0xffff uuid: 00002234-b38d-4985-720e-0f993a68ee41 To read Temperature in Degree C (use uuid 00001235).

To write Sync Time MS (use uuid 0000f235) Notify

[CB:D9:A4:93:23:FB][LE]> characteristics 0x0001 0x0035 handle: 0x0002, char properties: 0x0a, char value handle: 0x0003, uuid: 00002a00-0000-1000-8000-00805f9b34fb handle: 0x0004, char properties: 0x02, char value handle: 0x0005, uuid: 00002a01-0000-1000-8000-00805f9b34fb handle: 0x0006, char properties: 0x02, char value handle: 0x0007, uuid: 00002a04-0000-1000-8000-00805f9b34fb handle: 0x0009, char properties: 0x20, char value handle: 0x000a, uuid: 00002a05-0000-1000-8000-00805f9b34fb handle: 0x000d, char properties: 0x02, char value handle: 0x000e, uuid: 00002a23-0000-1000-8000-00805f9b34fb System ID handle: 0x000f, char properties: 0x02, char value handle: 0x0010, uuid: 00002a29-0000-1000-8000-00805f9b34fb Mfg Name Str handle: 0x0011, char properties: 0x02, char value handle: 0x0012, uuid: 00002a24-0000-1000-8000-00805f9b34fb Model Number Str handle: 0x0013, char properties: 0x02, char value handle: 0x0014, uuid: 00002a25-0000-1000-8000-00805f9b34f Serial Number Str handle: 0x0015, char properties: 0x02, char value handle: 0x0016, uuid: 00002a27-0000-1000-8000-00805f9b34fb HW Rev Str handle: 0x0017, char properties: 0x02, char value handle: 0x0018, uuid: 00002a26-0000-1000-8000-00805f9b34fb FW Rev Str handle: 0x0019, char properties: 0x02, char value handle: 0x001a, uuid: 00002a28-0000-1000-8000-00805f9b34fb SW Rev Str handle: 0x001c, char properties: 0x12, char value handle: 0x001d, uuid: 00002a19-0000-1000-8000-00805f9b34fb Battery Level Read Notify handle: 0x0020, char properties: 0x08, char value handle: 0x0021, uuid: 0000f235-b38d-4985-720e-0f993a68ee41 Sync Time MS handle: 0x0023, char properties: 0x0a, char value handle: 0x0024, uuid: 0000f236-b38d-4985-720e-0f993a68ee41 Oldest Sample Time MS Read handle: 0x0026, char properties: 0x0a, char value handle: 0x0027, uuid: 0000f237-b38d-4985-720e-0f993a68ee41 Newest Sample Time MS Read handle: 0x0029, char properties: 0x18, char value handle: 0x002a, uuid: 0000f238-b38d-4985-720e-0f993a68ee41 Start Logger Download Write Notify handle: 0x002d, char properties: 0x0a, char value handle: 0x002e, uuid: 0000f239-b38d-4985-720e-0f993a68ee41 Logger Interval MS Read Write handle: 0x0031, char properties: 0x12, char value handle: 0x0032, uuid: 00001235-b38d-4985-720e-0f993a68ee41 To read Relative Humidity in %RH (use uuid 00001235). handle: 0x0036, char properties: 0x12, char value handle: 0x0037, uuid: 00002235-b38d-4985-720e-0f993a68ee41 To read Temperature in Degree C (use uuid 00002235). -----X---------------

weliem commented 1 year ago

You seem to be working with a sensor that defines its own BLE protocol. You know the characteristics and what they mean. So now you need to find out if you need to start notifications or read characteristics.

Once you receive a value, you need to decode the byte array into a humidity/temperature value. I don't know what your device is sending but I assume it is documented somewhere....I would guess you are getting 'floats'. So my example code won't work for you since I am decoding according to the BT-SIG profile for thermometers.