Hi,
I’ve been working on a uni assignment where we need to establish a BLE link between Argons, with one argon being the “Central” and the others “peripheral”.
I’ve written code to get the peripheral devices to behave as BLE peripherals, but am having trouble getting the “central” to read the data from the peripherals. The peripherals have their own UUIDs for both the device itself and the individual sensors. I can see the devices using Lightblue on my phone, and can read the data ok, but can’t find a way to get the master Argon to do the same.
The examples and forum posts I’ve seen all seem to be for commercial peripheral devices with predefined characteristics(like the heart rate monitor example). I found one example that was trying to connect to a specific device, but it was looking for a six byte address not a uuid?
Here is a simplified version of the sensor code I’ve written, (the real version has more sensors and other functions.) I’d be very grateful if someone could point me towards a solution that would allow me to have another Argon read the BLE characteristics. Ideally just by having the target UUIDs hard coded in the “central” program.
Thanks for any help.
//Constants:
SYSTEM_MODE(MANUAL) //Disables WiFi and particle cloud functionality, greatly improves boot time after flashing.
#define Serial_Baud 9600
#define SAMPLE_PERIOD 5000
//Pin definitions:
#define LDR_PIN A0
//Bluetooth UUIDs & services.
const char* serviceUUID = "9EC9FA46-E01B-4A2E-974C-D577CDFAE788"; //Service UUID
const char* LightUUID = "172A2E64-6D0D-4C6F-B898-9BD6E5E00E75"; //Light(LDR) UUID
BleUuid Node2Service(serviceUUID);
BleCharacteristic LIGHTCharacteristic("LIGHT", BleCharacteristicProperty::READ, LightUUID, serviceUUID, onDataReceived,(void*)LightUUID);
//Timer setup:
Timer master_timer(SAMPLE_PERIOD, sample_sensors);
void setup(){
Serial.begin(Serial_Baud);
//Add BLE characteristics
BLE.addCharacteristic(LIGHTCharacteristic);
// Advertising data
BleAdvertisingData advData;
// Add the Node_2 service
advData.appendServiceUUID(Node2Service);
// Start advertising
BLE.advertise(&advData);
//Start Timer
master_timer.start();
}
void loop(){
Serial.println(analogRead(A2));
delay(500);
}
//This routine serves as the timer ISR, sampling all sensors and updating BLE characteristics.
void sample_sensors(){
LIGHTCharacteristic.setValue(analogRead(LDR_PIN));
}
// Static function for handling Bluetooth Low Energy callbacks
static void onDataReceived(const uint8_t* data, size_t len, const BlePeerDevice& peer, void* context) {}