|
1 | 1 | # AWS_IoT_Python
|
2 | 2 | This repository contains the steps and the code to Access the AWS IoT service using Python3, Paho-MQTT on Windows, Linux/Ubuntu and Raspberry Pi3.
|
3 | 3 |
|
4 |
| -Requirements: |
5 |
| -1. Python 3.4.x |
6 |
| -2. Paho-MQTT "pip install paho-mqtt" |
7 |
| -3. SSL "sudo apt-get install libssl-dev" |
8 |
| - |
9 |
| -1. Go to Amazon IoT website and follow this Guide "http://docs.aws.amazon.com/iot/latest/developerguide/iot-device-sdk-c.html". |
10 |
| -2. Click on "Create a Resource". |
11 |
| -3. Choose "Create a thing", type a name for the thing, and then choose Create. |
| 4 | +# Requirements: |
| 5 | +a) **Python 3.4 or above** [https://www.python.org/downloads/] (https://www.python.org/downloads/) |
| 6 | + |
| 7 | +b) **Paho-MQTT** |
| 8 | +``` |
| 9 | +"pip install paho-mqtt" |
| 10 | +``` |
| 11 | +c) **SSL** |
| 12 | +``` |
| 13 | +"sudo apt-get install libssl-dev" |
| 14 | +``` |
| 15 | + |
| 16 | +## Reference: |
| 17 | +AWS IoT Tutorial [http://docs.aws.amazon.com/iot/latest/developerguide/iot-device-sdk-c.html] (http://docs.aws.amazon.com/iot/latest/developerguide/iot-device-sdk-c.html) |
| 18 | + |
| 19 | +## Steps for Setup: |
| 20 | +1. Go to Amazon IoT website [https://aws.amazon.com/iot/] (https://aws.amazon.com/iot/) |
| 21 | +2. Follow this link [https://aws.amazon.com/iot/](https://aws.amazon.com/iot/). Click on "Get started with AWS IoT" and "Sign In" with your Amazon Account. |
| 22 | +2. Click on **Create a Resource**. |
| 23 | +3. Choose **Create a thing**, type a name for the thing, and then choose Create. The **thing** is a shadow of the Hardware device that you want to connect to the AWS IoT service. |
12 | 24 | 4. In addition to a confirmation message, the View thing button will be displayed.
|
13 |
| -5. Choose View thing to display information about your "thing". Here, thing is the shadow of the device that you want to connect to AWS IoT Service. |
14 |
| -6. Choose the Connect a device button to download a key pair and a certificate generated by AWS IoT. |
15 |
| -7. On the Connect a device page, select the SDK to use, and then choose Generate certificate and policy. We will use "Embedded C" here. |
16 |
| -8. This will generate an X.509 certificate and key pair; activate the X.509 certificate; and create an AWS IoT policy and attach it to the certificate. |
| 25 | +5. Choose View thing to display information about your "thing". |
| 26 | +6. Choose the **Connect a device** button on the side panel to download a **key pair** and a **certificate** generated by AWS IoT. |
| 27 | +7. On the Connect a device page, select the **SDK** to use, and then choose Generate certificate and policy. Choose **Embedded C** here. |
| 28 | +8. This will generate an X.509 certificate and key pair; activate the X.509 certificate; and create an **AWS IoT policy** and attach it to the certificate. |
17 | 29 | 9. Next you will get to see the Download Links for the certificates and the keys. Download them all.
|
18 |
| -10. Choose Confirm & start connecting. |
| 30 | +10. Choose **Confirm & start connecting**. |
| 31 | +11. On the next page you will get a sample format of the code. Save that in a text file for the reference. |
| 32 | + |
| 33 | +## Download the Code: |
| 34 | +You can either clone this repository using git clone: |
| 35 | +``` |
| 36 | +git clone https://github.com/anujdutt9/AWS_IoT_Python.git |
| 37 | +``` |
| 38 | +or download it as a ".zip" file. |
| 39 | + |
| 40 | +## Running the Code: |
| 41 | +There are two example code in the repository: |
| 42 | +1. **Publisher and Subscriber Code** |
| 43 | +2. **Code for Raspberry Pi** |
| 44 | + |
| 45 | +a) The **Publisher and Subscriber** folder contains **AWS_IoT_pub.py** file that **publishes(sends)** the data to the AWS IoT service and **AWS_IoT_sub.py** that **subscribes** to the service and shows(get) the data from the AWS IoT on the second Terminal. Currently, **AWS_IoT_sub.py** subscribes to any topic and will show all of the received msgs but we can customize it to get a perticular message. |
| 46 | + |
| 47 | +b) The second file consists of the code that reads the state of the pins of **Raspberry Pi3** (change Pin Numbers for other Raspberry Pi Boards) and sends this to the AWS IoT updating the state as its changed. |
| 48 | +For this, we have connected some LED's to the pins of the Raspberry Pi that represent the state of the pins. |
| 49 | +If the LED's glow, it's state is '1' else '0' (You can make changes in the code as you want). |
| 50 | + |
| 51 | +## To Test the sample Python Programs: |
| 52 | +i) In one terminal, run the **AWS_IoT_pub.py** code using |
| 53 | +``` |
| 54 | +python3 AWS_IoT_pub.py |
| 55 | +``` |
| 56 | +ii) In second terminal, run the **AWS_IoT_sub.py** code using |
| 57 | +``` |
| 58 | +python3 AWS_IoT_sub.py |
| 59 | +``` |
| 60 | +Follow the same steps for the Raspberry Pi code. |
| 61 | + |
| 62 | +You can check the sources and modify the topics used by both the programs. |
| 63 | + |
0 commit comments