অ্যান্ড্রয়েড অ্যাপ ডেভেলপাররা হোম এপিআই ব্যবহার করে একটি থ্রেড বর্ডার রাউটার পরিচালনা করতে পারেন।
GoogleBorderRouterDevice টি দুটি প্রধান ডিভাইস ট্রেইট ব্যবহার করে বাস্তবায়িত হয়: ThreadNetworkCapabilities , যা বর্ডার রাউটারের বৈশিষ্ট্যগুলো পরীক্ষা করার জন্য রিড-অনলি অ্যাট্রিবিউট প্রদান করে, এবং ThreadNetworkManagement , যা কমিশনারের জন্য একটি Ephemeral Pre-Shared Key (ePSKc) ব্যবহার করে নেটওয়ার্ক লাইফসাইকেল কমান্ড এবং ক্রেডেনশিয়াল শেয়ারিং পরিচালনা করে। স্ট্রাকচার-লেভেলের ইন্টারনেট অ্যাক্সেস পলিসিগুলো ThreadNetworkSettings ট্রেইট ব্যবহার করে পরিচালিত হয়।
যেকোনো বৈশিষ্ট্য ব্যবহার করার বা অ্যাট্রিবিউট আপডেট করার চেষ্টা করার আগে, ডিভাইসটির অ্যাট্রিবিউট এবং কমান্ড সমর্থনের বিষয়টি সর্বদা যাচাই করে নিন। ডিভাইস নিয়ন্ত্রণ দেখুন।Android আরও তথ্যের জন্য।
| হোম এপিআই ডিভাইসের ধরন | বৈশিষ্ট্য | কোটলিন নমুনা অ্যাপ | ব্যবহারের ক্ষেত্র |
|---|---|---|---|
বর্ডার রাউটার | প্রয়োজনীয় বৈশিষ্ট্য গুগল থ্রেডনেটওয়ার্কক্যাপাবিলিটিস গুগল থ্রেডনেটওয়ার্কম্যানেজমেন্ট | সীমান্ত রাউটার |
একটি ডিভাইস সম্পর্কে প্রাথমিক তথ্য জানুন
BasicInformation ট্রেইটটিতে একটি ডিভাইসের জন্য ভেন্ডরের নাম, ভেন্ডর আইডি, প্রোডাক্ট আইডি, প্রোডাক্টের নাম (মডেলের তথ্য সহ), এবং সফটওয়্যার ভার্সনের মতো তথ্য অন্তর্ভুক্ত থাকে:
// Get device basic information. All general information traits are on the RootNodeDevice type. device.type(RootNodeDevice).first().standardTraits.basicInformation?.let { basicInformation -> println("vendorName ${basicInformation.vendorName}") println("vendorId ${basicInformation.vendorId}") println("productId ${basicInformation.productId}") println("productName ${basicInformation.productName}") println("softwareVersion ${basicInformation.softwareVersion}") }
বর্ডার রাউটারের সক্ষমতা পরীক্ষা করুন
আপনি ThreadNetworkCapabilities ট্রেইট ব্যবহার করে একটি বর্ডার রাউটারের রিড-অনলি সক্ষমতা (যেমন ePSKc সাপোর্ট এবং ইন্টারনেট অ্যাক্সেস সেটিং কনফিগারেশন) পরীক্ষা করতে পারেন।
suspend fun checkBorderRouterCapabilities(device: HomeDevice) {
// Filter for GoogleBorderRouterDevice device type
val gtbrDevice = device.type(GoogleBorderRouterDevice).firstOrNull()
if (gtbrDevice == null) {
println("Device is not a Google border router.")
return
}
// Retrieve the ThreadNetworkCapabilities trait
val capabilitiesTrait = gtbrDevice.trait(ThreadNetworkCapabilities)
if (capabilitiesTrait == null) {
println("ThreadNetworkCapabilities trait not found on device.")
return
}
val isEpskcSupported = capabilitiesTrait.epskcSupported ?: false
val internetAccessOption = capabilitiesTrait.internetAccessOption?.name ?: "None"
val isIasSupported = !internetAccessOption.equals("None", ignoreCase = true)
println("ePSKc Supported: $isEpskcSupported")
println("Internet Access Setting Supported: $isIasSupported")
}
থ্রেড ক্রেডেনশিয়াল শেয়ারিং পরিচালনা করুন (ePSKc)
কমিশনারের জন্য একটি ক্ষণস্থায়ী পূর্ব-শেয়ারকৃত কী (ePSKc) ব্যবহার করে থ্রেড ক্রেডেনশিয়াল শেয়ারিং সম্পন্ন করা হয়। ePSKc মোড একটি অস্থায়ী, সুরক্ষিত পাসকী তৈরি করে যা বাহ্যিক ডিভাইস বা কমিশনাররা থ্রেড নেটওয়ার্ক ডেটাসেট নিরাপদে পেতে ব্যবহার করতে পারে।
ePSKc মোড সক্রিয় করুন
suspend fun startEpskcSession(device: HomeDevice, durationSeconds: Short): ActivateEpskcModeCommand.Response? {
val gtbrDevice = device.type(GoogleBorderRouterDevice).firstOrNull()
val mgmtTrait = gtbrDevice?.trait(ThreadNetworkManagement)
if (mgmtTrait == null) {
println("ThreadNetworkManagement trait not found.")
return null
}
return try {
val response = mgmtTrait.activateEpskcMode(
optionalArgs = { this.requestedDurationSeconds = durationSeconds }
)
println("ePSKc Session Activated!")
println("Status: ${response.status}")
println("Ephemeral PSKc: ${response.epskc}")
println("Valid Duration (s): ${response.validDurationSeconds}")
response
} catch (e: Exception) {
println("Failed to activate ePSKc mode: ${e.message}")
null
}
}
ePSKc মোড নিষ্ক্রিয় করুন
suspend fun stopEpskcSession(device: HomeDevice) {
val gtbrDevice = device.type(GoogleBorderRouterDevice).firstOrNull()
val mgmtTrait = gtbrDevice?.trait(ThreadNetworkManagement)
mgmtTrait?.deactivateEpskcMode()
println("ePSKc mode deactivated.")
}
ePSKc নিষ্ক্রিয়করণ ঘটনাগুলি পর্যবেক্ষণ করুন
যখন একটি ePSKc সেশন শেষ হয় (উদাহরণস্বরূপ, কী ব্যবহৃত হয়ে গেলে, সেশনের মেয়াদ শেষ হয়ে গেলে, বা এটি ম্যানুয়ালি বাতিল করা হলে), তখন থ্রেড বর্ডার রাউটারগুলো ইভেন্ট নির্গত করে।
suspend fun observeEpskcEvents(device: HomeDevice) {
val gtbrDevice = device.type(GoogleBorderRouterDevice).firstOrNull()
val mgmtTrait = gtbrDevice?.trait(ThreadNetworkManagement)
mgmtTrait?.epskcModeDeactivatedEventFlow()?.collect { event ->
println("ePSKc Session Ended. Reason: ${event.reason}")
when (event.reason?.name) {
"KeyUsed" -> println("Key was successfully used to commission a device.")
"Expired" -> println("Session timed out before the key was used.")
"Cancelled" -> println("Session was manually cancelled.")
}
}
}
থ্রেড নেটওয়ার্ক সদস্যপদ পরিচালনা করুন
আপনি সক্রিয় অপারেশনাল ডেটাসেট TLV-গুলো প্রদান করে একটি থ্রেড বর্ডার রাউটারকে নতুন থ্রেড নেটওয়ার্কে যোগ দেওয়ার নির্দেশ দিতে পারেন, অথবা এটিকে তার বর্তমান নেটওয়ার্ক ছেড়ে যাওয়ার নির্দেশ দিতে পারেন।
suspend fun joinNetwork(device: HomeDevice, datasetTlvs: ByteArray) {
val gtbrDevice = device.type(GoogleBorderRouterDevice).firstOrNull()
val mgmtTrait = gtbrDevice?.trait(ThreadNetworkManagement)
try {
val response = mgmtTrait?.joinNetwork(operationalDatasetTlvs = datasetTlvs)
println("Join network command sent. Status: ${response?.status}")
} catch (e: Exception) {
println("Join network failed: ${e.message}")
}
}
suspend fun leaveNetwork(device: HomeDevice) {
val gtbrDevice = device.type(GoogleBorderRouterDevice).firstOrNull()
val mgmtTrait = gtbrDevice?.trait(ThreadNetworkManagement)
try {
mgmtTrait?.leaveNetwork()
println("Leave network command sent successfully.")
} catch (e: Exception) {
println("Leave network failed: ${e.message}")
}
}
কাঠামো-স্তরের ইন্টারনেট অ্যাক্সেস কনফিগার করুন
ThreadNetworkSettings ট্রেইটটি একটি আপডেটেবল ট্রেইট যা একটি Structure (যা একটি বাড়ি বা বিল্ডিংয়ের প্রতিনিধিত্ব করে) সাথে সংযুক্ত থাকে। এটি ডেভেলপারদের থ্রেড বর্ডার রাউটারগুলোর জন্য স্ট্রাকচার-ব্যাপী ইন্টারনেট অ্যাক্সেস পলিসি কনফিগার করার সুযোগ দেয়।
suspend fun updateStructureInternetAccess(structure: Structure, enableInternetAccess: Boolean) {
// Retrieve the ThreadNetworkSettings trait for the structure
val settingsTrait = structure.trait(ThreadNetworkSettings).firstOrNull()
if (settingsTrait == null) {
println("ThreadNetworkSettings trait not found on structure.")
return
}
val option = if (enableInternetAccess) {
InternetAccessOption.InternetAccessOptionAll
} else {
InternetAccessOption.InternetAccessOptionNone
}
try {
settingsTrait.update {
setInternetAccessOption(option)
}
println("Successfully updated Thread internet access policy to: ${option.name}")
} catch (e: Exception) {
println("Failed to update Thread internet access policy: ${e.message}")
}
}