{"id":17914536,"url":"https://github.com/anurag01a/fbeats","last_synced_at":"2026-05-06T13:37:25.359Z","repository":{"id":179835267,"uuid":"425578686","full_name":"anurag01a/fbeats","owner":"anurag01a","description":"The project describes the real-time monitoring of various components of Plant such as Temperature, Sunlight, Humidity, and Moisture using Azure IoT Central which is a fully managed IoT Software as a Service (SaaS) solution that uses a model-based approach to build enterprise-grade IoT solutions without requiring expertise in cloud-solution development.","archived":false,"fork":false,"pushed_at":"2023-07-09T09:04:36.000Z","size":24303,"stargazers_count":0,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-17T22:41:44.379Z","etag":null,"topics":["azure","iot","iotcentral","iothub","raspberry-pi-4"],"latest_commit_sha":null,"homepage":"https://lab1sensor.azureiotcentral.com/dashboards/dtmi:kkfvwa2xi:p7pyt5x3o","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anurag01a.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-07T18:05:42.000Z","updated_at":"2023-07-18T09:08:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"f5d26908-f91b-412b-a7c1-ec88446620a5","html_url":"https://github.com/anurag01a/fbeats","commit_stats":null,"previous_names":["anurag01a/fbeats"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/anurag01a/fbeats","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anurag01a%2Ffbeats","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anurag01a%2Ffbeats/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anurag01a%2Ffbeats/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anurag01a%2Ffbeats/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anurag01a","download_url":"https://codeload.github.com/anurag01a/fbeats/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anurag01a%2Ffbeats/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281896749,"owners_count":26580176,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-30T02:00:06.501Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["azure","iot","iotcentral","iothub","raspberry-pi-4"],"created_at":"2024-10-28T19:58:41.371Z","updated_at":"2025-10-30T23:14:22.102Z","avatar_url":"https://github.com/anurag01a.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## ⚡ Technologies Learnt\n![Raspberry Pi](https://img.shields.io/badge/-Raspberry%20Pi-C51A4A?style=flat-square\u0026logo=Raspberry-Pi)\n![Linux](https://img.shields.io/badge/OS-Linux-informational?style=flat\u0026logo=linux\u0026logoColor=white\u0026color=2bbc8a)\n![Python](https://img.shields.io/badge/-Python-black?style=flat-square\u0026logo=Python)\n![Microsoft Azure](https://img.shields.io/badge/Microsoft%20Azure-232F7E?style=flat-square\u0026logo=microsoft-azure)\n![Azure-IoT hub](https://img.shields.io/badge/Azure--IotHub-Azure--IotHub-blue)\n\n\n\n# Table of Contents\n\n\u003c!-- TOC start --\u003e\n- [Azure Farmbeats: Plant Monitoring System](#azure-farmbeats-plant-monitoring-system)\n  * [About Farmbeats ](#about-farmbeats)\n  * [Components Required](#components-required)\n  * [STEP 1: INSTALLING RASPBERRY PI OS (RASPBIAN) ON OUR SD CARD](#step-1-installing-raspberry-pi-os-raspbian-on-our-sd-card)\n    + [Preparation](#preparation)\n    + [Download the Raspberry Pi Imager](#download-the-raspberry-pi-imager)\n    + [Assemble the DIY Sensor Device Hardware](#assemble-the-diy-sensor-device-hardware)\n    + [Insert the Micro SD Card](#insert-the-micro-sd-card)\n    + [Power on the device](#power-on-the-device)\n    + [Configuring the Network Settings](#configuring-the-network-settings)\n      - [Setting up our Pi](#setting-up-our-pi)\n    + [Turn on the I2C interface](#turn-on-the-i2c-interface)\n  * [STEP 2: AZURE SERVICES INTEGRATION](#step-2-azure-services-integration)\n    + [Create App using IoT Central](#create-app-using-iot-central)\n    + [Create IoT Central Application from Portal](#create-iot-central-application-from-portal)\n    + [Create a Device Template](#create-a-device-template)\n    + [Add a view](#add-a-view)\n    + [Publish the device template](#publish-the-device-template)\n    + [Create a device](#create-a-device)\n    + [Get the device connection details](#get-the-device-connection-details)\n  * [STEP3: INSTALLING PYTHON 3](#step3-installing-python-3)\n    + [Configure a virtual environment](#configure-a-virtual-environment)\n    + [Install the required python packages](#install-the-required-python-packages)\n  * [STEP 4: WRITE THE CODE](#step-4-write-the-code)\n    + [Define some environmental variables](#define-some-environmental-variables)\n    + [Create the application code](#create-the-application-code)\n    + [Check that the connection has been established](#check-that-the-connection-has-been-established)\n- [:film_projector: Presentation + Demo ](#film_projector-presentation--demo)\n\u003c!-- TOC end --\u003e\n\n\n# Azure Farmbeats: Plant Monitoring System\n\n## About Farmbeats \nThe project describes the real-time monitoring of various components of Plant such as Temperature, Sunlight, Humidity, and Moisture using Azure IoT Central which is a fully managed IoT Software as a Service (SaaS) solution that uses a model-based approach to build enterprise-grade IoT solutions without requiring expertise in cloud-solution development.\n\nSeveral studies have demonstrated the need to significantly increase the world’s food production by 2050. However, there is a limited amount of additional arable land, and water levels have also been receding. Although technology could help the farmer, its adoption is limited because the farms usually do not have power or Internet connectivity, and the farmers are typically not technology savvy. I am working towards an end-to-end approach, from sensors to the cloud, to solve the problem. \n\n## Components Required\n-\tRaspberry Pi 4 \n-\tGrove Base Hat for Raspberry Pi\n-\tScrewdriver, screws, and standoffs for Base Hat\n-\tGrove Connectors\n-\tSD Card USB Adapter\n-\tSD Card 32GB\n-\tGrove Temperature and \n-\tHumidity Sensor Sunlight sensor\n-\tCapacitive Soil Moisture Sensor\n\n## STEP 1: INSTALLING RASPBERRY PI OS (RASPBIAN) ON OUR SD CARD\n### Preparation\n-\tThis step can be completed using Windows, macOS, or Ubuntu\n-\tHave a Micro SD Card with an adapter to be able to use it on our PC\n\n### Download the Raspberry Pi Imager\n-\tWe will need to install the latest version of Raspbian Lite on a micro-SD card. An easy way to do this is to install the Raspberry Pi Imager\n-\tGo to the Official Raspberry Pi Downloads Page.\n-\tSelect the correct version of the Raspberry Pi Imager for our OS.\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image020.png)\n-\tInstall the Raspberry Pi Imager application and open it.\n-\tInstalling Raspberry Pi OS\n-\tInsert the microSD card into the computer or laptop. We may need to use the SD card adapter and plug it into a USB port on our PC.\n-\tSelect CHOOSE OS to see a list of the available operating systems\n-\tSelect Raspberry Pi OS (32-bit)\n\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image021.png)\n\n-\tNext, select CHOOSE SD CARD and find the SD card that we would like to install the OS on\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image023.png)\n-\tBefore hitting WRITE, press `Ctrl-Shift-X` to open a configuration menu like this.\n-\tIt will display a window in which we will select the **Enable SSH** box, it will also request that we enter a password for the pi user, which is the user that comes by default in Raspberry pi, usually, the password is **Raspberry** for this user, but with this option, we can enter the one we like.\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image026.png)\n-\tGoing down further in this window we can find the **configure wifi** box where we enter the network name and password\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image028.png)\n-\tSelect WRITE and wait for the process to complete before removing the SD card.\n\n### Assemble the DIY Sensor Device Hardware\nAdd the Grove Base Hat to our Raspberry Pi. Match the end pins up and press down firmly. Look at it from all angles to ensure that it is correctly connected.\n\n### Insert the Micro SD Card\nOn the bottom of the Raspberry Pi, there is a micro–SD card slot. Place the micro-SD card into this slot so that the printed side is visible. Push the card into the slot firmly. Always remember to unplug the Raspberry Pi when inserting or removing the SD card.\n\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image030.png)\n\n-\tPlug the Capacitive Soil Moisture Sensor into socket A2. If we have a second one plug it into A4.\n-\tPlug the Light Sensor into socket A0.\n-\tPlug the Temperature \u0026 Humidity into the bottom left I2C socket.\n-\tOnce all our sensors are plugged in, we should have something that looks like this.\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/iotsetup.jpg)\n\n### Power on the device\n-\tPlug the large end of the micro-USB cable into the power adapter and insert the power adapter into a power source\n-\tPlug the small end of the micro-USB cable into the Raspberry Pi and Power Up! A red light should shine on the motherboard.\n\n### Configuring the Network Settings\n#### Setting up our Pi\nWhen powered on for the first time we need to do a few steps on the device. We will need to change our login password, set up or test our connection to the internet, and enable the I2C interface (required for using the grove sensors). Try SSHing into the Pi. From the computer connect to pi@raspberrypi.local.\n```\nssh pi@raspberrypi.local\n```\nIf the host cannot be found then if we know the IP address (for example by using our router's management software) then we can log in to pi@192.168.0.1, replacing 192.168.0.1 with the IP address of our Pi. This can be found by typing the following command into the terminal on our pi:\n```\nhostname -I\n```\n### Turn on the I2C interface\nFor the grove sensor to work, the I2C interface needs to be enabled.\n1.\tLaunch the configuration tool on the Pi, found under Menu \u003e Preferences \u003e Raspberry Pi Configuration\n2.\tSelect the **Interfaces** tab\n3.\tSet I2C to **Enabled**\n4.\tSelect OK to confirm the changes\n5.\tSelect Yes to reboot the system if prompted.\n\nThe SSH connection will be terminated, so we will need to reconnect. Once the Pi reboots the I2C interface will be enabled.\n\n## STEP 2: AZURE SERVICES INTEGRATION\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image036.png)\n### Create App using IoT Central\nAzure IoT Central is an IoT application platform that allows us to interact with cloud services and interact with them.\nIoT central has a user-friendly UI that allows us to monitor device conditions, create rules, and manage millions of devices easily.\n### Create IoT Central Application from Portal\n1.\tLog in to the Azure Portal.\n2.\tClick on + **Create a new resource**.\n\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image037.png)\n\n3.\tSearch IoT Central and click on **IoT Central Application**. Then click on **Create**. \n\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image038.png)\n\n4.\tFill in the details for the IoT App.\n  - 1. Give our app a name such as lab1sensor.\n  - 2. Select the subscription.\n  - 3. Create a new resource group for the whole lab. In this case, I have named it Lab1.\n\n  Resource groups are logical groupings of Azure services, allowing us to manage all the services for a particular application or project together. \n  - 4. Select **Standard 1** for the Pricing plan.\n  - 5. In this case, I am going to create the app from scratch, so I chose a **custom application** in Template.\n  - 6. Select our location.\n  - 7. Click on **Create**.\n\n![replace this image with urs](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/azresource2.png)\n\n5.\tAfter that, our IoT Central app will start the deployment. Once it is finished, just click on **Go to Resource**.\n6.\tTo access the IoT Application Dashboard just press on the **IoT Central Application URL hyperlink**.\n\n![replace this image with urs](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/azresource.png)\n\n### Create a Device Template\nAzure IoT Central can work with multiple types of devices, and multiple devices per device type. Device types are defined using templates - these specify the capabilities of the device including the telemetry that can be received from the device and commands that can be sent to it.\nThe environment sensor captures temperature, humidity, soil moisture, and light conditions. We will need to define a template that has these values on it, so they can be received from the Pi.\n1.\tFrom the left panel select **Device Template**. Then click on **+ New**.\n\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image045.png)\n\n2.\tSelect the **IoT Device** template.\n\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image047.png)\n\n3.\tSelect the **Next: Customize** button.\n4.\tSelect the **Next: Review** button.\n5.\tSelect the **Create button**.\n6.\tName the template `SensorMonitor`.\n\nOnce the template is created, we need to add capabilities to it. These are defined using capability models, which define the capabilities of all devices that will use this template. Capability models are made up of three parts:\n-\t**Interfaces** - these are reusable collections of capabilities and are grouped into three categories:\n  - 1.\t**Telemetry** - actual values detected and sent by the device, for example in a thermostat it could be the current detected temperature\n  - 2.\t**Properties** - settings on the device, for example in a thermostat it could be the desired temperature. These can be set by the device, or via Azure IoT Central and synced to the device.\n  - 3.\t**Commands** - calls that can be made on the device, optionally passing data. For example, in a thermostat, it could be called by a mobile app to send a request to change the desired temperature.\n-\t**Cloud properties** - these are properties set in Azure IoT Central against a device, but not synced to the device. For example, a device could have a cloud property for the account name of the owner, the devices’ location, or the date it was last serviced.\n-\t**Views** - these are dashboards for a device that can contain charts, data values, and other information allowing you to visualize telemetry or send commands.\nThe environment sensor needs a capability model created, with an interface defined for the telemetry values being sent, a command to indicate that the plant needs watering, and a view to visualize these values.\n1.\tSelect the **Custom** capability model\n**Add an interface**\n2.\tAdd a new interface to the capability model by selecting the top-level Environment sensor item in the menu and selecting **+Add interface**\n\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image049.png)\n\n3.\tSelect **Custom**\n\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image051.png)\n\n4.\tThis interface needs 4 telemetry values added to it for the temperature, humidity, soil moisture, and sunlight level. Telemetry values have the following properties:\n-\t**Display name** - this defines what is shown on a view to display the value\n-\t**Name** - this map to the values being sent from the device\n-\t**Capability type** - this defines what type of value this is, and includes some standard types such as temperature or pressure.\n-\t**Schema** - this defines the data type for the value being received, such as an integer or a floating-point number\n-\t**Unit** - this defines the unit, for now, telemetry types, for example, °C for temperatures.\n-\tSelect the **+ Add capability** button to add new capabilities, and add the following five values:\n\n\n|     Display Name         |     Name             |     Capability Type    |     Semantic Type    |     Schema    |     Unit    |\n|--------------------------|----------------------|------------------------|----------------------|---------------|-------------|\n|     Temperature          |     temperature      |     Telemetry          |     Temperature      |     Double    |     °C      |\n|     Humidity (%)         |     humidity         |     Telemetry          |     Humidity         |     Double    |     %       |\n|     Soil Moisture (%)    |     soil_moisture    |     Telemetry          |     None             |     Double    |     %       |\n|     Sunlight             |     light_level      |     Telemetry          |     None             |     Double    |     %       |\n\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image053.png)\n\n### Add a view\n1.\tSelect Views from the menu.\n\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image055.png)\n\n2.\tSelect Visualizing the device\n\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image056.png)\n\n3.\tSet the view name to Overview. We will use this view to show the charts of the values recorded.\n4.\tDrag Temperature from the Telemetry section onto the dashboard. This will add a graph showing the temperature recorded over the past 30 minutes to the dashboard. We can configure this in multiple ways using the control buttons on the top of the panel:\n- Change the visualization to be several different chart types or the last known value\n- Change the size of the panel on the dashboard\n- Configure the chart including legend, axis labels, and the time range\n- Configure the chart or last know value to your liking.\n5.\tRepeat this for the other telemetry values. If we want to plot multiple telemetry values on the same chart use the checkboxes to select multiple values and drag them together. We can add telemetry values multiple times to get multiple views over the data.\n6.\tWe can also customize the view with labels, markdowns, or images if desired.\n7.\tSelect the Save button from the top menu\n\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image061.png)\n\n8.\tWe can create another view showing just the last value received if we want.\nHere is an example of what it can look like.\n\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image063.png)\n\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image064.png)\n\n### Publish the device template\nBefore the device template can be assigned to a device, it needs to be published. Once published, any interfaces defined on it cannot be changed, instead, a new version of the device template needs to be created.\n1.\tSelect the **Publish** button from the top-most menu.\n\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image066.png)\n\n2.  Click on **Publish**.\n\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image067.png)\n\n### Create a device\n1.\tGo to **Devices \u003e SensorMonitor**.\n\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image069.png)\n\n2.\tSelect **+ New**.\n3.\tSet the **Device Name** to `Raspberry pi` and the Device Id to `raspberry_pi`. Then click on **Create**.\n\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image070.png)\n\nA new device should appear in the devices list.\n\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image072.png)\n\n### Get the device connection details\nEach device has a set of connection details that will be used on the actual device to connect to Azure IoT Central and send telemetry.\n1.\tClick on the Raspberry pi device we have just created.\n2.\tClick on the Connect button located at the top right corner.\n\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image074.png)\n\n3.\tTake note of the **ID Scope, Device Id, and Primary key**. We will need these values to send the data from the raspberry pi.\n\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image075.png)\n\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/image076.png)\n\n## STEP3: INSTALLING PYTHON 3\nBy default, Raspbian uses Python 2. However, versions 2 and 3 come installed by default. We just have to make 1 minor change so that the Pi uses Python 3 whenever we type python into a terminal. In a terminal window, enter the following command:\n```\npython --version\n``` \nRaspbian Lite, the Python package manager, pip, does not come pre-installed. As a result, we will need to install it with the commands:\n```\nsudo apt-get update\nsudo apt-get install python3-pip\n```\nPress y when prompted.\nNote that to use pip for Python 3, we will need to use the command pip3.\n\n### Configure a virtual environment\nPython comes in various versions, and Python apps can use external code in packages installed via a tool called pip. This can lead to problems if different apps need different package versions or different Python versions. To make it easier to avoid issues with package or Python versions, it is best practice to use virtual environments, self-contained folder trees that contain a Python installation for a particular version of Python, plus several additional packages. Ensure that the Python 3 virtual environment tooling is installed by running the following commands in the terminal\n```\nsudo apt-get update\n```\n```\nsudo apt-get install python3-venv\n```\nCreate a new file inside the `EnvironmentMonitor` folder called `app.py`\n\n1.\tName the new file app.py and press return\n2.\tCreate a new virtual environment called **.venv** using Python 3 by running the following command in the terminal\n```\npython3 -m venv .venv\n```\n3.\tA dialog will pop up asking if we want to activate this virtual environment. Select **Yes**.\n\n### Install the required python packages\nPython has a package manager called pip that allows you to install code from other developers in packages called pip packages. We can read more about pip and see the available packages at pypi.org. Packages can either be installed into the virtual environment one at a time using the pip command, or multiple packages can be listed in a file called requirements.txt and installed together. The advantage of using a requirements.txt file is that this can be checked into source code control so that other developers can configure their environment the same way by installing the same packages from this file.\n1.\tCreate a new file inside the EnvironmentMonitorIoT folder called `requirements.txt`\n2.\tAdd the following to this file\n```\nazure-iot-device\npython-dotenv\nRPi.bme280\ngrove.py\nsmbus2\n```\nFrom the terminal, run the following command to install these packages:\n```\npip3 install -r requirements.txt\n```\nThe packages installed are:\n|      Package            |      Description                                                                                                  |     Capability Type    |     Semantic Type    |     Schema    |     Unit    |\n|-------------------------|-------------------------------------------------------------------------------------------------------------------|------------------------|----------------------|---------------|-------------|\n|     azure-iot-device    |     Allows communication with Azure IoT services including   Visual Studio Code                                   |     Telemetry          |     Temperature      |     Double    |     °C      |\n|     python-dotenv       |     Allows loading of environment variables   from .env files                                                     |     Telemetry          |     Humidity         |     Double    |     %       |\n|     RPi.bme280          |     Provides access to the BME280 temperature/pressure/humidity   sensor                                          |     Telemetry          |     None             |     Double    |     %       |\n|     grove.py            |     Provides access to the grove sensors including the Grove capacitive moisture sensor and the Light sensor    |     Telemetry          |     None             |     Double    |     %       |\n\nAlso, install the seeed-dht package with the following command.\n```\n!pip3 install seeed-python-dht \n``` \n\n## STEP 4: WRITE THE CODE\n### Define some environmental variables\nThe connection details for the device ideally should not be stored in the source code. They should be saved on the device and loaded as required. This is to avoid checking these details into source code control or sharing them publicly accidentally.\nPython has a concept of .env files to store secrets such as connection details. These files are managed by the python-dotenv pip package and are usually ignored when checking into git.\nCreate a new file inside the EnvironmentMonitorIoT folder called `.env`\n1.\tAdd the following entries to this file:\n2.\tID_SCOPE=\u003cId scope\u003e\nDEVICE_ID=`raspberry_pi`\nPRIMARY_KEY=\u003cprimary key\u003e\n3.\tSet \u003cId scope\u003e to be the value of the ID Scope from the Connect dialog in Azure IoT Central. Set \u003cprimary key\u003e to be the Primary key value from this dialog.\n\n### Create the application code\n1.\tOpen the app.py file\n2.\tAdd the following code to the file:\n```python\nfrom azure.iot.device.aio import IoTHubDeviceClient, ProvisioningDeviceClient\nfrom datetime import datetime, date\nimport os, asyncio, json, time\nfrom dotenv import load_dotenv\n\n#temperature and humidity\nimport seeed_dht\n\n#moisture\nimport math\nimport sys\nimport time\nfrom grove.adc import ADC\n\n__all__ = [\"GroveMoistureSensor\"]\n\nclass GroveMoistureSensor:\n  '''\n  Grove Moisture Sensor class\n  Args:\n    pin(int): number of analog pin/channel the sensor connected.\n  '''\n  def __init__(self, channel):\n      self.channel = channel\n      self.adc = ADC()\n\n  @property\n  def moisture(self):\n    '''\n    Get the moisture strength value/voltage\n    Returns:\n    (int): voltage, in mV\n    '''\n    value = self.adc.read_voltage(self.channel)\n    return value\n\n#sunlight\nimport seeed_si114x\nimport time\nimport signal\n\n# Configuration parameters\nbme_pin = 1\nbme_address = 0x76\nmoisture_pin = 0\nlight_pin = 0\n\n# Create the sensors\nsensor = seeed_dht.DHT(\"11\", 16)\nmoisture_sensor = GroveMoistureSensor(moisture_pin)\n\n#light_sensor = GroveLightSensor(light_pin)\n\nload_dotenv()\nid_scope = os.getenv('0ne0036E38B')\ndevice_id = os.getenv('Raspberry_pi')\nprimary_key = os.getenv('gymeiFeFoNwg2BV28flilg8slBwW6jbOq6oo96I2LJQ=')\n\ndef getTemperaturePressureHumidity():\n    # for DHT11/DHT22\n\n    humi, temp = sensor.read()\n    if not humi is None:\n      print('DHT{0}, humidity {1:.1f}%, temperature {2:.1f}*'.format(sensor.dht_type, humi, temp))\n    else:\n      print('DHT{0}, humidity \u0026 temperature: {1}'.format(sensor.dht_type, temp))\n    time.sleep(2)\n    #return bme280.sample(bus, bme_address, calibration_params)\n    return(humi, temp)\n\ndef getMoisture():\n\n    Grove = GroveMoistureSensor\n     \n    from grove.helper import SlotHelper\n    sh = SlotHelper(SlotHelper.ADC)\n    pin = 0\n\n    sensor = GroveMoistureSensor(pin)\n\n    print('Detecting moisture...')\n\n    m = sensor.moisture\n    if 0 \u003c= m and m \u003c 2000:\n      result = 'Dry'\n    elif 2000 \u003c= m and m \u003c 3000:\n      result = 'Moist'\n    else:\n      result = 'Wet'\n    print('Moisture value: {0}, {1}'.format(m, result))\n    time.sleep(1)\n    #return round(moisture_sensor.moisture, 2)\n    return round(m, 2)\n\ndef getLight():\n    SI1145 = seeed_si114x.grove_si114x()\n    print(\"Please use Ctrl C to quit\")\n    light_data=SI1145.ReadVisible\n    return (light_data)\n\ndef getTelemetryData():\n    temp = getTemperaturePressureHumidity() # degrees Celsius\n    moisture = getMoisture() # voltage in mV\n    #pressure = round(getTemperaturePressureHumidity().pressure, 2)/1000 # kPa\n    #humidity = round(getTemperaturePressureHumidity().humidity, 2) # % relative Humidity\n    light = getLight() # % Light Strength\n    data = {\n        \"temperature\": temp[1],\n        \"humidity\":temp[0],\n        \"soil_moisture\": moisture,\n        \"sunlight\": light\n    }\n\n    return json.dumps(data)\n\nasync def main():\n    # provision the device\n    async def register_device():\n        provisioning_device_client = ProvisioningDeviceClient.create_from_symmetric_key(\n            provisioning_host='global.azure-devices-provisioning.net',\n            registration_id='Raspberry_pi',\n            id_scope='#########', #hidden due to security\n            symmetric_key='###gymeiFeFoNwg2BV28flilg8slBwW6jbOq6oo96I2LJQ=###')\n\n        return await provisioning_device_client.register()\n    results = await asyncio.gather(register_device())\n    registration_result = results[0]\n\n    # build the connection string\n    conn_str='HostName=' + registration_result.registration_state.assigned_hub + \\\n                ';DeviceId=' + 'Raspberry_pi' + \\\n                ';SharedAccessKey=' + 'gymeiFeFoNwg2BV28flilg8slBwW6jbOq6oo96I2LJQ='\n\n    # The client object is used to interact with Azure IoT Central.\n    device_client = IoTHubDeviceClient.create_from_connection_string(conn_str)\n\n    # connect the client.\n    print('Connecting')\n    await device_client.connect()\n    print('Connected')\n\n    # async loop that sends the telemetry\n    async def main_loop():\n        while True:\n            telemetry = getTelemetryData()\n            print(telemetry)\n\n            await device_client.send_message(telemetry)\n            await asyncio.sleep(5)\n\n    await main_loop()\n\n    # Finally, disconnect\n    await device_client.disconnect()\n\nif __name__ == '__main__':\n    asyncio.run(main())\n```\n1.\tThis code connects to Azure IoT Central, and every 5-15 seconds will poll for data from the sensors and send it as a telemetry message.\n2.\tSave the file\n3.\tFrom the terminal, run the following command to start the app\n```  \npython3 app.py\n```\nThe app should start, connect to Azure IoT Hub, and send data. The data being sent will be printed to the terminal\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/azfboutput.png)\n  \n### Check that the connection has been established\n1.\tOpen the app in Azure IoT Central\n2.\tFrom the Devices tab, select the Raspberry Pi device\n3.\tThe view will load, and there should be data visible that matches the data being sent\n\n![](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/azfbapp.png)\n\n# :film_projector: Presentation + Demo \n[![Youtube Demo Video](https://github.com/Anurag-0-1-A/fbeats/blob/main/Images/thumbnail.png)](https://www.youtube.com/watch?v=3aq-GquDmZg)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanurag01a%2Ffbeats","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanurag01a%2Ffbeats","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanurag01a%2Ffbeats/lists"}