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

Capturing the correct nodeId #125

Open
jonsmirl opened this issue May 6, 2023 · 2 comments
Open

Capturing the correct nodeId #125

jonsmirl opened this issue May 6, 2023 · 2 comments

Comments

@jonsmirl
Copy link

jonsmirl commented May 6, 2023

First a little background.... GSAFM is establishing a PASE session using the deviceId. That works and it is convenient, but note that this ID (in the CHIP code this is remodeNodeID, not deviceId) can be anything you want it to be, it does not determine the deviceId. To make this more obvious you might want to use two different numbers, one for remodeNodeID and a different on for deviceId.

Another item to note is the deviceId is encoded into the NOC certificate and that is the source of truth for the deviceID.

GSAFM commissions the device using the default internally generated certificates. When you are using those, GSAFM is in control of the deviceId. It picks a deviceId and sends it into awaitCommissionDevice(). The default certificate code will generate a certificate containing that deviceId, and happily send it off to the device. And everything will work.

At the end of the commission process onCommissioningComplete() gets called reporting the nodeId (deviceId) and it then discards it. This works because GSAFM knows what deviceId it put into the certificate.

 override fun onCommissioningComplete(nodeId: Long, errorCode: Int) {
    Timber.d("onCommissioningComplete(): nodeId [${nodeId}] errorCode [${errorCode}]")
  }

then it exit out of awaitCommissionDevice() and ends up here using the DeviceID stored in a local variable.

            Timber.d("Commissioning: Calling commissioningServiceDelegate.sendCommissioningComplete()")

This is all good and works with default certificate generation.

But what if you aren't using default certificate generation and instead generate them in the cloud? In that case the DeviceID GSAFM generates and sends into awaitCommissionDevice() simply gets ignored. onCommissioningComplete() then gets called with the cloud assigned DeviceID.

 override fun onCommissioningComplete(nodeId: Long, errorCode: Int) {
    Timber.d("onCommissioningComplete(): nodeId [${nodeId}] errorCode [${errorCode}]")
  }

So the problem I'm trying to solve is, how do I get this information out of onCommissioningComplete() and back up into the control flow in onCommissioningRequested().

I would be very useful if GSAFM were adjusted to pick up the DeviceId from onCommissioningComplete() and not carry it through onCommissioningRequested() in a local variable. Retrieving it from onCommissioningComplete() works for both the default certificates and cloud generated ones.

@jonsmirl
Copy link
Author

jonsmirl commented May 7, 2023

Turns out this is easy to fix. Return the DeviceID from awaitCommissionDevice()

   suspend fun awaitCommissionDevice(deviceId: Long, networkCredentials: NetworkCredentials?): Long
                        } else {
                            continuation.resume(nodeId)
                        }

then in AppCommissioningService

                Timber.d(
                    "Commissioning: App fabric -> ChipClient.commissionDevice(): deviceId [${deviceId}]")
                deviceId = chipClient.awaitCommissionDevice(deviceId, null)

When using the default certificate generator, this will return the same deviceId passed in. But if it is cloud generated, it will ignore the one passed in and return the cloud one.

@jonsmirl
Copy link
Author

This is a FabricManagement issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant