https://aws.amazon.com/jp/iot/
AWS IoT, which is a relatively new service of Amazon Web Service, is evolving day by day as it begins to appear. I would like to experience AWS IoT using Mac and Python even if I don't have a device.
Select AWS IoT in the Amazon Web Service console and select "Configuring a device" from the Connect menu.
Select "Linux / OS X" as the Platform and select Python.
The name of Thing can be anything, but here it is "test_thing". You can add types and attributes to the thing by selecting "show optional configuration (this can be done later)". This makes it easier to find things later, but it's not necessary first.
If you set only the Thing name, the client certificate and policy will be created accordingly. With the client certificate created here, AWS IoT features can be accessed from Python applications.
When you press the "Linux / OS X" button, information such as the client certificate and private key will be downloaded.
The processing after the downloaded zip file will be as follows.
In my environment, I got a Permission error in ./start.sh. It seems that the necessary libraries are installed in the sample, but when I run it again with sudo, it succeeds.
$ cd aws-iot-device-sdk-python/
$ sudo python setup.py install
I tried running the sample app again using start.sh. Internally, the client certificate, root certificate, and private key are set and executed with the following commands.
python aws-iot-device-sdk-python/samples/basicPubSub/basicPubSub.py -e XXXXXXXX.iot.ap-northeast-1.amazonaws.com -r root-CA.crt -c test_thing.cert.pem -k test_thing.private.key
But unfortunately I got the following error:
ssl.SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:590)
It seems that the version of OpenSSL is old, so I changed the version. http://ytooyama.hatenadiary.jp/entry/2016/06/23/004429 https://teratail.com/questions/47299 http://stackoverflow.com/questions/35473033/how-to-fix-openssl-error-with-aws-cli-iot-api
When start.sh is executed again, the Python application sends and receives the following log message to the sdk / test / Python topic once every few seconds.
2017-01-08 16:54:54,102 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Try to put a publish request 178 in the TCP stack.
2017-01-08 16:54:54,102 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Publish request 178 succeeded.
Received a new message:
New Message 176
from topic:
sdk/test/Python
--------------
If you check it on the AWS IoT dashboard, the graph will be output as shown below.
It's very convenient because you can emulate a device with just a Mac and a Python app without a device. AWS IoT is becoming more and more convenient.
Recommended Posts