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

Example code for transmitting data from nrf51822 to mobile app

Can anyone please help me on this? I struggling in transmitting string and numbers from nrf51822 to mobile app through BLE. I need some sample code. thanks.

uint8_t numbers = 80;

GattCharacteristic characteristic2(service1_rx_uuid, (uint8_t *)numbers, sizeof(numbers), sizeof(numbers), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);

ble.updateCharacteristicValue(characteristic2.getValueAttribute().getHandle(), &numbers , sizeof(numbers));

Based on the code above, I keep on getting : 'P' rather than 80.

Please help!

Parents Reply
  • Umm... I have not met BLE_API. I don't know your target board(or controller), SDK, and mobile application. But if you want send uint16_t or uint32_t number, you need convert it to array of uint8_t. For example,

    uint16_t number = 800;
    uint8_t txbuffer[2];
    txbuffer[0] = (uint8_t)(number >> 8);
    txbuffer[1] = (uint8_t)(number & 0xff);
    

    Now you can send array of uint8_t. Of course you have to convert it back to uint16_t within your mobile application.

Children
No Data
Related