简体   繁体   English

通过 UDP 连接发送数据(桥接)

[英]Send data via UDP connection (Bridge)

I've been tasked to create a proof of concept with an Arduino Mega + Yun Shield.我的任务是使用 Arduino Mega + Yun Shield 创建概念验证。 I've started from the Bridge sample and I can read my sensors and exposed the data through REST.我从 Bridge 示例开始,我可以读取我的传感器并通过 REST 公开数据。

But, instead of REST, I want to send packets through UDP.但是,我想通过 UDP 发送数据包,而不是 REST。 I know there is samples around the web about UDP but I've have found nothing that use UDP with Bridge.我知道网络上有关于 UDP 的示例,但我没有发现将 UDP 与 Bridge 结合使用的任何内容。

Is this feasible?这可行吗?

UPDATE #1更新 #1

Ok, I read somewhere that is not possible.好的,我读到了不可能的地方。 But I read also that is possible to run a Python script to send data through UDP.但我也读到可以运行 Python 脚本通过 UDP 发送数据。

I made that script:我做了那个脚本:

import socket
import sys

# Create a UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

server_address = ('192.168.1.100', 9050)
message = 'This is the message.  It will be repeated.'

try:

    # Send data
    print >>sys.stderr, 'sending "%s"' % message
    sent = sock.sendto(message, server_address)

finally:
    print >>sys.stderr, 'closing socket'
    sock.close()

And call it from the Arduino this way:并以这种方式从 Arduino 调用它:

Process p;
p.begin("python");
p.addParameter("/test/sendUDP.py");  
p.run();

The code run without errors apparently, but my UDP server receive nothing.代码运行时显然没有错误,但我的 UDP 服务器什么也没收到。 However, it works with PuTTY.但是,它适用于 PuTTY。

UPDATE #2 It works!更新 #2它有效! I changed this line:我改变了这一行:

p.addParameter("/root/test/sendUDP.py"); 

我改变了这条线,它就像一个魅力:

p.addParameter("/root/test/sendUDP.py"); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM