正如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 ...