Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarification on thingName and ClientID #2

Closed
srini-murthy opened this issue Mar 10, 2016 · 5 comments
Closed

Clarification on thingName and ClientID #2

srini-murthy opened this issue Mar 10, 2016 · 5 comments

Comments

@srini-murthy
Copy link

Dear Author,

You are using thingName which is the name of a Thing and ClientID
How are these two variables:

clientId = "myThingName"
thingName = "myThingName"

used in awsiotsub.py and awsiotpub.py

Please clarify,

With Thanks and Regards
Srini

@mariocannistra
Copy link
Owner

Hello Srini.
Those 2 variables ( clientId and thingName ) are not used here and you can delete those 2 lines, the examples will still work fine. If you want to distinguish data being sent from different IoT devices you can easily set the messages "topic" that work in a "tree like" way. Good documentation here: http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/errata01/os/mqtt-v3.1.1-errata01-os-complete.html#_Toc442180919

I wrote these example programs when working at my radio-astronomy project https://www.hackster.io/mariocannistra/radio-astronomy-with-rtl-sdr-raspberrypi-and-amazon-aws-iot-45b617

In next version of that project I will probably use those two variables to identify different receiving stations sending data using MQTT on Raspberry PI.

Kind regards,
Mario

@srini-murthy
Copy link
Author

Dear Mario,

Thanks for the reply, Yes, understood

My need is to send the messages to thing shadow - if you can show me how to pass these two variables in API will be great and sincerely appreciated

Regards,
Srini

@srini-murthy
Copy link
Author

Dear Mario,

By the way your Astronomy project is Very Very Cool and I wish you all the best

Best,
Srini

@mariocannistra
Copy link
Owner

Thank you Srini. I hope to publish version 2 soon.

To update the state of a thing shadow you must send a properly formatted json message and in this case use the proper thing name.
To try this you can delete this line:

mqttc.publish("temperature", tempreading, qos=1)

and replace it with:

        jsonMessage = "{ \"state\": { \"reported\": { \"temperature\": " + str(tempreading) + "} } }"
        mqttc.publish("$aws/things/**myThingName**/shadow/update", jsonMessage, qos=1)

In this way you will update the state of the shadow for the thing named "myThingName". Obviously you have to use here the name that you used when creating the thing, certificates, etc like explained in my instructions.

You can check the shadow state on the AWS IoT dashboard. Selecting the thing and looking at the right side panel you will see something like:
image

Some useful docs:

http://docs.aws.amazon.com/iot/latest/developerguide/thing-shadow-mqtt.html

http://docs.aws.amazon.com/iot/latest/developerguide/thing-shadow-document.html#thing-shadow-example

http://docs.aws.amazon.com/iot/latest/developerguide/thing-shadow-document-syntax.html

Ciao,
Mario

@srini-murthy
Copy link
Author

Thank you very much Mario,

Greatly appreciated !

Best Regards,
Srini

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants