This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF51822 S110 BLE, use Advertising packet send skin temperature to iphone every 30min

The test code:

int main(void) {

sd_softdevice_enable(NRF_CLOCK_LFCLKSRC_RC_250_PPM_250MS_CALIBRATION, softdevice_assertion_handle);

temp_init();
unsigned int aaa=temp();
unsigned char advdata[] = {0x9,0x09,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38, 0x02,0x01,0x04, 0x03,0xff,0xff,0x34, 0x03,0x03,0x09,0x18};	// #define BLE_UUID_HEALTH_THERMOMETER_SERVICE  0x1809	// Health Thermometer service UUID.

advdata[15] = aaa>>8; advdata[16] = aaa;
sd_ble_gap_adv_data_set((unsigned char *)&advdata[0], 21, 0, 0);

static ble_gap_adv_params_t m_adv_params;
m_adv_params.type        = BLE_GAP_ADV_TYPE_ADV_NONCONN_IND;
m_adv_params.p_peer_addr = 0;	// Undirected advertisement
m_adv_params.fp          = BLE_GAP_ADV_FP_ANY;
m_adv_params.p_whitelist = 0;
m_adv_params.interval    = 480;	// The advertising interval (in units of 0.625 ms. 100ms/0.625ms=160). when advertising non-connectable, interval must be at least 100 ms.
m_adv_params.timeout     = 1;	// The advertising timeout in units of seconds.

advdata[0] = sd_ble_gap_adv_start(&m_adv_params);

{ for(unsigned int i=0;i<90000000;i++) { __ASM { NOP } } } // delay 30s, for test.
NVIC_SystemReset();
for (;;) { }

}

I'll optimize the code to Low power consume next.

The problem now is that Iphone app can not get data in "background mode" as refer in : developer.apple.com/.../CBCentralManager.html

"Apps that have specified the bluetooth-central background mode are allowed to scan while in the background. That said, they must explicitly scan for one or more services by specifying them in the serviceUUIDs parameter. The CBCentralManagerOptionShowPowerAlertKey scan option is ignored while scanning in the background."

means service UUID parameter is needed, but iphone APP give the uuid like: UUID= "187356E0-7327-22BA-DC77-BFA63240BBB0" and the UUID 0x1809(BLE_UUID_HEALTH_THERMOMETER_SERVICE) seems not work.

Iphone app like this: image description

When iphone screen black, the advertising packet data losed. I don't know how UUID= "187356E0-7327-22BA-DC77-BFA63240BBB0" work out.

I want use advertising packet send the temperature data, just 4byte, every 30min or 60min, one 100mAh battery one year.

Is it any example code for ios app get the adv packet data?

Best regards

BTW: wireshark sniffer picture:

image description

Parents
  • Here's a 10,000 ft overview (apologies if you already know this stuff) - an advertising packet is just 31 or fewer bytes stashed into a BLE payload after a special flag. This flag indicates that the data following the flag contains arbitrary data specified by the manufacturer. Here is a great StackOverflow link explaining the iBeacon adv packet format.

    stackoverflow.com/.../what-is-the-ibeacon-bluetooth-profile

    This guy is using advertising packets to announce IP addresses: object-network.blogspot.com/.../advertising-object-url-with-bluetooth-le.html

    Apple's advertising packet contains a 16byte UUID, a 2 byte major, a 2 byte minor and the transmission power (TX.) Theoretically, you can choose to make your advertising packet report skin temperature instead of say the minor number. Though I myself have not yet tried to change the advertising packet contents periodically on an nrf51822, here is what I'd try. After every timeout event while you read the latest skin temperature, just call advertising_init() with new values, then call advertising_start();

    Specifically, look at the following field in the docs:

    ble_advdata_manuf_data_t *   p_manuf_specific_data
    
  • Thinks for your answer. In my code: unsigned char advdata[] = {0x9,0x09,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38, 0x02,0x01,0x04, 0x03,0xff,0xff,0x34, 0x03,0x03,0x09,0x18}; sd_ble_gap_adv_data_set((unsigned char *)&advdata[0], 21, 0, 0); I directly write the raw advertising data, local name is 12345678, flag, and manufactor data, service uuid. So, I already know the 10,000 ft overview and use wireshark to sniffer the packets.

    How to sniffer Apple's advertising packet? I have the sniffer and wireshark.

Reply
  • Thinks for your answer. In my code: unsigned char advdata[] = {0x9,0x09,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38, 0x02,0x01,0x04, 0x03,0xff,0xff,0x34, 0x03,0x03,0x09,0x18}; sd_ble_gap_adv_data_set((unsigned char *)&advdata[0], 21, 0, 0); I directly write the raw advertising data, local name is 12345678, flag, and manufactor data, service uuid. So, I already know the 10,000 ft overview and use wireshark to sniffer the packets.

    How to sniffer Apple's advertising packet? I have the sniffer and wireshark.

Children
No Data
Related