DarkerWaters / flic_button

A flutter plugin for the Flic2 Button iOS and Android
BSD 3-Clause "New" or "Revised" License
8 stars 8 forks source link

This plugin does not work with offscreen streams #4

Closed Eccotech closed 1 year ago

butterbrain commented 1 year ago

Sorry to hear that... I am not totally familiar with BlocProvider, but if it is anything like the other providers, might it no longer be in the widget tree when you exit the screen? If you are getting the print to work then the plugin is firing but the BlocProvider.of is no longer available to be called - nor will the context be valid?

I would use a global singleton, or a provider registered in the app itself that is fetched as your screen is created so it is always available to the callback function?

Hope this helps? If not, I would need to have access to your code in order that I could debug it to help further.

On Wed, 19 Apr 2023 at 01:41, Eccotech @.***> wrote:

void onButtonClicked(Flic2ButtonClick buttonClick) { // callback from the plugin that someone just clicked a button print('button ${buttonClick.button.uuid} clicked');

setState(() { _lastClick = buttonClick; }); butonSound();

if(_lastClick.isSingleClick){ BlocProvider.of(context).add(FlicClicEvent(flicClic: FlicClicEnum.SINGLE_CLIC)); }else if(_lastClick.isDoubleClick){ BlocProvider.of(context).add(FlicClicEvent(flicClic: FlicClicEnum.DOUBLE_CLIC)); }else if(_lastClick.isHold){ BlocProvider.of(context).add(FlicClicEvent(flicClic: FlicClicEnum.HOLD)); }

}

When I add this code, the plugin emits the events by the block, however when I exit the screen it does not pass the data to the block but the print continues to last, I tried to do it with streams manually too but the same thing happens

— Reply to this email directly, view it on GitHub https://github.com/DarkerWaters/flic_button/issues/4, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABKMPQBAWTLO4BGK7KOGWGLXB4YEDANCNFSM6AAAAAAXDK35TI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Eccotech commented 1 year ago

That was all brother thanks for the help it already works for ios however for android it is giving me a small error I don't know if you know why it happens:

I/BluetoothAdapter(28451): STATE_ON D/BluetoothLeScanner(28451): Stop Scan with callback I/BluetoothAdapter(28451): STATE_ON D/BluetoothGatt(28451): connect() - device: 80:E4:DA:79:EE:BC, auto: true I/BluetoothAdapter(28451): isSecureModeEnabled D/BluetoothGatt(28451): registerApp() D/BluetoothGatt(28451): registerApp() - UUID=92d24bc7-ff0a-4c32-99a4-0b303fb9a75f D/BluetoothGatt(28451): onClientRegistered() - status=0 clientIf=12 I/flutter (28451): button @80:E4:DA:79:EE:BC discovered D/BluetoothGatt(28451): onClientConnectionState() - status=0 clientIf=12 device=80:E4:DA:79:EE:BC I/flutter (28451): button connected I/BluetoothSocket(28451): connect() for device 80E4DA called by pid: 28451 W/BluetoothAdapter(28451): getBluetoothService() called with no BluetoothManagerCallback I/BluetoothDevice(28451): createBondOutOfBand() for device 80E4DA called by pid: 28451 tid: 28451 I/flutter (28451): data back is not a valid button: {"uuid":"963baf8c559b45bb8a592496222d31a4","bdAddr":"80:E4:DA:79:EE:BC","readyTime":0,"name":"��� I/flutter (28451): button found I/flutter (28451): ERROR: Cannot to listen to a button as don't recognise the UUID D/BluetoothGatt(28451): onConnectionUpdated() - Device=80:E4:DA:79:EE:BC interval=84 latency=17 timeout=800 status=0 2 I/System.out(28451): (HTTPLog)-Static: isSBSettingEnabled false D/BluetoothGatt(28451): registerApp() - UUID=92d24bc7-ff0a-4c32-99a4-0b303fb9a75f D/BluetoothGatt(28451): onClientRegistered() - status=0 clientIf=12

butterbrain commented 1 year ago

That's weird - I have tried with the latest flutter etc on the example and mine searches for and finds my buttons fine... It looks a bit like the data coming back about the button found is corrupted? {"uuid":"963baf8c559b45bb8a592496222d31a4","bdAddr":"80:E4:DA:79:EE:BC","readyTime":0,"name":"���� If should end with ", serialNo:"eg", connectionState:0, firmwareVersion:"something", "battPercentage":10, "battTimestamp:"98319287", "battVoltage":3.12, "pressCount":213 }

I wonder if it can't cope with the name of your button having non utf chars? (I have tried naming mine but it always just returns empty string) or the serial number of something is throwing it out?

If you can debug using the example app at all, it's the _createFlic2FromData function you need to look at - there is something in the data returned from Flic that I have not properly covered or something that has changed since I got my buttons.

Sorry about this, without your actual button to see what's going on, I am a bit stuck )O:

On Fri, 19 May 2023 at 15:17, Eccotech @.***> wrote:

That was all brother thanks for the help it already works for ios however for android it is giving me a small error I don't know if you know why it happens:

I/BluetoothAdapter(28451): STATE_ON D/BluetoothLeScanner(28451): Stop Scan with callback I/BluetoothAdapter(28451): STATE_ON D/BluetoothGatt(28451): connect() - device: 80:E4:DA:79:EE:BC, auto: true I/BluetoothAdapter(28451): isSecureModeEnabled D/BluetoothGatt(28451): registerApp() D/BluetoothGatt(28451): registerApp() - UUID=92d24bc7-ff0a-4c32-99a4-0b303fb9a75f D/BluetoothGatt(28451): onClientRegistered() - status=0 clientIf=12 I/flutter (28451): button @80 https://github.com/80:E4:DA:79:EE:BC discovered D/BluetoothGatt(28451): onClientConnectionState() - status=0 clientIf=12 device=80:E4:DA:79:EE:BC I/flutter (28451): button connected I/BluetoothSocket(28451): connect() for device 80E4DA called by pid: 28451 W/BluetoothAdapter(28451): getBluetoothService() called with no BluetoothManagerCallback I/BluetoothDevice(28451): createBondOutOfBand() for device 80E4DA called by pid: 28451 tid: 28451 I/flutter (28451): data back is not a valid button: {"uuid":"963baf8c559b45bb8a592496222d31a4","bdAddr":"80:E4:DA:79:EE:BC","readyTime":0,"name":"���� I/flutter (28451): button found I/flutter (28451): ERROR: Cannot to listen to a button as don't recognise the UUID D/BluetoothGatt(28451): onConnectionUpdated() - Device=80:E4:DA:79:EE:BC interval=84 latency=17 timeout=800 status=0 2 I/System.out(28451): (HTTPLog)-Static: isSBSettingEnabled false D/BluetoothGatt(28451): registerApp() - UUID=92d24bc7-ff0a-4c32-99a4-0b303fb9a75f D/BluetoothGatt(28451): onClientRegistered() - status=0 clientIf=12

— Reply to this email directly, view it on GitHub https://github.com/DarkerWaters/flic_button/issues/4#issuecomment-1554657780, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABKMPQEF4BSFP3MNW54WCZLXG56HTANCNFSM6AAAAAAXDK35TI . You are receiving this because you commented.Message ID: @.***>

Eccotech commented 1 year ago

I understand bro, if it is quite strange I just tried it with the example you have but it happens to me anyway, however in ios it works

butterbrain commented 1 year ago

Something about the button I guess. If you get a chance, could you send me the data that iOS receives back as a button is found? Don't worry too much about it, don't think many people relying on the plugin anyway 😜

On Fri, 19 May 2023, 16:20 Eccotech, @.***> wrote:

I understand bro, if it is quite strange I just tried it with the example you have but it happens to me anyway, however in ios it works

— Reply to this email directly, view it on GitHub https://github.com/DarkerWaters/flic_button/issues/4#issuecomment-1554745360, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABKMPQET2MPK6WS6NOX2VUDXG6FSFANCNFSM6AAAAAAXDK35TI . You are receiving this because you commented.Message ID: @.***>

Eccotech commented 1 year ago

Of course look here is what ios returns when it finds the button and links it:

flutter: button @00:80:E4:DA:79:EE:BC discovered flutter: button found with address 00:80:E4:DA:79:EE:BC resolved to actual button data 963baf8c559b45bb8a592496222d31a4 flutter: button 963baf8c559b45bb8a592496222d31a4 found

On the screen it shows this: name: F210ee68 batt:3.030469v (100%) serial BG21-D49239

butterbrain commented 1 year ago

Hello again,

So I managed to replicate the error (maybe) in Android by adding quotes (") to the name I was returning... I changed the code a little and made it more protective to hopefully catch the error Flic are returning and carrying on with a proper JSON return.

flic_button should now be version 1.0.0 if you wanted to try again...

Thank you for your patience, it's hard to guess at debugging as I am sure you know (O:

On Fri, 19 May 2023 at 16:41, Eccotech @.***> wrote:

Of course look here is what ios returns when it finds the button and links it:

flutter: button @00 https://github.com/00:80:E4:DA:79:EE:BC discovered flutter: button found with address 00:80:E4:DA:79:EE:BC resolved to actual button data 963baf8c559b45bb8a592496222d31a4 flutter: button 963baf8c559b45bb8a592496222d31a4 found

On the screen it shows this: name: F210ee68 batt:3.030469v (100%) serial BG21-D49239

— Reply to this email directly, view it on GitHub https://github.com/DarkerWaters/flic_button/issues/4#issuecomment-1554770126, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABKMPQDXBEOISKZAMTGIV5LXG6IDJANCNFSM6AAAAAAXDK35TI . You are receiving this because you commented.Message ID: @.***>

Eccotech commented 1 year ago

Ok, I understand, I updated to the last version that you published and in the console of my editor it shows me this and maybe it will help you a little:

2 I/BluetoothAdapter(13071): STATE_ON 2 I/BluetoothAdapter(13071): STATE_ON D/BluetoothLeScanner(13071): Start Scan with callback onScannerRegistered() - status=0 scannerId=12 mScannerId=0 I/flutter (13071): 0 I/BluetoothAdapter(13071): STATE_ON D/BluetoothLeScanner(13071): Stop Scan with callback I/BluetoothAdapter(13071): STATE_ON D/BluetoothGatt(13071): connect() - device: 80:E4:DA:79:EE:BC, auto: true I/BluetoothAdapter(13071): isSecureModeEnabled D/BluetoothGatt(13071): registerApp() D/BluetoothGatt(13071): registerApp() - UUID=fa186f6f-d7fb-42dd-a4a8-fa5d98c3db48 D/BluetoothGatt(13071): onClientRegistered() - status=0 clientIf=12 I/flutter (13071): button @80:E4:DA:79:EE:BC discovered D/BluetoothGatt(13071): onClientConnectionState() - status=0 clientIf=12 device=80:E4:DA:79:EE:BC I/flutter (13071): button connected I/BluetoothSocket(13071): connect() for device 80E4DA called by pid: 13071 W/BluetoothAdapter(13071): getBluetoothService() called with no BluetoothManagerCallback I/BluetoothDevice(13071): createBondOutOfBand() for device 80E4DA called by pid: 13071 tid: 13071 I/flutter (13071): button found ERROR: Cannot to listen to a button as don't recognise the UUID I/BluetoothSocket(13071): close() this: android.bluetooth.BluetoothSocket@c568468, channel: 252, mSocketIS: android.net.LocalSocketImpl$SocketInputStream@d9e4081, mSocketOS: android.net.LocalSocketImpl$SocketOutputStream@8cef526mSocket: android.net.LocalSocket@342567 impl:android.net.LocalSocketImpl@e437f14 fd:java.io.FileDescriptor@ed63bd, mSocketState: CONNECTED D/BluetoothGatt(13071): onClientConnectionState() - status=8 clientIf=12 device=80:E4:DA:79:EE:BC D/BluetoothGatt(13071): onClientConnectionState() - status=0 clientIf=12 device=80:E4:DA:79:EE:BC I/BluetoothSocket(13071): connect() for device 80E4DA called by pid: 13071 W/BluetoothAdapter(13071): getBluetoothService() called with no BluetoothManagerCallback 2 I/System.out(13071): (HTTPLog)-Static: isSBSettingEnabled false D/BluetoothGatt(13071): onConnectionUpdated() - Device=80:E4:DA:79:EE:BC interval=84 latency=17 timeout=800 status=0 4 I/flutter (13071): 0

butterbrain commented 1 year ago

That's so annoying - now it's not sending any information about buttons at all )O:

I will have to leave it as I just can't repeat the error - I'm sorry about that.

I was hoping to see something in the console starting Something in flic which might have given me some clues as to what exactly was failing

On Tue, 23 May 2023 at 19:39, Eccotech @.***> wrote:

Ok, I understand, I updated to the last version that you published and in the console of my editor it shows me this and maybe it will help you a little:

2 I/BluetoothAdapter(13071): STATE_ON 2 I/BluetoothAdapter(13071): STATE_ON D/BluetoothLeScanner(13071): Start Scan with callback onScannerRegistered() - status=0 scannerId=12 mScannerId=0 I/flutter (13071): 0 I/BluetoothAdapter(13071): STATE_ON D/BluetoothLeScanner(13071): Stop Scan with callback I/BluetoothAdapter(13071): STATE_ON D/BluetoothGatt(13071): connect() - device: 80:E4:DA:79:EE:BC, auto: true I/BluetoothAdapter(13071): isSecureModeEnabled D/BluetoothGatt(13071): registerApp() D/BluetoothGatt(13071): registerApp() - UUID=fa186f6f-d7fb-42dd-a4a8-fa5d98c3db48 D/BluetoothGatt(13071): onClientRegistered() - status=0 clientIf=12 I/flutter (13071): button @80 https://github.com/80:E4:DA:79:EE:BC discovered D/BluetoothGatt(13071): onClientConnectionState() - status=0 clientIf=12 device=80:E4:DA:79:EE:BC I/flutter (13071): button connected I/BluetoothSocket(13071): connect() for device 80E4DA called by pid: 13071 W/BluetoothAdapter(13071): getBluetoothService() called with no BluetoothManagerCallback I/BluetoothDevice(13071): createBondOutOfBand() for device 80E4DA called by pid: 13071 tid: 13071 I/flutter (13071): button found ERROR: Cannot to listen to a button as don't recognise the UUID I/BluetoothSocket(13071): close() this: @., channel: 252, mSocketIS: @., mSocketOS: @.: @. @. @., mSocketState: CONNECTED D/BluetoothGatt(13071): onClientConnectionState() - status=8 clientIf=12 device=80:E4:DA:79:EE:BC D/BluetoothGatt(13071): onClientConnectionState() - status=0 clientIf=12 device=80:E4:DA:79:EE:BC I/BluetoothSocket(13071): connect() for device 80E4DA called by pid: 13071 W/BluetoothAdapter(13071): getBluetoothService() called with no BluetoothManagerCallback 2 I/System.out(13071): (HTTPLog)-Static: isSBSettingEnabled false D/BluetoothGatt(13071): onConnectionUpdated() - Device=80:E4:DA:79:EE:BC interval=84 latency=17 timeout=800 status=0 4 I/flutter (13071): 0

— Reply to this email directly, view it on GitHub https://github.com/DarkerWaters/flic_button/issues/4#issuecomment-1559956123, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABKMPQB7YYQKLZ45PAW3HMLXHT77TANCNFSM6AAAAAAXDK35TI . You are receiving this because you commented.Message ID: @.***>

butterbrain commented 1 year ago

I'm sorry it's been so long, but I finally ordered some new buttons and with the new ones I am finally seeing the error you are seeing - it's that the name is encoding invalid control characters into the JSON string which breaks the decoding.

Anyway, I have managed to repair the problem now I can finally replicate it and have published a working update!