Giter Site home page Giter Site logo

Comments (7)

aritchie avatar aritchie commented on August 18, 2024

Android has always looked for a notification characteristic because it is required. This has never been any different.

from shiny.

gianisimone avatar gianisimone commented on August 18, 2024

@aritchie thank you for your reply. I can guarantee that with 2.7.2 subscribing to the characteristic which had no descriptor with WhenNotificationReceived actually worked. The OnNext was called perfectly even if the EnableNotifications failed to complete.

from shiny.

aritchie avatar aritchie commented on August 18, 2024

Then send a reproducible case with the issue!

from shiny.

gianisimone avatar gianisimone commented on August 18, 2024

@aritchie Yes, sure.
This is the code using the v3 of Shiny:

private async Task WhenConnected(IPeripheral P)
{
    var characteristics = await P.GetAllCharacteristicsAsync();
    Command = characteristics.FirstOrDefault(c => c.Uuid == BLECharacteristicCommandUuid);    

    if(Command != null) 
    {
        P.NotifyCharacteristic(Command).ObserveOn(RxApp.MainThreadScheduler).Subscribe(notification =>
        {
            Log($"COMMAND CHANGED {Encoding.UTF8.GetString(notification.Data)}");
        },
        (notifyEx) => Log($"Error while enabling notifications for COMMAND. {notifyEx.Message}"));
    }
}
// peripheral is IPeripheral
whenConnected = peripheral.WhenConnected().Subscribe(conn => _ = WhenConnected(conn));

In this example, when calling NotifyCharacteristic the error handler is called and I am not able to process any notifications in the OnNext handler.

This is the code I have for version 2.7.2

var d = await peripheral.GetAllCharacteristics();
d.FirstOrDefault(_ => _.Uuid.ToGuid() == BT_CHARACTERISTIC_COMMAND_UUID);

if(d != null)
{
    TaskCompletionSource<bool> enableCommandNotificationTask = new TaskCompletionSource<bool>();

    CommandNotifyDisposable = Command.WhenNotificationReceived().Subscribe(g =>
    {
        Log(string.Format("COMMAND CHANGED {0}", Encoding.UTF8.GetString(g.Data)));
    }, 
    err => Log("Error"));

    Command.EnableNotifications(true).Subscribe(encd =>
    {
        Log("Command notifications enabled");
    }, 
    err =>
    {
        Log(string.Format("Error while enabling notifications for command {0}", err.Message));
    });
}

The EnableNotifications calls the error method, however, when a notification is received on the characteristic which has no descriptor, the OnNext is called properly.

If you need more details let me know

from shiny.

aritchie avatar aritchie commented on August 18, 2024

Ok so really this is more of a feature request. You would like the methods NotifyCharacteristic to be EnableNotification with a separate hook method. This is something I can consider for a future release, but honestly, I don't want to support the non-standard cases. I also merged these methods because people don't understand subscribing/unsubscribing/resubscribing post reconnect. It's a support case I don't want again

from shiny.

gianisimone avatar gianisimone commented on August 18, 2024

Yes, I would like to be able to process any notification received on the a Characteristic even if it has no descriptor.
Is there something I could do to workaround that Exception at the moment?

from shiny.

aritchie avatar aritchie commented on August 18, 2024

Not with the current implementation that I can think of. You can always create your own implementation.

from shiny.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.