Hello, I am using the 1.4.4 version OS for developing a BLE program. I have attached my code below.
// This #include statement was automatically added by the Particle IDE.
#include <CellularHelper.h>
// This #include statement was automatically added by the Particle IDE.
#include <DiagnosticsHelperRK.h>
//SYSTEM_MODE(MANUAL);
#define DEBUG_BUILD
BleAdvertisingData advData;
BleUuid hogpService(0x1812);
BleUuid deviceInfoService(0x180A);
#define BLE_WIRING_DEBUG_ENABLED 1
SerialLogHandler serialLogHandler(LOG_LEVEL_TRACE);
BleCharacteristic batLevelStateCharacteristic("batState", BleCharacteristicProperty::READ, BleUuid(0x2A1B), deviceInfoService);
BleCharacteristic powerSourceCharacteristic("powerSource", BleCharacteristicProperty::READ, BleUuid(0x2A1A), deviceInfoService);
BleCharacteristic batPowerCharacteristic("batLevel", BleCharacteristicProperty::READ, BleUuid(0x2A19), deviceInfoService);
BleCharacteristic signalStrengthValueCharacteristic("signalStrength", BleCharacteristicProperty::NOTIFY, BleUuid("247e76c8-9dd4-412d-a75b-5244ad4cb8f4"), deviceInfoService);
system_tick_t begin;
void setup() {
advData.appendServiceUUID(hogpService);
BLE.addCharacteristic(batLevelStateCharacteristic);
BLE.addCharacteristic(powerSourceCharacteristic);
BLE.addCharacteristic(batPowerCharacteristic);
BLE.addCharacteristic(signalStrengthValueCharacteristic);
advData.appendLocalName("Boron");
BLE.advertise(&advData);
begin = millis();
}
void loop() {
if(BLE.connected()) {
if ((millis()-begin) > (6*1000)) {
// reportChar.setValue(value, 8);
//protocolChar.setValue((uint8_t)1);
begin = millis();
// reportChar.setValue(value, 8);
// BATTERY_STATE_UNKNOWN = 0,
// BATTERY_STATE_NOT_CHARGING = 1,
// BATTERY_STATE_CHARGING = 2,
// BATTERY_STATE_CHARGED = 3,
// BATTERY_STATE_DISCHARGING = 4,
// BATTERY_STATE_FAULT = 5,
// BATTERY_STATE_DISCONNECTED = 6
uint8_t batState = (uint8_t) DiagnosticsHelper::getValue(DIAG_ID_SYSTEM_BATTERY_STATE);
batLevelStateCharacteristic.setValue(batState);
// POWER_SOURCE_UNKNOWN = 0,
// POWER_SOURCE_VIN = 1,
// POWER_SOURCE_USB_HOST = 2,
// POWER_SOURCE_USB_ADAPTER = 3,
// POWER_SOURCE_USB_OTG = 4,
// POWER_SOURCE_BATTERY = 5
uint8_t powerSource = (uint8_t) DiagnosticsHelper::getValue(DIAG_ID_SYSTEM_POWER_SOURCE);
powerSourceCharacteristic.setValue(powerSource);
// Diagnostics data is a fixed point number, convert to integer 0-100 %
//Use little or big endian
uint8_t batLevel = (uint8_t) (DiagnosticsHelper::getValue(DIAG_ID_SYSTEM_BATTERY_CHARGE) >> 8);
batPowerCharacteristic.setValue(batLevel);
//Signal strength
//uint8_t signalStrength = (uint8_t) (DiagnosticsHelper::getValue(DIAG_ID_NETWORK_SIGNAL_STRENGTH_VALUE));
//signalStrengthValueCharacteristic.setValue(signalStrength);
CellularHelperRSSIQualResponse rssiQual = CellularHelper.getRSSIQual();
uint8_t bars = (uint8_t)CellularHelperClass::rssiToBars(rssiQual.rssi);
//Log.info("rssi=%d, qual=%d, bars=%d", rssiQual.rssi, rssiQual.qual, bars);
signalStrengthValueCharacteristic.setValue(bars);
}
}
}
I would like to change advData.appendServiceUUID to advertise deviceInfoService. However everytime i changed the service and flashed it to boron, my IOS device cannot sense the particle boron. I have tried this on an Android device and it is able to pick up the signal so it should be an IOS specific problem.