Simulate a "thing" in Java?

1

I'm hoping I can write a quick function that simulates a "thing" in Java and be able to use it to either post messages to a topic, or update its shadow.

I have the AWS Java SDK in my project and I know how to use the IotClient and IotDataPlaneClient. The problem is that these clients are both authenticated with an access key that belongs to an AWS account, and in the case of the IotDataPlane client, I have to specify the name of the thing who's shadow I want to update.

What I'd like to do instead is mimic what an actual thing would do, which is to say, use a certificate to connect with the service, and only be able to update its own shadow, etc.

It seems like this should be possible, but I can't find any kind of credentials provider that works with certificates or any other obvious way to do it.

I know there is a complicated device simulator available and I may use it months from now when my application is further along, but for right now I'm just looking for something very quick and simple to prove a few concepts and work out my strategy.

Thanks, Frank

Frank
已提問 2 年前檢視次數 355 次
2 個答案
1

Hi Frank. I'm going to mention the device SDK again. It's what a device, implemented in Java, would normally use.

https://github.com/aws/aws-iot-device-sdk-java-v2/blob/main/samples/BasicPubSub/src/main/java/pubsub/PubSub.java

https://github.com/aws/aws-iot-device-sdk-java-v2/blob/main/samples/Shadow/src/main/java/shadow/ShadowSample.java

Stepping outside of Java, we have similar samples in most of our other-language device SDKs. We also have the Device Client: https://github.com/awslabs/aws-iot-device-client

You can use pretty much any MQTT client though. You could even use mosquitto_pub: https://manpages.debian.org/testing/mosquitto-clients/mosquitto_pub.1.en.html

profile pictureAWS
專家
Greg_B
已回答 2 年前
0

Thanks, I have that and I think I see how it can work with certificates. I guess that when a thing updates it's "shadow" it's just posting to a queue with a reserved name, correct? Does the "thing" need to tell its own name to IoT or does IoT figure that out from its certificate?

Frank
已回答 2 年前
  • The reserved topic includes the thing name, e.g. $aws/things/THING_NAME/shadow/update

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南