orbital-systems / react-native-esp-idf-provisioning

ESP IDF provisioning and custom data library for react-native
MIT License
26 stars 6 forks source link

[Android] `userName` property is never set #19

Closed robbeman closed 11 months ago

robbeman commented 11 months ago

Problem

When calling device.scanWifiList (or sendData) on a connected device that requires a username the following error occurs:

java.lang.IllegalArgumentException: The user identity 'I' must not be null or empty
    at com.espressif.provisioning.srp6a.SRP6ClientSession.step1
    at com.espressif.provisioning.security.Security2.<init>(Security2.java:84)
    at com.espressif.provisioning.ESPDevice.initSession(ESPDevice.java:640)
    at com.espressif.provisioning.ESPDevice.scanNetworks(ESPDevice.java:503)
    at com.espidfprovisioning.EspIdfProvisioningModule.scanWifiList
    at java.lang.reflect.Method.invoke(Native Method)
    at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.
    at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.
    at com.facebook.jni.NativeRunnable.run(Native Method)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage
    at android.os.Looper.loopOnce(Looper.java:226)
    at android.os.Looper.loop(Looper.java:313)
    at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run
    at java.lang.Thread.run(Thread.java:1012)

This is caused by the espDevices in EspIdfProvisioningModule not retaining the username used to connect to the device.

Proposed solution

I'm not sure if it is as simple as that, but this ~is what I think should work~ does seem to work in my local setup:

https://github.com/orbital-systems/react-native-esp-idf-provisioning/blob/b0e240de206abb27a1b7ce46a656d12540c2d89c/android/src/main/java/com/espidfprovisioning/EspIdfProvisioningModule.kt#L195

espDevice.userName = username

https://github.com/orbital-systems/react-native-esp-idf-provisioning/blob/b0e240de206abb27a1b7ce46a656d12540c2d89c/android/src/main/java/com/espidfprovisioning/EspIdfProvisioningModule.kt#L221

espDevices[deviceName]?.userName = username

Thank you for the time and effort you put into this package. I will continue debugging and let you know if I find anything substantial. 🙏

mateogianolio commented 11 months ago

Very nice find and thank you for testing the package!