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 call ProvisionListener in Kotlin Android #86

Open
adammizam opened this issue Mar 2, 2023 · 7 comments
Open

Unable to call ProvisionListener in Kotlin Android #86

adammizam opened this issue Mar 2, 2023 · 7 comments

Comments

@adammizam
Copy link

adammizam commented Mar 2, 2023

I'm new in kotlin android development, I have encounter one issue that unable to send the information for Provision. It keep crashing during testing and the error is 'int java.lang.String.length()' on a null object reference.
Below is an example of my test code:

provisionManager.espDevice.provision(ssidValue, passphraseValue, object : ProvisionListener
        {
            override fun createSessionFailed(e: Exception) {
                runOnUiThread {
                    Toast.makeText(applicationContext, "Create Session Failed", Toast.LENGTH_LONG).show()
                }
            }

            override fun wifiConfigSent() {
                runOnUiThread {
                    Toast.makeText(applicationContext, "Wifi Config Sent", Toast.LENGTH_LONG).show()
                }
            }

            override fun wifiConfigFailed(e: Exception) {
                runOnUiThread {
                    Toast.makeText(applicationContext, "Wifi Config Failed", Toast.LENGTH_LONG).show()
                }
            }

            override fun wifiConfigApplied() {
                runOnUiThread {
                    Toast.makeText(applicationContext, "Wifi Config Applied", Toast.LENGTH_LONG).show()
                }
            }

            override fun wifiConfigApplyFailed(e: Exception) {
                runOnUiThread {
                    Toast.makeText(applicationContext, "Wifi Config Apply Failed", Toast.LENGTH_LONG).show()
                }
            }

            override fun provisioningFailedFromDevice(failureReason: ProvisionFailureReason) {
                runOnUiThread {
                    when (failureReason) {
                        ProvisionFailureReason.AUTH_FAILED -> Toast.makeText(applicationContext, "Authentication Failed", Toast.LENGTH_LONG).show()
                        ProvisionFailureReason.NETWORK_NOT_FOUND -> Toast.makeText(applicationContext, "Network Not Found", Toast.LENGTH_LONG).show()
                        ProvisionFailureReason.DEVICE_DISCONNECTED, ProvisionFailureReason.UNKNOWN -> Toast.makeText(applicationContext, "Device disconnected", Toast.LENGTH_LONG).show()
                    }
                }
            }

            override fun deviceProvisioningSuccess() {
                runOnUiThread {
                    Toast.makeText(applicationContext, "Provisioning Success", Toast.LENGTH_LONG).show()
                }
            }

            override fun onProvisioningFailed(e: Exception) {
                runOnUiThread {
                    Toast.makeText(applicationContext, "Provisioning Failed", Toast.LENGTH_LONG).show()
                }
            }
        })

Below is the error:

java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
                                                      at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:121)
                                                      at org.json.JSONTokener.nextValue(JSONTokener.java:98)
                                                      at org.json.JSONObject.<init>(JSONObject.java:168)
                                                      at org.json.JSONObject.<init>(JSONObject.java:185)
                                                      at com.espressif.provisioning.ESPDevice.initSession(ESPDevice.java:593)
                                                      at com.espressif.provisioning.ESPDevice.provision(ESPDevice.java:569)
@lozaning
Copy link

Did you ever figure this out @adammizam? Im stuck with the exact same problem

@adammizam
Copy link
Author

Did you ever figure this out @adammizam? Im stuck with the exact same problem

If I not mistaken, last time what I did is try to check the sended command from the devices and retry to method. Sorry I have forgotten about the issues and already leave the company.

@ryanrampage1
Copy link

@lozaning you have any ideas on this? Im having the same issue. The actual NPE is in the following when it tries to get the version info off the BLE transport object. Just can not figure out where to set that.

/**
     * This method is used to get version information to determine what features are enabled in a device and act accordingly.
     *
     * @return Returns device version information.
     */
    public String getVersionInfo() {

        if (transport instanceof BLETransport) {
            return ((BLETransport) transport).versionInfo;
        } else {
            return versionInfo;
        }
    }

@ryanrampage1
Copy link

ryanrampage1 commented Jul 25, 2024

Looks like this commit switched from an independent runnable to set up that version info to on the first read. No idea how this is working at all for anyone.

Rolling back to implementation 'com.github.espressif:esp-idf-provisioning-android:lib-2.0.14' got me rolling to at least get developing for now

@ryanrampage1
Copy link

My quick update here, when I swapped over from WIFI_PROV_SECURITY_1 to WIFI_PROV_SECURITY_0 on the firmware. Guessing that is a big part of the issue.

@KhushbuShah25
Copy link
Contributor

Will check the issue and update soon.

@valientegaston
Copy link

Hi! same problem here... any fix available? Thank you!

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

5 participants