shadowDataList) {
45 | log.info("requestId={}", requestId);
46 | log.info("shadowDataList={}", shadowDataList);
47 | }
48 | });
49 |
50 | if (device.init() != 0) {
51 | return;
52 | }
53 |
54 | ShadowRequest shadowRequest = new ShadowRequest();
55 | shadowRequest.setDeviceId(deviceId);
56 | shadowRequest.setServiceId("smokeDetector");
57 | device.getClient().getShadow(shadowRequest, new ActionListener() {
58 | @Override
59 | public void onSuccess(Object context) {
60 | log.info("getShadow success");
61 | }
62 |
63 | @Override
64 | public void onFailure(Object context, Throwable var2) {
65 | log.warn("getShadow fail: " + var2);
66 | }
67 | });
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/iot-device-demo/src/main/java/com/huaweicloud/sdk/iot/device/demo/device/connect/DefaultX509TrustManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.demo.device.connect;
32 |
33 | import java.security.cert.X509Certificate;
34 |
35 | import javax.net.ssl.X509TrustManager;
36 |
37 | public class DefaultX509TrustManager implements X509TrustManager {
38 | @Override
39 | public void checkClientTrusted(X509Certificate[] x509Certificates, String s) {
40 |
41 | }
42 |
43 | @Override
44 | public void checkServerTrusted(X509Certificate[] x509Certificates, String s) {
45 |
46 | }
47 |
48 | @Override
49 | public X509Certificate[] getAcceptedIssuers() {
50 | return new X509Certificate[0];
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/iot-device-demo/src/main/java/com/huaweicloud/sdk/iot/device/demo/device/connect/ReConnect.java:
--------------------------------------------------------------------------------
1 | package com.huaweicloud.sdk.iot.device.demo.device.connect;
2 |
3 | import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
4 |
5 | import com.huaweicloud.sdk.iot.device.IoTDevice;
6 | import com.huaweicloud.sdk.iot.device.client.CustomOptions;
7 | import com.huaweicloud.sdk.iot.device.client.DeviceClient;
8 | import com.huaweicloud.sdk.iot.device.client.handler.CustomBackoffHandler;
9 | import com.huaweicloud.sdk.iot.device.transport.Connection;
10 | import lombok.extern.slf4j.Slf4j;
11 |
12 | import java.io.File;
13 | import java.io.IOException;
14 | import java.io.InputStream;
15 | import java.nio.file.Files;
16 |
17 | @Slf4j
18 | public class ReConnect extends DeviceClient {
19 |
20 | private static final String IOT_ROOT_CA_RES_PATH = "ca.jks";
21 |
22 | private static final String IOT_ROOT_CA_TMP_PATH = "huaweicloud-iotda-tmp-" + IOT_ROOT_CA_RES_PATH;
23 |
24 | // 创建设备, 用户请替换为自己的接入地址。
25 | static IoTDevice device = new IoTDevice("tcp://xxxxxx:1883",
26 | "xxxxxxxxxx", "xxxxxxxxxx", null);
27 |
28 | private static int retryTimes = 0;
29 | public static void main(String[] args) throws InterruptedException, IOException {
30 |
31 | File tmpCAFile = new File(IOT_ROOT_CA_TMP_PATH);
32 | try (InputStream resource = ReConnect.class.getClassLoader().getResourceAsStream(IOT_ROOT_CA_RES_PATH)) {
33 | Files.copy(resource, tmpCAFile.toPath(), REPLACE_EXISTING);
34 | }
35 |
36 | // 不使用使用默认断线重连
37 | CustomOptions customOptionsnew = new CustomOptions();
38 | customOptionsnew.setReConnect(false);
39 | customOptionsnew.setCustomBackoffHandler(new CustomBackoffHandler() {
40 | @Override
41 | public int backoffHandler(Connection connection) {
42 | int ret = -1;
43 | long time = 5000L;
44 | while (ret != 0) {
45 | // 退避重连
46 | if (retryTimes > 10) {
47 | time = 30000L;
48 | }
49 | try {
50 | Thread.sleep(time);
51 | } catch (InterruptedException e) {
52 | log.error("sleep failed, the reason is {}", e.getMessage());
53 | }
54 | retryTimes++;
55 | ret = connection.connect();
56 | }
57 | retryTimes = 0;
58 | return 0;
59 | }
60 | });
61 | device.getClient().setCustomOptions(customOptionsnew);
62 |
63 | // 建链
64 | if (device.init() != 0) {
65 | return;
66 | }
67 | }
68 | }
69 |
70 |
71 |
--------------------------------------------------------------------------------
/iot-device-demo/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/iot-device-demo/src/main/resources/bootstrap-ca.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huaweicloud/huaweicloud-iot-device-sdk-java/decdc0c045cd3049a12048a9032304401d763a92/iot-device-demo/src/main/resources/bootstrap-ca.jks
--------------------------------------------------------------------------------
/iot-device-demo/src/main/resources/ca.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huaweicloud/huaweicloud-iot-device-sdk-java/decdc0c045cd3049a12048a9032304401d763a92/iot-device-demo/src/main/resources/ca.jks
--------------------------------------------------------------------------------
/iot-device-demo/src/main/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | ### #配置根Logger ###
2 | log4j.rootLogger=debug,stdout
3 | ### 输出到控制台 ###
4 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender
5 | log4j.appender.stdout.Target=System.out
6 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
7 | log4j.appender.stdout.layout.ConversionPattern=%d{yyy-MM-dd HH\:mm\:ss} %5p %c{1}\:%L - %m%n
8 |
--------------------------------------------------------------------------------
/iot-device-demo/src/main/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/iot-device-demo/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | %d{yyy-MM-dd HH:mm:ss} %-5level %c{1}:%L - %m%n
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/iot-device-demo/src/main/resources/rootca/composed/huaweicloud-iot-root-ca-list - includingSelfSignedCA.bks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huaweicloud/huaweicloud-iot-device-sdk-java/decdc0c045cd3049a12048a9032304401d763a92/iot-device-demo/src/main/resources/rootca/composed/huaweicloud-iot-root-ca-list - includingSelfSignedCA.bks
--------------------------------------------------------------------------------
/iot-device-demo/src/main/resources/rootca/composed/huaweicloud-iot-root-ca-list - includingSelfSignedCA.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huaweicloud/huaweicloud-iot-device-sdk-java/decdc0c045cd3049a12048a9032304401d763a92/iot-device-demo/src/main/resources/rootca/composed/huaweicloud-iot-root-ca-list - includingSelfSignedCA.jks
--------------------------------------------------------------------------------
/iot-device-demo/src/main/resources/rootca/composed/huaweicloud-iot-root-ca-list.bks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huaweicloud/huaweicloud-iot-device-sdk-java/decdc0c045cd3049a12048a9032304401d763a92/iot-device-demo/src/main/resources/rootca/composed/huaweicloud-iot-root-ca-list.bks
--------------------------------------------------------------------------------
/iot-device-demo/src/main/resources/rootca/composed/huaweicloud-iot-root-ca-list.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huaweicloud/huaweicloud-iot-device-sdk-java/decdc0c045cd3049a12048a9032304401d763a92/iot-device-demo/src/main/resources/rootca/composed/huaweicloud-iot-root-ca-list.jks
--------------------------------------------------------------------------------
/iot-device-demo/src/main/resources/rootca/composed/huaweicloud-iot-root-ca-list.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh
3 | MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
4 | d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD
5 | QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT
6 | MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j
7 | b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG
8 | 9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB
9 | CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97
10 | nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt
11 | 43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P
12 | T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4
13 | gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO
14 | BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR
15 | TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw
16 | DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr
17 | hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg
18 | 06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF
19 | PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls
20 | YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk
21 | CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=
22 | -----END CERTIFICATE-----
23 | -----BEGIN CERTIFICATE-----
24 | MIIDXzCCAkegAwIBAgILBAAAAAABIVhTCKIwDQYJKoZIhvcNAQELBQAwTDEgMB4G
25 | A1UECxMXR2xvYmFsU2lnbiBSb290IENBIC0gUjMxEzARBgNVBAoTCkdsb2JhbFNp
26 | Z24xEzARBgNVBAMTCkdsb2JhbFNpZ24wHhcNMDkwMzE4MTAwMDAwWhcNMjkwMzE4
27 | MTAwMDAwWjBMMSAwHgYDVQQLExdHbG9iYWxTaWduIFJvb3QgQ0EgLSBSMzETMBEG
28 | A1UEChMKR2xvYmFsU2lnbjETMBEGA1UEAxMKR2xvYmFsU2lnbjCCASIwDQYJKoZI
29 | hvcNAQEBBQADggEPADCCAQoCggEBAMwldpB5BngiFvXAg7aEyiie/QV2EcWtiHL8
30 | RgJDx7KKnQRfJMsuS+FggkbhUqsMgUdwbN1k0ev1LKMPgj0MK66X17YUhhB5uzsT
31 | gHeMCOFJ0mpiLx9e+pZo34knlTifBtc+ycsmWQ1z3rDI6SYOgxXG71uL0gRgykmm
32 | KPZpO/bLyCiR5Z2KYVc3rHQU3HTgOu5yLy6c+9C7v/U9AOEGM+iCK65TpjoWc4zd
33 | QQ4gOsC0p6Hpsk+QLjJg6VfLuQSSaGjlOCZgdbKfd/+RFO+uIEn8rUAVSNECMWEZ
34 | XriX7613t2Saer9fwRPvm2L7DWzgVGkWqQPabumDk3F2xmmFghcCAwEAAaNCMEAw
35 | DgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFI/wS3+o
36 | LkUkrk1Q+mOai97i3Ru8MA0GCSqGSIb3DQEBCwUAA4IBAQBLQNvAUKr+yAzv95ZU
37 | RUm7lgAJQayzE4aGKAczymvmdLm6AC2upArT9fHxD4q/c2dKg8dEe3jgr25sbwMp
38 | jjM5RcOO5LlXbKr8EpbsU8Yt5CRsuZRj+9xTaGdWPoO4zzUhw8lo/s7awlOqzJCK
39 | 6fBdRoyV3XpYKBovHd7NADdBj+1EbddTKJd+82cEHhXXipa0095MJ6RMG3NzdvQX
40 | mcIfeg7jLQitChws/zyrVQ4PkX4268NXSb7hLi18YIvDQVETI53O9zJrlAGomecs
41 | Mx86OyXShkDOOyyGeMlhLxS67ttVb9+E7gUJTb0o2HLO02JQZR7rkpeDMdmztcpH
42 | WD9f
43 | -----END CERTIFICATE-----
44 |
45 |
--------------------------------------------------------------------------------
/iot-device-demo/src/main/resources/rootca/explicit/DigiCert Global Root CA.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh
3 | MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
4 | d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD
5 | QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT
6 | MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j
7 | b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG
8 | 9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB
9 | CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97
10 | nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt
11 | 43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P
12 | T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4
13 | gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO
14 | BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR
15 | TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw
16 | DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr
17 | hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg
18 | 06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF
19 | PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls
20 | YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk
21 | CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=
22 | -----END CERTIFICATE-----
--------------------------------------------------------------------------------
/iot-device-demo/src/main/resources/rootca/explicit/GlobalSign.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIDXzCCAkegAwIBAgILBAAAAAABIVhTCKIwDQYJKoZIhvcNAQELBQAwTDEgMB4G
3 | A1UECxMXR2xvYmFsU2lnbiBSb290IENBIC0gUjMxEzARBgNVBAoTCkdsb2JhbFNp
4 | Z24xEzARBgNVBAMTCkdsb2JhbFNpZ24wHhcNMDkwMzE4MTAwMDAwWhcNMjkwMzE4
5 | MTAwMDAwWjBMMSAwHgYDVQQLExdHbG9iYWxTaWduIFJvb3QgQ0EgLSBSMzETMBEG
6 | A1UEChMKR2xvYmFsU2lnbjETMBEGA1UEAxMKR2xvYmFsU2lnbjCCASIwDQYJKoZI
7 | hvcNAQEBBQADggEPADCCAQoCggEBAMwldpB5BngiFvXAg7aEyiie/QV2EcWtiHL8
8 | RgJDx7KKnQRfJMsuS+FggkbhUqsMgUdwbN1k0ev1LKMPgj0MK66X17YUhhB5uzsT
9 | gHeMCOFJ0mpiLx9e+pZo34knlTifBtc+ycsmWQ1z3rDI6SYOgxXG71uL0gRgykmm
10 | KPZpO/bLyCiR5Z2KYVc3rHQU3HTgOu5yLy6c+9C7v/U9AOEGM+iCK65TpjoWc4zd
11 | QQ4gOsC0p6Hpsk+QLjJg6VfLuQSSaGjlOCZgdbKfd/+RFO+uIEn8rUAVSNECMWEZ
12 | XriX7613t2Saer9fwRPvm2L7DWzgVGkWqQPabumDk3F2xmmFghcCAwEAAaNCMEAw
13 | DgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFI/wS3+o
14 | LkUkrk1Q+mOai97i3Ru8MA0GCSqGSIb3DQEBCwUAA4IBAQBLQNvAUKr+yAzv95ZU
15 | RUm7lgAJQayzE4aGKAczymvmdLm6AC2upArT9fHxD4q/c2dKg8dEe3jgr25sbwMp
16 | jjM5RcOO5LlXbKr8EpbsU8Yt5CRsuZRj+9xTaGdWPoO4zzUhw8lo/s7awlOqzJCK
17 | 6fBdRoyV3XpYKBovHd7NADdBj+1EbddTKJd+82cEHhXXipa0095MJ6RMG3NzdvQX
18 | mcIfeg7jLQitChws/zyrVQ4PkX4268NXSb7hLi18YIvDQVETI53O9zJrlAGomecs
19 | Mx86OyXShkDOOyyGeMlhLxS67ttVb9+E7gUJTb0o2HLO02JQZR7rkpeDMdmztcpH
20 | WD9f
21 | -----END CERTIFICATE-----
--------------------------------------------------------------------------------
/iot-device-demo/src/main/resources/rootca/explicit/iot.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIID4DCCAsigAwIBAgIJAK97nNS67HRvMA0GCSqGSIb3DQEBCwUAMFMxCzAJBgNV
3 | BAYTAkNOMQswCQYDVQQIEwJHRDELMAkGA1UEBxMCU1oxDzANBgNVBAoTBkh1YXdl
4 | aTELMAkGA1UECxMCQ04xDDAKBgNVBAMTA0lPVDAeFw0xNjA1MDQxMjE3MjdaFw0y
5 | NjA1MDIxMjE3MjdaMFMxCzAJBgNVBAYTAkNOMQswCQYDVQQIEwJHRDELMAkGA1UE
6 | BxMCU1oxDzANBgNVBAoTBkh1YXdlaTELMAkGA1UECxMCQ04xDDAKBgNVBAMTA0lP
7 | VDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJxM9fwkwvxeILpkvoAM
8 | Gdqq3x0G9o445F6Shg3I0xmmzu9Of8wYuW3c4jtQ/6zscuIGyWf06ke1z//AVZ/o
9 | dp8LkuFbBbDXR5swjUJ6z15b6yaYH614Ty/d6DrCM+RaU+FWmxmOon9W/VELu2BB
10 | NXDQHJBSbWrLNGnZA2erk4JSMp7RhHrZ0QaNtT4HhIczFYtQ2lYF+sQJpQMrjoRn
11 | dSV9WB872Ja4DgcISU1+wuWLmS/NKjIvOWW1upS79yu2I4Rxos2mFy9xxz311rGC
12 | Z3X65ejFNzCUrNgf6NEP1N7wB9hUu7u50aA+/56D7EgjeI0gpFytC+a4f6JCPVWI
13 | Lr0CAwEAAaOBtjCBszAdBgNVHQ4EFgQUcGqy59oawLEgMl21//7F5RyABpwwgYMG
14 | A1UdIwR8MHqAFHBqsufaGsCxIDJdtf/+xeUcgAacoVekVTBTMQswCQYDVQQGEwJD
15 | TjELMAkGA1UECBMCR0QxCzAJBgNVBAcTAlNaMQ8wDQYDVQQKEwZIdWF3ZWkxCzAJ
16 | BgNVBAsTAkNOMQwwCgYDVQQDEwNJT1SCCQCve5zUuux0bzAMBgNVHRMEBTADAQH/
17 | MA0GCSqGSIb3DQEBCwUAA4IBAQBgv2PQn66gRMbGJMSYS48GIFqpCo783TUTePNS
18 | tV8G1MIiQCpYNdk2wNw/iFjoLRkdx4va6jgceht5iX6SdjpoQF7y5qVDVrScQmsP
19 | U95IFcOkZJCNtOpUXdT+a3N+NlpxiScyIOtSrQnDFixWMCJQwEfg8j74qO96UvDA
20 | FuTCocOouER3ZZjQ8MEsMMquNEvMHJkMRX11L5Rxo1pc6J/EMWW5scK2rC0Hg91a
21 | Lod6aezh2K7KleC0V5ZlIuEvFoBc7bCwcBSAKA3BnQveJ8nEu9pbuBsVAjHOroVb
22 | 8/bL5retJigmAN2GIyFv39TFXIySw+lW0wlp+iSPxO9s9J+t
23 | -----END CERTIFICATE-----
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/bootstrap/DefaultPlatformCaProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.bootstrap;
32 |
33 | import java.io.File;
34 | import java.net.URL;
35 | import java.util.Objects;
36 |
37 | class DefaultPlatformCaProvider implements PlatformCaProvider {
38 | private final String iotPlatformCaFileResPath;
39 |
40 | public DefaultPlatformCaProvider(String iotPlatformCaFileResPath) {
41 | this.iotPlatformCaFileResPath = iotPlatformCaFileResPath;
42 | }
43 |
44 | @Override
45 | public File getIotCaFile() {
46 | URL resource = this.getClass().getClassLoader().getResource(iotPlatformCaFileResPath);
47 | if (Objects.isNull(resource)) {
48 | throw new IllegalArgumentException("iot platform ca path is null, path=" + iotPlatformCaFileResPath);
49 | }
50 | return new File(resource.getPath());
51 | }
52 |
53 | @Override
54 | public File getBootstrapCaFile() {
55 | return PlatformCaProvider.super.getBootstrapCaFile();
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/bootstrap/PlatformCaProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.bootstrap;
32 |
33 | import java.io.File;
34 |
35 | /**
36 | * 平台CA证书提供者
37 | *
38 | * @since 1.1.3
39 | */
40 | public interface PlatformCaProvider {
41 | /**
42 | * 用于获取验证服务端证书的CA文件
43 | *
44 | * @return 验证服务端证书的CA文件
45 | */
46 | File getIotCaFile();
47 |
48 | /**
49 | * 用于获取引导服务端证书的CA文件
50 | *
51 | * 通常引导服务端与连接服务端证书通常由同一个CA签发,可使用同一个根CA证书文件。
52 | *
53 | * @return 验证引导端证书的CA文件
54 | */
55 | default File getBootstrapCaFile() {
56 | return getIotCaFile();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/client/RequestListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.client;
32 |
33 | /**
34 | * 请求监听器
35 | */
36 | public interface RequestListener {
37 | /**
38 | * 请求执行完成通知
39 | *
40 | * @param result 请求执行结果
41 | */
42 | void onFinish(String result);
43 | }
44 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/client/handler/CommandV3Handler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.client.handler;
32 |
33 | import com.huaweicloud.sdk.iot.device.client.DeviceClient;
34 | import com.huaweicloud.sdk.iot.device.client.requests.CommandV3;
35 | import com.huaweicloud.sdk.iot.device.transport.RawMessage;
36 | import com.huaweicloud.sdk.iot.device.utils.JsonUtil;
37 | import lombok.extern.slf4j.Slf4j;
38 |
39 | @Slf4j
40 | public class CommandV3Handler implements MessageReceivedHandler {
41 |
42 | private final DeviceClient deviceClient;
43 |
44 | public CommandV3Handler(DeviceClient deviceClient) {
45 | this.deviceClient = deviceClient;
46 | }
47 |
48 | @Override
49 | public void messageHandler(RawMessage message) {
50 | CommandV3 commandV3 = JsonUtil.convertJsonStringToObject(message.toString(), CommandV3.class);
51 | if (commandV3 == null) {
52 | log.error("invalid commandV3");
53 | return;
54 | }
55 |
56 | if (deviceClient.getCommandV3Listener() != null) {
57 | deviceClient.getCommandV3Listener().onCommandV3(commandV3);
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/client/handler/CustomBackoffHandler.java:
--------------------------------------------------------------------------------
1 | package com.huaweicloud.sdk.iot.device.client.handler;
2 |
3 | import com.huaweicloud.sdk.iot.device.transport.Connection;
4 |
5 | public interface CustomBackoffHandler {
6 | /**
7 | * 自定义断线重连
8 | * @param connection IOT连接,代表设备和平台之间的一个连接
9 | * @return 0 代表重连成功, 其他代表重连失败
10 | */
11 | int backoffHandler(Connection connection);
12 | }
13 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/client/handler/MessageReceivedHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.client.handler;
32 |
33 | import com.huaweicloud.sdk.iot.device.transport.RawMessage;
34 |
35 | public interface MessageReceivedHandler {
36 | void messageHandler(RawMessage message);
37 | }
38 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/client/handler/ShadowHandler.java:
--------------------------------------------------------------------------------
1 | package com.huaweicloud.sdk.iot.device.client.handler;
2 |
3 | import com.huaweicloud.sdk.iot.device.client.DeviceClient;
4 | import com.huaweicloud.sdk.iot.device.client.requests.Shadow;
5 | import com.huaweicloud.sdk.iot.device.transport.RawMessage;
6 | import com.huaweicloud.sdk.iot.device.utils.IotUtil;
7 | import com.huaweicloud.sdk.iot.device.utils.JsonUtil;
8 | import lombok.extern.slf4j.Slf4j;
9 |
10 | @Slf4j
11 | public class ShadowHandler implements MessageReceivedHandler {
12 |
13 | private final DeviceClient deviceClient;
14 |
15 | public ShadowHandler(DeviceClient deviceClient) {
16 | this.deviceClient = deviceClient;
17 | }
18 |
19 | @Override
20 | public void messageHandler(RawMessage message) {
21 | String topic = message.getTopic();
22 | String requestId = IotUtil.getRequestId(topic);
23 |
24 | final Shadow shadow = JsonUtil.convertJsonStringToObject(message.toString(), Shadow.class);
25 | if (shadow == null) {
26 | log.warn("invalid shadow");
27 | return;
28 | }
29 |
30 | if (deviceClient.getShadowListener() != null && (shadow.getDeviceId() == null || shadow.getDeviceId()
31 | .equals(deviceClient.getDeviceId()))) {
32 | deviceClient.getShadowListener().onShadow(requestId, shadow.getShadow());
33 | return;
34 | }
35 |
36 | deviceClient.getDevice().onShadow(requestId, shadow);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/client/handler/ShadowResponseHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.client.handler;
32 |
33 | import com.huaweicloud.sdk.iot.device.client.DeviceClient;
34 | import com.huaweicloud.sdk.iot.device.transport.RawMessage;
35 |
36 | public class ShadowResponseHandler implements MessageReceivedHandler {
37 | private final DeviceClient deviceClient;
38 |
39 | public ShadowResponseHandler(DeviceClient deviceClient) {
40 | this.deviceClient = deviceClient;
41 | }
42 |
43 | @Override
44 | public void messageHandler(RawMessage message) {
45 | deviceClient.getRequestManager().onRequestResponse(message);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/client/listener/CommandListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.client.listener;
32 |
33 | import java.util.Map;
34 |
35 | /**
36 | * 命令监听器,用于接收平台下发的命令
37 | */
38 | public interface CommandListener {
39 | /**
40 | * 命令处理
41 | *
42 | * @param requestId 请求id
43 | * @param serviceId 服务id
44 | * @param commandName 命令名
45 | * @param paras 命令参数
46 | */
47 | void onCommand(String requestId, String serviceId, String commandName, Map paras);
48 | }
49 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/client/listener/CommandV3Listener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.client.listener;
32 |
33 | import com.huaweicloud.sdk.iot.device.client.requests.CommandV3;
34 |
35 | /**
36 | * 命令监听器,用于接收平台下发的V3命令
37 | */
38 | public interface CommandV3Listener {
39 | /**
40 | * 处理命令
41 | * @param commandV3
42 | */
43 | void onCommandV3(CommandV3 commandV3);
44 | }
45 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/client/listener/DefaultActionListenerImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.client.listener;
32 |
33 | import com.huaweicloud.sdk.iot.device.transport.ActionListener;
34 | import lombok.extern.slf4j.Slf4j;
35 |
36 | @Slf4j
37 | public class DefaultActionListenerImpl implements ActionListener {
38 |
39 | private final String actionType;
40 |
41 | public DefaultActionListenerImpl(String actionType) {
42 | this.actionType = actionType;
43 | }
44 |
45 | @Override
46 | public void onSuccess(Object context) {
47 |
48 | }
49 |
50 | @Override
51 | public void onFailure(Object context, Throwable var2) {
52 | log.error(actionType + "error", var2.getMessage());
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/client/listener/DeviceMessageListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.client.listener;
32 |
33 | import com.huaweicloud.sdk.iot.device.client.requests.DeviceMessage;
34 |
35 | /**
36 | * 设备消息监听器,用于接收平台下发的设备消息
37 | */
38 | public interface DeviceMessageListener {
39 |
40 | /**
41 | * 处理平台下发的设备消息
42 | *
43 | * @param deviceMessage 设备消息内容
44 | */
45 | void onDeviceMessage(DeviceMessage deviceMessage);
46 | }
47 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/client/listener/PropertyListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.client.listener;
32 |
33 | import com.huaweicloud.sdk.iot.device.client.requests.ServiceProperty;
34 |
35 | import java.util.List;
36 |
37 | /**
38 | * 属性监听器,用于接收平台下发的属性读写操作
39 | */
40 | public interface PropertyListener {
41 |
42 | /**
43 | * 处理写属性操作
44 | *
45 | * @param requestId 请求id
46 | * @param services 服务属性列表
47 | */
48 | void onPropertiesSet(String requestId, List services);
49 |
50 | /**
51 | * 处理读属性操作
52 | *
53 | * @param requestId 请求id
54 | * @param serviceId 服务id,可选
55 | */
56 | void onPropertiesGet(String requestId, String serviceId);
57 | }
58 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/client/listener/RawDeviceMessageListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.client.listener;
32 |
33 | import com.huaweicloud.sdk.iot.device.client.requests.RawDeviceMessage;
34 |
35 | /**
36 | * 设备消息监听器,用于接收平台下发的设备消息
37 | */
38 | public interface RawDeviceMessageListener {
39 |
40 | /**
41 | * 处理平台下发的设备消息
42 | *
43 | * @param rawDeviceMessage 原始设备消息内容,
44 | */
45 | void onRawDeviceMessage(RawDeviceMessage rawDeviceMessage);
46 | }
47 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/client/listener/ShadowListener.java:
--------------------------------------------------------------------------------
1 | package com.huaweicloud.sdk.iot.device.client.listener;
2 |
3 | import com.huaweicloud.sdk.iot.device.client.requests.ShadowData;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * 设备影子监听器,用于设备向平台获取设备影子数据
9 | */
10 | public interface ShadowListener {
11 | /**
12 | *
13 | * @param requestId 请求id
14 | * @param shadowDataList 服务影子数据
15 | */
16 | void onShadow(String requestId, List shadowDataList);
17 | }
18 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/client/requests/DeviceEvents.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.client.requests;
32 |
33 | import com.fasterxml.jackson.annotation.JsonProperty;
34 |
35 | import java.util.List;
36 |
37 | /**
38 | * 设备事件
39 | */
40 | public class DeviceEvents {
41 | /**
42 | * 设备id
43 | */
44 | @JsonProperty("object_device_id")
45 | private String deviceId;
46 |
47 | /**
48 | * 服务事件列表
49 | */
50 | @JsonProperty("services")
51 | private List services;
52 |
53 | public String getDeviceId() {
54 | return deviceId;
55 | }
56 |
57 | public void setDeviceId(String deviceId) {
58 | this.deviceId = deviceId;
59 | }
60 |
61 | public List getServices() {
62 | return services;
63 | }
64 |
65 | public void setServices(List services) {
66 | this.services = services;
67 | }
68 |
69 | @Override
70 | public String toString() {
71 | return "DeviceEvents{"
72 | + "deviceId='" + deviceId + '\''
73 | + ", services=" + services + '}';
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/client/requests/DeviceProperties.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.client.requests;
32 |
33 | import com.huaweicloud.sdk.iot.device.utils.JsonUtil;
34 |
35 | import java.util.List;
36 |
37 | /**
38 | * 设备属性内容
39 | */
40 | public class DeviceProperties {
41 | /**
42 | * 服务属性列表
43 | */
44 | private List services;
45 |
46 | public List getServices() {
47 | return services;
48 | }
49 |
50 | public void setServices(List services) {
51 | this.services = services;
52 | }
53 |
54 | @Override
55 | public String toString() {
56 | return JsonUtil.convertObject2String(this);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/client/requests/PropertiesData.java:
--------------------------------------------------------------------------------
1 | package com.huaweicloud.sdk.iot.device.client.requests;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 | import com.huaweicloud.sdk.iot.device.utils.JsonUtil;
5 |
6 | public class PropertiesData {
7 | @JsonProperty("properties")
8 | private Object properties;
9 |
10 | @JsonProperty("event_time")
11 | private String eventTime;
12 |
13 | public Object getProperties() {
14 | return properties;
15 | }
16 |
17 | public void setProperties(Object properties) {
18 | this.properties = properties;
19 | }
20 |
21 | public String getEventTime() {
22 | return eventTime;
23 | }
24 |
25 | public void setEventTime(String eventTime) {
26 | this.eventTime = eventTime;
27 | }
28 |
29 | @Override
30 | public String toString() {
31 | return JsonUtil.convertObject2String(this);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/client/requests/PropsGet.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.client.requests;
32 |
33 | import com.fasterxml.jackson.annotation.JsonProperty;
34 | import com.huaweicloud.sdk.iot.device.utils.JsonUtil;
35 |
36 | /**
37 | * 读属性操作
38 | */
39 | public class PropsGet {
40 | @JsonProperty("object_device_id")
41 | private String deviceId;
42 |
43 | @JsonProperty("service_id")
44 | private String serviceId;
45 |
46 | public String getDeviceId() {
47 | return deviceId;
48 | }
49 |
50 | public void setDeviceId(String deviceId) {
51 | this.deviceId = deviceId;
52 | }
53 |
54 | public String getServiceId() {
55 | return serviceId;
56 | }
57 |
58 | public void setServiceId(String serviceId) {
59 | this.serviceId = serviceId;
60 | }
61 |
62 | @Override
63 | public String toString() {
64 | return JsonUtil.convertObject2String(this);
65 | }
66 |
67 | }
68 |
69 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/client/requests/PropsSet.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.client.requests;
32 |
33 |
34 | import com.fasterxml.jackson.annotation.JsonProperty;
35 | import com.huaweicloud.sdk.iot.device.utils.JsonUtil;
36 |
37 | import java.util.List;
38 |
39 | /**
40 | * 写属性操作
41 | */
42 | public class PropsSet {
43 | @JsonProperty("object_device_id")
44 | private
45 | String deviceId;
46 |
47 | private List services;
48 |
49 | public String getDeviceId() {
50 | return deviceId;
51 | }
52 |
53 | public void setDeviceId(String deviceId) {
54 | this.deviceId = deviceId;
55 | }
56 |
57 | public List getServices() {
58 | return services;
59 | }
60 |
61 | public void setServices(List services) {
62 | this.services = services;
63 | }
64 |
65 | @Override
66 | public String toString() {
67 | return JsonUtil.convertObject2String(this);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/client/requests/Shadow.java:
--------------------------------------------------------------------------------
1 | package com.huaweicloud.sdk.iot.device.client.requests;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 | import com.huaweicloud.sdk.iot.device.utils.JsonUtil;
5 |
6 | import java.util.List;
7 |
8 | public class Shadow {
9 | @JsonProperty("object_device_id")
10 | private String deviceId;
11 |
12 | @JsonProperty("shadow")
13 | private List shadow;
14 |
15 | public String getDeviceId() {
16 | return deviceId;
17 | }
18 |
19 | public void setDeviceId(String deviceId) {
20 | this.deviceId = deviceId;
21 | }
22 |
23 | public List getShadow() {
24 | return shadow;
25 | }
26 |
27 | public void setShadow(List shadow) {
28 | this.shadow = shadow;
29 | }
30 |
31 | @Override
32 | public String toString() {
33 | return JsonUtil.convertObject2String(this);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/client/requests/ShadowData.java:
--------------------------------------------------------------------------------
1 | package com.huaweicloud.sdk.iot.device.client.requests;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 | import com.huaweicloud.sdk.iot.device.utils.JsonUtil;
5 |
6 | public class ShadowData {
7 | @JsonProperty("service_id")
8 | private String serviceId;
9 |
10 | @JsonProperty("desired")
11 | private PropertiesData desired;
12 |
13 | @JsonProperty("reported")
14 | private PropertiesData reported;
15 |
16 | @JsonProperty("version")
17 | private Integer version;
18 |
19 | public String getServiceId() {
20 | return serviceId;
21 | }
22 |
23 | public void setServiceId(String serviceId) {
24 | this.serviceId = serviceId;
25 | }
26 |
27 | public PropertiesData getDesired() {
28 | return desired;
29 | }
30 |
31 | public void setDesired(PropertiesData desired) {
32 | this.desired = desired;
33 | }
34 |
35 | public PropertiesData getReported() {
36 | return reported;
37 | }
38 |
39 | public void setReported(PropertiesData reported) {
40 | this.reported = reported;
41 | }
42 |
43 | public Integer getVersion() {
44 | return version;
45 | }
46 |
47 | public void setVersion(Integer version) {
48 | this.version = version;
49 | }
50 |
51 | @Override
52 | public String toString() {
53 | return JsonUtil.convertObject2String(this);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/client/requests/ShadowRequest.java:
--------------------------------------------------------------------------------
1 | package com.huaweicloud.sdk.iot.device.client.requests;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 | import com.huaweicloud.sdk.iot.device.utils.JsonUtil;
5 |
6 | public class ShadowRequest {
7 | @JsonProperty("object_device_id")
8 | private String deviceId;
9 |
10 | @JsonProperty("service_id")
11 | private String serviceId;
12 |
13 | public String getDeviceId() {
14 | return deviceId;
15 | }
16 |
17 | public void setDeviceId(String deviceId) {
18 | this.deviceId = deviceId;
19 | }
20 |
21 | public String getServiceId() {
22 | return serviceId;
23 | }
24 |
25 | public void setServiceId(String serviceId) {
26 | this.serviceId = serviceId;
27 | }
28 |
29 | @Override
30 | public String toString() {
31 | return JsonUtil.convertObject2String(this);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/constants/Constants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.constants;
32 |
33 | public class Constants {
34 |
35 | /**
36 | * 直连设备接入模式
37 | */
38 | public static final int CONNECT_OF_NORMAL_DEVICE_MODE = 0;
39 |
40 | /**
41 | * 网桥模式接入模式
42 | */
43 | public static final int CONNECT_OF_BRIDGE_MODE = 3;
44 |
45 | /**
46 | * 时间戳校验模式
47 | */
48 | public static final int CHECK_STAMP_SHA256_OFF = 0; // HMAC-SHA256不校验时间戳
49 |
50 | public static final int CHECK_STAMP_SHA256_ON = 1; // HMAC-SHA256校验时间戳
51 |
52 | public static final int CHECK_STAMP_SM3_ON = 2; // HMAC-SM3校验时间戳
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/devicerule/ActionHandler.java:
--------------------------------------------------------------------------------
1 | package com.huaweicloud.sdk.iot.device.devicerule;
2 |
3 | import com.huaweicloud.sdk.iot.device.devicerule.model.DeviceRuleAction;
4 |
5 | import java.util.List;
6 |
7 | public interface ActionHandler {
8 | /**
9 | * 自定义规则触发器,用于客户自定义触发规则
10 | * @param actionList 端侧规则动作列表
11 | */
12 | void handleRuleAction(List actionList);
13 | }
14 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/devicerule/DeviceRuleJob.java:
--------------------------------------------------------------------------------
1 | package com.huaweicloud.sdk.iot.device.devicerule;
2 |
3 | import com.huaweicloud.sdk.iot.device.devicerule.model.DeviceRuleAction;
4 | import com.huaweicloud.sdk.iot.device.devicerule.model.TimeRange;
5 | import com.huaweicloud.sdk.iot.device.utils.ExceptionUtil;
6 |
7 | import lombok.extern.slf4j.Slf4j;
8 | import org.quartz.Job;
9 | import org.quartz.JobExecutionContext;
10 |
11 | import java.util.List;
12 |
13 | @Slf4j
14 | public class DeviceRuleJob implements Job {
15 |
16 | @Override
17 | public void execute(JobExecutionContext context) {
18 | try {
19 | final List actionList = (List) context.getMergedJobDataMap()
20 | .get("actionList");
21 | final DeviceRuleService deviceRuleService = (DeviceRuleService) context.getMergedJobDataMap()
22 | .get("deviceRuleService");
23 | final TimeRange timeRange = (TimeRange) context.getMergedJobDataMap().get("timeRange");
24 | if (deviceRuleService.checkTimeRange(timeRange)) {
25 | deviceRuleService.onRuleActionHandler(actionList);
26 | }
27 | } catch (Exception e) {
28 | log.warn("failed to execute DeviceRuleJob, exception={}", ExceptionUtil.getBriefStackTrace(e));
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/devicerule/model/DeviceInfo.java:
--------------------------------------------------------------------------------
1 | package com.huaweicloud.sdk.iot.device.devicerule.model;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 | import com.huaweicloud.sdk.iot.device.utils.JsonUtil;
5 |
6 | public class DeviceInfo {
7 | @JsonProperty("deviceId")
8 | private String deviceId;
9 |
10 | @JsonProperty("path")
11 | private String path;
12 |
13 | public String getDeviceId() {
14 | return deviceId;
15 | }
16 |
17 | public void setDeviceId(String deviceId) {
18 | this.deviceId = deviceId;
19 | }
20 |
21 | public String getPath() {
22 | return path;
23 | }
24 |
25 | public void setPath(String path) {
26 | this.path = path;
27 | }
28 |
29 | @Override
30 | public String toString() {
31 | return JsonUtil.convertObject2String(this);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/devicerule/model/DeviceRuleAction.java:
--------------------------------------------------------------------------------
1 | package com.huaweicloud.sdk.iot.device.devicerule.model;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 | import com.huaweicloud.sdk.iot.device.utils.JsonUtil;
5 |
6 | public class DeviceRuleAction {
7 | @JsonProperty("type")
8 | private String type;
9 |
10 | @JsonProperty("deviceId")
11 | private String deviceId;
12 |
13 | @JsonProperty("status")
14 | private String status;
15 |
16 | @JsonProperty("command")
17 | private DeviceRuleCommand command;
18 |
19 | public String getType() {
20 | return type;
21 | }
22 |
23 | public void setType(String type) {
24 | this.type = type;
25 | }
26 |
27 | public String getDeviceId() {
28 | return deviceId;
29 | }
30 |
31 | public void setDeviceId(String deviceId) {
32 | this.deviceId = deviceId;
33 | }
34 |
35 | public String getStatus() {
36 | return status;
37 | }
38 |
39 | public void setStatus(String status) {
40 | this.status = status;
41 | }
42 |
43 | public DeviceRuleCommand getCommand() {
44 | return command;
45 | }
46 |
47 | public void setCommand(DeviceRuleCommand command) {
48 | this.command = command;
49 | }
50 |
51 | @Override
52 | public String toString() {
53 | return JsonUtil.convertObject2String(this);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/devicerule/model/DeviceRuleCommand.java:
--------------------------------------------------------------------------------
1 | package com.huaweicloud.sdk.iot.device.devicerule.model;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 | import com.huaweicloud.sdk.iot.device.utils.JsonUtil;
5 |
6 | import java.util.Map;
7 |
8 | public class DeviceRuleCommand {
9 | @JsonProperty("commandName")
10 | private String commandName;
11 |
12 | @JsonProperty("serviceId")
13 | private String serviceId;
14 |
15 | @JsonProperty("commandBody")
16 | private Map commandBody;
17 |
18 | public String getCommandName() {
19 | return commandName;
20 | }
21 |
22 | public void setCommandName(String commandName) {
23 | this.commandName = commandName;
24 | }
25 |
26 | public String getServiceId() {
27 | return serviceId;
28 | }
29 |
30 | public void setServiceId(String serviceId) {
31 | this.serviceId = serviceId;
32 | }
33 |
34 | public Map getCommandBody() {
35 | return commandBody;
36 | }
37 |
38 | public void setCommandBody(Map commandBody) {
39 | this.commandBody = commandBody;
40 | }
41 |
42 | @Override
43 | public String toString() {
44 | return JsonUtil.convertObject2String(this);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/devicerule/model/DeviceRuleEventInfo.java:
--------------------------------------------------------------------------------
1 | package com.huaweicloud.sdk.iot.device.devicerule.model;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 | import com.huaweicloud.sdk.iot.device.utils.JsonUtil;
5 |
6 | import java.util.List;
7 |
8 | public class DeviceRuleEventInfo {
9 | @JsonProperty("rulesInfos")
10 | private List ruleInfos;
11 |
12 | public List getRuleInfos() {
13 | return ruleInfos;
14 | }
15 |
16 | public void setRuleInfos(List ruleInfos) {
17 | this.ruleInfos = ruleInfos;
18 | }
19 |
20 | @Override
21 | public String toString() {
22 | return JsonUtil.convertObject2String(this);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/devicerule/model/DeviceRuleInfo.java:
--------------------------------------------------------------------------------
1 | package com.huaweicloud.sdk.iot.device.devicerule.model;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 | import com.huaweicloud.sdk.iot.device.utils.JsonUtil;
5 |
6 | import java.util.List;
7 |
8 | public class DeviceRuleInfo {
9 | @JsonProperty("ruleId")
10 | private String ruleId;
11 |
12 | @JsonProperty("ruleName")
13 | private String ruleName;
14 |
15 | @JsonProperty("logic")
16 | private String logic;
17 |
18 | @JsonProperty("timeRange")
19 | private TimeRange timeRange;
20 |
21 | @JsonProperty("status")
22 | private String status;
23 |
24 | @JsonProperty("conditions")
25 | private List conditions;
26 |
27 | @JsonProperty("actions")
28 | private List actions;
29 |
30 | @JsonProperty("ruleVersionInShadow")
31 | private int ruleVersionInShadow;
32 |
33 | public String getRuleId() {
34 | return ruleId;
35 | }
36 |
37 | public void setRuleId(String ruleId) {
38 | this.ruleId = ruleId;
39 | }
40 |
41 | public String getRuleName() {
42 | return ruleName;
43 | }
44 |
45 | public void setRuleName(String ruleName) {
46 | this.ruleName = ruleName;
47 | }
48 |
49 | public String getLogic() {
50 | return logic;
51 | }
52 |
53 | public void setLogic(String logic) {
54 | this.logic = logic;
55 | }
56 |
57 | public TimeRange getTimeRange() {
58 | return timeRange;
59 | }
60 |
61 | public void setTimeRange(TimeRange timeRange) {
62 | this.timeRange = timeRange;
63 | }
64 |
65 | public String getStatus() {
66 | return status;
67 | }
68 |
69 | public void setStatus(String status) {
70 | this.status = status;
71 | }
72 |
73 | public List getConditions() {
74 | return conditions;
75 | }
76 |
77 | public void setConditions(List conditions) {
78 | this.conditions = conditions;
79 | }
80 |
81 | public List getActions() {
82 | return actions;
83 | }
84 |
85 | public void setActions(List actions) {
86 | this.actions = actions;
87 | }
88 |
89 | public int getRuleVersionInShadow() {
90 | return ruleVersionInShadow;
91 | }
92 |
93 | public void setRuleVersionInShadow(int ruleVersionInShadow) {
94 | this.ruleVersionInShadow = ruleVersionInShadow;
95 | }
96 |
97 | @Override
98 | public String toString() {
99 | return JsonUtil.convertObject2String(this);
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/devicerule/model/TimeRange.java:
--------------------------------------------------------------------------------
1 | package com.huaweicloud.sdk.iot.device.devicerule.model;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 | import com.huaweicloud.sdk.iot.device.utils.JsonUtil;
5 |
6 | public class TimeRange {
7 | @JsonProperty("startTime")
8 | private String startTime;
9 |
10 | @JsonProperty("endTime")
11 | private String endTime;
12 |
13 | @JsonProperty("daysOfWeek")
14 | private String daysOfWeek;
15 |
16 | public String getStartTime() {
17 | return startTime;
18 | }
19 |
20 | public void setStartTime(String startTime) {
21 | this.startTime = startTime;
22 | }
23 |
24 | public String getEndTime() {
25 | return endTime;
26 | }
27 |
28 | public void setEndTime(String endTime) {
29 | this.endTime = endTime;
30 | }
31 |
32 | public String getDaysOfWeek() {
33 | return daysOfWeek;
34 | }
35 |
36 | public void setDaysOfWeek(String daysOfWeek) {
37 | this.daysOfWeek = daysOfWeek;
38 | }
39 |
40 | @Override
41 | public String toString() {
42 | return JsonUtil.convertObject2String(this);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/filemanager/BridgeFileMangerListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.filemanager;
32 |
33 | import com.huaweicloud.sdk.iot.device.filemanager.response.UrlResponse;
34 |
35 | /**
36 | * 监听文件上传下载事件
37 | */
38 | public interface BridgeFileMangerListener {
39 | /**
40 | * 接收文件上传url
41 | *
42 | * @param param 上传参数
43 | * @param deviceId 设备Id
44 | */
45 | void onUploadUrl(UrlResponse param, String deviceId);
46 |
47 | /**
48 | * 接收文件下载url
49 | *
50 | * @param param 下载参数`
51 | * @param deviceId 设备Id
52 | */
53 | void onDownloadUrl(UrlResponse param, String deviceId);
54 | }
55 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/filemanager/FileMangerListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.filemanager;
32 |
33 | import com.huaweicloud.sdk.iot.device.filemanager.response.UrlResponse;
34 |
35 | /**
36 | * 监听文件上传下载事件
37 | */
38 | public interface FileMangerListener {
39 | /**
40 | * 接收文件上传url
41 | *
42 | * @param param 上传参数
43 | */
44 | void onUploadUrl(UrlResponse param);
45 |
46 | /**
47 | * 接收文件下载url
48 | *
49 | * @param param 下载参数
50 | */
51 | void onDownloadUrl(UrlResponse param);
52 | }
53 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/filemanager/request/UrlRequest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.filemanager.request;
32 |
33 | import com.fasterxml.jackson.annotation.JsonProperty;
34 |
35 | import java.util.Map;
36 |
37 | public class UrlRequest {
38 | @JsonProperty("file_name")
39 | private String fileName;
40 |
41 | @JsonProperty("file_attributes")
42 | private Map fileAttributes;
43 |
44 | public String getFileName() {
45 | return fileName;
46 | }
47 |
48 | public void setFileName(String fileName) {
49 | this.fileName = fileName;
50 | }
51 |
52 | public Map getFileAttributes() {
53 | return fileAttributes;
54 | }
55 |
56 | public void setFileAttributes(Map fileAttributes) {
57 | this.fileAttributes = fileAttributes;
58 | }
59 |
60 | @Override
61 | public String toString() {
62 | return "UrlRequest{" + "fileName='" + fileName + '\'' + ", fileAttributes=" + fileAttributes + '}';
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/gateway/GtwOperateSubDeviceListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.gateway;
32 |
33 | import com.huaweicloud.sdk.iot.device.gateway.requests.GtwAddSubDeviceRsp;
34 | import com.huaweicloud.sdk.iot.device.gateway.requests.GtwDelSubDeviceRsp;
35 |
36 | public interface GtwOperateSubDeviceListener {
37 | /**
38 | * 处理网关增加子设备返回结果
39 | *
40 | * @param gtwAddSubDeviceRsp 网关增加子设备响应
41 | * @param eventId 事件Id
42 | */
43 | void onAddSubDeviceRsp(GtwAddSubDeviceRsp gtwAddSubDeviceRsp, String eventId);
44 |
45 | /**
46 | * 处理网关删除子设备返回结果
47 | *
48 | * @param gtwDelSubDeviceRsp 网关删除子设备响应
49 | * @param eventId 事件Id
50 | */
51 | void onDelSubDeviceRsp(GtwDelSubDeviceRsp gtwDelSubDeviceRsp, String eventId);
52 | }
53 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/gateway/SubDevDiscoveryListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.gateway;
32 |
33 | import com.huaweicloud.sdk.iot.device.gateway.requests.ScanSubdeviceNotify;
34 |
35 | public interface SubDevDiscoveryListener {
36 | /**
37 | * 平台通知网关扫描子设备
38 | *
39 | * @param scanSubdeviceNotify 子设备扫描通知
40 | * @return 0表示处理成功,其他表示处理失败
41 | */
42 | int onScan(ScanSubdeviceNotify scanSubdeviceNotify);
43 | }
44 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/gateway/SubDevicesPersistence.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.gateway;
32 |
33 | import com.huaweicloud.sdk.iot.device.gateway.requests.DeviceInfo;
34 | import com.huaweicloud.sdk.iot.device.gateway.requests.SubDevicesInfo;
35 |
36 | /**
37 | * 提供子设备信息持久化保存,网关场景使用
38 | */
39 | public interface SubDevicesPersistence {
40 | /**
41 | * 获取子设备信息
42 | *
43 | * @param nodeId 设备标识码
44 | * @return 子设备信息
45 | */
46 | DeviceInfo getSubDevice(String nodeId);
47 |
48 | /**
49 | * 添加子设备接口
50 | *
51 | * @param subDevicesInfo 子设备信息
52 | * @return 0代表成功;其它代表失败
53 | */
54 | int addSubDevices(SubDevicesInfo subDevicesInfo);
55 |
56 | /**
57 | * 删除子设备接口
58 | *
59 | * @param subDevicesInfo 子设备信息
60 | * @return 0代表成功;其它代表失败
61 | */
62 | int deleteSubDevices(SubDevicesInfo subDevicesInfo);
63 |
64 | /**
65 | * 获取设备版本号
66 | *
67 | * @return 设备版本号
68 | */
69 | long getVersion();
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/gateway/requests/DeviceProperty.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.gateway.requests;
32 |
33 | import com.fasterxml.jackson.annotation.JsonProperty;
34 | import com.huaweicloud.sdk.iot.device.client.requests.ServiceProperty;
35 |
36 | import java.util.List;
37 |
38 | /**
39 | * 设备属性
40 | */
41 | public class DeviceProperty {
42 | @JsonProperty("device_id")
43 | private String deviceId;
44 |
45 | private List services;
46 |
47 | public String getDeviceId() {
48 | return deviceId;
49 | }
50 |
51 | public void setDeviceId(String deviceId) {
52 | this.deviceId = deviceId;
53 | }
54 |
55 | public List getServices() {
56 | return services;
57 | }
58 |
59 | public void setServices(List services) {
60 | this.services = services;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/gateway/requests/DeviceStatus.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.gateway.requests;
32 |
33 | import com.fasterxml.jackson.annotation.JsonProperty;
34 |
35 | /**
36 | * 设备状态
37 | */
38 | public class DeviceStatus {
39 | @JsonProperty("device_id")
40 | private String deviceId;
41 |
42 | private String status;
43 |
44 | public String getDeviceId() {
45 | return deviceId;
46 | }
47 |
48 | public void setDeviceId(String deviceId) {
49 | this.deviceId = deviceId;
50 | }
51 |
52 | public String getStatus() {
53 | return status;
54 | }
55 |
56 | public void setStatus(String status) {
57 | this.status = status;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/gateway/requests/SubDevicesInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.gateway.requests;
32 |
33 | import java.util.List;
34 |
35 | /**
36 | * 子设备信息
37 | */
38 | public class SubDevicesInfo {
39 | private List devices;
40 |
41 | private long version;
42 |
43 | public List getDevices() {
44 | return devices;
45 | }
46 |
47 | public void setDevices(List devices) {
48 | this.devices = devices;
49 | }
50 |
51 | public long getVersion() {
52 | return version;
53 | }
54 |
55 | public void setVersion(long version) {
56 | this.version = version;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/ota/OTABase.java:
--------------------------------------------------------------------------------
1 | package com.huaweicloud.sdk.iot.device.ota;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 | import com.huaweicloud.sdk.iot.device.utils.JsonUtil;
5 |
6 | public class OTABase {
7 | @JsonProperty("task_id")
8 | private String taskId;
9 |
10 | @JsonProperty("sub_device_count")
11 | private Integer subDeviceCount;
12 |
13 | @JsonProperty("task_ext_info")
14 | private Object taskExtInfo;
15 |
16 | public String getTaskId() {
17 | return taskId;
18 | }
19 |
20 | public void setTaskId(String taskId) {
21 | this.taskId = taskId;
22 | }
23 |
24 | public Integer getSubDeviceCount() {
25 | return subDeviceCount;
26 | }
27 |
28 | public void setSubDeviceCount(Integer subDeviceCount) {
29 | this.subDeviceCount = subDeviceCount;
30 | }
31 |
32 | public Object getTaskExtInfo() {
33 | return taskExtInfo;
34 | }
35 |
36 | public void setTaskExtInfo(Object taskExtInfo) {
37 | this.taskExtInfo = taskExtInfo;
38 | }
39 |
40 | @Override
41 | public String toString() {
42 | return "OTABase{" +
43 | "taskId='" + taskId + '\'' +
44 | ", subDeviceCount='" + subDeviceCount + '\'' +
45 | ", taskExtInfo=" + JsonUtil.convertObject2String(taskExtInfo) +
46 | '}';
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/ota/OTAListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.ota;
32 |
33 | /**
34 | * OTA监听器
35 | */
36 | public interface OTAListener {
37 | /**
38 | * 接收查询版本通知
39 | */
40 | void onQueryVersion(OTAQueryInfo queryInfo);
41 |
42 | /**
43 | * 接收新版本通知
44 | *
45 | * @param pkg 新版本包信息
46 | */
47 | void onNewPackage(OTAPackage pkg);
48 |
49 | /**
50 | * 接收V2新版本通知
51 | *
52 | * @param pkg 新版本包信息
53 | */
54 | void onNewPackageV2(OTAPackageV2 pkg);
55 | }
56 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/ota/OTAPackage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.ota;
32 |
33 | import com.fasterxml.jackson.annotation.JsonProperty;
34 |
35 | public class OTAPackage extends OTAPackageV2 {
36 | @JsonProperty("access_token")
37 | private String token;
38 |
39 | public String getToken() {
40 | return token;
41 | }
42 |
43 | public void setToken(String token) {
44 | this.token = token;
45 | }
46 |
47 | @Override
48 | public String toString() {
49 | return "OTAPackage{" +
50 | ", token='" + token + '\'' +
51 | "} " + super.toString();
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/ota/OTAQueryInfo.java:
--------------------------------------------------------------------------------
1 | package com.huaweicloud.sdk.iot.device.ota;
2 |
3 | public class OTAQueryInfo extends OTABase {
4 | @Override
5 | public String toString() {
6 | return "OTAQueryInfo{} " + super.toString();
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/service/DeviceCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.service;
32 |
33 | import java.lang.annotation.Documented;
34 | import java.lang.annotation.ElementType;
35 | import java.lang.annotation.Inherited;
36 | import java.lang.annotation.Retention;
37 | import java.lang.annotation.RetentionPolicy;
38 | import java.lang.annotation.Target;
39 |
40 |
41 | /**
42 | * 设备命令
43 | */
44 | @Documented
45 | @Inherited
46 | @Retention(RetentionPolicy.RUNTIME)
47 | @Target({ElementType.METHOD})
48 | public @interface DeviceCommand {
49 |
50 | /**
51 | * @return 命令名,不提供默认为方法名
52 | */
53 | String name() default "";
54 | }
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/service/Property.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.service;
32 |
33 | import java.lang.annotation.Documented;
34 | import java.lang.annotation.ElementType;
35 | import java.lang.annotation.Inherited;
36 | import java.lang.annotation.Retention;
37 | import java.lang.annotation.RetentionPolicy;
38 | import java.lang.annotation.Target;
39 |
40 | /**
41 | * 属性
42 | */
43 | @Documented
44 | @Inherited
45 | @Retention(RetentionPolicy.RUNTIME)
46 | @Target({ElementType.FIELD})
47 | public @interface Property {
48 | /**
49 | * 属性是否可写。注:所有属性默认都可读
50 | *
51 | * @return true表示可写
52 | */
53 | boolean writeable() default true;
54 |
55 | /**
56 | * @return 属性名,不提供默认为字段名
57 | */
58 | String name() default "";
59 |
60 | }
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/service/SdkInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.service;
32 |
33 | /**
34 | * 此服务实现sdk信息
35 | */
36 | public class SdkInfo extends AbstractService {
37 | @Property(writeable = false)
38 | private String type = "Java";
39 |
40 | @Property(writeable = false)
41 | private String version = "1.2.2";
42 |
43 | public String getType() {
44 | return type;
45 | }
46 |
47 | public void setType(String type) {
48 | this.type = type;
49 | }
50 |
51 | public String getVersion() {
52 | return version;
53 | }
54 |
55 | public void setVersion(String version) {
56 | this.version = version;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/timesync/TimeSyncListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.timesync;
32 |
33 | /**
34 | * 监听时间同步事件
35 | */
36 | public interface TimeSyncListener {
37 | /**
38 | * 时间同步响应
39 | * 假设设备收到的设备侧时间为device_recv_time ,则设备计算自己的准确时间为:
40 | * (serverRecvTime + serverSendTime + device_recv_time - deviceSendTime) / 2
41 | *
42 | * @param deviceSendTime 设备发送时间
43 | * @param serverRecvTime 服务端接收时间
44 | * @param serverSendTime 服务端响应发送时间
45 | */
46 | void onTimeSyncResponse(long deviceSendTime, long serverRecvTime, long serverSendTime);
47 | }
48 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/transport/ActionListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.transport;
32 |
33 |
34 | /**
35 | * 动作监听器,用户接收动作执行结果
36 | */
37 | public interface ActionListener {
38 | /**
39 | * 执行成功通知
40 | *
41 | * @param context 上下文信息
42 | */
43 | void onSuccess(Object context);
44 |
45 | /**
46 | * 执行失败通知
47 | *
48 | * @param context 上下文信息
49 | * @param var2 失败的原因
50 | */
51 | void onFailure(Object context, Throwable var2);
52 | }
53 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/transport/ConnectActionListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.transport;
32 |
33 | import org.eclipse.paho.client.mqttv3.IMqttToken;
34 |
35 | /**
36 | * 连接动作监听器
37 | */
38 | public interface ConnectActionListener {
39 | /**
40 | * 连接成功
41 | *
42 | * @param iMqttToken 返回token
43 | */
44 | void onSuccess(IMqttToken iMqttToken);
45 |
46 | /**
47 | * 连接失败
48 | *
49 | * @param iMqttToken 返回token
50 | * @param throwable 失败异常
51 | */
52 | void onFailure(IMqttToken iMqttToken, Throwable throwable);
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/transport/ConnectListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.transport;
32 |
33 | /**
34 | * 连接监听器
35 | */
36 | public interface ConnectListener {
37 | /**
38 | * 连接丢失通知
39 | *
40 | * @param cause 连接丢失原因
41 | */
42 | void connectionLost(Throwable cause);
43 |
44 | /**
45 | * 连接成功通知
46 | *
47 | * @param reconnect 是否为重连
48 | * @param serverURI 服务端地址
49 | */
50 | void connectComplete(boolean reconnect, String serverURI);
51 | }
52 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/transport/RawMessageListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.transport;
32 |
33 | /**
34 | * 原始消息接收监听器
35 | */
36 | public interface RawMessageListener {
37 | /**
38 | * 收到消息通知
39 | *
40 | * @param message 原始消息
41 | */
42 | void onMessageReceived(RawMessage message);
43 | }
44 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/java/com/huaweicloud/sdk/iot/device/transport/mqtt/IotMqttAsyncClient.java:
--------------------------------------------------------------------------------
1 | package com.huaweicloud.sdk.iot.device.transport.mqtt;
2 |
3 | import org.eclipse.paho.client.mqttv3.MqttAsyncClient;
4 | import org.eclipse.paho.client.mqttv3.MqttClientPersistence;
5 | import org.eclipse.paho.client.mqttv3.MqttException;
6 | import org.eclipse.paho.client.mqttv3.MqttPingSender;
7 | import org.eclipse.paho.client.mqttv3.internal.DisconnectedMessageBuffer;
8 | import org.eclipse.paho.client.mqttv3.internal.HighResolutionTimer;
9 |
10 | import java.util.concurrent.ScheduledExecutorService;
11 |
12 | public class IotMqttAsyncClient extends MqttAsyncClient {
13 | public IotMqttAsyncClient(String serverURI, String clientId) throws MqttException {
14 | super(serverURI, clientId);
15 | }
16 |
17 | public IotMqttAsyncClient(String serverURI, String clientId,
18 | MqttClientPersistence persistence) throws MqttException {
19 | super(serverURI, clientId, persistence);
20 | }
21 |
22 | public IotMqttAsyncClient(String serverURI, String clientId, MqttClientPersistence persistence,
23 | MqttPingSender pingSender) throws MqttException {
24 | super(serverURI, clientId, persistence, pingSender);
25 | }
26 |
27 | public IotMqttAsyncClient(String serverURI, String clientId, MqttClientPersistence persistence,
28 | MqttPingSender pingSender, ScheduledExecutorService executorService) throws MqttException {
29 | super(serverURI, clientId, persistence, pingSender, executorService);
30 | }
31 |
32 | public IotMqttAsyncClient(String serverURI, String clientId, MqttClientPersistence persistence,
33 | MqttPingSender pingSender, ScheduledExecutorService executorService,
34 | HighResolutionTimer highResolutionTimer) throws MqttException {
35 | super(serverURI, clientId, persistence, pingSender, executorService, highResolutionTimer);
36 | }
37 |
38 | public void setDisconnectedMessageBuffer(DisconnectedMessageBuffer disconnectedMessageBuffer) {
39 | this.comms.setDisconnectedMessageBuffer(disconnectedMessageBuffer);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | ### #配置根Logger ###
2 | log4j.rootLogger=debug,stdout
3 | ### 输出到控制台 ###
4 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender
5 | log4j.appender.stdout.Target=System.out
6 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
7 | log4j.appender.stdout.layout.ConversionPattern=%d{yyy-MM-dd HH\:mm\:ss} %5p %c{1}\:%L - %m%n
8 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/iot-device-sdk-java/src/main/resources/simplelogger.properties:
--------------------------------------------------------------------------------
1 | # ??????
2 | org.slf4j.simpleLogger.showDateTime=true
3 | # ??????
4 | org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss
5 | # ?????????
6 | org.slf4j.simpleLogger.showShortLogName=true
7 | # ??????
8 | org.slf4j.simpleLogger.defaultLogLevel=info
9 | # ???????
10 | org.slf4j.simpleLogger.showThreadName=false
11 | # ?????????
12 | org.slf4j.simpleLogger.format=%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{1}:%line - %message%n
--------------------------------------------------------------------------------
/iot-gateway-demo/src/main/java/com/huaweicloud/sdk/iot/device/demo/Session.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.demo;
32 |
33 | import io.netty.channel.Channel;
34 |
35 | public class Session {
36 | private String nodeId;
37 |
38 | private String deviceId;
39 |
40 | private Channel channel;
41 |
42 | String getNodeId() {
43 | return nodeId;
44 | }
45 |
46 | void setNodeId(String nodeId) {
47 | this.nodeId = nodeId;
48 | }
49 |
50 | String getDeviceId() {
51 | return deviceId;
52 | }
53 |
54 | void setDeviceId(String deviceId) {
55 | this.deviceId = deviceId;
56 | }
57 |
58 | Channel getChannel() {
59 | return channel;
60 | }
61 |
62 | void setChannel(Channel channel) {
63 | this.channel = channel;
64 | }
65 |
66 | @Override
67 | public String toString() {
68 | return "Session{"
69 | + "nodeId='" + nodeId + '\'' + ", channel="
70 | + channel + ", deviceId='" + deviceId + '\'' + '}';
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/iot-gateway-demo/src/main/java/com/huaweicloud/sdk/iot/device/demo/SubDevInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020-2023 Huawei Cloud Computing Technology Co., Ltd. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification,
5 | * are permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific prior written
16 | * permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | package com.huaweicloud.sdk.iot.device.demo;
32 |
33 | import com.huaweicloud.sdk.iot.device.gateway.requests.DeviceInfo;
34 |
35 | import java.util.Map;
36 |
37 | public class SubDevInfo {
38 | private long version;
39 |
40 | private Map subdevices;
41 |
42 | public long getVersion() {
43 | return version;
44 | }
45 |
46 | public void setVersion(long version) {
47 | this.version = version;
48 | }
49 |
50 | public Map getSubdevices() {
51 | return subdevices;
52 | }
53 |
54 | public void setSubdevices(Map subdevices) {
55 | this.subdevices = subdevices;
56 | }
57 |
58 | @Override
59 | public String toString() {
60 | return "SubDevInfo{"
61 | + "version=" + version
62 | + ", subdevices=" + subdevices
63 | + '}';
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/iot-gateway-demo/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/iot-gateway-demo/src/main/resources/ca.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/huaweicloud/huaweicloud-iot-device-sdk-java/decdc0c045cd3049a12048a9032304401d763a92/iot-gateway-demo/src/main/resources/ca.jks
--------------------------------------------------------------------------------
/iot-gateway-demo/src/main/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | ### #配置根Logger ###
2 | log4j.rootLogger=debug,stdout
3 | ### 输出到控制台 ###
4 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender
5 | log4j.appender.stdout.Target=System.out
6 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
7 | log4j.appender.stdout.layout.ConversionPattern=%d{yyy-MM-dd HH\:mm\:ss} %5p %c{1}\:%L - %m%n
8 |
--------------------------------------------------------------------------------
/iot-gateway-demo/src/main/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/iot-gateway-demo/src/main/resources/subdevices.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": 0,
3 | "subdevices": {
4 | "subdev1": {
5 | "node_id": "subdev1",
6 | "device_id": "xxxxxx_subdev1"
7 | }
8 | }
9 | }
--------------------------------------------------------------------------------