So its better to delete the global BLECharacteristic *pCharacteristic; ? since i declare it in setup .
And here pCharacteristic->setValue(txString); I dont understand what you mean , do you mean i should Declare BLECharacteristic *pCharacteristic; and give it a value so its not a null pointer , so i can store the value i get from analogRead(A0) ??
Also i thought u always had to dtostrf in order to upload to iot or ble devices .
Then i guess a simple pCharacteristic->setValue(sensorvalue); will do
Just keep the global one, don’t redeclare it locally.
The value for a characteristic is just a "sequence of bytes". These bytes are then stored by the BLE Server and made available to a BLE client that requests them. What the bytes represent is user defined.
There are a number of setValue signatures to hand over the sequence of bytes to the BLE Server as defined in the class
Yes i know it was a bad question , but ok i keep it as a global , i still need to declare the characteristics of my ble device , so should i redeclear all that outside of the setup?
and keep inside the setup the server creation etc?
Hmm so pCharacteristic->setValue(uint16_t& sensorvalue)); to access pointer and put sensorvalue in there ?
Read again I was editing my post when you answered
For declaring it, keep it global since you want to use it both in setup and the loop. You create an instance in the setup, only once, and then That’s the one you use in the loop.
Seems you are not fully getting what’s happening with classes and instances =>You have examples you could study in the library
The & in the signature means they pass by reference. It might mean the data is not duplicated and thus needs to refer to some static data in your app so that the reference stays legit. (I’ve not explored this with the ESP32)
Wait i get it now . I know what's an instance of a class , but really while automating with wifi is piece of cake , BLE is something new for me . So from what i understand J-M-L , i declare the global variable BLECharacteristic* pCharacteristic = NULL; and in the setup i am using pCharacteristic = pService->createCharacteristic( "place things here")
and i pass sensor data to BLE with pCharacteristic->setValue((uint16_t*)&value, sensorvalue);
Hey Stefan , yes i ve seen it , but i had to adjust the code anyway because i wanted things to happen inside the loop .
I think i am close to the solution but will test it tomorrow