Goodday
I have asked this already here but see it does not show up . I may have tagged it incorrectly (BLE service + connect not working on all devices)
The code below is based on the HTM example. But I have noticed it does not run on Xenons and only on some Argons. Im using nRF connect to test.
#include "Particle.h"
float battVoltage;//holds the local battery voltage
SerialLogHandler logHandler(LOG_LEVEL_TRACE);
const unsigned long UPDATE_INTERVAL_MS = 2000;
unsigned long lastUpdate = 0;
float getTempC();
uint32_t ieee11073_from_float(float temperature);
const char* xenonBattService = "b4250400-fb4b-4746-b2b0-93f0e61122c6"; //service
BleUuid xenonBattBleService(xenonBattService);
BleCharacteristic batteryMeasurementCharacteristic("bat", BleCharacteristicProperty::NOTIFY, BleUuid(0x2A19), xenonBattService);
void setup() {
(void)logHandler; // Does nothing, just to eliminate the unused variable warning
BLE.on();
//BLE.setAdvertisingTimeout(500); // 1000 * 10 ms // time period of the the detonation period (how long it get transmitted)
Particle.keepAlive(20);
Serial.begin(115200);
pinMode(BATT, INPUT); // argon battery
BLE.setTxPower(0); // Use lower power // Use lower power -20, -16, -12, -8, -4, 0, 4, 8.
// set initial IO states
pinMode(BATT, INPUT);
BLE.addCharacteristic(batteryMeasurementCharacteristic);
BleAdvertisingData advData;
advData.appendServiceUUID(xenonBattService);
BLE.advertise(&advData);
}
void loop() {
if (millis() - lastUpdate >= UPDATE_INTERVAL_MS) {
lastUpdate = millis();
if (BLE.connected()) {
uint8_t buf[6];
battVoltage = analogRead(BATT) * 0.0011224;
//battVoltage = analogRead(BATT) * 0.0011224 / 3.7 * 100; /// in percentage
buf[0] = 0x01;
memcpy(&buf[1], &battVoltage, 5);
batteryMeasurementCharacteristic.setValue(buf, sizeof(buf));
}
}
}
When I run the code on Xenons and try to conenct I get
Invalid handle
BLE_HCI_CONN_FAILED_TO_BE_ESTABLISHED
BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION
Is this normal?