Esempio n. 1
0
    void onBLEServicesDiscovered(MLBluetoothLE.Status status)
    {
        print("onBLEServicesDiscovered: " + status.ToString());
        // You can now read and write to GATT characteristics and descriptors
        // or set notification for when a GATT characteristic changes.
        // Each time you start an operation on the GATT server, you must wait until
        // the corresponding callback is called before you can start another operation.
        // The callbacks include the operation status, which you can use to determine
        // next steps on the operation.
        MLBluetoothLE.Service[] services;

        MLBluetoothLE.GetServiceRecord(out services);
        print("Found " + services.Length + " services");

        printBLEState();

        foreach (MLBluetoothLE.Service service in services)
        {
            // print(service.Uuid);
            if (service.Uuid.Equals(SERVICE_UUID))
            {
                print("---------Found Service!!!!!!!!!");

                //foreach (MLBluetoothLE.Characteristic characteristic in service.Characteristics) {'


                // This characteristic is neither readable or writable. a client can obtain its value only through notifications sent by the server.
                this.characteristic = service.Characteristics[0];
                print("Enabling notifications for: " + characteristic.Uuid);


                printCharacteristicInfo();


                characteristic.WriteType = MLBluetoothLE.WriteType.Default;


                MLBluetoothLE.EnableCharacteristicNotification(characteristic, true);


                // Every time a client wants to enable notifications or indications for a particular characteristic that supports them, it simply uses a Write Request ATT packet to set the corresponding bit to 1
                descriptor = characteristic.Descriptors[0];
                //descriptor.Buffer = new byte[] { 0x01 | 0x02 | 0x04 | 0x10, 0x00 };
                //descriptor.Buffer = new byte[] { 0x11, 0x11 };

                descriptor.Buffer = new byte[] { 0x01, 0x00 };

                printDescriptorInfo(descriptor);

                MLBluetoothLE.WriteDescriptor(descriptor);
                MLBluetoothLE.EnableCharacteristicNotification(characteristic, true);


                characteristic.Descriptors[0] = descriptor;

                MLBluetoothLE.WriteCharacteristic(characteristic);



                //MLBluetoothLE.EnableCharacteristicNotification(characteristic, true);
            }
        }
    }
Esempio n. 2
0
 void onCharacteristicRead(MLBluetoothLE.Characteristic characteristic, MLBluetoothLE.Status status)
 {
     print("**********************************--------------------------------------------------onCharacteristicRead");
     print(string.Join(",", characteristic.Buffer));
 }
Esempio n. 3
0
 void onCharacteristicChanged(MLBluetoothLE.Characteristic characteristic)
 {
     print("**************************************-------------------------------------------------onCharaceristicChanged");
     print(string.Join(",", characteristic.Buffer));
 }
Esempio n. 4
0
 void onCharacteristicWrite(MLBluetoothLE.Characteristic characteristic, MLBluetoothLE.Status status)
 {
     print("--------------------------------------------------onCharacteristicWrite");
     this.characteristic = characteristic;
     printCharacteristicInfo();
 }