Skip to content

zdeptawa/azure-iot-temp-humidity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

azure-iot-temp-humidity

This python script logs temperature and humidity data from a DHT11 temperature and humidity sensor via a RaspberryPi. it then pushes that information up to an endpoint. I am personally using Microsoft Azure Logic App for this functionality.

Hardware Needed

The following is a list of the exact hardware I've tested this on:

  1. RaspberryPi Zero
  2. DHT11 3-pin sensor

NOTE: This may work for the DHT22 sensor as well, but I have not tested it. More info about the different types of basic sensors can be found here.

Software Needed

This was tested using the following software:

NOTE: This may work with other Linux distributions and versions of Python, but I have not tested any other than those mentioned above.

This script is set to pull two important pieces of data from environment variables:

  1. The URL of the endpoint where the data is to be sent
  2. The name of the IOT device sending this data

Make sure you're exporting these prior to running the script!

NOTE: My RaspberryPi did not see my DHT11 unless I ran this script as root. To use environment variables exported by my underprivileged user, I ran this script with sudo -E. Your mileage may vary here.

For my purposes, I'm sending my data to a Microsoft Azure Logic App configured to accept this sample schema:

{
  "properties": {
    "epoch": {
      "type": "number"
    },
    "humidity": {
      "type": "number"
    },
    "name": {
      "type": "string"
    },
    "partition_key": {
      "type": "string"
    },
    "temp": {
      "type": "number"
    }
  },
  "type": "object"
}

You can check out this sample_object.json file to see a sample payload this script will send in its current form. You don't have to send your data to Azure, but you will need to make sure wherever you're sending it that the mapping/schema is configured properly.

How to Use This Software

To use this software, perform the following on your Raspberry Pi:

NOTE: These steps tested on Raspbian 8.0 (jessie). IMPORTANT: Make sure you've got your DHT11 sensor connected to your RaspberryPi's GPIO properly before starting! Also double check that you have Python on your system!

  1. Update apt.
    sudo apt-get update
  2. Ensure the packages needed are installed.
    sudo apt-get install git python python-pip build-essential python-dev -y
  3. Clone the Adafruit_Python_DHT repository.
    git clone https://github.com/adafruit/Adafruit_Python_DHT.git
  4. Build the library.
    cd Adafruit_Python_DHT && sudo python setup.py install && cd ..
  5. Clone this repository.
    git clone https://github.com/zdeptawa/azure-iot-temp-humidity.git
  6. Install the requirements for the script using pip.
    pip install -r azure-iot-temp-humidity/requirements.txt
  7. Export your endpoint URL.
    export CRYPTO_LOGICAPP_URL='<your_endpoint_url>'
  8. Export your IoT device's name.
    export IOT_DEVICE_NAME='<your_iot_device_name>'
  9. Run the script.
    sudo -E python azure-iot-temp-humidity/temp_humidity_logger.py

This script is currently set to log INFO to it's local directory under temp.log as well as send the JSON payload to the URL endpoint you set.

Questions

Please let me know if you have any questions or run into any problems! I am here to help. =]

Author

Zachary Deptawa - Twitter @zdeptawa

About

Temperature and humidity monitor using Azure IoT.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages