首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用Edge SDK 1.0将传感器数据接收到Watson cloud

无法使用Edge SDK 1.0将传感器数据接收到Watson cloud
EN

Stack Overflow用户
提问于 2017-08-25 18:59:49
回答 1查看 45关注 0票数 0

我使用的是EDGE SDK1.0,用java创建的网关设备模拟器代码。在我的程序中,连接到网关后进入云。我正在发送已经在云中注册的传感器设备的数据。下面给出的是代码片段

代码语言:javascript
复制
public class SampleApplication {
   public static void main(String[] args) throws Exception {
    Properties props = loadProperties();
    String ORG_ID = props.getProperty("Organization-ID");
    String AUTH_KEY = props.getProperty("API-Key");
    String AUTH_TOKEN = props.getProperty("API-Token");
    String APP_ID = props.getProperty("Application-ID");
    String GATEWAY_ID = props.getProperty("Gateway-ID");
    String GATEWAY_TYPE = props.getProperty("Gateway-Type");
    String GATEWAY_AUTH_TOKEN = props.getProperty("Authentication-Token");

    EdgeProperties edgeProps = new EdgeProperties(ORG_ID, APP_ID, AUTH_KEY, 
 AUTH_TOKEN,GATEWAY_TYPE, GATEWAY_ID, GATEWAY_AUTH_TOKEN);

    EdgeAnalyticsClient edgeAnalyticsClient = new EdgeAnalyticsClient(edgeProps);
    EdgeAnalyticsAgent eaa = edgeAnalyticsClient.getAgent();

    // Start edge analytics agent with the new gateway.
    eaa.start();

    // (Optional) Register an alert handler
    eaa.registerDeviceActionHandler(new AlertFileActionHandler("ABC.CSV"));

    // Publish a event every 10 seconds.
      int i = 0;
      Random random = new Random();
      while (i++ < 100000) {
        JsonObject data = new JsonObject();
        data.addProperty("pir", random.nextInt(2));
        data.addProperty("temp", 34 + random.nextDouble() - random.nextInt(3));
        System.out.println(" data is "+data.toString());
      Event event = new Event("84_18_26_00_00_07_AB_55", "Sensor", data.toString());
      eaa.deviceData(event);
      Thread.sleep(10000);
    }
  }

  private static Properties loadProperties() throws IOException {
    String configPath = "sample-config/sample_app.conf";
    Properties props = new Properties();
    props.load(new FileInputStream(configPath));
    return props;
  }

  } 

但上面的代码没有将数据发送到正确的主题,或者它没有在watson云中创建的internetofthings服务上显示数据。我使用了IBM提供的示例程序,这些示例程序运行得很好。但是当我使用相同的pom.xml创建我的程序时,它并没有发布数据。

Pom.xml为">http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

代码语言:javascript
复制
<groupId>com.vriot</groupId>
<artifactId>IBMConnector_V1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>IBMConnector_V1</name>
<url>http://maven.apache.org</url>

<properties>

    <!-- This project specific properties -->
    <maven.javadoc.failOnError>false</maven.javadoc.failOnError>
    <maven.build.skipTests>true</maven.build.skipTests>

    <!-- General properties -->
    <java.version>1.7</java.version>

    <!-- maven-compiler-plugin configuration -->
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>edge-sdk-1.0.0</groupId>
        <artifactId>edge-sdk-1.0.0</artifactId>
        <version>1.0.0</version>
        <scope>system</scope>
        <systemPath>${basedir}\lib\edge-sdk-1.0.0.jar</systemPath>
    </dependency>

    <dependency>
        <groupId>com.rabbitmq</groupId>
        <artifactId>amqp-client</artifactId>
        <version>3.0.4</version>
    </dependency>
    <dependency>
        <groupId>com.ibm.messaging</groupId>
        <artifactId>watson-iot</artifactId>
        <version>0.1.0</version>
    </dependency>
    <dependency>
        <groupId>org.bidib.jbidib.org.qbang.rxtx</groupId>
        <artifactId>rxtxcomm</artifactId>
        <version>2.2</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>${maven.compiler.source}</source>
                <target>${maven.compiler.target}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.7</version>
            <configuration>
                <delimiters>
                    <delimiter>@</delimiter>
                </delimiters>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <archive>
                    <manifest>
                        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>2.4</version>
            <executions>
                <execution>
                    <id>attach-sources</id>
                    <goals>
                        <goal>jar-no-fork</goal>
                    </goals>
                </execution>
            </executions>

        </plugin>
    </plugins>
</build>

EN

回答 1

Stack Overflow用户

发布于 2017-09-09 16:41:38

基本上,我知道java,但不知道Watson IoT的事情。将edgeApp.eaa.start()之前的1-2行代码与示例应用程序进行比较。它们应该具有类似的逻辑。在引入ABC.CSV之前,您的代码可能需要在edgeApp.eaa.start()之前执行一些操作。如果不知道他们的示例应用程序,实际上很难确认。

因为到目前为止还没有人回答,你可以在IBM developer works上询问。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45879884

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档