Friday, May 6, 2016

Amazon AWS IoT: quick update

Since one of the communication protocol supported is MQTT, the obvious question is: can I use directly a MQTT client (in addition to the AWS SDK that we have used in the last post)?

Yes, you can.

For example, if you have some familiarity with MQTT, you probably have installed and worked with Mosquitto.

With Mosquitto you get installed two utilities that can be used to test publish and subscribe:

  • mosquitto_pub
  • mosquitto_sub

To test the transmission of a MQTT messages to your IoT gateway in AWS you need, as always, the certificate and the private key generated when you have registered your thing (the abstract representation in AWS of your device).

To publish a message:

/usr/local/bin/mosquitto_pub --cafile ./rootCA.pem --cert ./thunder10-certificate.pem.crt --key ./thunder10-private.pem.key -p 8883 -q 1 -d -t thunder10/test -m "Hello" -h A1NQFCHBXLAAH3.iot.eu-west-1.amazonaws.com

Client mosqpub/29492-MacBook-P sending CONNECT

Client mosqpub/29492-MacBook-P received CONNACK

Client mosqpub/29492-MacBook-P sending PUBLISH (d0, q1, r0, m1, 'thunder10/test', ... (5 bytes))

Client mosqpub/29492-MacBook-P received PUBACK (Mid: 1)

Client mosqpub/29492-MacBook-P sending DISCONNECT


The value you pass in the parameter -h is the hostname you have to refer to. You find it in your AWS IoT console.

-m: the value of the message (any sequence of bytes).

-p is the port

-q for the QoS; 1 means “at least once”. AWS doesn’t support “only once”.


You can easily run also a subscriber (mosquito_sub) on the same topic (in the example thunder10/test) and receive on your board (or laptop) the msg sent.


 

/usr/local/bin/mosquitto_sub --cafile ./rootCA.pem --cert ./thunder10-certificate.pem.crt --key ./thunder10-private.pem.key -p 8883 -d -t thunder10/test -h A1NQFCHBXLAAH3.iot.eu-west-1.amazonaws.com

 

Client mosqsub/29874-MacBook-P sending CONNECT

 

Client mosqsub/29874-MacBook-P received CONNACK

 

Client mosqsub/29874-MacBook-P sending SUBSCRIBE (Mid: 1, Topic: thunder10/test, QoS: 0)

 

Client mosqsub/29874-MacBook-P received SUBACK

 

Subscribed (mid: 1): 0

 

Client mosqsub/29874-MacBook-P received PUBLISH (d0, q0, r0, m0, 'thunder10/test', ... (5 bytes))

 

Hello

 

Client mosqsub/29874-MacBook-P received PUBLISH (d0, q0, r0, m0, 'thunder10/test', ... (5 bytes))

 

Hello




No comments:

Post a Comment