IoT Platformでは、デバイスプロパティに必要な値を指定できます。 これにより、IoT Platformに必要な値をキャッシュし、その値を使用してデバイスをリモート制御できます。 このトピックでは、IoT Platformコンソールでデバイスプロパティに必要な値を指定して、電球のステータスを制御する方法について説明します。
背景情報
電球がIoT Platformに接続された後、電球のステータスを制御するためにデバイスがオンラインのままであることを確認します。 IoT Platformコンソールのバルブは、オン (1) またはオフ (0) の状態にすることができます。 実際のシナリオでは、電球がオンラインのままにならない場合があります。
bulbに必要な値を指定し、その値をIoT Platformに保存できます。 デバイスがオンラインになった後、デバイスはIoT Platformに保存されている目的のプロパティ値を読み取り、プロパティ値を更新できます。 その後、更新されたプロパティ値がIoT Platformに送信され、IoT Platformコンソールの [ステータス] タブに表示されます。
プロダクトを作成してデバイスを追加する
- IoT Platformコンソールにログインします。
[概要] ページで、[すべての環境] をクリックします。 [すべての環境] タブで、管理するインスタンスを見つけ、インスタンスIDまたはインスタンス名をクリックします。
- 左側のナビゲーションウィンドウで、 を選択します。 [製品] ページで、[製品の作成] をクリックして電球製品を作成します。
- プロダクトを作成したら、[TSLの作成] をクリックしてThing Specification Language (TSL) 機能をプロダクトに追加し、TSLモデルを公開します。 詳細については、「TSL機能の追加」をご参照ください。 この例では、LightStatusプロパティが追加されています。
- 左側のナビゲーションウィンドウで、 を選択し、[デバイスの追加] をクリックしてランプデバイスを製品に追加します。 デバイスを追加したら、デバイスに関する証明書情報を取得します。 証明書情報には、ProductKey、DeviceName、およびDeviceSecretが含まれます。
デバイスリストでLampデバイスを見つけ、[操作] 列の [表示] をクリックして、[デバイスの詳細] ページに移動します。 デバイスの詳細ページの [ステータス] タブで、デバイスのプロパティ値と目的のプロパティ値を確認できます。 この例では、パラメータは空です。 目的のプロパティ値のバージョンは0です。
IoT Platformで目的のプロパティ値を指定してクエリする
IoT Platform API操作を呼び出して、デバイスの目的のプロパティ値を指定したり、最新の目的のプロパティ値を取得したりできます。
詳細は、「API操作」をご参照ください。 この例では、IoT Platform SDK for Javaが使用されています。
- SetDeviceDesiredProperty操作を呼び出して、デバイスプロパティに必要な値を指定します。
DefaultProfile profile = DefaultProfile.getProfile () "<RegionId>", // リージョンID。 "<accessKey>", // Alibaba CloudアカウントのAccessKey ID。 "<accessSecret>"); // Alibaba CloudアカウントのAccessKeyシークレット。 IAcsClientクライアント=新しいDefaultAcsClient (プロファイル); // APIリクエストを作成し、必要なパラメーターを設定します。 SetDeviceDesiredPropertyRequest request=新しいSetDeviceDesiredPropertyRequest(); request.setIotInstanceId("iot-060 ***"); request.setDeviceName("ランプ"); request.setProductKey("g4r ***"); // プロパティに指定する識別子と必要な値。 request.setItems("{\" LightStatus\": 1}"); request.setVersions("{\" LightStatus\": 0}"); // リクエストを送信し、レスポンスまたは例外を処理します。 try { SetDeviceDesiredPropertyResponse response = client.getAcsResponse (リクエスト); System.out.println (新しいGson().toJson (応答)); } catch (ServerException e) { e.printStackTrace(); } catch (ClientException e) { System.out.println("ErrCode:" + e.getErrCode()); System.out.println("ErrMsg:" + e.getErrMsg()); System.out.println("RequestId:" + e.getRequestId()); }
- QueryDeviceDesiredProperty操作を呼び出して、デバイスの目的のプロパティ値を照会します。
DefaultProfile profile = DefaultProfile.getProfile () "<RegionId>", // リージョンID。 "<accessKey>", // Alibaba CloudアカウントのAccessKey ID。 "<accessSecret>"); // Alibaba CloudアカウントのAccessKeyシークレット。 IAcsClientクライアント=新しいDefaultAcsClient (プロファイル); // APIリクエストを作成し、必要なパラメーターを設定します。 QueryDeviceDesiredPropertyRequest request=新しいQueryDeviceDesiredPropertyRequest(); request.setIotInstanceId("iot-06 ****"); request.setProductKey("g4rm ****"); request.setDeviceName("ランプ"); // クエリするプロパティの識別子。 プロパティ識別子を指定しない場合、読み取り専用プロパティを除くすべてのプロパティの必要な値が照会されます。 List<String> identifierList = new ArrayList<String>(); identifierList.add("LightStatus"); request.setIdentifiers(identifierList); // リクエストを送信し、レスポンスまたは例外を処理します。 try { QueryDeviceDesiredPropertyResponseレスポンス=client.getAcsResponse (リクエスト); System.out.println (新しいGson().toJson (応答)); } catch (ServerException e) { e.printStackTrace(); } catch (ClientException e) { System.out.println("ErrCode:" + e.getErrCode()); System.out.println("ErrMsg:" + e.getErrMsg()); System.out.println("RequestId:" + e.getRequestId()); }
コード内のパラメーターを設定する方法の詳細については、「IoT Platform SDK For Javaの使用」をご参照ください。
Lampデバイスに必要なプロパティ値を指定すると、[ステータス] タブに値が表示されます。

デバイス側の開発
電球は、次のシナリオで目的のプロパティ値を取得できます。
- 電球がオフラインからオンラインに移行すると、デバイスはIoT Platformにキャッシュされている必要なプロパティ値を要求します。
- 電球がオンラインの場合、デバイスはIoT Platformによってリアルタイムでプッシュされる目的のプロパティ値を受け取ります。
詳細については、「デバイスSDKを使用してデバイスをIoT Platformに接続する」をご参照ください。
このトピックでは、デバイス側の完全なサンプルコードについて説明します。 詳細については、「付録: デバイスを構成するサンプルコード」をご参照ください。
- デバイス証明書、リージョン、およびMQTTエンドポイントを指定します。
/** * デバイスに関する証明書情報。 * / プライベート静的文字列productKey = "******"; プライベート静的文字列deviceName = "********"; プライベート静的文字列deviceSecret = "*************"; /** * MQTT接続情報。 * / プライベート静的文字列regionId = "******"; ...... /** * MQTT初期化のパラメーターを設定します。 * / config.channelHost = deviceInfo.productKey + ".iot-as-mqtt" + リージョン + ".aliyuncs.com:1883";
説明- デバイス証明書情報の取得方法については、このトピックの「プロダクトの作成とデバイスの追加」をご参照ください。
- regionIdは、サービスが存在するリージョンのIDを指定します。 IoT Platformコンソールの左上隅にリージョンを表示できます。 リージョンIDの形式については、「サポートされているリージョン」をご参照ください。
- channelHostは、デバイスをMQTT経由でIoT Platformに接続するために使用するエンドポイントを指定します。 リージョンIDの取得方法の詳細については、「インスタンスのエンドポイントの管理」をご参照ください。
- 次のメソッドを追加します。 これらのメソッドを使用して、バルブの実際のプロパティ値を変更し、変更をIoT Platformに自動的に報告できます。
/** * デバイスがプロパティ値の変更を処理すると、次のシナリオでメソッドが呼び出されます。 * シナリオ1: デバイスがIoT Platformに接続された後、デバイスは自動的にIoT Platformから最新の目的のプロパティ値を取得するように要求します。 * シナリオ2: デバイスがオンラインの場合、デバイスは、IoT Platformが値をプッシュするproperty.setトピックから目的のプロパティ値を受け取ります。 * @ param identifier: プロパティ識別子。 * @ param value: 目的のプロパティ値。 * @ param needReport: property.postトピックを使用して、IoT Platformにプロパティ値を報告するかどうかを指定します。 * シナリオ2では、プロパティレポート機能が処理機能に統合され、needReportパラメーターがfalseに設定されます。 * @return * / private boolean handlePropertySet(String identifier, ValueWrapper値, boolean needReport) { ALog.d(TAG, "The device handles property changes= [" + identifier + "], value = [" + value + "]"); // 応答に基づいて、プロパティ設定が期待どおりに構成されているかどうかを確認します。 この例では、成功メッセージが返されます。 ブール成功=true; if (needReport) { reportProperty (識別子、値); } 成功を返す。} private void reportProperty(String identifier, ValueWrapper value){ if (StringUtils.isEmptyString (識別子) | | value == null) { return; } ALog.d(TAG, "Report the property identity=" + identifier); Map<String, ValueWrapper> reportData = new HashMap<>(); reportData.put (識別子、値); LinkKit.getInstance().getDeviceThing().thingPropertyPost(reportData, new IPublishResourceListener() { public void onSuccess(String s, Object o) { // プロパティ値が報告されます。 ALog.d(TAG、"Report success onSuccess() called with: s = [" s + "], o = [" o + "]"); } public void onError(String s, AError aError) { // プロパティ値の報告に失敗しました。 ALog.d(TAG, "Report failure onError() called with: s = [" + s + "], aError = [" + JSON.toJSONString(aError) + "]"); } }); }
- 電球がオンラインで、IoT Platformコンソールで電球に必要なプロパティ値が指定されている場合、IoT Platformはその値を電球にプッシュします。 電球はメッセージを処理し、ステータスを変更します。
次のコードでは、メッセージを処理するために
connectNotifyListener()
メソッドが呼び出されます。 Alinkプロトコルの詳細については、「デバイスがプロパティデータをIoT Platformに送信」をご参照ください。デバイスがIoT Platformから非同期メッセージを受信した後、デバイスは
mCommonHandler()
メソッドを呼び出し、次にhandlePropertySet
メソッドを呼び出してプロパティ値を更新します。/** * サービスコールとプロパティ設定に応答する関数を登録します。 * IoT Platformがデバイスからサービスを呼び出す場合、デバイスは呼び出しに応答して応答を返す必要があります。 * / public void connectNotifyListener() { List<Service> serviceList = LinkKit.getInstance().getDeviceThing().getServices(); for (int i = 0; serviceList != null && i < serviceList.size(); i ++) { サービスサービス=serviceList.get(i); LinkKit.getInstance().getDeviceThing().setServiceHandler(service.getIdentifier(), mCommonHandler); } } プライベートITResRequestHandler mCommonHandler = new ITResRequestHandler() { public void onProcess(String serviceIdentifier, Object result, ITResResponseCallback itResResResponseCallback) { ALog.d(TAG, "onProcess() called with: s = [" + serviceIdentifier + "]," + "o = [" + result + "], itResResResponseCallback= [" + itResResResResponseCallback + "]"); ALog.d(TAG、"IoT Platformからの非同期サービスコールの受信" + serviceIdentifier); try { if (SERVICE_SET.equals(serviceIdentifier)) { Map<String, ValueWrapper> data = (Map<String, ValueWrapper>)((InputParams)result).getData(); ALog.d(TAG, "Received asynchronous downstream data" + data); // デバイスのプロパティを設定し、プロパティ値をIoT Platformに報告します。 ブールisSetPropertySuccess= handlePropertySet("LightStatus" 、data.get("LightStatus") 、false); if (isSetPropertySuccess) { if (result instanceof InputParams) { // IoT Platformに応答を返します。 応答は、データが受信されたことを示す。 itResResResponseCallback. onComplete(serviceIdentifier、null、null); } else { itResResResponseCallback. onComplete(serviceIdentifier、null、null); } } else { AError error = new AError(); error.setCode(100); error.setMsg("setPropertyFailed."); itResResResponseCallback. onComplete(serviceIdentifier、新しいErrorInfo (エラー) 、null); } } else if (SERVICE_GET.equals(serviceIdentifier)) { } else { // デバイスの操作はサービスによって異なります。 ALog.d(TAG, "Return a response to IoT Platform."); OutputParams outputParams = new OutputParams(); // outputParams.put("op", new ValueWrapper.IntValueWrapper(20)); itResResResponseCallback. onComplete(serviceIdentifier、null、outputParams); } } catch (Exception e) { e.printStackTrace(); ALog.d(TAG, "返されたデータの形式は無効です"); } } public void onSuccess(Object o, OutputParams outputParams) { ALog.d(TAG, "onSuccess() called with: o = [" o "], outputParams = [" + outputParams + "]"); ALog.d(TAG、「サービスが登録されました」); } public void onFail(Object o, ErrorInfo errorInfo) { ALog.d(TAG, "onFail() called with: o = [" + o + "], errorInfo = [" + errorInfo + "]"); ALog.d(TAG、"サービス登録に失敗しました。"); } };
- 電球がオフラインで、IoT Platformコンソールで電球に目的のプロパティ値が指定されている場合、値はIoT Platformに保存されます。
bulbがオンラインになった後、bulbはIoT Platformに必要なプロパティ値を要求し、
handlePropertySet()
メソッドを呼び出してプロパティ値を更新します。LinkKit.getInstance().init(params, new ILinkKitConnectListener() { public void onError(AError aError) { ALog.e(TAG、"Init Error error=" + aError); } public void onInitDone(InitResult initResult) { ALog.i(TAG, "onInitDone result=" + initResult); connectNotifyListener(); // IoT Platformから必要な最新のプロパティ値を要求します。 getDesiredProperty(deviceInfo, Arrays.asList("LightStatus")), new IConnectSendListener() { public void onResponse(ARequest aRequest, AResponse aResponse) { if(aRequest instanceof MqttPublishRequest && aResponse.data! =null) { JSONObject jsonObject = JSONObject.parseObject(aResponse.data.toString()); ALog.i(TAG, "onResponse result=" + jsonObject); JSONObject dataObj = jsonObject.getJSONObject("data"); if (dataObj != null) { if (dataObj.getJSONObject("LightStatus") == null) { // 目的の値が指定されていません。 } else { 整数値=dataObj.getJSONObject("LightStatus").getInteger("value"); handlePropertySet("LightStatus", new ValueWrapper.IntValueWrapper(value), true); } } } } public void onFailure(ARequest aRequest, AError aError) { ALog.d(TAG, "onFailure() called with: aRequest = [" + aRequest + "], aError = [" + aError + "]"); } }); } }); private void getDesiredProperty(BaseInfo info, List<String> プロパティ, IConnectSendListenerリスナー) { ALog.d(TAG, "getDesiredProperty() called with: info = [" + info + "], listener = [" + listener + "]"); if (情報!) =null && ! StringUtils.isEmptyString(info.productKey) && ! StringUtils.isEmptyString(info.de viceName) { MqttPublishRequest request = new MqttPublishRequest(); request.topic = DESIRED_PROPERTY_GET.replace("{productKey}", info.productKey).replace("{deviceName}", info.de viceName); request.replyTopic = DESIRED_PROPERTY_GET_REPLY.replace("{productKey}", info.productKey).replace("{deviceName}", info.de viceName); request.isRPC = true; RequestModel<List<String>> model = new RequestModel<>(); model.id = String.valueOf(IDGeneraterUtils.getId()); model.method = METHOD_GET_DESIRED_PROPERTY; model.params=プロパティ; model.version = "1.0"; request.payloadObj = model.toString(); ALog.d(TAG, "getDesiredProperty: payloadObj=" + request.payloadObj); ConnectSDK.getInstance().send (要求、リスナー); } else { ALog.w(TAG、"getDesiredProperty failed, baseInfo Empty."); if (リスナー!) =null) { AError error = new AError(); error.setMsg("BaseInfoEmpty."); listener.onFailure(null、エラー); } } }
移行結果の確認
次のシナリオに基づいてサンプルコードを実行し、電球のオンラインまたはオフラインの状態を確認します。 IoT Platformで目的のプロパティ値を指定することで、デバイスプロパティ値を変更できます。
- 電球がオンラインの場合、IoT Platformで電球のステータスを変更できます。 電球はリアルタイムで変化に反応します。
- 電球がオフラインの場合、IoT Platformで電球のステータスを変更することもできます。 この場合、IoT Platformの望ましいプロパティ値と最新のデバイスプロパティ値は異なります。
- 電球がオフラインからオンラインに移行すると、電球は所望の特性値を要求する。 最新のプロパティ値は、すぐに目的の値に同期されます。
付録: デバイスを構成するサンプルコード
パッケージcom.aliyun.alink.devicesdk.de mo;
com.alibaba.fastjson.JSONをインポートします。com.alibaba.fastjson.JSONObjectをインポートします。com.aliyun.alink.apiclient.utils.StringUtilsをインポートします。com.aliyun.alink.dm.api.BaseInfoをインポートします。com.aliyun.alink.dm.api.DeviceInfoをインポートします。com.aliyun.alink.dm.api.InitResultをインポートします。com.aliyun.alink.dm.mo del.RequestModelをインポートします。com.aliyun.alink.dm.utils.IDGeneraterUtilsをインポートします。com.aliyun.alink.linkkit.api.ILinkKitConnectListenerをインポートします。com.aliyun.alink.linkkit.api.IoTMqttClientConfigをインポートします。com.aliyun.alink.linkkit.api.LinkKitをインポートします。com.aliyun.alink.linkkit.api.LinkKitInitParamsをインポートします。com.aliyun.alink.linksdk.cmp.api.ConnectSDKをインポートします。com.aliyun.alink.linksdk.cmp.connect.channel.MqttPublishRequestをインポートします。com.aliyun.alink.linksdk.cmp.core.base.ARequestをインポートします。com.aliyun.alink.linksdk.cmp.core.base.AResponseをインポートします。com.aliyun.alink.linksdk.cmp.core.listener.IConnectSendListenerをインポートします。com.aliyun.alink.linksdk.tmp.api.InputParamsをインポートします。com.aliyun.alink.linksdk.tmp.api.OutputParamsをインポートします。com.aliyun.alink.linksdk.tmp.de vice.payload.ValueWrapperをインポートします。import com.aliyun.alink.linksdk.tmp.de vicemodel.Service;
com.aliyun.alink.linksdk.tmp.listener.IPublishResourceListenerをインポートします。com.aliyun.alink.linksdk.tmp.listener.ITResRequestHandlerをインポートします。com.aliyun.alink.linksdk.tmp.listener. ITResponseCallbackをインポートします。com.aliyun.alink.linksdk.tmp.utils.ErrorInfoをインポートします。com.aliyun.alink.linksdk.tools.AErrorをインポートします。com.aliyun.alink.linksdk.tools.ALogをインポートします。java.util.Arraysをインポートします。java.util.HashMapをインポートします。java.util.Listをインポートします。java.util.Mapをインポートします。パブリッククラスLampDemo {
プライベート静的最終文字列TAG = "LampDemo";
プライベートファイナル静的文字列SERVICE_SET = "set";
プライベートファイナル静的文字列SERVICE_GET = "get";
public static String DESIRED_PROPERTY_GET = "/sys/${productKey}/${deviceName}/thing/property/desired/get";
public static String DESIRED_PROPERTY_GET_REPLY = "/sys/${productKey}/${deviceName}/thing/property/desired/get_reply";
public静的文字列METHOD_GET_DESIRED_PROPERTY = "thing.property.de sired.get";
public static void main(String[] args) {
/**
* デバイスに関する証明書情報。
*/
文字列productKey = "****";
文字列deviceName = "ランプ";
文字列deviceSecret = "****";
/**
* MQTT接続情報。
*/
String regionId = "cn-shanghai";
LampDemoマネージャー=新しいLampDemo();
DeviceInfo deviceInfo = new DeviceInfo();
deviceInfo.productKey = productKey;
deviceInfo.deviceName = deviceName;
deviceInfo.de viceSecret = deviceSecret;
manager.init(deviceInfo, regionId);
}
public void init(final DeviceInfo deviceInfo, String region) {
LinkKitInitParams params = new LinkKitInitParams();
/**
* MQTT初期化のパラメーターを設定します。
*/
IoTMqttClientConfig config = new IoTMqttClientConfig();
config.productKey = deviceInfo.productKey;
config.de viceName = deviceInfo.de viceName;
config.de viceSecret = deviceInfo.de viceSecret;
config.channelHost = deviceInfo.productKey + ".iot-as-mqtt" + リージョン + ".aliyuncs.com:1883";
/**
* オフラインメッセージを受信するかどうかを指定します。
* MQTT接続に対応するcleanSessionフィールド。
*/
config.receiveOfflineMsg = false;
params.mqttClientConfig = config;
/**
* 初期化を設定し、デバイスに関する証明書情報を渡します。
*/
params.deviceInfo = deviceInfo;
LinkKit.getInstance().init(params, new ILinkKitConnectListener() {
public void onError(AError aError) {
ALog.e(TAG、"Init Error error=" + aError);
}
public void onInitDone(InitResult initResult) {
ALog.i(TAG, "onInitDone result=" + initResult);
connectNotifyListener();
// IoT Platformから必要な最新のプロパティ値を要求します。
getDesiredProperty(deviceInfo, Arrays.asList("LightStatus")), new IConnectSendListener() {
public void onResponse(ARequest aRequest, AResponse aResponse) {
if(aRequest instanceof MqttPublishRequest && aResponse.data! =null) {
JSONObject jsonObject = JSONObject.parseObject(aResponse.data.toString());
ALog.i(TAG, "onResponse result=" + jsonObject);
JSONObject dataObj = jsonObject.getJSONObject("data");
if (dataObj != null) {
if (dataObj.getJSONObject("LightStatus") == null) {
// 目的の値が指定されていません。
} else {
整数値=dataObj.getJSONObject("LightStatus").getInteger("value");
handlePropertySet("LightStatus", new ValueWrapper.IntValueWrapper(value), true);
}
}
}
}
public void onFailure(ARequest aRequest, AError aError) {
ALog.d(TAG, "onFailure() called with: aRequest = [" + aRequest + "], aError = [" + aError + "]");
}
});
}
});
}
/**
* デバイスがプロパティ値の変更を処理すると、次のシナリオでメソッドが呼び出されます。
* シナリオ1: デバイスがIoT Platformに再接続された後、デバイスは自動的にIoT Platformから最新の目的のプロパティ値を取得するように要求します。
* シナリオ2: デバイスがオンラインの場合、デバイスは、IoT Platformが値をプッシュするproperty.setトピックから目的のプロパティ値を受け取ります。
* @ param identifier: プロパティ識別子。
* @ param value: 目的のプロパティ値。
* @ param needReport: property.postトピックを使用して、IoT Platformにプロパティ値を報告するかどうかを指定します。
* シナリオ2では、プロパティレポート機能が処理機能に統合され、needReportパラメーターがfalseに設定されます。
* @return
*/
private boolean handlePropertySet(String identifier, ValueWrapper値, boolean needReport) {
ALog.d(TAG, "The device handles property changes= [" + identifier + "], value = [" + value + "]");
// 応答に基づいて、プロパティ設定が期待どおりに構成されているかどうかを確認します。 この例では、成功メッセージが返されます。
ブール成功=true;
if (needReport) {
reportProperty (識別子、値);
}
return success;
}
private void reportProperty(String identifier, ValueWrapper value){
if (StringUtils.isEmptyString (識別子) | | value == null) {
return;
}
ALog.d(TAG, "Report property identity=" + identifier);
Map<String, ValueWrapper> reportData = new HashMap<>();
reportData.put (識別子、値);
LinkKit.getInstance().getDeviceThing().thingPropertyPost(reportData, new IPublishResourceListener() {
public void onSuccess(String s, Object o) {
// プロパティ値が報告されます。
ALog.d(TAG、"Report success onSuccess() called with: s = [" s + "], o = [" o + "]");
}
public void onError(String s, AError aError) {
// プロパティ値の報告に失敗しました。
ALog.d(TAG, "Report failure onError() called with: s = [" + s + "], aError = [" + JSON.toJSONString(aError) + "]");
}
});
}
/**
* サービスコールとプロパティ設定に応答する関数を登録します。
* IoT Platformがデバイスからサービスを呼び出す場合、デバイスは呼び出しに応答して応答を返す必要があります。
*/
public void connectNotifyListener() {
List<Service> serviceList = LinkKit.getInstance().getDeviceThing().getServices();
for (int i = 0; serviceList != null && i < serviceList.size(); i ++) {
サービスサービス=serviceList.get(i);
LinkKit.getInstance().getDeviceThing().setServiceHandler(service.getIdentifier(), mCommonHandler);
}
}
private ITResRequestHandler mCommonHandler = new ITResRequestHandler() {
public void onProcess(String serviceIdentifier, Object result, ITResResponseCallback itResResResponseCallback) {
ALog.d(TAG, "onProcess() called with: s = [" + serviceIdentifier + "]," +
"o = [" + result + "], itResResResponseCallback= [" + itResResResResponseCallback + "]");
ALog.d(TAG、"IoT Platformからの非同期サービスコールの受信" + serviceIdentifier);
try {
if (SERVICE_SET.equals(serviceIdentifier)) {
Map<String, ValueWrapper> data = (Map<String, ValueWrapper>)((InputParams)result).getData();
ALog.d(TAG, "Received asynchronous downstream data" + data);
// デバイスのプロパティを設定し、プロパティ値をIoT Platformに報告します。
ブールisSetPropertySuccess=
handlePropertySet("LightStatus" 、data.get("LightStatus") 、false);
if (isSetPropertySuccess) {
if (result instanceof InputParams) {
// IoT Platformに応答を返します。
itResResResponseCallback. onComplete(serviceIdentifier、null、null);
} else {
itResResResponseCallback. onComplete(serviceIdentifier、null、null);
}
} else {
AError error = new AError();
error.setCode(100);
error.setMsg("setPropertyFailed.");
itResResResponseCallback. onComplete(serviceIdentifier、新しいErrorInfo (エラー) 、null);
}
} else if (SERVICE_GET.equals(serviceIdentifier)) {
} else {
// デバイスの操作はサービスによって異なります。
ALog.d(TAG, "サービスに対応する戻り値");
OutputParams outputParams = new OutputParams();
// outputParams.put("op", new ValueWrapper.IntValueWrapper(20));
itResResResponseCallback. onComplete(serviceIdentifier、null、outputParams);
}
} catch (Exception e) {
e.printStackTrace();
ALog.d(TAG, "返されたデータの形式は無効です");
}
}
public void onSuccess(Object o, OutputParams outputParams) {
ALog.d(TAG, "onSuccess() called with: o = [" o "], outputParams = [" + outputParams + "]");
ALog.d(TAG、「サービスが登録されました」);
}
public void onFail(Object o, ErrorInfo errorInfo) {
ALog.d(TAG, "onFail() called with: o = [" + o + "], errorInfo = [" + errorInfo + "]");
ALog.d(TAG、"サービス登録に失敗しました。");
}
};
private void getDesiredProperty(BaseInfo info, List<String> プロパティ, IConnectSendListenerリスナー) {
ALog.d(TAG, "getDesiredProperty() called with: info = [" + info + "], listener = [" + listener + "]");
if (情報!) =null && ! StringUtils.isEmptyString(info.productKey) && ! StringUtils.isEmptyString(info.de viceName) {
MqttPublishRequest request = new MqttPublishRequest();
request.topic = DESIRED_PROPERTY_GET.replace("{productKey}", info.productKey).replace("{deviceName}", info.de viceName);
request.replyTopic = DESIRED_PROPERTY_GET_REPLY.replace("{productKey}", info.productKey).replace("{deviceName}", info.de viceName);
request.isRPC = true;
RequestModel<List<String>> model = new RequestModel<>();
model.id = String.valueOf(IDGeneraterUtils.getId());
model.method = METHOD_GET_DESIRED_PROPERTY;
model.params=プロパティ;
model.version = "1.0";
request.payloadObj = model.toString();
ALog.d(TAG, "getDesiredProperty: payloadObj=" + request.payloadObj);
ConnectSDK.getInstance().send (要求、リスナー);
} else {
ALog.w(TAG、"getDesiredProperty failed, baseInfo Empty.");
if (リスナー!) =null) {
AError error = new AError();
error.setMsg("BaseInfoEmpty.");
listener.onFailure(null、エラー);
}
}
}
}