Device Information

Last Updated on : 2023-10-07 07:17:46download

Overview

A device information query can return the following information.

  • The device ID.
  • The IP address of the device.
  • The local IP address of the device.
  • The time zone of the device.
  • The MAC addresses.
  • The signal strength of the device.
  • The integrated circuit card identifier (ICCID) of the SIM card.
  • The connectivity of the device.
  • The device channel (for Zigbee devices only).
  • The manufacturer of the device (for third-party Matter devices only).
  • The reference signal received power (RSRP) of the device (for LTE Cat.1 devices only).

API list

Device information model

ThingDeviceDetailInfo

Property Type Description
devId NSString The device ID.
iccid NSString The ICCID, the unique ID of the SIM card. This parameter applies to LTE Cat.1 devices only.
netStrength NSString The signal strength of the device.
lanIp NSString The local IP address of the device.
ip NSString The IP address of the device.
mac NSString The MAC address of the device.
timezone NSString The time zone of the device.
channel NSString The channel ID. This parameter applies to Zigbee gateways only.
rsrp NSNumber The RSRP value, indicating the network signal strength of the device. This parameter applies to LTE Cat.1 devices only.
wifiSignal NSNumber The Wi-Fi signal strength of the device.
homekitCode NSString The HomeKit code.
connectAbility ThingDeviceInfoConnectAbility Device connectivity:
  • ThingDeviceInfoConnectAbilityUnknown: Unknown
  • ThingDeviceInfoConnectAbilityPhone: Mobile phone only
  • ThingDeviceInfoConnectAbilityGateway: Gateway only
  • ThingDeviceInfoConnectAbilityPhoneAndGateway: Mobile phone and gateway
vendorName NSString The manufacturer of the device. This parameter applies to third-party Matter devices only.

Get device information

API description

This method returns the existing device information immediately. The information is displayed on the launch screen to prevent the app from showing a blank screen due to network latency.

- (nullable ThingDeviceDetailInfo *)deviceInfo;

Description of return values

For more information about the data model of return values, see Device information model.

Get device information asynchronously

API description

This method retrieves device information from the server asynchronously.

- (void)fetchDataSuccess:(void(^)(ThingDeviceDetailInfo *info, NSDictionary *hardwareInfo))success failure:(void(^)(NSError *error))failure;

Description of return values

Data Type Description
success None. The success callback.
  • info: Device information. For more information, see Device information model.
  • hardwareInfo: Reserved for firmware information.
failure None. The failure callback.

Method and protocol for listener

API description

Listen for changes in Wi-Fi signals.

@protocol ThingDeviceInfoManagerListener <NSObject>
@optional
- (void)deviceInfoManager:(ThingDeviceInfoManager *)manager wifiSignalDidUpdate:(int)wifiSignal;
@end

Before listening for events, add a listener through addListener:.

- (void)addListener:(id<ThingDeviceInfoManagerListener>)listener;

Remove a listener through removeListener:.

- (void)removeListener:(id<ThingDeviceInfoManagerListener>)listener;

Example

import ThingDeviceDetailKit

class DeviceDetailKitInfoVC: UITableViewController {

    var deviceId: String
    var manager: ThingDeviceInfoManager
    var items: [CustomMenuModel] = []

    init(deviceId: String) {
        self.deviceId = deviceId
        self.manager = ThingDeviceInfoManager(deviceId: deviceId)
        super.init(nibName: nil, bundle: nil)
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }


    override func viewDidLoad() {
        super.viewDidLoad()
        self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "DeviceDetailListViewControllerReuseIdentifier")
        self.manager.add(self)
        self.loadData()

    }

    func loadData() {
        SVProgressHUD.show()
        self.manager.fetchDataSuccess { [weak self] info, hardware in
            var list = [CustomMenuModel]()
            list.append(CustomMenuModel(title: "devId", detail: info.devId))
            list.append(CustomMenuModel(title: "iccid", detail: info.iccid ?? ""))
            list.append(CustomMenuModel(title: "netStrength", detail: info.netStrength ?? ""))
            list.append(CustomMenuModel(title: "lanIp", detail: info.lanIp ?? ""))
            list.append(CustomMenuModel(title: "ip", detail: info.ip ?? ""))
            list.append(CustomMenuModel(title: "mac", detail: info.mac ?? ""))
            list.append(CustomMenuModel(title: "timezone", detail: info.timezone ?? ""))
            list.append(CustomMenuModel(title: "channel", detail: info.channel ?? ""))
            list.append(CustomMenuModel(title: "rsrp", detail: info.rsrp != nil ? "\(info.rsrp!)" : ""))
            list.append(CustomMenuModel(title: "wifiSignal", detail: info.wifiSignal != nil ? "\(info.wifiSignal!)" : ""))
            list.append(CustomMenuModel(title: "homekitCode", detail: info.homekitCode ?? ""))
            list.append(CustomMenuModel(title: "connectAbility", detail: "\(info.connectAbility)"))
            list.append(CustomMenuModel(title: "vendorName", detail: info.vendorName ?? ""))
            self?.items = list
            self?.tableView.reloadData()
            SVProgressHUD.dismiss()
        } failure: { e in
            SVProgressHUD.dismiss()
        }

    }

    override func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return items.count
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = UITableViewCell(style: .value1, reuseIdentifier: "DeviceDetailListViewControllerReuseIdentifier")
        cell.textLabel?.text = self.items[indexPath.row].title
        cell.detailTextLabel?.text = self.items[indexPath.row].detail
        return cell
    }

}

extension DeviceDetailKitInfoVC: ThingDeviceInfoManagerListener {
    func deviceInfoManager(_ manager: ThingDeviceInfoManager, wifiSignalDidUpdate wifiSignal: Int32) {
        let item = self.items.first { item in
            return item.title == "wifiSignal"
        }
        item?.detail = "\(wifiSignal)"
        self.tableView.reloadData()
    }
}