Can't Compile Argon BLE Example (HTM)

Hello,

I’ve been trying to compile and flash the “Body temperature thermometer” to an Argon and running into a bunch of errors. Is there a separate library I need to #include along with <Particle.h>? I copied the code from the example here https://docs.particle.io/tutorials/device-os/bluetooth-le/#examples
Image of errors attached, any help is appreciated!

Code:

#include "Particle.h"

// This example does not require the cloud so you can run it in manual mode or
// normal cloud-connected mode
// SYSTEM_MODE(MANUAL);

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);

// The "Health Thermometer" service is 0x1809.
// See https://www.bluetooth.com/specifications/gatt/services/
BleUuid healthThermometerService(BLE_SIG_UUID_HEALTH_THERMONETER_SVC);

// We're using a well-known characteristics UUID. They're defined here:
// https://www.bluetooth.com/specifications/gatt/characteristics/
// The temperature-measurement is 16-bit UUID 0x2A1C
BleCharacteristic temperatureMeasurementCharacteristic("temp", BleCharacteristicProperty::NOTIFY, BleUuid(0x2A1C), healthThermometerService);

// The battery level service allows the battery level to be monitored
BleUuid batteryLevelService(BLE_SIG_UUID_BATTERY_SVC);

// The battery_level characteristic shows the battery level of
BleCharacteristic batteryLevelCharacteristic("bat", BleCharacteristicProperty::NOTIFY, BleUuid(0x2A19), batteryLevelService);


// We don't actually have a thermometer here, we just randomly adjust this value
float lastValue = 37.0; // 98.6 deg F;

uint8_t lastBattery = 100;

void setup() {
    (void)logHandler; // Does nothing, just to eliminate the unused variable warning

    BLE.addCharacteristic(temperatureMeasurementCharacteristic);

    BLE.addCharacteristic(batteryLevelCharacteristic);
    batteryLevelCharacteristic.setValue(&lastBattery, 1);

    BleAdvertisingData advData;

    // While we support both the health thermometer service and the battery service, we
    // only advertise the health thermometer. The battery service will be found after
    // connecting.
    advData.appendServiceUUID(healthThermometerService);

    // Continuously advertise when not connected
    BLE.advertise(&advData);
}

void loop() {
    if (millis() - lastUpdate >= UPDATE_INTERVAL_MS) {
        lastUpdate = millis();

        if (BLE.connected()) {
            uint8_t buf[6];

            // The Temperature Measurement characteristic data is defined here:
            // https://www.bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/Xml/Characteristics/org.bluetooth.characteristic.temperature_measurement.xml

            // First byte is flags. We're using Celsius (bit 0b001 == 0), no timestamp (bit 0b010 == 0), with temperature type (bit 0b100), so the flags are 0x04.
            buf[0] = 0x04;

            // Value is a ieee11073 floating point number
            uint32_t value = ieee11073_from_float(getTempC());
            memcpy(&buf[1], &value, 4);

            // TempType is a constant for where the sensor is sensing:
            // <Enumeration key="1" value="Armpit" />
            // <Enumeration key="2" value="Body (general)" />
            // <Enumeration key="3" value="Ear (usually ear lobe)" />
            // <Enumeration key="4" value="Finger" />
            // <Enumeration key="5" value="Gastro-intestinal Tract" />
            // <Enumeration key="6" value="Mouth" />
            // <Enumeration key="7" value="Rectum" />
            // <Enumeration key="8" value="Toe" />
            // <Enumeration key="9" value="Tympanum (ear drum)" />
            buf[5] = 6; // Mouth

            temperatureMeasurementCharacteristic.setValue(buf, sizeof(buf));

            // The battery starts at 100% and drops to 10% then will jump back up again
            batteryLevelCharacteristic.setValue(&lastBattery, 1);
            if (--lastBattery < 10) {
                lastBattery = 100;
            }
        }
    }
}

float getTempC() {
    // Adjust this by a little bit each check so we can see it change
    if (rand() > (RAND_MAX / 2)) {
        lastValue += 0.1;
    }
    else {
        lastValue -= 0.1;
    }

    return lastValue;
}

uint32_t ieee11073_from_float(float temperature) {
    // This code is from the ARM mbed temperature demo:
    // https://github.com/ARMmbed/ble/blob/master/ble/services/HealthThermometerService.h
    // I'm pretty sure this only works for positive values of temperature, but that's OK for the health thermometer.
    uint8_t  exponent = 0xFE; // Exponent is -2
    uint32_t mantissa = (uint32_t)(temperature * 100);

    return (((uint32_t)exponent) << 24) | mantissa;
}

Compiling CLI Command:
particle compile argon --saveTo ble.bin

It’s seems you’re compiling against system version 1.2.1, whereas Bluetooth is first supported > 1.3.x. Try updating your CLI to see if that makes a difference?

1 Like

I am running Version 1.43.0.
particle update-cli produces the following output:
Updating CLI… no plugins to update.

EDIT: used the --target option to specify 1.3.0-rc.1 and it worked, thanks :slight_smile:

@babsndeep, what @Moors7 is referring to is the DeviceOS version you are targeting. To user BLE/NFC you need to use DeviceOS 1.3.0-rc.1.

1 Like

Yup, through the CLI automatically compiles against the latest DeviceOS but I am guessing its the latest released DeviceOS and since 1.3.0 is RC I needed to specify the version using the --target option.

1 Like

With 1.2.1 being the latest default (1.3.x is still beta), try this: particle compile argon --target 1.3.0-rc.1

2 Likes

While I have you here :slight_smile: here’s what I downloaded for for DeviceOS/SystemFW for 1.3.0-rc (attached), is there supposed to be argon-system-part2@1.3.0-rc.1?

Of the three .bin files under /argon/release do I just need to flash the argon-system-part1@1.3.0-rc.1 alone?

particle flash --usb argon-system-part1@1.3.0-rc.1system-fw

@babsndeep, that’s the whole enchilada!

1 Like

Nope, Gen3 only has one system part.

1 Like