Ble.writeValue()

  • Home
  • Download
  • Guide
  • Pin Maps
  • Reference
  • Getting Help
  • Contact

ble.writeValue()

Description

Writes to a characteristic value. This handles validation, notifications and indications, and other necessary bookkeeping. The data type of the characteristic is set to the type of the variable passed as value. Use this to initialize the characteristics after calling ble.addService().

Syntax

ble.writeValue(&bleChar, value);

Parameters

&bleChar: A pointer to a BLE_Char.

value: The value to write. The following types are supported: bool, char, unsigned char, int, unsigned int, long, unsigned long, float, double, uint8_t*, char*, String

Returns

Status code

Example

#include <BLE.h> char char1Value = 0; int char2Value = 0; long char3Value = 0; String char4Value = String("Hello, world!"); BLE_Char char1 = { {0xF1, 0xFF}, BLE_READABLE | BLE_WRITABLE, "Characteristic 1" }; BLE_Char char2 = { {0xF2, 0xFF}, BLE_READABLE, "Characteristic 2" }; BLE_Char char3 = { {0xF3, 0xFF}, BLE_WRITABLE, "Characteristic 3" }; BLE_Char char4 = { {0xF4, 0xFF}, BLE_NOTIFIABLE, "Characteristic 4" }; BLE_Char *simpleServiceChars[] = {&char1, &char2, &char3, &char4}; BLE_Service simpleService = { {0xF0, 0xFF}, 4, simpleServiceChars }; void setup() { ble.begin(); ble.addService(&simpleService); ble.writeValue(&char1, char1Value); ble.writeValue(&char2, char2Value); ble.writeValue(&char3, char3Value); ble.writeValue(&char4, char4Value); ble.setAdvertName("Simple Profile"); ble.startAdvert(); } void loop() { ble.handleEvents(); // Increment the value of characteristic 1 every second if (millis() % 1000 == 0) { char1Value++; ble.writeValue(&char1, char1Value); } } Guide Home

Corrections, suggestions, and new documentation are very welcomed. They can be contributed to the energia website repository on Github.

The text of the Energia getting started and reference guides are licensed under a Creative Commons Attribution-ShareAlike 3.0 License. The Energia reference is based on the Wiring/Arduino reference. Code samples in the guide are released into the public domain.

Energia sketches are C/C++ based and compiled with the open-source compiler MSPGCC or arm-gcc-none-eabi. The Energia language comes from Wiring. The Energia environment is based on Processing and includes modifications made by Wiring and Arduino.

© Energia

Tag » Arduino Ble Characteristic Writevalue