<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Yokogawa-Tamajit</title>
    <description>The latest articles on Forem by Yokogawa-Tamajit (@yokogawatamajit).</description>
    <link>https://forem.com/yokogawatamajit</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F569032%2F73fd4b35-6e9d-4046-9d2b-6e763336473e.png</url>
      <title>Forem: Yokogawa-Tamajit</title>
      <link>https://forem.com/yokogawatamajit</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/yokogawatamajit"/>
    <language>en</language>
    <item>
      <title>Send telemetry data from e-RT3 Plus to Azure IoT hub</title>
      <dc:creator>Yokogawa-Tamajit</dc:creator>
      <pubDate>Wed, 03 Mar 2021 13:14:00 +0000</pubDate>
      <link>https://forem.com/yokogawa-yts_india/send-telemetry-data-from-e-rt3-plus-to-azure-iot-hub-41i</link>
      <guid>https://forem.com/yokogawa-yts_india/send-telemetry-data-from-e-rt3-plus-to-azure-iot-hub-41i</guid>
      <description>&lt;p&gt;In this tutorial, we are going to establish telemetry communication between e-RT3 Plus and azure IoT Hub. There&lt;br&gt;
are some basic pre-requisites for this tutorial as followed -&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://portal.azure.com/" rel="noopener noreferrer"&gt;Azure IoT Hub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.python.org/" rel="noopener noreferrer"&gt;Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/yokogawa-yts_india/communication-with-e-rt3-plus-remote-2014#:~:text=Communicating%20with%20e-RT3%20plus%20by%20SSH"&gt;&lt;strong&gt;SSH communication between e-RT3 Plus and PC&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this tutorial, we have used -&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://portal.azure.com/" rel="noopener noreferrer"&gt;Azure Portal&lt;/a&gt; to &lt;strong&gt;Create an IoT Hub&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://shell.azure.com/" rel="noopener noreferrer"&gt;Azure Cloud Shell&lt;/a&gt; to &lt;strong&gt;Create a device&lt;/strong&gt; and to get the &lt;strong&gt;Connection String&lt;/strong&gt; from the created device.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://code.visualstudio.com/" rel="noopener noreferrer"&gt;Visual Studio Code&lt;/a&gt; to write a &lt;code&gt;Python&lt;/code&gt; script to &lt;strong&gt;&lt;em&gt;send the telemetry data&lt;/em&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/Azure/azure-iot-explorer/releases" rel="noopener noreferrer"&gt;Azure IoT explorer&lt;/a&gt; to &lt;strong&gt;verify the received data&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;


&lt;h2&gt;
  
  
  Table of contents
&lt;/h2&gt;

&lt;p&gt;In this tutorial, we are going to cover the following things -&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1. Configure Azure IoT hub

&lt;ul&gt;
&lt;li&gt;1.1. Create an IoT hub
&lt;/li&gt;
&lt;li&gt;1.2. Register a device in the IoT hub
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;2. Send simulated telemetry data with python

&lt;ul&gt;
&lt;li&gt;2.1. Create a python virtual environment
&lt;/li&gt;
&lt;li&gt;2.2. Python code to send the simulated data
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;3. Read the telemetry data from the IoT hub
&lt;/li&gt;
&lt;li&gt;4. Supplementary

&lt;ul&gt;
&lt;li&gt;4.1. Proxy settings
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;5. Conclusion
&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  Configure Azure IoT hub
&lt;/h2&gt;

&lt;p&gt;This section is to describes how to configure an IoT hub in &lt;a href="https://portal.azure.com/" rel="noopener noreferrer"&gt;Azure Portal&lt;/a&gt;. This section is divided into two parts -&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create an IoT hub&lt;/li&gt;
&lt;li&gt;Register a device in the IoT hub&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Create an IoT hub
&lt;/h3&gt;

&lt;p&gt;To create an IoT hub in &lt;a href="https://portal.azure.com/" rel="noopener noreferrer"&gt;Azure portal&lt;/a&gt; we need to follow the following steps -&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Sign in to your &lt;a href="https://portal.azure.com/" rel="noopener noreferrer"&gt;Azure portal&lt;/a&gt;. After a successful login to the portal, your web browser should look like as follow -
&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz8lox2re4gc4yascrplc.jpg" title="Displaying screen capture after sign-in" alt="Screen capture after signed in to azure portal" width="800" height="390"&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note:&lt;/em&gt;&lt;/strong&gt; If your web browser does not look like the same as mentioned here, then please consider to refer the &lt;a href="https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-create-through-portal" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt; provided by Microsoft.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create an &lt;code&gt;IoT Hub resource&lt;/code&gt;. To create an IoT hub please select the &lt;strong&gt;+ Create a resource&lt;/strong&gt; button.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0xbi6hwi2odlqd1di9yt.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0xbi6hwi2odlqd1di9yt.jpg" title="Displaying screen capture create a resource button" alt="Screen capture for creating a resource button" width="800" height="390"&gt;&lt;/a&gt;&lt;br&gt;
After clicking this button it will navigate to the Azure marketplace.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7n1n53wv1uwkng4afhwg.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7n1n53wv1uwkng4afhwg.jpg" title="Displaying screen capture for search box of the Azure marketplace" alt="Screen capture for search box of azure marketplace" width="800" height="391"&gt;&lt;/a&gt;&lt;br&gt;
Type &lt;code&gt;IoT hub&lt;/code&gt; in the search box and &lt;strong&gt;select IoT Hub&lt;/strong&gt; from the drop-down option.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuphvduwz1t8rom3e2auq.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuphvduwz1t8rom3e2auq.jpg" title="Displaying screen capture for search box of the Azure marketplace" alt="Screen capture for search box of azure marketplace" width="800" height="392"&gt;&lt;/a&gt;&lt;br&gt;
Once you select the &lt;code&gt;IoT Hub&lt;/code&gt; from the list it will navigate to the hub page. After successful navigation click on the &lt;strong&gt;Create&lt;/strong&gt; button.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk3bmeyeh9rmgo3fysj34.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk3bmeyeh9rmgo3fysj34.jpg" title="Displaying screen capture for hub creation" alt="Screen capture - create hun" width="800" height="392"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Complete the &lt;code&gt;IoT Hub&lt;/code&gt; form.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuspkijw3yq8wr9tw246v.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuspkijw3yq8wr9tw246v.jpg" title="Displaying screen capture for hub creation form" alt="Screen capture - hub form" width="800" height="729"&gt;&lt;/a&gt;&lt;br&gt;
On the &lt;strong&gt;Basics&lt;/strong&gt; tab, you need to fill-up the form provided by Azure.&lt;br&gt;
Once you complete the review click on the &lt;strong&gt;Create&lt;/strong&gt; button to create the hub (This might take some time to complete).&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Register a device in the IoT hub
&lt;/h3&gt;

&lt;p&gt;To register a device inside your IoT hub you need to follow the following steps -&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open a new tab and navigate to &lt;a href="https://shell.azure.com/" rel="noopener noreferrer"&gt;Azure Cloud Shell&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now, checked whether your account has an &lt;code&gt;azure-iot&lt;/code&gt; extension or not by using the following command&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;az extension list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;If you can't find an extension named &lt;code&gt;azure-iot&lt;/code&gt; then you should install it by using the following command
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;az extension add --name azure-iot
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Execute the following command, Where, &lt;strong&gt;YOUR_HUB_NAME&lt;/strong&gt; is the name of the IoT hub you provided during the creation of the IoT hub and &lt;strong&gt;YOUR_DEVICE_ID&lt;/strong&gt; This is the name of the device you're registering.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;az iot hub device-identity create --hub-name YOUR_HUB_NAME --device-id YOUR_DEVICE_ID
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;To get the &lt;strong&gt;&lt;em&gt;device connection string&lt;/em&gt;&lt;/strong&gt;, execute the following command (This connection string will be required by the python script, so take a backup of your connection string into some file).
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;az iot hub device-identity connection-string show --hub-name YOUR_HUB_NAME --device-id YOUR_DEVICE_ID --output table
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note:&lt;/em&gt;&lt;/strong&gt; To create the device instance into &lt;em&gt;Azure IoT Hub&lt;/em&gt; we are using &lt;a href="https://shell.azure.com/" rel="noopener noreferrer"&gt;Azure Cloud Shell&lt;/a&gt;. Without accessing the &lt;code&gt;Azure Cloud Shell&lt;/code&gt;, you might lose your connect string. It's always a good idea to take a backup of your connection string into somewhere else like a temporary file.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Send simulated telemetry data with python
&lt;/h2&gt;

&lt;p&gt;To send the telemetry data, we are using the &lt;code&gt;Python&lt;/code&gt; script. For this step please Make sure that &lt;strong&gt;&lt;em&gt;you have installed &lt;code&gt;pip3&lt;/code&gt; and &lt;code&gt;venv&lt;/code&gt; on your e-RT3 Plus device&lt;/em&gt;&lt;/strong&gt;. &lt;code&gt;pip3&lt;/code&gt; comes by default with the &lt;a href="https://partner.yokogawa.com/global/itc/index.htm" rel="noopener noreferrer"&gt;e-RT3 Plus OS&lt;/a&gt;. &lt;em&gt;Please note that the e-RT3 Plus OS file is only accessible to the registered member of the partner portal&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;In case you did not install the &lt;strong&gt;&lt;em&gt;python virtual module (venv)&lt;/em&gt;&lt;/strong&gt; previously, then you can install it by using the following steps -&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  Enabling SUDO user
&lt;/h3&gt;

&lt;p&gt;When you are working as a normal user and you want to use commands that require root privileges, you usually add &lt;code&gt;sudo&lt;/code&gt; to the beginning, but you may be rejected as follows -&lt;/p&gt;


&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Working with the General User username&lt;/span&gt;
&lt;span class="nv"&gt;$sudo&lt;/span&gt; apt update
&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; password &lt;span class="k"&gt;for &lt;/span&gt;username:     &lt;span class="c"&gt;# Enter Password&lt;/span&gt;
username is not &lt;span class="k"&gt;in &lt;/span&gt;the sudoers file.  This incident will be &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; reported.
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;If that is the case, you could resolve it by using the following steps -&lt;/p&gt;

&lt;p&gt;Since the configuration is done as root, switch to the root user with the &lt;code&gt;su&lt;/code&gt; command once.&lt;/p&gt;


&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$su&lt;/span&gt;
Password:     &lt;span class="c"&gt;# Enter root password&lt;/span&gt;
root @ ubuntu:/home/username &lt;span class="c"&gt;#&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Edit the configuration file with the &lt;code&gt;visudo&lt;/code&gt; command -&lt;/p&gt;


&lt;pre class="highlight shell"&gt;&lt;code&gt;visudo
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Add the following lines at the end of the configuration file and save it -&lt;br&gt;
&lt;strong&gt;Replace username with your username.&lt;/strong&gt;&lt;/p&gt;


&lt;pre class="highlight shell"&gt;&lt;code&gt;username ALL &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;ALL&lt;span class="o"&gt;)&lt;/span&gt; ALL     &lt;span class="c"&gt;# replace username with your username&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Log out of root and see if the sudo command works -&lt;/p&gt;


&lt;pre class="highlight shell"&gt;&lt;code&gt;root @ ubuntu:/home/username &lt;span class="c"&gt;# exit&lt;/span&gt;
&lt;span class="nb"&gt;exit
&lt;/span&gt;username @ ubuntu: ~ &lt;span class="nv"&gt;$sudo&lt;/span&gt; apt update
&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;sudo&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; password &lt;span class="k"&gt;for &lt;/span&gt;username:     &lt;span class="c"&gt;# Enter Password&lt;/span&gt;
Get: 1 http://ports.ubuntu.com/ubuntu-ports bionic InRelease &lt;span class="o"&gt;[&lt;/span&gt;242 kB]
...

username @ ubuntu: ~ &lt;span class="err"&gt;$&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;If you have configured your ert3 user with &lt;code&gt;sudo&lt;/code&gt; permissions, then you may try to use the following commands to install the same -&lt;/p&gt;


&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;python3-venv
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Once the installation is completed you are ready to create a virtual python environment. If you need Proxy settings, please visit the supplementary section.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  Create a python virtual environment
&lt;/h3&gt;

&lt;p&gt;To create a &lt;a href="https://docs.python.org/3/tutorial/venv.html" rel="noopener noreferrer"&gt;python virtual environment&lt;/a&gt;, first, you have to &lt;strong&gt;&lt;em&gt;navigate to your desire folder location (workspace)&lt;/em&gt;&lt;/strong&gt;. Once navigated please execute the following command to create a python virtual environment -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python3 &lt;span class="nt"&gt;-m&lt;/span&gt; venv YOUR_ENV_NAME
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you have created a virtual environment, you may activate it by using the following command -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;source &lt;/span&gt;YOUR_ENV_NAME/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After activation is completed your &lt;code&gt;terminal&lt;/code&gt; should be like as follow -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;(&lt;/span&gt;YOUR_ENV_NAME&lt;span class="o"&gt;)&lt;/span&gt;username@ubuntu: ~ &lt;span class="err"&gt;$&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you have activated the virtual environment, you may want to create a python script to &lt;strong&gt;send the telemetry data&lt;/strong&gt;. To create a python script, you can execute the following command -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;YOUR_FILE_NAME.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Python code to send the simulated data
&lt;/h3&gt;

&lt;p&gt;Once you have access to the "e-RT3 Plus" and able to execute a python script, then it's time to send some simulated data to &lt;a href="https://portal.azure.com/" rel="noopener noreferrer"&gt;Azure IoT Hub&lt;/a&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To send simulated data we are going to use a python module provided by azure called &lt;a href="https://pypi.org/project/azure-iot-device/" rel="noopener noreferrer"&gt;azure-iot-device&lt;/a&gt;.
In your terminal window, run the following command to install &lt;a href="https://pypi.org/project/azure-iot-device/" rel="noopener noreferrer"&gt;azure-iot-device&lt;/a&gt; if required.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   pip3 &lt;span class="nb"&gt;install &lt;/span&gt;azure-iot-device
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the installation is completed, then start writing the code to the created file.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;first of all we need to import the module by using the following line
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;   &lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;azure.iot.device&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;IoTHubDeviceClient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Message&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Then. declare a variable to store the &lt;code&gt;device connection string&lt;/code&gt; (for reference you may follow the &lt;em&gt;5&lt;sup&gt;th&lt;/sup&gt; step of Register a device in the IoT hub&lt;/em&gt;)
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;   &lt;span class="n"&gt;CONNECTION_STRING&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;YOUR_CONNECTION_STRING&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;After that, create a client instance by using the following line
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;   &lt;span class="c1"&gt;# Method to initialize the iot hub client instance
&lt;/span&gt;   &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;iothub_client_init&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
       &lt;span class="c1"&gt;# Create an IoT Hub client
&lt;/span&gt;       &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;IoTHubDeviceClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create_from_connection_string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;CONNECTION_STRING&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
       &lt;span class="c1"&gt;# return the client instance
&lt;/span&gt;       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Next, add the following function, which will send the &lt;em&gt;telemetry data to Azure IoT hub&lt;/em&gt;.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;   &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;iothub_client_telemetry_sample_run&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
     &lt;span class="c1"&gt;# crete a client instance
&lt;/span&gt;     &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;iothub_client_init&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
     &lt;span class="c1"&gt;# create a Message to send to the IoT Hub
&lt;/span&gt;     &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;YOUR_TELEMETRY_DATA_AS_STRING&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
     &lt;span class="c1"&gt;# Send the message to IoT hub
&lt;/span&gt;     &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send_message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Call the &lt;code&gt;iothub_client_telemetry_sample_run&lt;/code&gt; from the main method to send the telemetry data as followed -
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;   &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
     &lt;span class="nf"&gt;iothub_client_telemetry_sample_run&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Complete sample code with the simulated data will look as follow -
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;   &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;random&lt;/span&gt;
   &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;
   &lt;span class="c1"&gt;# Import azure IoT hub client and Message from `azure-iot-device`
&lt;/span&gt;   &lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;azure.iot.device&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;IoTHubDeviceClient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Message&lt;/span&gt;

   &lt;span class="c1"&gt;# Your connection string of the IoT Device
&lt;/span&gt;   &lt;span class="n"&gt;CONNECTION_STRING&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;YOUR_CONNECT_STRING&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

   &lt;span class="c1"&gt;# Initializing the iot hub client instance
&lt;/span&gt;   &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;iothub_client_init&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
       &lt;span class="c1"&gt;# Create an IoT Hub client with connection string
&lt;/span&gt;       &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;IoTHubDeviceClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create_from_connection_string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;CONNECTION_STRING&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
       &lt;span class="c1"&gt;# returning the client
&lt;/span&gt;       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;

   &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;iothub_client_telemetry_sample_run&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
       &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
           &lt;span class="c1"&gt;# crete a client instance
&lt;/span&gt;           &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;iothub_client_init&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
           &lt;span class="nf"&gt;print &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;IoT Hub device sending messages, press Ctrl+C to exit&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
           &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
               &lt;span class="c1"&gt;# create a Message to send to the IoT Hub
&lt;/span&gt;               &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;YOUR_TELEMETRY_DATA_AS_STRING&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
               &lt;span class="c1"&gt;# Create a custom property with the Message payload
&lt;/span&gt;               &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;custom_properties&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;myCustomProp&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
               &lt;span class="c1"&gt;# Send the message to IoT hub
&lt;/span&gt;               &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Sending message: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
               &lt;span class="c1"&gt;#print data and both system and application (custom) properties
&lt;/span&gt;               &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nb"&gt;property&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;vars&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
                   &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;property&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
                       &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;    {0}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;property&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
               &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send_message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
               &lt;span class="nf"&gt;print &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Message successfully sent&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
               &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
       &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;KeyboardInterrupt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
           &lt;span class="nf"&gt;print &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;IoTHubClient sample stopped&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;

   &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
       &lt;span class="nf"&gt;iothub_client_telemetry_sample_run&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note:&lt;/em&gt;&lt;/strong&gt; You may require proxy setup to send the telemetry data to azure could. In that case please replace the &lt;code&gt;iothub_client_init()&lt;/code&gt; function with the following code -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;   &lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;azure.iot.device&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ProxyOptions&lt;/span&gt;
   &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;socks&lt;/span&gt;

   &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;iothub_client_init&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
       &lt;span class="n"&gt;proxy_opts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ProxyOptions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
           &lt;span class="n"&gt;proxy_type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;socks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HTTP&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
           &lt;span class="n"&gt;proxy_addr&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;YOUR_PROXY_ADDRESS&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
           &lt;span class="n"&gt;proxy_port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;YOUR_PROXY_PORT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
           &lt;span class="n"&gt;proxy_username&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;YOUR_PROXY_USERNAME&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
           &lt;span class="n"&gt;proxy_password&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;YOUR_PROXY_PASSWORD&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
       &lt;span class="p"&gt;)&lt;/span&gt;
       &lt;span class="c1"&gt;# Create an IoT Hub client with connection string
&lt;/span&gt;       &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;IoTHubDeviceClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create_from_connection_string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;CONNECTION_STRING&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;websockets&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;proxy_options&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;proxy_opts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
       &lt;span class="c1"&gt;# returning the client
&lt;/span&gt;       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Save the file and run the script by using the following command -
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   python3 YOUR_FILE_NAME.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;After executing the script your console might like as follow -
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   &lt;span class="o"&gt;(&lt;/span&gt;YOUR_ENV_NAME&lt;span class="o"&gt;)&lt;/span&gt; username@ubuntu:~/workspace&lt;span class="nv"&gt;$ &lt;/span&gt;python3 YOUR_FILE_NAME.py
   IoT Hub device sending messages, press Ctrl+C to &lt;span class="nb"&gt;exit
   &lt;/span&gt;Sending message:
       &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'data'&lt;/span&gt;, &lt;span class="s1"&gt;'YOUR_TELEMETRY_DATA_AS_STRING'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
       &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'custom_properties'&lt;/span&gt;, &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s1"&gt;'myCustomProp'&lt;/span&gt;: 13.066109804837703&lt;span class="o"&gt;})&lt;/span&gt;
   Message successfully sent
   Sending message:
       &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'data'&lt;/span&gt;, &lt;span class="s1"&gt;'YOUR_TELEMETRY_DATA_AS_STRING'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
       &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'custom_properties'&lt;/span&gt;, &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s1"&gt;'myCustomProp'&lt;/span&gt;: 11.664970897921908&lt;span class="o"&gt;})&lt;/span&gt;
   Message successfully sent
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Read the telemetry data from the IoT hub
&lt;/h2&gt;

&lt;p&gt;Once telemetry data successfully updated to the Azure IoT hub You may verify it by using &lt;a href="https://github.com/Azure/azure-iot-explorer/releases" rel="noopener noreferrer"&gt;azure-iot-explorer&lt;/a&gt;. Microsoft has provided very good documentation on this software please, &lt;strong&gt;read more about it by clicking &lt;a href="https://docs.microsoft.com/en-us/azure/iot-pnp/howto-use-iot-explorer" rel="noopener noreferrer"&gt;this link&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Once, you have installed and able to connect to the IoT hub click on the &lt;strong&gt;Telemetry&lt;/strong&gt; tab and hit the &lt;strong&gt;start&lt;/strong&gt; button to read those telemetry data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqpk6x2ahxy6qzqrwpiw9.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqpk6x2ahxy6qzqrwpiw9.jpg" title="Displaying screen capture explored view" alt="Screen capture - Explorer view" width="800" height="549"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Supplementary
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Proxy settings
&lt;/h3&gt;

&lt;p&gt;Personally for me, one of the most difficult things is to configure the &lt;code&gt;Proxy&lt;/code&gt; settings, and also I think this varies from environment to environment. Here I'm going to mention my setting for this e-RT3 Plus device.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open a Terminal window where you need proxy access.&lt;/li&gt;
&lt;li&gt;Set and export the HTTP_PROXY variable.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   &lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;HTTP_PROXY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;USERNAME:PASSWORD@your.proxy.server:port
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Set and export the HTTPS_PROXY variable.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   &lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;HTTPS_PROXY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;USERNAME:PASSWORD@your.proxy.server:port
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Set and export the NO_PROXY variable to prevent local traffic from being sent to the proxy.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   &lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;NO_PROXY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;localhost,127.0.0.1,&lt;span class="k"&gt;*&lt;/span&gt;.my.lan.domain
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If Proxy settings are made, add the &lt;code&gt;-E&lt;/code&gt; option to inherit environment variables and execute&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# apt command example&lt;/span&gt;
&lt;span class="nb"&gt;sudo&lt;/span&gt;  &lt;span class="nt"&gt;-E&lt;/span&gt; apt update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once completed, Use the following command to delete the environment variables -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;unset &lt;/span&gt;HTTP_PROXY HTTPS_PROXY NO_PROXY
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This is an entry-level python script to upload the telemetry data which might require some pre-knowledge of e-RT3 Plus and Azure IoT hub.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reference
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; &lt;a href="https://docs.microsoft.com/en-us/azure/iot-hub/quickstart-send-telemetry-python" rel="noopener noreferrer"&gt;Azure Tutorial&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; &lt;a href="https://github.com/Azure/azure-iot-explorer/" rel="noopener noreferrer"&gt;Azure IoT Explorer&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.&lt;/strong&gt; &lt;a href="https://docs.python.org/3/tutorial/venv.html" rel="noopener noreferrer"&gt;Python Virtual Environments and Packages&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.&lt;/strong&gt; &lt;a href="https://docs.microsoft.com/en-us/python/api/azure-iot-device/?view=azure-python" rel="noopener noreferrer"&gt;Azure SDK for Python&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ert3</category>
      <category>azure</category>
      <category>iot</category>
      <category>telemerty</category>
    </item>
  </channel>
</rss>
