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

Related