android - Get temperature data from SensorTag as an advertisement -


i doing works texas instruments sensortag cc2541. trying show temperature data in advertising packets.

first, implemented temperature service uuid in advertising data packet. done in sensortag.c firmware (using iar workbench 8051).

static uint8 advertdata[] = {   // flags; sets device use limited discoverable   // mode (advertises 30 seconds @ time) instead of general   // discoverable mode (advertises indefinitely)   0x02,   // length of data   gap_adtype_flags,   default_discoverable_mode | gap_adtype_flags_bredr_not_supported,    0x03,   gap_adtype_16bit_more,   lo_uint16(irtemperature_serv_uuid),   hi_uint16(irtemperature_serv_uuid)  }; 

and here scan response array:

// gap - scan rsp data (max size = 31 bytes) static uint8 scanrspdata[] = {   // complete name   0x0a,   // length of data   gap_adtype_local_name_complete,   0x53,   // 's'   0x65,   // 'e'   0x6e,   // 'n'   0x73,   // 's'   0x6f,   // 'o'   0x66,   // 'f'   0x74,   // 't'   0x69,   // 'i'   0x61,   // 'a'    // connection interval range   0x05,   // length of data   gap_adtype_slave_conn_interval_range,   lo_uint16( default_desired_min_conn_interval ),   hi_uint16( default_desired_min_conn_interval ),   lo_uint16( default_desired_max_conn_interval ),   hi_uint16( default_desired_max_conn_interval ),    0x03,   gap_adtype_16bit_more,   lo_uint16(irtemperature_serv_uuid),   hi_uint16(irtemperature_serv_uuid)  }; 

then, use sample bluetooth low energy gat application , modify show data when scanning. original app used beacon device , showed beacon name + rssi + thermometer service when scanning. here original code:

class temperaturebeacon {      /* full bluetooth uuid defines health thermometer service */     public static final parceluuid therm_service = parceluuid.fromstring("00001809-0000-1000-8000-00805f9b34fb");       /* short-form uuid defines health thermometer service */     private static final int uuid_service_thermometer = 0x1809;       private string mname;     private float mcurrenttemp;     //device metadata     private int msignal;     private string maddress;      /* builder lollipop+ */     @targetapi(build.version_codes.lollipop)     public temperaturebeacon(scanrecord record, string deviceaddress, int rssi) {         msignal = rssi;         maddress = deviceaddress;          mname = record.getdevicename();          byte[] data = record.getservicedata(therm_service);         if (data != null) {             mcurrenttemp = parsetemp(data);         } else {             mcurrenttemp = 0f;         }     }      /* builder pre-lollipop */     public temperaturebeacon(list<adrecord> records, string deviceaddress, int rssi) {         msignal = rssi;         maddress = deviceaddress;          for(adrecord packet : records) {             //find device name record             if (packet.gettype() == adrecord.type_name) {                 mname = adrecord.getname(packet);             }             //find service data record contains our service's uuid             if (packet.gettype() == adrecord.type_servicedata                     && adrecord.getservicedatauuid(packet) == uuid_service_thermometer) {                 byte[] data = adrecord.getservicedata(packet);                 mcurrenttemp = parsetemp(data);             }         }     }      private float parsetemp(byte[] servicedata) {         /*          * temperature data 2 bytes, , precision 0.5degc.          * lsb contains temperature whole number          * msb contains bit flag noting if fractional part exists          */         float temp = (servicedata[0] & 0xff);         if ((servicedata[1] & 0x80) != 0) {             temp += 0.5f;         }          return temp;     }      public string getname() {         return mname;     }      public int getsignal() {         return msignal;     }      public float getcurrenttemp() {         return mcurrenttemp;     }      public string getaddress() {         return maddress;     }      @override     public string tostring() {         return string.format("%s (%ddbm): %.1fc", mname, msignal, mcurrenttemp);     } } 

as can see, program uses therm_service uuid (00001809-0000-1000-8000-00805f9b34fb) , short form (0x1809). tried modify sensortag ir temperature uuid service (f000aa00-0451-4000-b000-000000000000). , result that, cannot show neither name of scanned device nor temperature data.

can give suggestions problem? thank you!

the missing part in question scan response structure in modified sensortag code. advertdata notifies central (ios) of it's presence , available services (temperature). scan response may carry more information, such value of temperature. post scan response array?


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -