Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am trying to connect to an adafruit bluefruit LE micro with a windows 10 surface pro 3.

I have loaded an app onto the device using Arduino IDE 1.6.5

When I try to enumerate the list. Nothing show up?

ARDUINO CODE
****************
C++
// TimerOne library: https://code.google.com/p/arduino-timerone/
#include <timerone.h>
// DHT library: https://github.com/adafruit/DHT-sensor-library
#include "DHT.h"
#include <spi.h>
#include <bleperipheral.h>

// define pins (varies per shield/board)
#define BLE_REQ   10
#define BLE_RDY   2
#define BLE_RST   9

#define DHTTYPE DHT22
#define DHTPIN 3

DHT dht(DHTPIN, DHTTYPE);

BLEPeripheral blePeripheral = BLEPeripheral(BLE_REQ, BLE_RDY, BLE_RST);

BLEService tempService = BLEService("CCC0");
// this is the one I was trying to connect to "CCC0"


BLEFloatCharacteristic tempCharacteristic = BLEFloatCharacteristic("CCC1", BLERead | BLENotify);
BLEDescriptor tempDescriptor = BLEDescriptor("2901", "Temp Celsius");

BLEService humidityService = BLEService("DDD0");
BLEFloatCharacteristic humidityCharacteristic = BLEFloatCharacteristic("DDD1", BLERead | BLENotify);
BLEDescriptor humidityDescriptor = BLEDescriptor("2901", "Humidity Percent");

volatile bool readFromSensor = false;

float lastTempReading;
float lastHumidityReading;

void setup() {
  Serial.begin(115200);
#if defined (__AVR_ATmega32U4__)
  delay(5000);  //5 seconds delay for enabling to see the start up comments on the serial board
#endif

  blePeripheral.setLocalName("Temperature");

  blePeripheral.setAdvertisedServiceUuid(tempService.uuid());
  blePeripheral.addAttribute(tempService);
  blePeripheral.addAttribute(tempCharacteristic);
  blePeripheral.addAttribute(tempDescriptor);

  blePeripheral.setAdvertisedServiceUuid(humidityService.uuid());
  blePeripheral.addAttribute(humidityService);
  blePeripheral.addAttribute(humidityCharacteristic);
  blePeripheral.addAttribute(humidityDescriptor);

  blePeripheral.setEventHandler(BLEConnected, blePeripheralConnectHandler);
  blePeripheral.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);

  blePeripheral.begin();

  Timer1.initialize(2 * 1000000); // in milliseconds
  Timer1.attachInterrupt(timerHandler);

  Serial.println(F("BLE Temperature Sensor Peripheral"));
}

void loop() {
  blePeripheral.poll();

  if (readFromSensor) {
    setTempCharacteristicValue();
    setHumidityCharacteristicValue();
    readFromSensor = false;
  }
}

void timerHandler() {
  readFromSensor = true;
}

void setTempCharacteristicValue() {
  float reading = dht.readTemperature();
//  float reading = random(100);

  if (!isnan(reading) && significantChange(lastTempReading, reading, 0.5)) {
    tempCharacteristic.setValue(reading);

    Serial.print(F("Temperature: ")); Serial.print(reading); Serial.println(F("C"));

    lastTempReading = reading;
  }
}

void setHumidityCharacteristicValue() {
  float reading = dht.readHumidity();
//  float reading = random(100);

  if (!isnan(reading) && significantChange(lastHumidityReading, reading, 1.0)) {
    humidityCharacteristic.setValue(reading);

    Serial.print(F("Humidity: ")); Serial.print(reading); Serial.println(F("%"));

    lastHumidityReading = reading;
  }
}

boolean significantChange(float val1, float val2, float threshold) {
  return (abs(val1 - val2) >= threshold);
}

void blePeripheralConnectHandler(BLECentral& central) {
  Serial.print(F("Connected event, central: "));
  Serial.println(central.address());
}

void blePeripheralDisconnectHandler(BLECentral& central) {
  Serial.print(F("Disconnected event, central: "));
  Serial.println(central.address());
}

********************************************

End of Arduino code
********************************************


This is the C# I am trying. I copied it from several examples that are around.

*********************************************************
C#
async void Initialize()
        {
           


         
            var devices = await DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromShortId(0xCCC0));

            GattDeviceService Firstdevice = await GattDeviceService.FromIdAsync(devices[0].Id);
           

            serviceNameTextBlock.Text = "Using service: " + devices[0].Name;

            GattCharacteristic FirstdeviceCharacteristic =
                Firstdevice.GetCharacteristics(
                    GattCharacteristicUuids.TemperatureMeasurement)[0];

            FirstdeviceCharacteristic.ValueChanged += temperatureMeasurementChanged;

            await FirstdeviceCharacteristic
                .WriteClientCharacteristicConfigurationDescriptorAsync(
                    GattClientCharacteristicConfigurationDescriptorValue.Notify);
        }



***********************************
End of c# example
***********************************

It complies an und ok.... BUt the list is empty

"Enumeration yielded no results"

If I try to find all device with
var devices = await DeviceInformation.FindAllAsync();

It show every device except the bluefruit

It seem like I can't find the service they way I am trying?

Any help greatly appreciated
Posted
Updated 3-Nov-15 3:40am
v2

1 solution

This line:-

C++
Timer1.initialize(2 * 1000000); // in milliseconds


Will make the startup wait for 2000 seconds. I suspect you only want to wait for 2 seconds?

C++
Timer1.initialize(2 * 1000); // in milliseconds
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900