BLE - Problem with pCharacteristic->setValue Syntax

Knobsi
Posts: 1
Joined: Mon Jan 11, 2021 10:33 am

BLE - Problem with pCharacteristic->setValue Syntax

Postby Knobsi » Mon Jan 11, 2021 10:58 am

Hi there,

i´m new into the ESP32, but love all its capabilities.
Actually i´m sitting in front of a small problem, so maybe you can help me?!
it´s a ble notify isssue what i cant get solved.
- within the void loop i call a function with mynum = loveit();
- inside the if (deviceConnected) { i try to to notify that variable mynum like:
-- put it into a buf with sprintf (cause it contains strings and numbers)
-- set the pCharacteristic->setValue((uint8_t*)buf, strlen(buf)) with the buf
- it should be everytime notified when the mynum is changed

but it will not work. what i achieved was that i only can notify ONE mynum value....
but thats all. even mynum will not ber serial.print within the if (deviceConnected)

if someone could help me out?
Would be awesome !!
Best, K


This is my problem code:

Code: Select all

void loop() {

       mynum = loveit();			// mynum should contains values like 1.1# or 5.8#  i declared mynum as a global var char*
      if(mynum != 0) {      
      Serial.print(mynum);
      } //till here it runs until the device is connected
 
    if (deviceConnected) { 
  
        char buf[100];
        sprintf(buf, mynum, value);
        pCharacteristic->setValue((uint8_t*)buf, strlen(buf));
        pCharacteristic->notify();
 //    Serial.print(mynum);        <- i tried to test if any value exists, but nothing happend inside the serial monitor
      	value++;				// thought this will keep it sniffing if mynum is changed
        delay(100); // 
    }
    
    // disconnecting
...
   
    // connecting
...
 }
 
 function loveit();
 
 

Who is online

Users browsing this forum: Baidu [Spider] and 16 guests