Bash 从 ttyUSB0 读取并发送到 URL
我是一个 bash 新手,我正在努力将它们组合在一起。
我想做的是:
1)设置端口(stty)
2) 从 dev/ttyUSB0 读取 - 数据应类似于 000118110000101(cat 或 Gawk?)
3) 将读取的数据设置为变量(例如 DATA)并创建 URL,例如 http://domain.com/get_data .php?data=$DATA
4) 使用 wget 加载 URL?
5) 等待来自 ttyUSB0 的更多数据(轮询或循环?)
我尝试过 php DIO 扩展,它确实有效,但不可靠,因为它由于某种原因停止/启动。
任何建议将不胜感激,如果有人能建议最好的方法,我将非常感激,
谢谢
布伦特
I am a bash novice and I am struggling with putting it all together.
What I am trying to do is:
1) Set Port (stty)
2) Read from dev/ttyUSB0 - data should look like 000118110000101 (cat or Gawk?)
3) Set read data into a variable eg DATA and create a URL eg http://domain.com/get_data.php?data=$DATA
4) load the URL with wget?
5) Wait for more data from ttyUSB0 (polling or loop?)
I have tried the php DIO extention that does work but is not reliable because it stops/starts for some reason.
ANY suggestions would be much appreciated, I will be very great-full if anyone could advise the best way to do this
Thanks
Brent
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是我用的。
This is what I used.
对于第一步,我建议读取一个文件,然后使用 od 来获取八进制(据我所知没有二进制)表示,因为标准 awk 不处理 NUL(我认为 gawk 也是如此)。因此,在获得字节后,您可以通过 sed 脚本将其通过管道将八进制更改为二进制,使用
$()
(或撇号)获取输出并创建一个 URL,将其提供给wget
。我能看到的唯一问题是从 USB 读取阻塞/非阻塞。如果有请报告。
For the first step i would advise to read to a file and then use od to get an octal (there's no binary as far as i can see) representation, because standard awk doesn't cope with NULs (i think gawk too). So after you get the bytes, you pipe it through sed script to change octals to binaries, grab the output with
$()
(or apostrophs) and make an URL, which you feed towget
.The only problem i can see is blocked/nonblocked read from usb. Please report if there will be one.