Windows 10 GAT如何连接到adafruite bluefruit LE micro [英] Windows 10 GAT How to connect to adafruite bluefruit LE micro

查看:77
本文介绍了Windows 10 GAT如何连接到adafruite bluefruit LE micro的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我正在尝试连接到具有Windows 10 Surface pro 3的adafruit蓝莓LE micro。



我已经使用Arduino IDE 1.6.5将应用程序加载到设备上



当我尝试枚举列表时。什么都没有出现?



ARDUINO CODE

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

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
****************

// 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());
}



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



Arduino代码结束

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





这是我正在尝试的C#。我从几个例子中复制了它。



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


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

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


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

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

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







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

结束c#示例

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



它符合要求...... BUK清单是空的



枚举没有结果



如果我试图找到全部设备与

var devices = await DeviceInformation.FindAllAsync();



显示除bluefruit之外的所有设备



好​​像我找不到他正在尝试的服务?



任何帮助都非常感激




***********************************
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

推荐答案

这一行: -



This line:-

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





将使启动等待2000秒。我怀疑你只想等待2秒钟?





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

Timer1.initialize(2 * 1000); // in milliseconds


这篇关于Windows 10 GAT如何连接到adafruite bluefruit LE micro的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆