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

iOS chiptool fails to pair and commission the esp32 device #15640

Closed
danh-geo opened this issue Feb 28, 2022 · 7 comments
Closed

iOS chiptool fails to pair and commission the esp32 device #15640

danh-geo opened this issue Feb 28, 2022 · 7 comments

Comments

@danh-geo
Copy link
Contributor

danh-geo commented Feb 28, 2022

CHIP commit id: 031edd0
esp32 App: examples/all-clusters-app
Device: esp32devkit-c

I'm attempting to pair our esp32 device using the iOS app. I can pair it just fine when I use the standalone CHIPTool using terminal with the following command:

./out/debug/chip-tool pairing ble-wifi {NODE_ID} {SSID} {PW_FOR_SSID} {SETUP_PIN_CODE} {DISCRIMINATOR}

Once paired with theabove, I can turn the light on my board on and off using:
./out/debug/chip-tool onoff on {NODE_ID} 1
./out/debug/chip-tool onoff off {NODE_ID} 1

Now when I use the QR Code Scanner in the iOS app I can see things happening, it asks me for bluetooth prompt, it also asks me for my ssid and pw which I provide. I can see in the logs it mentions:

DevicePairingDelegate Pairing complete. Status ../../../../../../../../../../../Desktop/oldCHIP/src/controller/CHIPDeviceController.cpp:979: Success

But ultimately, towards the end it fails with:

2022-02-28 12:33:03.658356+0000 CHIPTool[11820:3043551] New SSID: {MY_SSID} Password: {MY_SSID_PW}
2022-02-28 12:33:03.658485+0000 CHIPTool[11820:3043551] [all] 🔴 [1646051583658] [11820:3043551] CHIP: [CTL] Invalid device for commissioning 0000000000000000
2022-02-28 12:33:03.658516+0000 CHIPTool[11820:3043551] Error(../../../../../../../../../../../Desktop/oldCHIP/src/controller/CHIPDeviceController.cpp:858: CHIP Error 0x00000003: Incorrect state): Failure while pairing the device
2022-02-28 12:33:03.658586+0000 CHIPTool[11820:3043551] Failed to commission Device 0, with error Error Domain=CHIPErrorDomain Code=6 "Invalid object state." UserInfo={NSLocalizedDescription=Invalid object state.}

In the app Paired Devices is still empty as indicated by empty brackets () on the QR Code screen, as well as the Light on/off cluster screen which shows zero device ids in the picker.

I've attached the logs of the app when I attempt to pair with the QR code, and the logs of my esp32 board during this process.

Ultimately, it seems to be when it gets inside here when it fails and calling the commissionDevice function.

- (void)commissionWithSSID:(NSString *)ssid password:(NSString *)password
{

    NSError * error;
    CHIPDeviceController * controller = [CHIPDeviceController sharedController];
    // create commissioning params in ObjC. Pass those in here with network credentials.
    // maybe this just becomes the new norm
    CHIPCommissioningParameters * params = [[CHIPCommissioningParameters alloc] init];
    params.wifiSSID = [ssid dataUsingEncoding:NSUTF8StringEncoding];
    params.wifiCredentials = [password dataUsingEncoding:NSUTF8StringEncoding];

    uint64_t deviceId = CHIPGetNextAvailableDeviceID() - 1;

    if (![controller commissionDevice:deviceId commissioningParams:params error:&error]) {
        NSLog(@"Failed to commission Device %llu, with error %@", deviceId, error);
    }
}

Thanks for any help.

(on a side note to enter the QR code scanning screen due to it crashing, see issue: #15638 we had to modify KeyValueStoreManagerImpl.mm see link for details.)

app-log.txt
board-log.txt

@ajay-gantayet
Copy link

@danh-geo I faced a similar issue with commissioning esp32c3 devkit using the latest CHIPTool app.
In my case the issue was resolved by upgrading to the latest iOS 15.4 beta.

For more information please go though this: #15299 (comment)

@danh-geo
Copy link
Contributor Author

danh-geo commented Mar 1, 2022

Thanks @ajay-gantayet for your experience.

I'll give that a try. If this is to be the case, it would be useful if the app in its UI or even in the README would specify this?
I feel a lot of people will attempt to use the latest iOS available (15.3.1) and run into these issues. It would be great if the README mentions to use iOS 15.4 beta if thats what has to be used and also how to use it, e.g. follow the guidance over at https://beta.apple.com/sp/betaprogram/enroll#ios to learn how to install a beta iOS onto your device.

@danh-geo
Copy link
Contributor Author

danh-geo commented Mar 1, 2022

I installed 15.4 beta onto my device. Whilst I no longer see the issue above, the QR scanner still doesn't pair/commission the device properly.

I was expecting the textfield "Paired Devices" to populate which it didn't. I was also expecting the onPairingComplete delegate function to be called which it wasn't.

At the moment of scanning the QR code, these are the app logs I now retrieve:

2022-03-01 16:43:56.681629+0000 CHIPTool[480:18931] displayQRCodeInSetupPayloadView
2022-03-01 16:43:56.682103+0000 CHIPTool[480:18931] showPayload
2022-03-01 16:43:56.697848+0000 CHIPTool[480:18931] Payload vendorID 65521
2022-03-01 16:43:56.698236+0000 CHIPTool[480:18931] handleRendezVous
2022-03-01 16:43:56.698378+0000 CHIPTool[480:18931] Rendezvous Default
2022-03-01 16:43:56.698560+0000 CHIPTool[480:18931] handleRendezVousDefault payload: MT:-24J042C00KA0648G00
2022-03-01 16:43:56.698865+0000 CHIPTool[480:18931] [all] 🔵 [1646153036698] [480:18931] CHIP: [BLE] NewConnection
2022-03-01 16:43:56.707379+0000 CHIPTool[480:18931] handleRendezVousDefault 1
2022-03-01 16:43:56.727241+0000 CHIPTool[480:19169] [all] 🟢 [1646153036727] [480:19169] CHIP: [BLE] CBManagerState: ON

Which means I see it get as far as this:

- (void)handleRendezVousDefault:(NSString *)payload
{
    NSError * error;
    uint64_t deviceID = CHIPGetNextAvailableDeviceID();
    
    NSLog(@"handleRendezVousDefault payload: %@", payload);
    if ([self.chipController pairDevice:deviceID onboardingPayload:payload error:&error]) {
        deviceID++;
        CHIPSetNextAvailableDeviceID(deviceID);
        NSLog(@"handleRendezVousDefault 1");
    } else {
        NSLog(@"handleRendezVousDefault 2");
    }
}

Has anyone actually manage to pair it with the iOS device and have it list the paired device within the app? My aim is to use the app to pair and send on/off commands. Whilst I can successfully do this via the standalone CHIP tool, I cannot achieve it with the iOS demo app.

@danh-geo
Copy link
Contributor Author

danh-geo commented Mar 2, 2022

OK I finally got it to work using the 15.4 beta on my device.

My issue was that I had already paired the esp32 with the standalone CHIP tool.

So I ran the following commands:

idf.py set-target esp32
idf.py -p /dev/cu.SLAB_USBtoUART erase_flash
idf.py -p /dev/cu.SLAB_USBtoUART flash monitor

Which cleared the state/pairing info. This time instead of pairing the standalone CHIP tool to test it, I launched the iOS app and used the QR scanner. I scanned the code successfully and it paired/commissioned. I noticed the textfield for "Paired devices" didn't update, it still has () but if I left the screen and re-entered, it finally had my device id. And then I could access the light on/off cluster screen and successfully turned the light on and off.

@danh-geo
Copy link
Contributor Author

danh-geo commented Mar 2, 2022

Can someone also let me know if this is possible...

I have the iOS app paired and sending on/off commands to the esp32. I can see it has used device id 8 within the app.

How can I use the standalone chip tool to also send on/off commands to the esp32?
I'm assuming I don't need to pair again with the standalone chip tool, given the iOS app already paired and assigned a nodeId (8) to it.

I've tried:
./out/debug/chip-tool onoff on 0x0000000000000008 1
./out/debug/chip-tool onoff on 8 1

But it doesn't work.

I'd like to be able to send on/off commands from the app AND the standalone chip tool. Is this possible? And if so, how do I do it?

woody-apple pushed a commit that referenced this issue Mar 3, 2022
#15715)

* Updated iOS CHIP tool README and qr scanner to indicate requirement >= iOS 15.4 (#15640)

* Restyled by clang-format

* Restyled by prettier-markdown

Co-authored-by: Restyled.io <commits@restyled.io>
@danh-geo
Copy link
Contributor Author

danh-geo commented Mar 3, 2022

I managed to send ono/off commands with both the iOS app and the standalone chip tool.

It only worked when I added the iOS app first, and then the standalone CHIP tool as the second admin. I wasn't able to pair via the standalone chip tool first, and then add the iOS app as a second admin. Regardless here are the steps for both...

Working:

  • Paired with iOS app first using QR code scanner
  • After pairing complete, iOS app Main Menu > Enable Pairing > Open Pairing Window
    This reveals a manual code. Then in the standalone chip tool use this command:
    ./out/debug/chip-tool pairing manualcode {nodeIdFromTheApp} {manualCodeFromTheApp}

I could then send on/off commands with both chip tools (app and standalone)

Couldn't get working:

  • Paired with standalone tool first
  • ./out/debug/chip-tool pairing ble-wifi 112233 {ssid} {pw} 20202021 3840
  • ./out/debug/chip-tool pairing open-commissioning-window 112233 1 600 1000 3840
  • Copy the manual code from the command above and paste it into the QRCode scanner screen on iOS CHIPTool.
  • I was expecting the paired devices list to show the nodeId 112233 but it never did...

@bzbarsky-apple
Copy link
Contributor

iOS CHIPTool and the command-line chip-tool are separate admins on separate fabrics. The "Couldn't get working" steps should allow you to paste the manual code and then commission the same device in iOS CHIPTool, and this does work last I tested. But the node id will be different, because these are independent fabrics.

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

3 participants