Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't show elementsForGroup #257

Open
Hung6129 opened this issue Dec 29, 2022 · 11 comments
Open

Can't show elementsForGroup #257

Hung6129 opened this issue Dec 29, 2022 · 11 comments
Labels
bug Something isn't working flutter

Comments

@Hung6129
Copy link

Hung6129 commented Dec 29, 2022

Hi @R0m4in-dooz
I want to expose elements for group
Here is my inputs:

image

image

It show the "OK" snack bar and log success

I go back and want to see the elements

image

It pop this error when i try to expose elements for group:

I/flutter (25433): load elements
I/flutter (25433): []
E/flutter (25433): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'Null' is not a subtype of type 'int' in type cast
E/flutter (25433): #0      _$ElementDataFromJson (package:nordic_nrf_mesh/src/models/mesh_node/provisioned_mesh_node.g.dart:27:17)
E/flutter (25433): #1      new ElementData.fromJson (package:nordic_nrf_mesh/src/models/mesh_node/provisioned_mesh_node.dart:48:45)        
E/flutter (25433): #2      MeshNetwork.elementsForGroup.<anonymous closure> (package:nordic_nrf_mesh/src/mesh_network.dart:128:57)
E/flutter (25433): #3      MappedListIterable.elementAt (dart:_internal/iterable.dart:413:31)
E/flutter (25433): #4      ListIterator.moveNext (dart:_internal/iterable.dart:342:26)
E/flutter (25433): #5      new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:189:27)
E/flutter (25433): #6      new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
E/flutter (25433): #7      new List.of (dart:core-patch/array_patch.dart:51:28)
E/flutter (25433): #8      ListIterable.toList (dart:_internal/iterable.dart:213:44)
E/flutter (25433): #9      MeshNetwork.elementsForGroup (package:nordic_nrf_mesh/src/mesh_network.dart:128:94)
E/flutter (25433): <asynchronous suspension>
E/flutter (25433):

But when i export and check in the JSON file it show the model

image

Are my inputs for the subscription add correct ?

Hope you can check it out
Thanks

@ghost
Copy link

ghost commented Dec 30, 2022

Hello @Hung6129
Thanks for the report ! 🙌

The node's description display a model with weird value (-2147418111), or it's normal on ur device ?

Otherwise it seems there is no issue with your usage.
But the freezed data model throws because of a missing required int value. This seems like a bug. Could you check if issue is also present on iOS ?

@ghost ghost added bug Something isn't working android labels Dec 30, 2022
@Hung6129
Copy link
Author

Hung6129 commented Dec 30, 2022

Hi @R0m4in-dooz

Yes this issue also happen on iOS, i tested and get the same error

About the (-2147418111), i also confuse and don't know why it has a "-" in front of the value, it expose like that on android and iOS, i just assume it's the vendor model id

As i record it should be 2147549185(Decimal ) or 0x80010001(Hex) for Vendor model ??

And last but not least i think i want to contribute to this plugin 👌 :

I will integrate some flutter code to make the example more clear and features look like nRF Mesh App 👍

  1. Expose device name
  2. Export JSON file to the local device
  3. Show model name, model id in hex and decimal

It not much 😢 but hope i can do something for the plugin

@ghost
Copy link

ghost commented Dec 30, 2022

Yes this issue also happen on iOS, i tested and get the same error

Ok, thx for checking !

About the (-2147418111), i also confuse and don't know why it has a "-" in front of the value, it expose like that on android and iOS, i just assume it's the vendor model id

As i record it should be 2147549185(Decimal ) or 0x80010001(Hex) for Vendor model ??

Ok, yes it's probably that there is some change in how vendor model is defined that the plugin is not aware of, thus displaying wrongly formatted value

And last but not least i think i want to contribute to this plugin 👌 :

I will integrate some flutter code to make the example more clear and features look like nRF Mesh App 👍

  1. Expose device name

  2. Export JSON file to the local device

  3. Show model name, model id in hex and decimal

It not much 😢 but hope i can do something for the plugin

Great ! Feel free to open new Pull requests 🤩 just try to either :

  • use atomic commits
  • or separate each related changes in a new pr

@ghost ghost added flutter and removed android labels Dec 30, 2022
@Hung6129
Copy link
Author

Hung6129 commented Jan 13, 2023

[Update]
Hi @R0m4in-dooz
Sorry i forget to mention that i fixed the error about a week ago 😄

image

I added a "?" for a nullable
And re-generated freezed
And it work fine now on android

@Hung6129
Copy link
Author

🥂 [DoozProvisionedDevice] Received flutter call : elements
🥂 [DoozProvisionedDevice] Received flutter call : unicastAddress
🥂 [DoozProvisionedDevice] Received flutter call : name
🥂 [DoozMeshNetwork] Received flutter call : groups
🥂 [DoozMeshNetwork] Received flutter call : getElementsForGroup
[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(errorDecoding, An error occured attempting to decode arguments, null, null)
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:653:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:296:18)
<asynchronous suspension>
#2      MeshNetwork.elementsForGroup (package:nordic_nrf_mesh/src/mesh_network.dart:127:22)
<asynchronous suspension>

But when i tested on ios
It show this error

Hmm.. something relate to method channel call i assume??

@ghost
Copy link

ghost commented Jan 13, 2023

Hi @Hung6129

The value of key is not nullable. It is received as null in Dart because there is a bug on native code ;) the fix would be to edit native code so the key value is indeed sent to Dart.

For the next error, yes your guess is right ! On iOS I think we had a breaking change at some point when we updated the Nordic SDK. The address is now an object with a field named address, so I think the fix would be to edit the swift method and in the returned data, there must be smth like data.address, just change it to data.address.address

@Hung6129
Copy link
Author

Hung6129 commented Jan 16, 2023

Hello @R0m4in-dooz

Well i add like you said in the DoozMeshNetWork.swift on the getElementsForGroup

        case .getElementsForGroup(let data):
            if let group = meshNetwork.group(withAddress: MeshAddress(Address(exactly: /*data.address*/ data.address.address )!)){
                let models = meshNetwork.models(subscribedTo: group)
                let elements = models.compactMap { model in
                    return model.parentElement
                }
                
                let mappedElements = elements.map { element in
                    return [
                        "name" : element.name ?? "",
                        "address" : element.unicastAddress,
                        "locationDescriptor" : element.location,
                        "models" : models.filter({$0.parentElement == element}).map({ m in
                            return [
                                "subscribedAddresses" : m.subscriptions.map({ s in
                                    return s.address
                                }),
                                "boundAppKey" : m.boundApplicationKeys.map{ key in
                                    return key.index
                                }
                            ]
                        })
                    ]
                }
                
                result(mappedElements)
            }else{
                result(false)
            }

Then this pop up

Error output from Xcode build:
↳
    ** BUILD FAILED **
Xcode's output:
↳
    Writing result bundle at path:
    	/var/folders/2b/gs9zhc0x1hz563667j2hvygm0000gn/T/flutter_tools.O7VRT1/flutter_ios_build_temp_dirvvm7Rf/temporary_xcresult_bundle
    /Applications/Coding/Users/flutter_apollo_libraries/ios/Classes/DoozMeshNetwork/DoozMeshNetwork.swift:171:22: warning: TODO: impl. meshAddress hex in most cases
                #warning("TODO: impl. meshAddress hex in most cases")
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /Applications/Coding/Users/flutter_apollo_libraries/ios/Classes/DoozMeshNetwork/DoozMeshNetwork.swift:190:101: error: value of type 'Int16' has no member 'address'
                if let group = meshNetwork.group(withAddress: MeshAddress(Address(exactly: data.address.address)!)){
                                                                                          ~~~~~~~~~~~~ ^~~~~~~
    /Applications/Coding/Users/flutter_apollo_libraries/ios/Classes/DoozMeshNetwork/DoozMeshNetwork.swift:196:38: error: the compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions

Am i missing something ?

@ghost
Copy link

ghost commented Jan 16, 2023

Hello @Hung6129

Indeed you are doing .address on the address sent by flutter, which is an integer, not Nordic's Address object.
Do you have a Mac computer ? To use Xcode and do the fix there?
If not, then I'm afraid it will be difficult to fix.. by reading the code I see that the error is not what I expected but I can't see it without proper IDE. I'll try to fix this week 😇

@ghost
Copy link

ghost commented Jan 16, 2023

Ah! Maybe in the subscribed addresses. See there is "s.address", try adding .address there

@Hung6129
Copy link
Author

Hung6129 commented Jan 16, 2023

Hello @R0m4in-dooz

So tried like you said and...

image

It still show the old error 😿

I'am still learning swift rn 👶 and this is pretty hard for me

Hope you can check it out

Thank youuu

@ghost
Copy link

ghost commented Jan 16, 2023

🤔 yeh but this error is more on the input..seems that the flutter args parsing is failing. You gotta check how the data is sent to swift because the error lies there, not in building the answer it seems

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working flutter
Projects
None yet
Development

No branches or pull requests

1 participant