gpt4 book ai didi

python - Raspberry RFSniffer 使用 python 读取输出

转载 作者:太空狗 更新时间:2023-10-29 11:18:55 25 4
gpt4 key购买 nike

我正在尝试运行 RFSniffer 进程来监听传入的 433mhz 信号。

如果我运行该过程,它只会输出来自 433mhz 接收器的值。我想用 Python 读取此输出,以便执行特定操作。

我找到了很多运行它并使用 Python 获取输出的方法,但其中的命令是自终止的 (ls -ial)。 RFSniffer 进程一直运行到您手动停止它为止。

这是我现在拥有的(不工作):

#!/usr/bin/python
# -*- coding: utf-8 -*-
import subprocess, time, os, sys

cmd = ["sudo", "/home/pi/433Utils/RPi_utils/RFSniffer"]

p = subprocess.Popen(cmd, stdout=subprocess.PIPE, bufsize=1)
for line in iter(p.stdout.readline, b''):
print line,
p.stdout.close()
p.wait()

最佳答案

这个解决方案应该有效:

os.system("sudo /home/pi/433Utils/RPi_utils/RFSniffer >output.txt & pkill --signal SIGINT RFSniffer")
f = open("output.txt","r")
readf = f.read()
for line in readf:
print line,
#close file
if f.closed == "False":
f.close()

您可以将它放在一个 while 循环中以不断扫描,直到找到一个参数。

这是我遇到的唯一一种可以将实时扫描(无限且不停止,不像 ls -l)输出到文件然后读取值的方法。

这是我使用蓝牙进行的实时扫描之一的示例:

sensortag=0
while sensortag != "B4:99:4C:64:33:E0":
#call the command and write to scan.txt file and then fill the process.
#loop to find if the MAC address given is available
os.system("hcitool lescan> scan.txt & pkill --signal SIGINT hcitool")
scan = open("scan.txt","r")
readscan = scan.read()
if "B4:99:4C:64:33:E0" in readscan:
print "SensorTag found."
sensortag = "B4:99:4C:64:33:E0"

关于python - Raspberry RFSniffer 使用 python 读取输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26948861/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com