AWS IoT Device SDK for Python This time, I will run the sample attached to AWS IoT Device SDK for Python with Raspberry Pi and store the data in S3.
RaspberryPi 3 Any Raspberry Pi in the first place will do
RASPBIAN JESSIE OS has been updated to the latest
pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.4.13-v7+ #894 SMP Mon Jun 13 13:13:27 BST 2016 armv7l GNU/Linux
Set from the AWS Management Console.
Create a thing First, make something.
Here, the name is raspi1.
Create a rule Next, create a rule for things.
If you click the "raspi1" thing you created earlier, Details will appear on the right side. Then press the Create a rule button at the bottom right.
Then this screen.
Here, the name of the rule is raspi1_rule.
Where it looks like SQL, you can filter the data sent from thing. In the sample code of the SDK, the Topic "sdk / test / Python" will be sent, so enter the following here.
name | value |
---|---|
Attribute | * |
Topic filter | sdk/test/Python |
Scrolling the screen and setting the next Choose an action is where you decide what to do with the received data.
Here, we will store the data in S3.
Enter the S3 bucket, Key, and Role name. You can also create and configure it on the fly with Create a new resource, so I created a temporary bucket for testing. Please be careful about permissions when using existing ones.
Press the Add Action → Create button to complete the rule.
Connect a device Finally, set the authentication information from the device that actually connects to thing.
Press the Connect a device button to the right of the button that created the rule.
Then, which SDK do you use? I can choose, but I can't find Python.
There is no way to do it, so if you select NodeJS, a button called Generate certificate and policy will appear, so press it.
This time, you will see three links and buttons.
First, click the three links from Download to download the certificate.
After downloading, press the Confirm & start connecting button.
Copy and paste in the text box here and press the Return to Thing Detail button.
Saitama's RASPBIAN JESSIE contains pip, so install it with pip.
sudo pip install AWSIoTPythonSDK
With or without sudo as appropriate.
The sample code is also included in the source tree, so clone it from github.
git clone https://github.com/aws/aws-iot-device-sdk-python.git
Three certificate files are required to execute the sample code. This time, put it in the same directory as the sample code.
Send all the certificates downloaded when you prepared AWS IoT to Raspberry Pi by scp etc.
--Honyara-certificate.pem.crt --Honyara-private.pem.key
Next, prepare the AWS IoT root CA.
curl https://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem -o rootCA.pem
It is saved as rootCA.pem.
Specify endpoint and various certificate paths as arguments.
The endpoint is the AWS host name, and "" host ":" somewhere "" appears in the text box that appears at the end of the AWS IoT preparation. Alternatively, in the management console, the host name will also appear in the Detail that appears when you click thing (correctly, it is the destination of the REST API, so only the host name part of it)
python basicPubSub.py -e Somewhere .amazonaws.com -r rootCA.pem -c Honyara -certificate.pem.crt -k Honyara -private.pem.key
When executed, it throws a message at 1 second intervals. Check the displayed log and if there is no problem, Ctrl + C in about 10 seconds.
The file will be created in the bucket set this time.
It is successful if the contents are updated for the number of seconds that the sample code is executed.
New Message 10
Recommended Posts