c# - Windows Phone 8.1 - Bluetooth Low Energy and Authentication -


i'm having authentication issue bluetooth low energy devices c#.

i can connect ble, read services, when try write function, following error:

"the attribute requires authentication before can read or written. (exception hresult: 0x80650005)"

i've paired device and, said, can read it. problem when need write. if don't pair device, when write automatically pairs, gives error.

    public async static task<bool> writebyte(string paramdeviceid, guid paramservice, byte paramvalue)     {         string debug;         var services = await windows.devices.enumeration.deviceinformation.findallasync(gattdeviceservice.getdeviceselectorfromuuid([uuid here]), null);         gattdeviceservice service = await gattdeviceservice.fromidasync(paramdeviceid);         debug = "using service: " + services[0].name; // service name correct          gattcharacteristic gattcharacteristic = service.getcharacteristics(paramservice)[0];         var writer = new windows.storage.streams.datawriter();         writer.writebyte(paramvalue);          // error happens here         gattcommunicationstatus status = await gattcharacteristic.writevalueasync(writer.detachbuffer());           // code never executed, error occurs before         if (gattcommunicationstatus.unreachable == status)         {             debug = "write failed";             return false;         }          return true;      } 

anyone has had same issue? how can solve it? thank you!

update - code works when remove device phone, reset bluetooth device , new pairing of phone ble device. then, whenever disconnect device , reconnect, returns error when call writevalueasync function. if connect , disconnect without having used device...

however, android app uses same device, has no problem use device. when i've used before.

seems there's problem reconnection of windows phone 8.1 device...

i error when have app connected device. try this:

public async static task<gattcommunicationstatus> writebyte(string paramdeviceid, guid paramservice, byte paramvalue) {     string debug;     var services = await windows.devices.enumeration.deviceinformation.findallasync(gattdeviceservice.getdeviceselectorfromuuid([uuid here]), null);     gattdeviceservice service = await gattdeviceservice.fromidasync(paramdeviceid);     debug = "using service: " + services[0].name; // service name correct      gattcharacteristic gattcharacteristic = service.getcharacteristics(paramservice)[0];     var writer = new windows.storage.streams.datawriter();     writer.writebyte(paramvalue);      try{         return gattcommunicationstatus status = await gattcharacteristic.writevalueasync(writer.detachbuffer());      }     catch()     {         debug = "write failed";         return gattcommunicationstatus.unreachable;     } } 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -