跳至主要內容

SDK使用

技术中心大约 3 分钟

SDK使用

JAVA SDK

Maven坐标

<dependency>
    <groupId>com.clzy.cljs.sdk</groupId>
    <artifactId>cljs-sdk-iot</artifactId>
    <version>${version}</version>
</dependency>

使用介绍

介绍SDK的使用流程

申请AppID

联系管理员申请AppID,该AppID将会在后续使用。申请到的AppID信息如下所示:

app-id: geo3.0
auth-server-url: http://sso.jsyun.clzytech.com:30600/auth/
app-secret: 111111111111111111111111
realm: cljs

获取AIOT接入地址

base-url: http://192.168.110.81:3790/
default-project-id: d2a67e99a5ce4911984fdf464dd3dab9

参数说明:

参数名描述
base-urlAIOT数据开发接口
default-project-id需要访问的AIOT中的项目

引入sdk

在您的项目中使用SDK

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.12.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.clzy.cljs</groupId>
    <artifactId>iot2-sdk-test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>iot2-sdk-test</name>
    <description>iot2-sdk-test</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <!-- ...... -->
        <dependency>
            <groupId>com.clzy.cljs.sdk</groupId>
            <artifactId>cljs-sdk-iot</artifactId>
            <version>1.2-SNAPSHOT</version>
        </dependency>
        <!-- ...... -->
    </dependencies>
</project>

配置SDK参数

配置AppIDAIOT接入地址

com:
  clzy:
    cljs:
      sdk:
        iot:
          base-url: http://192.168.110.81:3790/
          default-project-id: d2a67e99a5ce4911984fdf464dd3dab9
          enable: true
        sso:
          app-id: geo3.0
          auth-server-url: http://sso.jsyun.clzytech.com:30600/auth/
          app-secret: 1b51ee09-2ee8-49e5-b958-52d90d2b9f1b
          realm: cljs
          enabled: true
server:
  port: 8081

接入测试

Spring代码:

@Slf4j
@SpringBootApplication
public class Iot2SdkTestApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(Iot2SdkTestApplication.class, args);
        // 查询设备
        DeviceApi deviceApi = context.getBean(DeviceApi.class);
        log.info("查询到设备数据:{}", JSON.toJSONString(deviceApi.list(new Device())));
    }
}

程序输出:


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::       (v2.3.12.RELEASE)

2023-10-12 10:28:52.729  INFO 9516 --- [           main] c.c.c.i.Iot2SdkTestApplication           : Starting Iot2SdkTestApplication on DESKTOP-QPNEAIQ with PID 9516 (E:\itouxin\Downloads\iot2-sdk-test\target\classes started by itoux in E:\itouxin\Downloads\iot2-sdk-test)
2023-10-12 10:28:52.731  INFO 9516 --- [           main] c.c.c.i.Iot2SdkTestApplication           : No active profile set, falling back to default profiles: default
2023-10-12 10:28:53.234  INFO 9516 --- [           main] faultConfiguringBeanFactoryPostProcessor : No bean named 'errorChannel' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created.
2023-10-12 10:28:53.239  INFO 9516 --- [           main] faultConfiguringBeanFactoryPostProcessor : No bean named 'taskScheduler' has been explicitly defined. Therefore, a default ThreadPoolTaskScheduler will be created.
2023-10-12 10:28:53.241  INFO 9516 --- [           main] faultConfiguringBeanFactoryPostProcessor : No bean named 'integrationHeaderChannelRegistry' has been explicitly defined. Therefore, a default DefaultHeaderChannelRegistry will be created.
2023-10-12 10:28:53.282  INFO 9516 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.retry.annotation.RetryConfiguration' of type [org.springframework.retry.annotation.RetryConfiguration$$EnhancerBySpringCGLIB$$e0e8fde6] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2023-10-12 10:28:53.300  INFO 9516 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.integration.config.IntegrationManagementConfiguration' of type [org.springframework.integration.config.IntegrationManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2023-10-12 10:28:53.305  INFO 9516 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'integrationChannelResolver' of type [org.springframework.integration.support.channel.BeanFactoryChannelResolver] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2023-10-12 10:28:53.306  INFO 9516 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'integrationDisposableAutoCreatedBeans' of type [org.springframework.integration.config.annotation.Disposables] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2023-10-12 10:28:53.429  INFO 9516 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2023-10-12 10:28:53.434  INFO 9516 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-10-12 10:28:53.434  INFO 9516 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.46]
2023-10-12 10:28:53.482  INFO 9516 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-10-12 10:28:53.482  INFO 9516 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 726 ms
2023-10-12 10:28:53.773  INFO 9516 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2023-10-12 10:28:53.993  INFO 9516 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 2 endpoint(s) beneath base path '/actuator'
2023-10-12 10:28:54.032  INFO 9516 --- [           main] o.s.s.c.ThreadPoolTaskScheduler          : Initializing ExecutorService 'taskScheduler'
2023-10-12 10:28:54.056  INFO 9516 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2023-10-12 10:28:54.056  INFO 9516 --- [           main] o.s.i.channel.PublishSubscribeChannel    : Channel 'application.errorChannel' has 1 subscriber(s).
2023-10-12 10:28:54.057  INFO 9516 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : started bean '_org.springframework.integration.errorLogger'
2023-10-12 10:28:54.068  INFO 9516 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2023-10-12 10:28:54.083  INFO 9516 --- [           main] c.c.c.i.Iot2SdkTestApplication           : Started Iot2SdkTestApplication in 1.548 seconds (JVM running for 1.989)
2023-10-12 10:28:54.244  INFO 9516 --- [           main] c.c.c.i.Iot2SdkTestApplication           : 查询到设备数据:[]
2023-10-12 10:28:54.307  INFO 9516 --- [-192.168.104.20] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2023-10-12 10:28:54.307  INFO 9516 --- [-192.168.104.20] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2023-10-12 10:28:54.310  INFO 9516 --- [-192.168.104.20] o.s.web.servlet.DispatcherServlet        : Completed initialization in 3 ms

开发文档

javadocopen in new window

版本更新

  1. 版本号:1.2-SNAPSHOT,发布时间:2023-10-12

适配AIOT2.0.0

常见问题

  1. AppIDAIOT接入地址配置正确,但是查询不到相应数据?
    可能有如下原因:
    • 接入的项目确实没有数据
    • 接入的项目没有为SSO账号授权