In this repo you will find a Simple Python code that simulates an IoT Temperature device capable of connecting to Azure Iothub using x509 (SSL/TLS certificates) or SAS (device Connection String) authentication method. The idea is to be able to easily and quickly test multiple authentication options in your IoT application with Azure Iothub
Along with the python code, in this repo you will find the links to deploy the Azure Components needed successfully execute the application. At this point, this is no a step by step guide, the main point is for you to understand the Python code used to develop the solution
- Internet connectivity
- Visual Studio Code
- Python version 3
- Create an Azure Iothub service
- Register an IoT device and choose your preferred authentication method:
- If you chose x509 as your authentication method, follow this link to create required certificates
- If you want to test x509 authentication, make sure you follow the steps mentioned in the "If you chose x509 as your authentication method, follow this link to create required certificates" link. At the end you will need to create the following SSL/TLS objects:
- Self Signed Certificate Authority files
- Certificate
- Private Key
- Configuration File
- Certificate Sign Request
- Intermediate Certificate Authority files (this is OPTIONAL)
- Certificate
- Private Key
- Configuration File
- Certificate Sign Request
- IoT Device Certificates
- Certificate
- Private Key
- Certificate Sign Request
- Self Signed Certificate Authority files
-
Functions
- Uncomment your preferred Authentication Method. Only one option must be uncommented
- x509 Authentication
- Save the device .CRT and .KEY files in the same folder as the "app-temperature.py" code
- SaS Authentication
- Get the connection string from the "SAS - Follow the Register a new device instructions" link.
- x509 Authentication
- Establish connectivity to Iothub
- Create a random integer for the temperature
- Create a dictionaru with the temperature value
- Create a JSON object from the dictionary
- Create a formatted message
- Send messsage to Iothub
- Repeat the code Infinitely
- Uncomment your preferred Authentication Method. Only one option must be uncommented
-
Execute the code in a bash CLI
- python3 app-temperature.py