├── .gitignore ├── LICENSE ├── README.md ├── README_EN.md ├── doc └── figure_cn │ ├── Delete sub devices.png │ ├── add sub 2.png │ ├── add sub device.png │ ├── bridge_demo_pkg_structure.png │ ├── bridge_get_auth_info.png │ ├── delete sub success.png │ └── generic_sdk_1.png ├── iot-bridge-demo ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── huaweicloud │ │ └── sdk │ │ └── iot │ │ └── device │ │ └── demo │ │ ├── Bridge.java │ │ ├── BridgeSample.java │ │ ├── DefaultBridgePropertyListener.java │ │ ├── DefaultDeviceIdentityRegistry.java │ │ ├── DeviceIdentity.java │ │ ├── DeviceIdentityRegistry.java │ │ ├── Session.java │ │ ├── TcpDevice.java │ │ └── TcpServer.java │ └── resources │ ├── application.properties │ ├── ca.jks │ ├── deviceIdentity.json │ ├── log4j.properties │ ├── log4j2.xml │ └── logback.xml ├── iot-bridge-sample-tcp-protocol ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── huaweicloud │ │ └── sdk │ │ └── iot │ │ └── bridge │ │ └── sample │ │ └── tcp │ │ ├── Main.java │ │ ├── bridge │ │ └── BridgeService.java │ │ ├── codec │ │ ├── MessageDecoder.java │ │ └── MessageEncoder.java │ │ ├── constants │ │ └── Constants.java │ │ ├── dto │ │ ├── BaseMessage.java │ │ ├── CommonResponse.java │ │ ├── DeviceLocationFrequencySet.java │ │ ├── DeviceLocationMessage.java │ │ ├── DeviceLoginMessage.java │ │ └── MsgHeader.java │ │ ├── handler │ │ ├── DownLinkHandler.java │ │ └── UpLinkHandler.java │ │ ├── server │ │ └── TcpServer.java │ │ └── session │ │ ├── DeviceSession.java │ │ ├── DeviceSessionManger.java │ │ ├── NettyUtils.java │ │ └── RequestIdCache.java │ └── resources │ └── log4j2.xml ├── iot-bridge-sdk ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── huaweicloud │ │ │ └── bridge │ │ │ └── sdk │ │ │ ├── BridgeClient.java │ │ │ ├── BridgeDevice.java │ │ │ ├── bootstrap │ │ │ ├── BridgeBootstrap.java │ │ │ └── BridgeClientConf.java │ │ │ ├── constants │ │ │ └── BridgeSDKConstants.java │ │ │ ├── handler │ │ │ ├── BridgeCommandHandler.java │ │ │ ├── BridgeMessageHandler.java │ │ │ ├── BridgePropertyGetHandler.java │ │ │ ├── BridgePropertySetHandler.java │ │ │ ├── DeviceDisConnHandler.java │ │ │ ├── DeviceLoginHandler.java │ │ │ ├── DeviceLogoutHandler.java │ │ │ └── SecretResetHandler.java │ │ │ ├── listener │ │ │ ├── BridgeCommandListener.java │ │ │ ├── BridgeDeviceDisConnListener.java │ │ │ ├── BridgeDeviceMessageListener.java │ │ │ ├── BridgePropertyListener.java │ │ │ ├── LoginListener.java │ │ │ ├── LogoutListener.java │ │ │ └── ResetDeviceSecretListener.java │ │ │ ├── request │ │ │ ├── BridgeCommand.java │ │ │ ├── DeviceSecret.java │ │ │ └── RequestIdCache.java │ │ │ └── response │ │ │ └── ResetDeviceSecretResponse.java │ └── resources │ │ ├── log4j.properties │ │ └── log4j2.xml │ └── test │ └── java │ └── com │ └── huaweicloud │ └── bridge │ └── sdk │ ├── BridgeClientTest.java │ ├── BridgeDeviceTest.java │ ├── bootstrap │ └── BridgeBootstrapTest.java │ └── handler │ ├── BridgeCommandHandlerTest.java │ ├── BridgeMessageHandlerTest.java │ ├── BridgePropertyGetHandlerTest.java │ ├── BridgePropertySetHandlerTest.java │ ├── DeviceDisConnHandlerTest.java │ ├── DeviceLoginHandlerTest.java │ ├── DeviceLogoutHandlerTest.java │ └── SecretResetHandlerTest.java ├── iot-device-code-generator ├── README.md ├── README_EN.md ├── device-code-genarator.bat ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── huaweicloud │ │ └── sdk │ │ └── iot │ │ └── device │ │ └── codegenerator │ │ ├── DeviceCodeGenerator.java │ │ └── productparser │ │ ├── DeviceCapability.java │ │ ├── DeviceProfileParser.java │ │ ├── DeviceService.java │ │ ├── ProductInfo.java │ │ ├── ServiceCommand.java │ │ ├── ServiceCommandPara.java │ │ ├── ServiceCommandResponse.java │ │ └── ServiceProperty.java │ └── resources │ ├── device.ftl │ ├── generated-demo.zip │ ├── log4j.properties │ ├── service.ftl │ └── smokeDetector_cb097d20d77b4240adf1f33d36b3c278_smokeDetector.zip ├── iot-device-demo ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── huaweicloud │ │ └── sdk │ │ └── iot │ │ └── device │ │ └── demo │ │ ├── bootstrap │ │ ├── BaseBootstrapSample.java │ │ ├── BootstrapMessageSample.java │ │ ├── BootstrapSample.java │ │ ├── BootstrapSelfRegCcmSample.java │ │ ├── BootstrapSelfRegGroupPasswordSample.java │ │ ├── BootstrapSelfRegSample.java │ │ ├── DefaultBootstrapActionListener.java │ │ └── SimpleBootstrapActionListener.java │ │ ├── device │ │ ├── CommandSample.java │ │ ├── CustomDeviceRuleSample.java │ │ ├── CustomizeTopicSample.java │ │ ├── DeviceRuleSample.java │ │ ├── FileManagerSample.java │ │ ├── MessageSample.java │ │ ├── NtpSample.java │ │ ├── OTASample.java │ │ ├── OTAV2Sample.java │ │ ├── PropertySample.java │ │ ├── PropertyV3AndCmdV3Sample.java │ │ ├── ReportDeviceInfoSample.java │ │ ├── ReportDeviceLogSample.java │ │ ├── ShadowSample.java │ │ ├── SmokeDetector.java │ │ └── connect │ │ │ ├── DefaultX509TrustManager.java │ │ │ ├── GmTlsAuthConnect.java │ │ │ ├── ReConnect.java │ │ │ ├── SecretAuthConnect.java │ │ │ └── X509CertificateDeviceSample.java │ │ └── utils │ │ ├── CertificateUtil.java │ │ └── GmCertificate.java │ └── resources │ ├── application.properties │ ├── bootstrap-ca.jks │ ├── ca.jks │ ├── log4j.properties │ ├── log4j2.xml │ ├── logback.xml │ └── rootca │ ├── composed │ ├── huaweicloud-iot-root-ca-list - includingSelfSignedCA.bks │ ├── huaweicloud-iot-root-ca-list - includingSelfSignedCA.jks │ ├── huaweicloud-iot-root-ca-list - includingSelfSignedCA.pem │ ├── huaweicloud-iot-root-ca-list.bks │ ├── huaweicloud-iot-root-ca-list.jks │ └── huaweicloud-iot-root-ca-list.pem │ └── explicit │ ├── DigiCert Global Root CA.pem │ ├── GlobalSign.pem │ └── iot.pem ├── iot-device-sdk-java ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── huaweicloud │ │ │ └── sdk │ │ │ └── iot │ │ │ └── device │ │ │ ├── IoTDevice.java │ │ │ ├── bootstrap │ │ │ ├── BootstrapClient.java │ │ │ ├── DefaultPlatformCaProvider.java │ │ │ └── PlatformCaProvider.java │ │ │ ├── client │ │ │ ├── ClientConf.java │ │ │ ├── CustomOptions.java │ │ │ ├── DeviceClient.java │ │ │ ├── IotRequest.java │ │ │ ├── IotResult.java │ │ │ ├── RequestListener.java │ │ │ ├── RequestManager.java │ │ │ ├── handler │ │ │ │ ├── CommandHandler.java │ │ │ │ ├── CommandV3Handler.java │ │ │ │ ├── CustomBackoffHandler.java │ │ │ │ ├── EventDownHandler.java │ │ │ │ ├── MessageHandler.java │ │ │ │ ├── MessageReceivedHandler.java │ │ │ │ ├── PropertyGetHandler.java │ │ │ │ ├── PropertySetHandler.java │ │ │ │ ├── ShadowHandler.java │ │ │ │ └── ShadowResponseHandler.java │ │ │ ├── listener │ │ │ │ ├── CommandListener.java │ │ │ │ ├── CommandV3Listener.java │ │ │ │ ├── DefaultActionListenerImpl.java │ │ │ │ ├── DefaultPublishListenerImpl.java │ │ │ │ ├── DefaultSubscribeListenerImpl.java │ │ │ │ ├── DeviceMessageListener.java │ │ │ │ ├── PropertyListener.java │ │ │ │ ├── RawDeviceMessageListener.java │ │ │ │ └── ShadowListener.java │ │ │ └── requests │ │ │ │ ├── Command.java │ │ │ │ ├── CommandRsp.java │ │ │ │ ├── CommandRspV3.java │ │ │ │ ├── CommandV3.java │ │ │ │ ├── DeviceEvent.java │ │ │ │ ├── DeviceEvents.java │ │ │ │ ├── DeviceMessage.java │ │ │ │ ├── DeviceProperties.java │ │ │ │ ├── DevicePropertiesV3.java │ │ │ │ ├── PropertiesData.java │ │ │ │ ├── PropsGet.java │ │ │ │ ├── PropsSet.java │ │ │ │ ├── RawDeviceMessage.java │ │ │ │ ├── ServiceData.java │ │ │ │ ├── ServiceProperty.java │ │ │ │ ├── Shadow.java │ │ │ │ ├── ShadowData.java │ │ │ │ └── ShadowRequest.java │ │ │ ├── constants │ │ │ └── Constants.java │ │ │ ├── devicelog │ │ │ ├── DeviceLogService.java │ │ │ └── listener │ │ │ │ ├── DefaultConnActionLogListener.java │ │ │ │ └── DefaultConnLogListener.java │ │ │ ├── devicerule │ │ │ ├── ActionHandler.java │ │ │ ├── DeviceRuleJob.java │ │ │ ├── DeviceRuleService.java │ │ │ ├── TimerRuleInstance.java │ │ │ └── model │ │ │ │ ├── DeviceInfo.java │ │ │ │ ├── DeviceRuleAction.java │ │ │ │ ├── DeviceRuleCommand.java │ │ │ │ ├── DeviceRuleCondition.java │ │ │ │ ├── DeviceRuleEventInfo.java │ │ │ │ ├── DeviceRuleInfo.java │ │ │ │ └── TimeRange.java │ │ │ ├── filemanager │ │ │ ├── BridgeFileMangerListener.java │ │ │ ├── FileManagerService.java │ │ │ ├── FileMangerListener.java │ │ │ ├── request │ │ │ │ ├── OpFileStatusRequest.java │ │ │ │ └── UrlRequest.java │ │ │ └── response │ │ │ │ └── UrlResponse.java │ │ │ ├── gateway │ │ │ ├── AbstractGateway.java │ │ │ ├── GtwOperateSubDeviceListener.java │ │ │ ├── SubDevDiscoveryListener.java │ │ │ ├── SubDevDownlinkListener.java │ │ │ ├── SubDevicesPersistence.java │ │ │ └── requests │ │ │ │ ├── AddSubDeviceFailedReason.java │ │ │ │ ├── AddedSubDeviceInfo.java │ │ │ │ ├── AddedSubDeviceInfoRsp.java │ │ │ │ ├── DelSubDeviceFailedReason.java │ │ │ │ ├── DeviceInfo.java │ │ │ │ ├── DeviceProperty.java │ │ │ │ ├── DeviceStatus.java │ │ │ │ ├── GtwAddSubDeviceRsp.java │ │ │ │ ├── GtwDelSubDeviceRsp.java │ │ │ │ ├── ScanSubdeviceNotify.java │ │ │ │ └── SubDevicesInfo.java │ │ │ ├── ota │ │ │ ├── OTABase.java │ │ │ ├── OTAListener.java │ │ │ ├── OTAPackage.java │ │ │ ├── OTAPackageV2.java │ │ │ ├── OTAQueryInfo.java │ │ │ └── OTAService.java │ │ │ ├── service │ │ │ ├── AbstractDevice.java │ │ │ ├── AbstractService.java │ │ │ ├── DeviceCommand.java │ │ │ ├── IService.java │ │ │ ├── Property.java │ │ │ └── SdkInfo.java │ │ │ ├── timesync │ │ │ ├── TimeSyncListener.java │ │ │ └── TimeSyncService.java │ │ │ ├── transport │ │ │ ├── ActionListener.java │ │ │ ├── ConnectActionListener.java │ │ │ ├── ConnectListener.java │ │ │ ├── Connection.java │ │ │ ├── RawMessage.java │ │ │ ├── RawMessageListener.java │ │ │ └── mqtt │ │ │ │ ├── IotMqttAsyncClient.java │ │ │ │ └── MqttConnection.java │ │ │ └── utils │ │ │ ├── ExceptionUtil.java │ │ │ ├── IotUtil.java │ │ │ └── JsonUtil.java │ └── resources │ │ ├── application.properties │ │ ├── log4j.properties │ │ ├── log4j2.xml │ │ └── simplelogger.properties │ └── test │ └── java │ └── com │ └── huaweicloud │ └── sdk │ └── iot │ └── device │ └── client │ └── handler │ └── MessageHandlerTest.java ├── iot-gateway-demo ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── huaweicloud │ │ └── sdk │ │ └── iot │ │ └── device │ │ └── demo │ │ ├── Session.java │ │ ├── SimpleGateway.java │ │ ├── StringTcpServer.java │ │ ├── SubDevInfo.java │ │ ├── SubDevicesFilePersistence.java │ │ └── TcpDevice.java │ └── resources │ ├── application.properties │ ├── ca.jks │ ├── log4j.properties │ ├── log4j2.xml │ └── subdevices.json └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | # file system 2 | .DS_Store 3 | 4 | # ide 5 | .idea/** 6 | 7 | target/ 8 | pom.xml.tag 9 | pom.xml.releaseBackup 10 | pom.xml.versionsBackup 11 | pom.xml.next 12 | release.properties 13 | dependency-reduced-pom.xml 14 | buildNumber.properties 15 | .mvn/timing.properties 16 | # https://github.com/takari/maven-wrapper#usage-without-binary-jar 17 | .mvn/wrapper/maven-wrapper.jar 18 | 19 | .settings/ 20 | .classpath 21 | .vscode/ 22 | .project 23 | .factorypath 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2019, HUAWEI CLOUD 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /doc/figure_cn/Delete sub devices.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huaweicloud/huaweicloud-iot-device-sdk-java/decdc0c045cd3049a12048a9032304401d763a92/doc/figure_cn/Delete sub devices.png -------------------------------------------------------------------------------- /doc/figure_cn/add sub 2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huaweicloud/huaweicloud-iot-device-sdk-java/decdc0c045cd3049a12048a9032304401d763a92/doc/figure_cn/add sub 2.png -------------------------------------------------------------------------------- /doc/figure_cn/add sub device.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huaweicloud/huaweicloud-iot-device-sdk-java/decdc0c045cd3049a12048a9032304401d763a92/doc/figure_cn/add sub device.png -------------------------------------------------------------------------------- /doc/figure_cn/bridge_demo_pkg_structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huaweicloud/huaweicloud-iot-device-sdk-java/decdc0c045cd3049a12048a9032304401d763a92/doc/figure_cn/bridge_demo_pkg_structure.png -------------------------------------------------------------------------------- /doc/figure_cn/bridge_get_auth_info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huaweicloud/huaweicloud-iot-device-sdk-java/decdc0c045cd3049a12048a9032304401d763a92/doc/figure_cn/bridge_get_auth_info.png -------------------------------------------------------------------------------- /doc/figure_cn/delete sub success.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huaweicloud/huaweicloud-iot-device-sdk-java/decdc0c045cd3049a12048a9032304401d763a92/doc/figure_cn/delete sub success.png -------------------------------------------------------------------------------- /doc/figure_cn/generic_sdk_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huaweicloud/huaweicloud-iot-device-sdk-java/decdc0c045cd3049a12048a9032304401d763a92/doc/figure_cn/generic_sdk_1.png -------------------------------------------------------------------------------- /iot-bridge-demo/src/main/java/com/huaweicloud/sdk/iot/device/demo/DeviceIdentity.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 | /** 34 | * 设备接入标识 35 | */ 36 | public class DeviceIdentity { 37 | 38 | private String deviceId; 39 | 40 | private String secret; 41 | 42 | String getDeviceId() { 43 | return deviceId; 44 | } 45 | 46 | public void setDeviceId(String deviceId) { 47 | this.deviceId = deviceId; 48 | } 49 | 50 | String getSecret() { 51 | return secret; 52 | } 53 | 54 | public void setSecret(String secret) { 55 | this.secret = secret; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /iot-bridge-demo/src/main/java/com/huaweicloud/sdk/iot/device/demo/DeviceIdentityRegistry.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 | 34 | /** 35 | * 设备接入标识管理,提供获取设备标识信息能力 36 | */ 37 | public interface DeviceIdentityRegistry { 38 | 39 | DeviceIdentity getDeviceIdentity(String nodeId); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /iot-bridge-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /iot-bridge-demo/src/main/resources/ca.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huaweicloud/huaweicloud-iot-device-sdk-java/decdc0c045cd3049a12048a9032304401d763a92/iot-bridge-demo/src/main/resources/ca.jks -------------------------------------------------------------------------------- /iot-bridge-demo/src/main/resources/deviceIdentity.json: -------------------------------------------------------------------------------- 1 | { 2 | "demo": { 3 | "deviceId": "5e06bfee334dd4f33759f5b3_demo", 4 | "secret": "mysecret" 5 | }, 6 | "testDevice2": { 7 | "deviceId": "5df08775334dd4f3373a44a3_testDevice2", 8 | "secret": "xxx" 9 | } 10 | } -------------------------------------------------------------------------------- /iot-bridge-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-bridge-demo/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /iot-bridge-demo/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %d{yyyy-MM-dd HH:mm:ss} %-5level %c{1}:%L - %m%n 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /iot-bridge-sample-tcp-protocol/src/main/java/com/huaweicloud/sdk/iot/bridge/sample/tcp/Main.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.bridge.sample.tcp; 32 | 33 | import com.huaweicloud.sdk.iot.bridge.sample.tcp.bridge.BridgeService; 34 | import com.huaweicloud.sdk.iot.bridge.sample.tcp.server.TcpServer; 35 | 36 | public class Main { 37 | 38 | public static void main(String[] args) { 39 | 40 | // 启动时初始化网桥连接 41 | BridgeService bridgeService = new BridgeService(); 42 | bridgeService.init(); 43 | 44 | // 启动TCP服务 45 | TcpServer tcpServer = new TcpServer(); 46 | tcpServer.start("localhost", 8900); 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /iot-bridge-sample-tcp-protocol/src/main/java/com/huaweicloud/sdk/iot/bridge/sample/tcp/dto/BaseMessage.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.bridge.sample.tcp.dto; 32 | 33 | public class BaseMessage { 34 | 35 | private MsgHeader msgHeader; 36 | 37 | public MsgHeader getMsgHeader() { 38 | return msgHeader; 39 | } 40 | 41 | public void setMsgHeader(MsgHeader msgHeader) { 42 | this.msgHeader = msgHeader; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /iot-bridge-sample-tcp-protocol/src/main/java/com/huaweicloud/sdk/iot/bridge/sample/tcp/dto/CommonResponse.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.bridge.sample.tcp.dto; 32 | 33 | /** 34 | * 通用响应消息 35 | */ 36 | public class CommonResponse extends BaseMessage { 37 | 38 | // 响应码 39 | private int resultCode; 40 | 41 | public int getResultCode() { 42 | return resultCode; 43 | } 44 | 45 | public void setResultCode(int resultCode) { 46 | this.resultCode = resultCode; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /iot-bridge-sample-tcp-protocol/src/main/java/com/huaweicloud/sdk/iot/bridge/sample/tcp/dto/DeviceLocationFrequencySet.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.bridge.sample.tcp.dto; 32 | 33 | /** 34 | * 位置上报周期 35 | */ 36 | public class DeviceLocationFrequencySet extends BaseMessage { 37 | 38 | private int period; 39 | 40 | public int getPeriod() { 41 | return period; 42 | } 43 | 44 | public void setPeriod(int period) { 45 | this.period = period; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /iot-bridge-sample-tcp-protocol/src/main/java/com/huaweicloud/sdk/iot/bridge/sample/tcp/dto/DeviceLocationMessage.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.bridge.sample.tcp.dto; 32 | 33 | /** 34 | * 设备位置信息 35 | */ 36 | public class DeviceLocationMessage extends BaseMessage { 37 | 38 | private String longitude; 39 | 40 | private String latitude; 41 | 42 | public String getLongitude() { 43 | return longitude; 44 | } 45 | 46 | public void setLongitude(String longitude) { 47 | this.longitude = longitude; 48 | } 49 | 50 | public String getLatitude() { 51 | return latitude; 52 | } 53 | 54 | public void setLatitude(String latitude) { 55 | this.latitude = latitude; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /iot-bridge-sample-tcp-protocol/src/main/java/com/huaweicloud/sdk/iot/bridge/sample/tcp/dto/DeviceLoginMessage.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.bridge.sample.tcp.dto; 32 | 33 | /** 34 | * 设备登录消息 35 | */ 36 | public class DeviceLoginMessage extends BaseMessage { 37 | 38 | // 设备鉴权码 39 | private String secret; 40 | 41 | public String getSecret() { 42 | return secret; 43 | } 44 | 45 | public void setSecret(String secret) { 46 | this.secret = secret; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /iot-bridge-sample-tcp-protocol/src/main/java/com/huaweicloud/sdk/iot/bridge/sample/tcp/session/DeviceSession.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.bridge.sample.tcp.session; 32 | 33 | import io.netty.channel.Channel; 34 | 35 | /** 36 | * 设备会话信息 37 | */ 38 | public class DeviceSession { 39 | 40 | private static final int MAX_FLOW_NO = 0xFFFF; 41 | 42 | private String deviceId; 43 | 44 | private Channel channel; 45 | 46 | private int seqId; 47 | 48 | public String getDeviceId() { 49 | return deviceId; 50 | } 51 | 52 | public void setDeviceId(String deviceId) { 53 | this.deviceId = deviceId; 54 | } 55 | 56 | public Channel getChannel() { 57 | return channel; 58 | } 59 | 60 | public void setChannel(Channel channel) { 61 | this.channel = channel; 62 | } 63 | 64 | public int getAndUpdateSeqId() { 65 | if (seqId >= MAX_FLOW_NO - 1) { 66 | seqId = 0; 67 | } else { 68 | seqId++; 69 | } 70 | return seqId; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /iot-bridge-sample-tcp-protocol/src/main/java/com/huaweicloud/sdk/iot/bridge/sample/tcp/session/DeviceSessionManger.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.bridge.sample.tcp.session; 32 | 33 | import java.util.concurrent.ConcurrentHashMap; 34 | import java.util.concurrent.ConcurrentMap; 35 | 36 | public class DeviceSessionManger { 37 | 38 | private static final DeviceSessionManger INSTANCE = new DeviceSessionManger(); 39 | 40 | private final ConcurrentMap sessions = new ConcurrentHashMap<>(); 41 | 42 | public static DeviceSessionManger getInstance() { 43 | return INSTANCE; 44 | } 45 | 46 | public void createSession(String deviceId, DeviceSession session) { 47 | sessions.put(deviceId, session); 48 | } 49 | 50 | public DeviceSession getSession(String deviceId) { 51 | return sessions.get(deviceId); 52 | } 53 | 54 | public void deleteSession(String deviceId) { 55 | sessions.remove(deviceId); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /iot-bridge-sample-tcp-protocol/src/main/java/com/huaweicloud/sdk/iot/bridge/sample/tcp/session/NettyUtils.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.bridge.sample.tcp.session; 32 | 33 | import io.netty.channel.Channel; 34 | import io.netty.util.AttributeKey; 35 | 36 | public final class NettyUtils { 37 | 38 | private static final String ATTR_DEVICE_ID = "deviceId"; 39 | 40 | private static final AttributeKey ATTR_KEY_DEVICE_ID = AttributeKey.valueOf(ATTR_DEVICE_ID); 41 | 42 | public static void setDeviceId(Channel channel, String deviceId) { 43 | channel.attr(NettyUtils.ATTR_KEY_DEVICE_ID).set(deviceId); 44 | } 45 | 46 | public static String getDeviceId(Channel channel) { 47 | return (String) channel.attr(NettyUtils.ATTR_KEY_DEVICE_ID).get(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /iot-bridge-sample-tcp-protocol/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 16 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /iot-bridge-sdk/src/main/java/com/huaweicloud/bridge/sdk/constants/BridgeSDKConstants.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.bridge.sdk.constants; 32 | 33 | public class BridgeSDKConstants { 34 | 35 | public static final String BRIDGE_TOPIC_KEYWORD = "$oc/bridges/"; 36 | 37 | public static final String RESULET_CODE = "result_code"; 38 | 39 | public static final String HASH_CODE = "hash_code"; 40 | 41 | public static final String SIZE = "size"; 42 | 43 | public static final int DEVICE_SIGN_TYPE = 1; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /iot-bridge-sdk/src/main/java/com/huaweicloud/bridge/sdk/handler/DeviceDisConnHandler.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.bridge.sdk.handler; 32 | 33 | import com.huaweicloud.bridge.sdk.BridgeClient; 34 | import com.huaweicloud.sdk.iot.device.client.handler.MessageReceivedHandler; 35 | import com.huaweicloud.sdk.iot.device.transport.RawMessage; 36 | import com.huaweicloud.sdk.iot.device.utils.IotUtil; 37 | import lombok.extern.slf4j.Slf4j; 38 | 39 | @Slf4j 40 | public class DeviceDisConnHandler implements MessageReceivedHandler { 41 | 42 | private final BridgeClient bridgeClient; 43 | 44 | public DeviceDisConnHandler(BridgeClient bridgeClient) { 45 | this.bridgeClient = bridgeClient; 46 | } 47 | 48 | @Override 49 | public void messageHandler(RawMessage message) { 50 | log.debug("received the message of the device under one bridge disconnects, the message is {}", 51 | message); 52 | String deviceId = IotUtil.getDeviceId(message.getTopic()); 53 | if (bridgeClient.getBridgeDeviceDisConnListener() != null) { 54 | bridgeClient.getBridgeDeviceDisConnListener().onDisConnect(deviceId); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /iot-bridge-sdk/src/main/java/com/huaweicloud/bridge/sdk/listener/BridgeCommandListener.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.bridge.sdk.listener; 32 | 33 | import com.huaweicloud.bridge.sdk.request.BridgeCommand; 34 | 35 | public interface BridgeCommandListener { 36 | 37 | /** 38 | * 网桥命令处理 39 | * @param deviceId 设备Id 40 | * @param requestId 请求Id 41 | * @param bridgeCommand 网桥命令 42 | */ 43 | void onCommand(String deviceId, String requestId, BridgeCommand bridgeCommand); 44 | } 45 | -------------------------------------------------------------------------------- /iot-bridge-sdk/src/main/java/com/huaweicloud/bridge/sdk/listener/BridgeDeviceDisConnListener.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.bridge.sdk.listener; 32 | 33 | public interface BridgeDeviceDisConnListener { 34 | 35 | /** 36 | * 网桥设备断链通知处理 37 | * 38 | * @param deviceId 设备Id 39 | */ 40 | void onDisConnect(String deviceId); 41 | } 42 | -------------------------------------------------------------------------------- /iot-bridge-sdk/src/main/java/com/huaweicloud/bridge/sdk/listener/BridgeDeviceMessageListener.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.bridge.sdk.listener; 32 | 33 | import com.huaweicloud.sdk.iot.device.client.requests.DeviceMessage; 34 | 35 | public interface BridgeDeviceMessageListener { 36 | 37 | /** 38 | * 处理平台给网桥下发的消息 39 | * 40 | * @param deviceId 设备Id 41 | * @param deviceMessage 消息体 42 | */ 43 | void onDeviceMessage(String deviceId, DeviceMessage deviceMessage); 44 | } 45 | -------------------------------------------------------------------------------- /iot-bridge-sdk/src/main/java/com/huaweicloud/bridge/sdk/listener/BridgePropertyListener.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.bridge.sdk.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 BridgePropertyListener { 41 | 42 | /** 43 | * 处理写属性操作 44 | * 45 | * @param requestId 设备id 46 | * @param requestId 请求id 47 | * @param services 服务属性列表 48 | */ 49 | void onPropertiesSet(String deviceId, String requestId, List services); 50 | 51 | /** 52 | * 处理读属性操作 53 | * 54 | * @param requestId 设备id 55 | * @param requestId 请求id 56 | * @param serviceId 服务id,可选 57 | */ 58 | void onPropertiesGet(String deviceId, String requestId, String serviceId); 59 | } 60 | -------------------------------------------------------------------------------- /iot-bridge-sdk/src/main/java/com/huaweicloud/bridge/sdk/listener/LoginListener.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.bridge.sdk.listener; 32 | 33 | public interface LoginListener { 34 | 35 | /** 36 | * 网桥下设备登录监听器 37 | * 38 | * @param deviceId 设备Id 39 | * @param requestId 请求Id 40 | * @param resultCode 登录响应码 41 | */ 42 | void onLogin(String deviceId, String requestId, int resultCode); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /iot-bridge-sdk/src/main/java/com/huaweicloud/bridge/sdk/listener/LogoutListener.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.bridge.sdk.listener; 32 | 33 | import java.util.Map; 34 | 35 | public interface LogoutListener { 36 | /** 37 | * 网桥下设备登出监听器 38 | * 39 | * @param deviceId 设备Id 40 | * @param requestId 请求Id 41 | * @param map 响应体 42 | */ 43 | void onLogout(String deviceId, String requestId, Map map); 44 | } 45 | -------------------------------------------------------------------------------- /iot-bridge-sdk/src/main/java/com/huaweicloud/bridge/sdk/listener/ResetDeviceSecretListener.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.bridge.sdk.listener; 32 | 33 | public interface ResetDeviceSecretListener { 34 | 35 | /** 36 | * 网桥设置设备密钥监听器 37 | * 38 | * @param deviceId 设备Id 39 | * @param requestId 请求Id 40 | * @param resultCode 结果码,0表示成功,其他表示失败。不带默认认为成功。 41 | * @param newSecret 设备新secret 42 | */ 43 | void onResetDeviceSecret(String deviceId, String requestId, int resultCode, String newSecret); 44 | } 45 | -------------------------------------------------------------------------------- /iot-bridge-sdk/src/main/java/com/huaweicloud/bridge/sdk/request/BridgeCommand.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.bridge.sdk.request; 32 | 33 | import com.huaweicloud.sdk.iot.device.client.requests.Command; 34 | 35 | /** 36 | * 网桥设备命令 37 | */ 38 | public class BridgeCommand { 39 | 40 | private String deviceId; 41 | 42 | private Command command; 43 | 44 | public String getDeviceId() { 45 | return deviceId; 46 | } 47 | 48 | public void setDeviceId(String deviceId) { 49 | this.deviceId = deviceId; 50 | } 51 | 52 | public Command getCommand() { 53 | return command; 54 | } 55 | 56 | public void setCommand(Command command) { 57 | this.command = command; 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return "BridgeCommand{" + "deviceId='" + deviceId + '\'' + ", command=" + command + '}'; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /iot-bridge-sdk/src/main/java/com/huaweicloud/bridge/sdk/request/DeviceSecret.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.bridge.sdk.request; 32 | 33 | import com.fasterxml.jackson.annotation.JsonProperty; 34 | 35 | public class DeviceSecret { 36 | 37 | @JsonProperty("old_secret") 38 | private String oldSecret; 39 | 40 | @JsonProperty("new_secret") 41 | private String newSecret; 42 | 43 | public DeviceSecret(String oldSecret, String newSecret) { 44 | this.oldSecret = oldSecret; 45 | this.newSecret = newSecret; 46 | } 47 | 48 | public String getOldSecret() { 49 | return oldSecret; 50 | } 51 | 52 | public void setOldSecret(String oldSecret) { 53 | this.oldSecret = oldSecret; 54 | } 55 | 56 | public String getNewSecret() { 57 | return newSecret; 58 | } 59 | 60 | public void setNewSecret(String newSecret) { 61 | this.newSecret = newSecret; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /iot-bridge-sdk/src/main/java/com/huaweicloud/bridge/sdk/response/ResetDeviceSecretResponse.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.bridge.sdk.response; 32 | 33 | import com.fasterxml.jackson.annotation.JsonProperty; 34 | import com.huaweicloud.sdk.iot.device.utils.JsonUtil; 35 | 36 | import java.util.Map; 37 | 38 | public class ResetDeviceSecretResponse { 39 | @JsonProperty("result_code") 40 | private int resultCode; 41 | 42 | Map paras; 43 | 44 | public int getResultCode() { 45 | return resultCode; 46 | } 47 | 48 | public void setResultCode(int resultCode) { 49 | this.resultCode = resultCode; 50 | } 51 | 52 | public Map getParas() { 53 | return paras; 54 | } 55 | 56 | public void setParas(Map paras) { 57 | this.paras = paras; 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return JsonUtil.convertObject2String(this); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /iot-bridge-sdk/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-bridge-sdk/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /iot-device-code-generator/README.md: -------------------------------------------------------------------------------- 1 | # iot-device-code-generator 2 | 3 | iot-device-code-generator提供设备代码自动生成功能,用户只需要提供设备的产品模型文件,就可以自动生成设备代码框架,简化设备代码开发工作量。 4 | 5 | 6 | ## 如何使用 7 | ### 使用使用代码生成器生成设备代码 8 | 1、下载huaweicloud-iot-device-sdk-java工程,解压缩后进入huaweicloud-iot-device-sdk-java目录执行mvn install 9 | 执行完成会在iot-device-code-generator的target下生成可执行jar包 10 | 11 | 2、将产品模型文件保存到本地,比如我的模型文件smokeDetector_cb097d20d77b4240adf1f33d36b3c278_smokeDetector.zip放到D盘 12 | 3、进到 iot-device-code-generator\target\目录下执行 13 | java -jar iot-device-code-generator-0.2.0-with-deps.jar D:\smokeDetector_cb097d20d77b4240adf1f33d36b3c278_smokeDetector.zip 14 | jar包名注意修改为正确的版本号 15 | 16 | 在huaweicloud-iot-device-sdk-java目录下会生成generated-demo包 17 | 至此,设备代码已经生成 18 | 19 | ### 编译运行自动生成的设备代码 20 | 1、进到huaweicloud-iot-device-sdk-java\generated-demo目录下执行`mvn install`, 在target下生成jar包 21 | 22 | 2、执行`java -jar target\iot-device-demo-ganerated-0.2.0-with-deps.jar 接入域名 设备id 设备secret`。 23 | 24 | 如果觉得上面操作比较烦,可以打开iot-device-code-generator目录下的device-code-genarator.bat脚本,修改上面的参数,然后双击运行即可 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /iot-device-code-generator/README_EN.md: -------------------------------------------------------------------------------- 1 | # iot-device-code-generator 2 | 3 | iot-device-code-generator generates device code automatically, simplifying device code development. You can use it to generate the device code framework based on the product model file. 4 | 5 | 6 | ## How to Use 7 | ### Using the Code Generator to Generate Device Code 8 | 1. Download the **huaweicloud-iot-device-sdk-java** project, decompress it, go to the **huaweicloud-iot-device-sdk-java** directory, and run the **mvn install** command. 9 | Check whether an executable JAR package is generated in the **target** folder of **iot-device-code-generator**. 10 | 11 | 2. Save the product model to a local directory. For example, save the **smokeDetector_cb097d20d77b4240adf1f33d36b3c278_smokeDetector.zip** file to drive D. 12 | 3. Run the following command in the **iot-device-code-generator\target\ **directory: 13 | **java -jar iot-device-code-generator-0.2.0-with-deps.jar D:\smokeDetector_cb097d20d77b4240adf1f33d36b3c278_smokeDetector.zip ** 14 | Use a correct version number for the JAR package name. 15 | 16 | If the **generated-demo** package is generated in the **huaweicloud-iot-device-sdk-java** directory, the device code is generated. 17 | 18 | 19 | ### Compiling and Runing the Generated Device Code 20 | 1. Go to the **huaweicloud-iot-device-sdk-java\generated-demo** directory and run the **mvn install** command. 21 | Generate a JAR package in the **target** directory. 22 | 2. Run the **java -jar target\iot-device-demo-generated-0.2.0-with-deps.jar 5e06bfee334dd4f33759f5b3_demo** ***\**\** command. 23 | Set the two parameters to the device ID and password, respectively. 24 | 25 | Alternatively, open the **device-code-generator.bat** script in the **iot-device-code-generator** directory, modify the preceding parameters, and double-click the script to run it. 26 | ​ 27 | -------------------------------------------------------------------------------- /iot-device-code-generator/device-code-genarator.bat: -------------------------------------------------------------------------------- 1 | ::请修改自己的参数,productZip为产品模型包路径 2 | set productZip=".\iot-device-code-generator\src\main\resources\smokeDetector_cb097d20d77b4240adf1f33d36b3c278_smokeDetector.zip" 3 | ::修改为自己的接入域名 4 | set accessAddress="000000000.st1.iotda-device.cn-south-1.myhuaweicloud.com" 5 | set deviceId="5e06bfee334dd4f33759f5b3_demo" 6 | set secret="******" 7 | cd .. 8 | call mvn clean install 9 | call java -jar iot-device-code-generator\target\iot-device-code-generator-1.2.1-with-deps.jar %productZip% 10 | cd generated-demo 11 | call mvn install 12 | call java -jar target\iot-device-demo-ganerated-1.2.1-with-deps.jar %accessAddress% %deviceId% %secret% 13 | pause 14 | 15 | -------------------------------------------------------------------------------- /iot-device-code-generator/src/main/java/com/huaweicloud/sdk/iot/device/codegenerator/productparser/ProductInfo.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.codegenerator.productparser; 32 | 33 | import java.util.Map; 34 | 35 | public class ProductInfo { 36 | 37 | private DeviceCapability deviceCapability; 38 | 39 | private Map serviceCapabilityMap; 40 | 41 | public DeviceCapability getDeviceCapability() { 42 | return deviceCapability; 43 | } 44 | 45 | void setDeviceCapability(DeviceCapability deviceCapability) { 46 | this.deviceCapability = deviceCapability; 47 | } 48 | 49 | public Map getServiceCapabilityMap() { 50 | return serviceCapabilityMap; 51 | } 52 | 53 | void setServiceCapabilityMap(Map serviceCapabilityMap) { 54 | this.serviceCapabilityMap = serviceCapabilityMap; 55 | } 56 | 57 | @Override 58 | public String toString() { 59 | return "ProductInfo{" + "deviceCapability=" + deviceCapability 60 | + ", serviceCapabilityMap=" + serviceCapabilityMap + '}'; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /iot-device-code-generator/src/main/java/com/huaweicloud/sdk/iot/device/codegenerator/productparser/ServiceCommandResponse.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.codegenerator.productparser; 32 | 33 | import java.io.Serializable; 34 | import java.util.List; 35 | 36 | public class ServiceCommandResponse implements Serializable { 37 | private static final long serialVersionUID = 4535630761027464385L; 38 | 39 | private String responseName; 40 | 41 | private List paras; 42 | 43 | public String getResponseName() { 44 | return responseName; 45 | } 46 | 47 | public void setResponseName(String responseName) { 48 | this.responseName = responseName; 49 | } 50 | 51 | public List getParas() { 52 | return paras; 53 | } 54 | 55 | public void setParas(List paras) { 56 | this.paras = paras; 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | 62 | return "ServiceCommandResponse [responseName=" + responseName 63 | + ", paras=" + paras + "]"; 64 | 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /iot-device-code-generator/src/main/resources/generated-demo.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huaweicloud/huaweicloud-iot-device-sdk-java/decdc0c045cd3049a12048a9032304401d763a92/iot-device-code-generator/src/main/resources/generated-demo.zip -------------------------------------------------------------------------------- /iot-device-code-generator/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | ### #配置根Logger ### 2 | log4j.rootLogger=info,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-code-generator/src/main/resources/smokeDetector_cb097d20d77b4240adf1f33d36b3c278_smokeDetector.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huaweicloud/huaweicloud-iot-device-sdk-java/decdc0c045cd3049a12048a9032304401d763a92/iot-device-code-generator/src/main/resources/smokeDetector_cb097d20d77b4240adf1f33d36b3c278_smokeDetector.zip -------------------------------------------------------------------------------- /iot-device-demo/src/main/java/com/huaweicloud/sdk/iot/device/demo/bootstrap/BootstrapMessageSample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2024 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.bootstrap; 32 | 33 | import com.huaweicloud.sdk.iot.device.bootstrap.BootstrapClient; 34 | 35 | /** 36 | * 演示密钥认证设备启动时,通过引导服务数据上报获取真实的服务器地址 37 | */ 38 | public class BootstrapMessageSample extends BaseBootstrapSample { 39 | public static void main(String[] args) { 40 | 41 | // 设备ID(设备ID需在设备发放上注册) 42 | String deviceId = "[Please input your device id here, example:702b1038-a174-4a1d-969f-f67f8df43c4a]"; 43 | 44 | // 设备密钥 45 | String secret = "[Please input your device secret here, example:mysecret]"; 46 | 47 | // 数据上报的关键字,使用时需要把里面的test替换成对应的关键字 48 | String message = "{\"baseStrategyKeyword\":\"test\"}"; 49 | 50 | // 创建引导客户端,发起引导 51 | BootstrapClient bootstrapClient = new BootstrapClient(BOOTSTRAP_URI, deviceId, secret, PLATFORM_CA_PROVIDER); 52 | DefaultBootstrapActionListener defaultBootstrapActionListener = new DefaultBootstrapActionListener(bootstrapClient); 53 | bootstrapClient.bootstrap(defaultBootstrapActionListener, message); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /iot-device-demo/src/main/java/com/huaweicloud/sdk/iot/device/demo/bootstrap/BootstrapSample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2024 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.bootstrap; 32 | 33 | import com.huaweicloud.sdk.iot.device.bootstrap.BootstrapClient; 34 | 35 | /** 36 | * 演示密钥认证设备启动时,通过引导服务获取真实的服务器地址 37 | */ 38 | public class BootstrapSample extends BaseBootstrapSample { 39 | public static void main(String[] args) { 40 | // 设备ID(设备ID需在设备发放上注册) 41 | String deviceId = "[Please input your device id here, example:702b1038-a174-4a1d-969f-f67f8df43c4a]"; 42 | 43 | // 设备密钥 44 | String secret = "[Please input your device secret here, example:mysecret]"; 45 | 46 | // 创建引导客户端,发起引导 47 | BootstrapClient bootstrapClient = new BootstrapClient(BOOTSTRAP_URI, deviceId, secret, PLATFORM_CA_PROVIDER); 48 | DefaultBootstrapActionListener defaultBootstrapActionListener = new DefaultBootstrapActionListener(bootstrapClient); 49 | bootstrapClient.bootstrap(defaultBootstrapActionListener); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /iot-device-demo/src/main/java/com/huaweicloud/sdk/iot/device/demo/bootstrap/BootstrapSelfRegGroupPasswordSample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2024 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.bootstrap; 32 | 33 | import com.huaweicloud.sdk.iot.device.bootstrap.BootstrapClient; 34 | 35 | /** 36 | * 演示自注册场景(注册组秘钥认证方式),设备启动时,通过引导服务获取真实的服务器地址 37 | */ 38 | public class BootstrapSelfRegGroupPasswordSample extends BaseBootstrapSample { 39 | 40 | public static void main(String[] args) throws Exception { 41 | // ScopeID,与租户相关,请从注册组页面获取 42 | String scopeId = "[Please input your scope id here, example:f67f8df43c4a]"; 43 | 44 | // 设备ID(自注册场景下,设备ID无需提前在设备发放上注册) 45 | String deviceId = "[Please input your device id here, example:702b1038-a174-4a1d-969f-f67f8df43c4a]"; 46 | 47 | // 注册组密钥 48 | String groupSecret = "[Please input your group secret here, example:mysecret]"; 49 | // 创建引导客户端,发起引导 50 | BootstrapClient bootstrapClient = new BootstrapClient(BOOTSTRAP_URI, deviceId, groupSecret, scopeId, 51 | PLATFORM_CA_PROVIDER); 52 | bootstrapClient.bootstrap(new SimpleBootstrapActionListener(bootstrapClient)); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /iot-device-demo/src/main/java/com/huaweicloud/sdk/iot/device/demo/device/ShadowSample.java: -------------------------------------------------------------------------------- 1 | package com.huaweicloud.sdk.iot.device.demo.device; 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.listener.ShadowListener; 7 | import com.huaweicloud.sdk.iot.device.client.requests.ShadowData; 8 | import com.huaweicloud.sdk.iot.device.client.requests.ShadowRequest; 9 | import com.huaweicloud.sdk.iot.device.transport.ActionListener; 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 | import java.util.List; 17 | 18 | /** 19 | * 演示如何直接使用DeviceClient获取设备影子 20 | */ 21 | @Slf4j 22 | public class ShadowSample { 23 | 24 | public static final String IOT_ROOT_CA_RES_PATH = "ca.jks"; 25 | 26 | private static final String IOT_ROOT_CA_TMP_PATH = "huaweicloud-iotda-tmp-" + IOT_ROOT_CA_RES_PATH; 27 | 28 | public static void main(String[] args) throws IOException { 29 | // 用户请替换为自己的接入地址。 30 | String serverUri = "ssl://xxx.st1.iotda-device.cn-north-4.myhuaweicloud.com:8883"; 31 | String deviceId = "702b1038-a174-4a1d-969f-f67f8df43c4a"; 32 | String secret = "my secret"; 33 | 34 | // 加载iot平台的ca证书,进行服务端校验 35 | File tmpCAFile = new File(IOT_ROOT_CA_TMP_PATH); 36 | try (InputStream resource = CommandSample.class.getClassLoader().getResourceAsStream(IOT_ROOT_CA_RES_PATH)) { 37 | Files.copy(resource, tmpCAFile.toPath(), REPLACE_EXISTING); 38 | } 39 | 40 | // 创建设备 41 | IoTDevice device = new IoTDevice(serverUri, deviceId, secret, tmpCAFile); 42 | device.getClient().setShadowListener(new ShadowListener() { 43 | @Override 44 | public void onShadow(String requestId, List 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 | } --------------------------------------------------------------------------------