espressif / esp-idf-provisioning-android

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

Qrcode is not valid #90

Closed MakeMeCookie closed 1 year ago

MakeMeCookie commented 1 year ago

I git clone the https://github.com/espressif/esp-idf-provisioning-android.git' site and succeeded in building Android. When you click Provision New Device and scan for QRCODE, the phrase "QRCODE is not valid" appears and does not go any further.

I checked the code and it looks like this part. I'd like to connect the qrcode to the ble, but how can I correct it?

/esp-idf-provisioning-android/provisioning/src/main/java/com/espressif/provisioning/ESPProvisionManager.java `@RequiresPermission(allOf = {Manifest.permission.CAMERA, Manifest.permission.BLUETOOTH_ADMIN, Manifest.permission.BLUETOOTH, Manifest.permission.ACCESS_FINE_LOCATION}) public void scanQRCode(final CodeScanner codeScanner, final QRCodeScanListener qrCodeScanListener) {

    isScanned = false;
    List<BarcodeFormat> formats = new ArrayList<>();
    formats.add(BarcodeFormat.QR_CODE);

    codeScanner.setDecodeCallback(new DecodeCallback() {
        @Override
        public void onDecoded(@NonNull final Result result) {

            String scannedData = result.getText();

            if (!TextUtils.isEmpty(scannedData) && !isScanned) {

                Log.d(TAG, "QR Code Data : " + scannedData);

                try {
                    JSONObject jsonObject = new JSONObject(scannedData);

                    String deviceName = jsonObject.optString("name");
                    String pop = jsonObject.optString("pop");
                    String transport = jsonObject.optString("transport");
                    int security = jsonObject.optInt("security", ESPConstants.SecurityType.SECURITY_2.ordinal());
                    String userName = jsonObject.optString("username");
                    String password = jsonObject.optString("password");
                    isScanned = true;

                    if (qrCodeScanListener != null) {
                        qrCodeScanListener.qrCodeScanned();
                    }

                    Handler handler = new Handler(Looper.getMainLooper());
                    handler.post(new Runnable() {

                        @Override
                        public void run() {
                            codeScanner.releaseResources();
                        }
                    });

                    ESPConstants.TransportType transportType = null;
                    ESPConstants.SecurityType securityType = null;

                    if (!TextUtils.isEmpty(transport)) {

                        if (transport.equalsIgnoreCase("softap")) {

                            transportType = ESPConstants.TransportType.TRANSPORT_SOFTAP;

                        } else if (transport.equalsIgnoreCase("ble")) {

                            transportType = ESPConstants.TransportType.TRANSPORT_BLE;

                        } else {
                            Log.e(TAG, "" + transport + " Transport type is not supported");
                            qrCodeScanListener.onFailure(new RuntimeException("Transport type is not supported"));
                            return;
                        }
                    } else {
                        Log.e(TAG, "Transport is not available in QR code data");
                        qrCodeScanListener.onFailure(new RuntimeException("QR code is not valid"), scannedData);
                        return;
                    }

                    securityType = setSecurityType(security);

                    espDevice = new ESPDevice(context, transportType, securityType);
                    espDevice.setDeviceName(deviceName);
                    espDevice.setProofOfPossession(pop);
                    espDevice.setUserName(userName);

                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && transportType.equals(ESPConstants.TransportType.TRANSPORT_SOFTAP)) {

                        WiFiAccessPoint wiFiDevice = new WiFiAccessPoint();
                        wiFiDevice.setWifiName(deviceName);
                        wiFiDevice.setPassword(password);
                        espDevice.setWifiDevice(wiFiDevice);
                        qrCodeScanListener.deviceDetected(espDevice);
                    } else {
                        isDeviceAvailable(espDevice, password, qrCodeScanListener);
                    }

                } catch (JSONException e) {

                    e.printStackTrace();
                    qrCodeScanListener.onFailure(new RuntimeException("QR code is not valid"), scannedData);
                }
            } else {
                qrCodeScanListener.onFailure(new RuntimeException("QR code is not valid"), scannedData);
            }
        }
    });
}

`

Screenshot_20231106-170923_ESP Provisioning Screenshot_20231106-170932_ESP Provisioning