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

Unable to use setParingCode() successfully #786

Open
dsbeach opened this issue Feb 25, 2024 · 5 comments
Open

Unable to use setParingCode() successfully #786

dsbeach opened this issue Feb 25, 2024 · 5 comments
Labels
bug Something isn't working fixed in dev A bug fix available now in dev

Comments

@dsbeach
Copy link

dsbeach commented Feb 25, 2024

Problem: unable to pair device after invocation of setParingCode()
HomeSpan version 1.9.0

Steps to reproduce:

  • modify 01-SimpleLightBulb example as follows:
  • insert the lines below before call to homeSpan.begin()
    homeSpan.setLogLevel(2);
    homeSpan.setPairingCode("32154876");

Attempts to pair are unsuccessful, however the same pairing code can be set successfully via the serial interface

Note:

log output from setPariringCode() shows:
Generating SRP verification data for new Setup Code: 321-54-876 ... New Code Saved!
Setup Payload for Optional QR Code: X-HM://0004YYOZG

serial interface change shows:
Generating SRP verification data for new Setup Code: 321-54-876 ... New Code Saved!
Setup Payload for Optional QR Code: X-HM://0052JQTX8HSPN

@HomeSpan
Copy link
Owner

I think you've identified a bug in the new release (likely a result of all the refactoring). I can see by the QR code it generates that something is incorrect.

Thanks for finding this --- will check it out and fix in a patch release.

@HomeSpan HomeSpan added the bug Something isn't working label Feb 25, 2024
@dsbeach
Copy link
Author

dsbeach commented Feb 25, 2024

Closer examination of the log reveals a second reference to Setup Code. Here is a full log following a command line E

*** ALL DATA ERASED!  Restarting...

ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0xc (RTC_SW_CPU_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x420c350a
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x44c
load:0x403c9700,len:0xbd8
load:0x403cc700,len:0x2a80
entry 0x403c98d0

Generating SRP verification data for new Setup Code: 321-54-876 ... New Code Saved!
Setup Payload for Optional QR Code: X-HM://0004YYOZG    


************************************************************
Welcome to HomeSpan!
Apple HomeKit for the Espressif ESP-32 WROOM and Arduino IDE
************************************************************

** Please ensure serial monitor is set to transmit <newlines>

Message Logs:     Level 2
Status LED:       Pin -  *** WARNING: Status LED Pin is UNDEFINED
Device Control:   Pin -  *** WARNING: Device Control Pin is UNDEFINED
Sketch Version:   n/a
HomeSpan Version: 1.9.0
Arduino-ESP Ver.: 2.0.14
ESP-IDF Version:  4.4.6
ESP32 Chip:       ESP32-S3 Rev 0 dual-core 8MB Flash
ESP32 Board:      esp32s3
PWM Resources:    8 channels, 4 timers, max 14-bit duty resolution
Sodium Version:   1.0.12-idf  Lib 9.4
MbedTLS Version:  mbed TLS 2.28.4
Sketch Compiled:  Feb 25 2024 08:55:11
Partition:        app0
MAC Address:      DC:DA:0C:4B:33:2C

Device Name:      HomeSpan LightBulb

*** HomeSpan Info ***

➤ Accessory:  AID=1
   ➟ Service AccessoryInformation:  IID=1, UUID="3E"
      ⇨ Characteristic Identify(1):  IID=2, UUID="14", Perms=PW
   ➟ Service LightBulb:  IID=3, UUID="43"
      ⇨ Characteristic On(0):  IID=4, UUID="25", Perms=PR+PW+EV

Service                             UUID         AID  IID  Update  Loop  Button  Linked Services
------------------------------  --------  ----------  ---  ------  ----  ------  ---------------
AccessoryInformation                  3E           1    1      NO    NO      NO  -
LightBulb                             43           1    3      NO    NO      NO  -

Configured as Bridge: NO

Database Validation:  Warnings=0, Errors=0

*** End Info ***


Generating SRP verification data for new Setup Code: 466-37-726 ... New Code Saved!
Setup Payload for Optional QR Code: X-HM://0052SD8YM    

Generating new random Accessory ID and Long-Term Ed25519 Signature Keys...

Accessory ID:      41:14:AA:6D:CD:82                               LTPK: 472E3FEADFBDDDA01C7DD46C97579BE2EFC9662452FB2AF8B436D1383407465B
No Paired Controllers
Resetting Database Hash...

Accessory configuration has changed.  Updating configuration number to 1

*** WIFI CREDENTIALS DATA NOT FOUND.  YOU MAY CONFIGURE BY TYPING 'W <RETURN>'.

HomeSpan LightBulb is READY!

@HomeSpan
Copy link
Owner

I have identified the problem and will fix in the next release (was an inadvertent error introduced in 1.9.0).

However, there is an easy workaround:

  • If you are using a WiFi Callback, call homeSpan.setPairingCode("32154876"); from within that callback instead of from within setup()
  • If you are NOT using a WiFi Callback, create one in setup() as follows:
// place the following in setup() before homeSpan.begin()

homeSpan.setWifiCallback([](){homeSpan.setPairingCode("32154876");});

The root of the issue is that as part of changes to 1.9.0 I no longer store the hashed setup code in memory when it is changed, but only in NVS, where it is read when needed for pairing. However, the NVS space that stores this information does not get opened and initialized until after homeSpan polling is started. This means calling setPairingCode() in setup() fails to store the hash in NVS as needed.

@dsbeach
Copy link
Author

dsbeach commented Feb 26, 2024

Thanks for your prompt investigation and workaround for this issue. I can confirm the use of WiFi Callback has the desired result.

@HomeSpan
Copy link
Owner

HomeSpan commented Mar 2, 2024

This has now been fixed -- homeSpan.setPairingCode() works as before with two slight changes to behavior:

  1. the method now operates silently if a valid pairing code is provided (i.e. nothing is printed to the Serial Monitor); and
  2. if an invalid code is provided, the usual error messages are output on the Serial Monitor, AND the sketch is halted.

Fix is available in "dev" branch and will be part of the next release.

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

No branches or pull requests

2 participants