I'm trying to set a 6 byte value onto a BleCharacteristic, but when I do, I only get 4 bytes on the central side. So I've tried to call the method like this:
uint8_t buf[6];
buf[0] = 0x01;
uint32_t value = ieee11073_from_float(71.2); // hard-coded for this example
memcpy(&buf[1], &value, 4);
buf[5] = 0x1;
myCharacteristic.setValue(&buf, sizeof(buf));
but I get an error that there's no matching function.
Specifically, the error I get is:
error: no matching function for call to 'particle::BleCharacteristic::setValue(uint8_t (*)[6], unsigned int)'
It doesn't like the len parameter. Without the len parameter, I get some weird 4 byte array that doesn't represent the 6 bytes I set.
This almost exactly from the temperaturethemometer.ino example from the Particle library BLE documentation. Additionally, when I look at spark_wiring_ble.h there is a matching overloaded method:
ssize_t setValue(const uint8_t* buf, size_t len, BleTxRxType type = BleTxRxType::AUTO);
The weird thing is if I load the temperaturethermometer.ino example, it works! What's going on?
It's defined globally as a part of an environmental sensing service, I have characteristics (temperature and humidity). I have a method that I pass a value and characteristic into when the values update.
I believe the problem is that this is making a copy of the characteristic on the stack when calling publishCharacteristic. It may work if you declare it as:
While you can change all of the characteristics from by value to by pointer like you did, the other alternative is to change it to pass by reference as I did here.