espressif / esp-idf-provisioning-android

Android Provisioning application for ESP-IDF Unified provisioning
Apache License 2.0
194 stars 129 forks source link

Unable to call ProvisionListener in Kotlin Android #86

Open adammizam opened 1 year ago

adammizam commented 1 year ago

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 commented 1 month ago

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

adammizam commented 1 month ago

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.