@@ -473,7 +473,7 @@ void BLERemoteCharacteristic::registerForNotify(notify_callback notifyCallback,
473473 }
474474
475475 uint8_t val[] = {0x00 , 0x00 };
476- BLERemoteDescriptor* desc = getDescriptor (BLEUUID ( " 0x2902 " ) );
476+ BLERemoteDescriptor* desc = getDescriptor (( uint16_t ) 0x2902 );
477477 desc->writeValue (val, 2 );
478478 } // End Unregister
479479
@@ -520,7 +520,32 @@ std::string BLERemoteCharacteristic::toString() {
520520 * @return N/A.
521521 */
522522void BLERemoteCharacteristic::writeValue (std::string newValue, bool response) {
523- ESP_LOGD (LOG_TAG, " >> writeValue(), length: %d" , newValue.length ());
523+ writeValue ((uint8_t *)newValue.c_str (), strlen (newValue.c_str ()), response);
524+ } // writeValue
525+
526+
527+ /* *
528+ * @brief Write the new value for the characteristic.
529+ *
530+ * This is a convenience function. Many BLE characteristics are a single byte of data.
531+ * @param [in] newValue The new byte value to write.
532+ * @param [in] response Whether we require a response from the write.
533+ * @return N/A.
534+ */
535+ void BLERemoteCharacteristic::writeValue (uint8_t newValue, bool response) {
536+ writeValue (&newValue, 1 , response);
537+ } // writeValue
538+
539+
540+ /* *
541+ * @brief Write the new value for the characteristic from a data buffer.
542+ * @param [in] data A pointer to a data buffer.
543+ * @param [in] length The length of the data in the data buffer.
544+ * @param [in] response Whether we require a response from the write.
545+ */
546+ void BLERemoteCharacteristic::writeValue (uint8_t * data, size_t length, bool response) {
547+ // writeValue(std::string((char*)data, length), response);
548+ ESP_LOGD (LOG_TAG, " >> writeValue(), length: %d" , length);
524549
525550 // Check to see that we are connected.
526551 if (!getRemoteService ()->getClient ()->isConnected ()) {
@@ -534,8 +559,8 @@ void BLERemoteCharacteristic::writeValue(std::string newValue, bool response) {
534559 m_pRemoteService->getClient ()->getGattcIf (),
535560 m_pRemoteService->getClient ()->getConnId (),
536561 getHandle (),
537- newValue. length () ,
538- ( uint8_t *)newValue. data () ,
562+ length,
563+ data,
539564 response?ESP_GATT_WRITE_TYPE_RSP:ESP_GATT_WRITE_TYPE_NO_RSP,
540565 ESP_GATT_AUTH_REQ_NONE
541566 );
@@ -550,30 +575,6 @@ void BLERemoteCharacteristic::writeValue(std::string newValue, bool response) {
550575 ESP_LOGD (LOG_TAG, " << writeValue" );
551576} // writeValue
552577
553-
554- /* *
555- * @brief Write the new value for the characteristic.
556- *
557- * This is a convenience function. Many BLE characteristics are a single byte of data.
558- * @param [in] newValue The new byte value to write.
559- * @param [in] response Whether we require a response from the write.
560- * @return N/A.
561- */
562- void BLERemoteCharacteristic::writeValue (uint8_t newValue, bool response) {
563- writeValue (std::string (reinterpret_cast <char *>(&
D306
newValue), 1 ), response);
564- } // writeValue
565-
566-
567- /* *
568- * @brief Write the new value for the characteristic from a data buffer.
569- * @param [in] data A pointer to a data buffer.
570- * @param [in] length The length of the data in the data buffer.
571- * @param [in] response Whether we require a response from the write.
572- */
573- void BLERemoteCharacteristic::writeValue (uint8_t * data, size_t length, bool response) {
574- writeValue (std::string ((char *)data, length), response);
575- } // writeValue
576-
577578/* *
578579 * @brief Read raw data from remote characteristic as hex bytes
579580 * @return return pointer data read
0 commit comments