2

关于实时通知的问题..

Post: https://xxxiot.cumulocity.com/cep/realtime
Body: 
[
 { 
  "channel": "/meta/handshake",
  "version": "1.0",
  "mininumVersion": "1.0beta",
  "supportedConnectionTypes": ["long-polling","callback-polling"],
  "advice":{"timeout":120000,"interval":30000}
 }
]

我的回复:

[
 {
  "minimumVersion": "1.0",
  "supportedConnectionTypes": [
  "smartrest-long-polling",
  "long-polling"
],
  "successful": true,
  "channel": "/meta/handshake",
  "ext": {
  "ack": true
},
 "clientId": "5o0ghvle7yy4ix41on423v6k3j87",
 "version": "1.0"
}

]

收到clientId后..我运行了以下命令:

Post: https://xxxiot.cumulocity.com/cep/realtime
Body:
[
 {
  "channel": "/meta/subscribe",
  "clientId": "5o0ghvle7yy4ix41on423v6k3j87",
  "subscription": "/alarms/overHeatAlarms"
 }
]

回复:

[
 {
 "error": "403:denied_by_security_policy:create_denied",
 "subscription": "/alarms/overHeatAlarms",
 "successful": false,
 "channel": "/meta/subscribe"
 }
]

问题出在哪里?我正在尝试订阅“overheatAlarms”!它可能不存在?我可以阅读现有信息吗?谢谢, 阿利姆

4

2 回答 2

2

是的,你的怀疑是正确的。基本上有两种选择:

  • 订阅来自特定设备的所有警报或警报:使用“/cep/realtime”和通道“/alarms/* 对应通道“/alarms/[设备 ID]”。
  • 创建过滤过热警报的处理规则并订阅该规则:使用“/cep/notifications”和通道“/[模块名称]/[语句名称]”。

模块名称是您在单击“新建模块”时输入的名称。语句名称是您添加到语句中的内容,例如

@Name('overHeatAlarms')
select * from AlarmsCreated where [your condition for overheat alarms]

(如果您不在那里输入名称,它们将是名称 statement_1,statement_2,...。)

要从 Java 获取通知,请查看获取设备更改通知的示例。在 subscribe() 方法中,您传递“*”或设备 ID。要获取通知,请传递SubscriptionListener的实现,特别是 onNotification 方法。您可以将“channelPrefix”修改为“/alarms/”或“/measurements/”以获取其他通知。

于 2016-02-02T09:12:28.330 回答
0

谢谢,安德烈。我已经测试了以下代码片段..它有效,但它不是最好的解决方案:-)

    MeasurementApi measurementApi = getMeasurementApi();
    MeasurementFilter measurementFilter = new MeasurementFilter();
    while (true) {
        Calendar cal = Calendar.getInstance();

        Date toDate = cal.getTime();
        cal.add(Calendar.SECOND, -25);
        Date fromDate = cal.getTime();
        measurementFilter.byDate(fromDate, toDate);
        measurementFilter.byFragmentType(TemperatureMeasurement.class);
        measurementFilter.bySource(new GId(DEVICE_SIMULATOR));
        MeasurementCollection mc = measurementApi
                .getMeasurementsByFilter(measurementFilter);

        MeasurementCollectionRepresentation measurements = mc.get();
        for (; measurements != null; measurements = mc
                .getNextPage(measurements)) {
            for (MeasurementRepresentation measurement : measurements
                    .getMeasurements()) {
                TemperatureMeasurement temperatureSensor = measurement
                        .get(TemperatureMeasurement.class);

                System.out.println(measurement.getSource().getId() + " "
                        + measurement.getTime()+ " " + temperatureSensor.getTemperature() );

            }
        }
    }
于 2016-02-02T20:46:34.207 回答