adafruit / Adafruit_BluefruitLE_nRF51

Arduino library for nRF51822-based Adafruit Bluefruit LE modules
197 stars 122 forks source link

sendCommanWithIntReply returns false values #13

Closed binloan closed 8 years ago

binloan commented 8 years ago

Imagine the read command below. It shall read the current value of the first characteristic in the service which is active.

if (ble.sendCommandWithIntReply(F("AT+GATTCHAR=1"), &value))
{
  Serial.println(value);
}else{
  Serial.println(F("Failed to get response!"));
}

But if you try to read a value thats bigger than one byte the value will only contain the first byte. Example:

READ: 01-FF-22 Value (converted to int32_t) will be: 1

The issue is inside the int32_t Adafruit_BLE::readline_parseInt(void) function. The input of the buffer is a char array which also contains "-" as seperators. strtol fails here because it can not convert the "-" into a number, so only the first byte is converted. Also if the characteristic value starts with a 0 in the first byte, the whole value is ignored.

hathach commented 8 years ago

Thank for filing the issue, we are working on a helper class that make get/set characteristics and working with Gatt Server easier than currently. If you like to test it out, you can switch to the development branch, you will need to flash with the latest 0.7.0 beta firmware as well.

https://github.com/adafruit/Adafruit_BluefruitLE_nRF51/blob/development/examples/healththermometer/healththermometer.ino