简体   繁体   English

AWS IOT-如何模拟事物以将MQTT消息发布到主题?

[英]AWS IOT - how to simulate a thing to publish an MQTT message to a topic?

Apologies if this is a noob. 抱歉,如果这是菜鸟。 I am trying to learn the ropes of AWS IOT. 我正在尝试学习AWS IOT的绳索。

I understand that I can use a client like MQTT.fx to publish messages to a topic in a message broker 我了解可以使用MQTT.fx之类的客户端将消息发布到消息代理中的主题

I also see that AWS IOT resources console, I can create things, attach certificates, policies, and create rules. 我还看到了AWS IOT资源控制台,我可以创建事物,附加证书,策略和创建规则。

If I create a thing say 'car' using the IOT resources console, is there some way that the console gives where i can have the car publish MQTT messages to a topic? 如果我使用IOT资源控制台创建一个东西,说“汽车”,那么控制台是否可以通过某种方式让汽车将MQTT消息发布到某个主题? Or is the only way wiring up the simulate car to an actual device using the SDK. 还是使用SDK将模拟汽车连接到实际设备的唯一方法。

Like I mentioned, I am aware of publishing through an MQTT client. 就像我提到的那样,我知道通过MQTT客户端进行发布。 I just want to understand how to make a 'thing' I created in the resources console, to publish the MQTT messages to a message broker? 我只想了解如何制作在资源控制台中创建的“东西”,以将MQTT消息发布到消息代理?

Thanks 谢谢

I think you are looking for information how to obtain endpoint that will handle subscribe and publish messages. 我认为您正在寻找有关如何获取将处理订阅和发布消息的终结点的信息。 This is described in Verify MQTT Subscribe and Publish section of Developers Guide. 开发人员指南的验证MQTT订阅和发布部分中对此进行了描述。 Using AWS CLI: 使用AWS CLI:

aws iot describe-endpoint

It will return something like that: 它将返回类似的内容:

{
    "endpointAddress": "ABCDEF12345678.iot.eu-west-1.amazonaws.com"
}

Your thing should use one of existing AWS IoT SDKs to subscribe to MQTT topic and start publishing some data ie. 您应该使用现有的AWS IoT SDK之一来订阅MQTT主题并开始发布一些数据,例如。 speed, fuel consumption, etc. 速度,油耗等

In general you can simulate your thing (ie. car) by subscribing to some topic: 通常,您可以通过订阅以下主题来模拟事物(例如汽车):

mosquitto_sub --cafile "path-to-cert\rootCA.pem" --cert "path-to-cert\cert.pem" \
--key "path-to-cert\privateKey.pem" \
-h "ABCDEF12345678.iot.eu-west-1.amazonaws.com" -p 8883 -q 1 -d -t "topic/test" \
-i "car1"

Then in other terminal you can publish: 然后可以在其他终端上发布:

mosquitto_pub --cafile rootCA.pem --cert certs\cert.pem --key privateKey.pem \
-h "ABCDEF12345678.iot.eu-west-1.amazonaws.com" -p 8883 -q 1 -d -t topic/test 
-i car2 -m "Hello, World"

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

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