BlueZ / Pybluez - 蓝牙LE扫描,同时连接到外围设备(BlueZ/Pybluez - Bluetooth LE scan while connected to peripheral)
简短问题:是否可以扫描LE设备,同时定期连接到某些设备并读取特征a)一般[协议是否允许]和b)使用BlueZ堆栈?
长问题:我正在编写一个Python脚本来扫描广告某个UUID的LE设备。 如果找到一个,我们应该连接,读取特定的特征值(调用此
ValueA
),然后断开连接。 我们的想法是保持ValueA
存在的实时列表。 我希望能够生成一个启动LE扫描的线程,并将广告事件收集到一个线程安全的容器中。 发现新设备时,应触发处理程序以读取ValueA
。我使用PyBluez和BluePy (连接外围设备)的努力都失败了。 当我使用终端命令(
sudo hcitool lescan --duplicates
和sudo gatttool -I
后跟连接和读取命令)时,如果我在开始扫描后尝试连接(扫描中止),则这些命令会失败我很困惑,因为我注意到如果我在开始LE扫描之前通过
gatttool
连接到设备,我可以启动扫描并继续读取ValueA
而不影响扫描,但反之亦然。任何见解或良好的BlueZ编程文档将不胜感激。 在Ubuntu 14.10 Macbook Pro上使用BlueZ 4.1
Short question: Is it possible to scan for LE devices while periodically connecting to some and reading characteristics a) in general [does the protocol allow it] and b) with the BlueZ stack?
Long question: I'm writing a Python script to scan for LE devices advertising a certain UUID. If one is found, we should connect, read a specific characteristic value (call this
ValueA
), and disconnect. The idea is to maintain a real-time list of whatValueA
's are present. I want to be able to spawn a thread that starts the LE scans and collects the advertising events into a thread-safe container. When a new device is discovered, a handler should be fired to readValueA
.My efforts using PyBluez and BluePy (to connect to peripherals) have failed. When I use terminal commands (
sudo hcitool lescan --duplicates
andsudo gatttool -I
followed by the connect and read commands), these fail if I try to connect after I start scanning (scan aborts)I am confused because I notice that if I am connected to a device via
gatttool
prior to starting an LE scan, I can kick off the scan and continue to readValueA
without impacting the scan, but not vice versa.Any insights or good BlueZ programming documentation would be appreciated. Using BlueZ 4.1 on Ubuntu 14.10 Macbook Pro
原文:https://stackoverflow.com/questions/29437750
最满意答案
尝试
gContains(sp1, sp2, byid = TRUE)
对于成对包含特征对的关系。
sp2[sp1,]
选择与
sp1
相交的sp2
特征,但是读取vignette('over')
以找出限制(它包括仅触摸的特征)。try
gContains(sp1, sp2, byid = TRUE)
for pair-wise contains relations for feature pairs.
sp2[sp1,]
selects those
sp2
features that intersect withsp1
, but do readvignette('over')
to find out about the limitations (it includes features that only touch).
相关问答
更多-
R - SpatialPolygons列表中的SpatialPolygonsDataFrame(R - SpatialPolygonsDataFrame from a list of SpatialPolygons)[2022-03-13]
这很简单...... 尝试这个: #Creating a dataframe with Spol IDs Spol_df<- as.data.frame(sapply(slot(Spol, "polygons"), function(x) slot(x, "ID"))) #Making the IDs row names row.names(Spol_df) <- sapply(slot(Spol, "polygons"), function(x) slot(x, "ID")) # Making th ... -
如果你想使用ggplot你需要从SpatialPolygonsDataFrame强制SpatialPolygonsDataFrame为data.frame 。 ggplot2提供了许多fortify方法,可以创建格式正确的数据。 目前fortify.SpatialPolygonsDataFrame方法不保留data组件,它确实提供了一个列id ,其中包含原始SpatialPolygonsDataFrame data槽中SpatialPolygonsDataFrame 。 请注意, data.frames是存 ...
-
单个spatialPolygonsDataFrame行的子集多边形(Subset polygons of a single spatialPolygonsDataFrame row)[2023-04-18]
对于"Spatial-class"对象,这种操作通常需要对组件数据结构进行一些痛苦的低级操作。 (当然,更大的期望是你会做一次,然后写一个你自己的好的包装函数,它完全符合你下次需要的时候!) 在任何情况下,这是您的情况下的低级操作可能是什么样的: ## Extract component "Polygon" objects pp <- usa@polygons[[1]]@Polygons ## Find indices of non-Alaska Polygon objects ii <- sapply(p ... -
将SpatialPolygonsDataFrame与数据集合并时出错(Errors when merging SpatialPolygonsDataFrame with dataset)[2023-01-14]
最简单的方法是将数据( .xlsx文件)连接到SpatialPolygonsDataFrame对象中的@data框架。 问题是这期望每个国家一行(这是SpatialPolygonsDataFrame对象的设置方式),但每个国家的数据分布在每个国家三行(每年一个)。 我建议最好的办法是将数据转换为与空间数据兼容的格式。 我会通过制作数据框的副本和子集在所有年份保持不变的列(如国家名称,地区,纬度,经度等)来实现此目的: df <- elephByCountry[, c("region", "subregion ... -
要有一个程序化的版本 one_spdf <- rbind(list_of_spdf[1][[1]], list_of_spdf[2][[1]], list_of_spdf[3][[1]], ... makeUniqueIDs = TRUE) 对于list_of_spdf一个很长的列表,会有类似下面的工作吗? # generate list containin ...
-
可耻地从gri.stackexchange.com上的Ari的帖子中获取 。 请参阅图片链接。 这里有更多的例子。 library(sp) Srs1 = Polygons(list(Polygon(cbind(c(2,4,4,1,2),c(2,3,5,4,2)))), "s1") Srs2 = Polygons(list(Polygon(cbind(c(5,4,2,5),c(2,3,2,2)))), "s2") SpDF <- SpatialPolygonsDataFrame( SpatialPolyg ...
-
在@ Bastien的评论之后,我想你可能会尝试使用: plot.window(xlim, ylim, log = "", asp = NA, ...) 指定绘图窗口的尺寸。 我不确定你想要你的情节如何出现,但有一些影响: plot.window(xlim=c(118.8333, 141), ylim=( -9.166667, 5.583333)) 如果您指定这些值,则应该强制R每次都正确重绘绘图窗口。 Following on @Bastien's comment, I think you might ...
-
为什么可以使用`$`来子集SpatialPolygonsDataFrame?(Why is it possible to use `$` to subset SpatialPolygonsDataFrame?)[2021-10-07]
简短的回答是$这种行为是由sp包中的Spatial类实现的,并不是一般S4对象的特性。 长的答案(我如何了解这一点): 使用showMethods("$")来查找通用$所有方法。 The result shows: Function: $ (package base) x="C++Class" x="envRefClass" x="Module" x="Raster" x="refObjectGenerator" x="Spatial" x="SpatialGDAL" x="SpatialPoints" x ... -
现在你不能。 这有些不一致,对于SpatialPointsDataFrame对象,您可以: library(sp) demo(meuse, ask = FALSE) x = meuse[F,] 虽然有警告; 另外, validObject(x)返回FALSE ,因此不允许使用它们! 这些对象应该代表什么有点抽象,但我可以看到与零行的data.frame对象的类比:它们可以存在是有用的。 Right now you can't. This is somewhat inconsistent, as for S ...
-
尝试 gContains(sp1, sp2, byid = TRUE) 对于成对包含特征对的关系。 sp2[sp1,] 选择与sp1相交的sp2特征,但是读取vignette('over')以找出限制(它包括仅触摸的特征)。 try gContains(sp1, sp2, byid = TRUE) for pair-wise contains relations for feature pairs. sp2[sp1,] selects those sp2 features that intersec ...