OpenCV(C++年)到MQTT代理
OpenCV (in C++) to MQTT broker
我的目标是从OpenCV(C++)发布(x,y)坐标的JSON流到MQTT代理。我对从OpenCV将JSON数据传输到MQTT的好方法感到困惑。
我目前有一个 MQTT 代理,它管理计算机 1 上的 Python 发布者脚本和计算机 2 上的 Javascript 客户端脚本之间的 JSON 消息队列。我有运行OpenCV的计算机3,需要近乎实时地向MQTT代理发送许多(x,y)坐标的小JSON斑点。
我最初考虑将坐标从OpenCV连续写入本地文本文件,然后由并行运行的Python MQTT发布者脚本连续读取。但是,文件锁定存在问题,似乎不需要写入磁盘。
理想情况下,我希望坐标流保留在内存中并经常发布到 MQTT 代理,例如每 10 毫秒发布一次。我正在努力寻找一种方法来使用stdin/stdout在OpenCV代码和Python发布者脚本之间工作。
感谢您的指导。谢谢。
不确定你缺少哪些部分,但你基本上想要:
#include "mqtt.h"
...
// Start up
mqtt_broker_handle_t *broker = mqtt_connect(client_name, ip_addr, port);
...
...
// Update broker
mqtt_publish(broker, topic, msg, QoS1);
你提到了一个发布者的python脚本。
这是发布者:
#!/usr/bin/env python3
import paho.mqtt.client as mqtt
# This is the Publisher
client = mqtt.Client()
client.connect("localhost",1883,60)
client.publish("topic/test", "Hello world!", qos=0, retain=False)
client.disconnect()
这是一个订阅者: #!/usr/bin/env python3 import paho.mqtt.client as mqtt
# This is the Subscriber
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
client.subscribe("topic/test")
def on_message(client, userdata, msg):
if msg.payload.decode() == "Hello world!":
print("Yes!")
client.disconnect()
client = mqtt.Client()
client.connect("localhost",1883,60)
client.on_connect = on_connect
client.on_message = on_message
client.loop_forever()
相关文章:
- 代理对象的常量正确性
- 有什么好的方法可以让系统调用代理允许在单元测试中进行模拟
- 具有所表示类的相同构造函数签名的代理类模板
- AWS IoT 开发工具包:通过 TCP 端口 443 使用 MQTT
- 在Visual Studio中使用vcpkg使用paho-mqtt x64时出错
- 类型为 'std::map< char,int > 的 <Swig 对象的代理
- 无法在 Mosquitto MQTT Broker 插件上访问结构体 mosquitto 的元素
- 我如何知道QNetWorkReped来自哪个代理?
- C++向量初始化遗传算法的代理向量
- 类(可能是代理)的命名,允许在不修改基础容器的情况下对项目进行排序和删除
- 如何将HTTPS流量重定向到本地主机:443上的代理?
- 适用于 Linux 的 c++ 上的代理脚本
- SNMP 代理在单元测试期间断开连接
- 如何测量paho mqtt网络中的延迟
- 模板代理方法无法编译
- 对于代理容器上的迭代器来说,"least bad implementation"可能是什么?
- 如何在ZMQ代理中记录接收消息?
- C++ boost::asio https 通过代理
- 使用函数指针作为成员函数的代理
- OpenCV(C++年)到MQTT代理