diff --git a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/AddressCommissioningFragment.kt b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/AddressCommissioningFragment.kt index 8f95c2d0b00a22..64bd9b31c55a66 100644 --- a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/AddressCommissioningFragment.kt +++ b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/AddressCommissioningFragment.kt @@ -51,6 +51,7 @@ class AddressCommissioningFragment : Fragment() { val address = binding.addressEditText.text.toString() val discriminator = binding.discriminatorEditText.text.toString() val pincode = binding.pincodeEditText.text.toString() + val port = binding.portEditText.text.toString() if (address.isEmpty() || discriminator.isEmpty() || pincode.isEmpty()) { Log.e(TAG, "Address, discriminator, or pincode was empty: $address $discriminator $pincode") @@ -62,7 +63,8 @@ class AddressCommissioningFragment : Fragment() { CHIPDeviceInfo( discriminator = discriminator.toInt(), setupPinCode = pincode.toLong(), - ipAddress = address + ipAddress = address, + port = port.toInt() ) ) } @@ -169,7 +171,7 @@ class AddressCommissioningFragment : Fragment() { val deviceController = ChipClient.getDeviceController(requireContext()) for (i in 0..10) { val device = deviceController.getDiscoveredDevice(i) ?: break - ipAddressList.add("${device.ipAddress}, ${device.discriminator}") + ipAddressList.add("${device.ipAddress}, ${device.discriminator}, ${device.port}") } requireActivity().runOnUiThread { binding.discoverListSpinner.adapter = @@ -179,9 +181,11 @@ class AddressCommissioningFragment : Fragment() { override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) { val address = ipAddressList[position].split(",")[0].trim() val discriminator = ipAddressList[position].split(",")[1].trim() + val port = ipAddressList[position].split(",")[2].trim() binding.addressEditText.setText(address) binding.discriminatorEditText.setText(discriminator) + binding.portEditText.setText(port) } override fun onNothingSelected(parent: AdapterView<*>) {} diff --git a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt index 991a1f58311e55..aa3488248b81a3 100644 --- a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt +++ b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt @@ -160,7 +160,6 @@ class DeviceProvisioningFragment : Fragment() { private fun pairDeviceWithAddress() { // IANA CHIP port - val port = 5540 val id = DeviceIdUtil.getNextAvailableId(requireContext()) DeviceIdUtil.setNextAvailableId(requireContext(), id + 1) @@ -171,7 +170,7 @@ class DeviceProvisioningFragment : Fragment() { deviceController.pairDeviceWithAddress( id, deviceInfo.ipAddress, - port, + deviceInfo.port, deviceInfo.discriminator, deviceInfo.setupPinCode, null diff --git a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/CHIPDeviceInfo.kt b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/CHIPDeviceInfo.kt index cbeb3746665b6f..d8fb51bbb3d844 100644 --- a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/CHIPDeviceInfo.kt +++ b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/setuppayloadscanner/CHIPDeviceInfo.kt @@ -36,6 +36,7 @@ data class CHIPDeviceInfo( val discoveryCapabilities: MutableSet = mutableSetOf(), val isShortDiscriminator: Boolean = false, val ipAddress: String? = null, + val port: Int = 5540 ) : Parcelable { companion object { diff --git a/examples/android/CHIPTool/app/src/main/res/layout/address_commissioning_fragment.xml b/examples/android/CHIPTool/app/src/main/res/layout/address_commissioning_fragment.xml index b82df0400a7a45..e2ad4c58cf4d7a 100644 --- a/examples/android/CHIPTool/app/src/main/res/layout/address_commissioning_fragment.xml +++ b/examples/android/CHIPTool/app/src/main/res/layout/address_commissioning_fragment.xml @@ -19,7 +19,7 @@ android:id="@+id/address_commissioning_fragment_flow" android:layout_width="0dp" android:layout_height="wrap_content" - app:constraint_referenced_ids="addressLabel,addressEditText,discriminatorLabel,discriminatorEditText,pincodeLabel,pincodeEditText" + app:constraint_referenced_ids="addressLabel,addressEditText,discriminatorLabel,discriminatorEditText,pincodeLabel,pincodeEditText,portLabel,portEditText" app:flow_horizontalStyle="packed" app:flow_wrapMode="aligned" app:flow_maxElementsWrap="2" @@ -75,6 +75,22 @@ android:inputType="number" android:text="@string/default_pincode" /> + + + + Commission with IP address 3840 20202021 + 5540 Device address Discriminator Pincode + Port Commission Discover Wi-Fi Scan diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index 7f311a823850f1..29cab3b22424e3 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -1910,6 +1910,7 @@ JNI_METHOD(jobject, getDiscoveredDevice)(JNIEnv * env, jobject self, jlong handl if (data == nullptr) { + ChipLogError(Controller, "GetDiscoveredDevice - not found"); return nullptr; } @@ -1918,6 +1919,7 @@ JNI_METHOD(jobject, getDiscoveredDevice)(JNIEnv * env, jobject self, jlong handl jfieldID discrminatorID = env->GetFieldID(discoveredDeviceCls, "discriminator", "J"); jfieldID ipAddressID = env->GetFieldID(discoveredDeviceCls, "ipAddress", "Ljava/lang/String;"); + jfieldID portID = env->GetFieldID(discoveredDeviceCls, "port", "I"); jobject discoveredObj = env->NewObject(discoveredDeviceCls, constructor); @@ -1926,12 +1928,10 @@ JNI_METHOD(jobject, getDiscoveredDevice)(JNIEnv * env, jobject self, jlong handl char ipAddress[100]; data->resolutionData.ipAddress[0].ToString(ipAddress, 100); jstring jniipAdress = env->NewStringUTF(ipAddress); + env->SetObjectField(discoveredObj, ipAddressID, jniipAdress); + env->SetIntField(discoveredObj, portID, static_cast(data->resolutionData.port)); - if (data == nullptr) - { - ChipLogError(Controller, "GetDiscoveredDevice - not found"); - } return discoveredObj; } diff --git a/src/controller/java/src/chip/devicecontroller/DiscoveredDevice.java b/src/controller/java/src/chip/devicecontroller/DiscoveredDevice.java index 3be9631512af42..01d6ecc28cce42 100644 --- a/src/controller/java/src/chip/devicecontroller/DiscoveredDevice.java +++ b/src/controller/java/src/chip/devicecontroller/DiscoveredDevice.java @@ -20,4 +20,5 @@ public class DiscoveredDevice { public long discriminator; public String ipAddress; + public int port; }