【发布时间】:2018-05-27 18:12:58
【问题描述】:
正如docs of Apache Edgent 中给出的那样,我试图过滤掉我的传感器读数,其中温度传感器的值必须在 80 到 85 F 之间。
但是当我尝试连接传感器时,读数为 75F,并且没有显示如下消息:温度超出范围。
是不是过滤方法不起作用?如果是这样,请尝试帮助我。谢谢。
范围值设置为:
static double OPTIMAL_TEMP_LOW = 80.0;
static double OPTIMAL_TEMP_HIGH = 85.0;
static Range<Double> optimalTempRange = Ranges.closed(OPTIMAL_TEMP_LOW, OPTIMAL_TEMP_HIGH);
传感器对象是TempSensor ts
TempSensor ts = new TempSensor();
Stream<Double> temp = top.poll(ts, 1, TimeUnit.MILLISECONDS);
过滤部分:
TStream<Double> simpleFiltered = temp.filter(tuple ->
tuple < OPTIMAL_TEMP_LOW || tuple > OPTIMAL_TEMP_HIGH);
simpleFiltered.sink(tuple -> System.out.println("Temperature is out of range! "
+ "It is " + tuple + "\u00b0F!"));
/*TStream<Double> simpleFiltered = temp.filter(tuple ->
!optimalTempRange.contains(tuple));
simpleFiltered.sink(tuple -> System.out.println("Temperature is out of range! "
+ "It is " + tuple + "\u00b0F!"));*/
// See what the temperatures look like
simpleFiltered.print();
dp.submit(top);
输出:
Selet a port:
1: ttyACM0 Port opened succesefully.
7373.40
73.40
73.40 ...
【问题讨论】:
-
当您使用“optimalTempRange”时发生了什么? (已被注释掉)
-
@mangusta 输出保持不变。
-
请检查下面的答案并给出反馈
标签: java apache apache-edgent