sandeepmistry / arduino-BLEPeripheral

An Arduino library for creating custom BLE peripherals with Nordic Semiconductor's nRF8001 or nR51822.
MIT License
462 stars 179 forks source link

Make BLEDevice::requestTemperature() accessible for BLEPeripheral class. #115

Closed bojh closed 7 years ago

bojh commented 7 years ago

Signed-off-by: Joerg Hubschneider joerg.hubschneider@bosch-si.com ... reflecting issue #33

sandeepmistry commented 7 years ago

@bojh how can the temperature value be accessed then?

An example sketch would be helpful to explain this.

bojh commented 7 years ago

No problem at all. I have added an example requesting the SoC temperature. Idea: I just saw, that we can change the "Environmental Sensing Service" (0x181e) and the characteristics service to "Temperature" (0x2A6e) using sint16.

sandeepmistry commented 7 years ago

@bojh thanks for adding the example, I'm still not keen about making the user extend a class to gain access to this feature ...

bojh commented 7 years ago

@sandeepmistry as I can asume the requestTemperuture() method was design originally for the externel nrf8001 sub-device as a async construction. For to keep the interface for nrf5x micro controller with softdevice a sync method could be called as it is relaized at the moment. So if you are not keen to support the current API for the device objects (nrf8001 & nrf51822 classes) an application also can call directly the softdevice function like the implementation in the nrf51822 class.

void nRF51822::requestTemperature() {
#ifndef __RFduino__
  int32_t rawTemperature = 0;

  sd_temp_get(&rawTemperature);

  float temperature = rawTemperature / 4.0;

  if (this->_eventListener) {
    this->_eventListener->BLEDeviceTemperatureReceived(*this, temperature);
  }
#endif
}

The pro argument: The applicaton does not have to create a BLEPeripheral subclass and should than directly call the softdevice function it self. The con: No unified way to get the SoC temperature. Any thought from your side?

sandeepmistry commented 7 years ago

@bojh yes, that sound reasonable.

Maybe we should remove all of the battery level and temperature code from the library internals since it's not actually used or exposed?

bojh commented 7 years ago

@sandeepmistry with an viewing angle of an multi platform BLE library (i.e. Areduino101 CurieBLE) you are right. SoC temperature from nRF5 would than be more a library idea for arduino nRF5 core.

probonopd commented 6 years ago

What is the status of this? Is requestTemperature() usable now?