I recently bought a Raspberry PI 3 Model B for another project, but I have also been using it for other things. So I followed this guide to create a Real-time IoT Dashboard which gives me sensor data for humidity and temprature. The process was fairly easy following Sirui Sun’ guide on PowerBI.com.

What you’ll need

  • Raspberry PI 3 with Rapsbian Jessie installed (You can read more about installing Rapsbian here)
  • DHT22 temperature and humidity sensor (I bought this sensor from DX.com)
  • PowerBI.com account

Power BI

Log into PowerBI.com and head over to the “Streaming datasets” button under the Datasets tab. Streaming datasets in Power BI represents streams of incoming data. From there, click “Add streaming dataset” and select the API option:

2

Give it a fitting name and add three fields:

  1. timestamp (DateTime): When the weather measurement were taken
  2. temperature (Number): the temperature at that point of time
  3. humidity (Number): the humidity at that point of time

93eec3e0-2686-41b3-8d62-671b2eb8aceb
Tips! Enable the “Historic data analysis” if you want Power BI to store the data sent via the APIs for use in reporting and analysis down the road.

Select “Create”. Copy the PUSH URL and save it in a Notepad text file – We’ll need it for later.

4

Now we have a streaming dataset! Your application can make HTTP POST request to this endpoint in order to send data to the streaming dataset.

Hooking up the Raspberry Pi

This is where the DHT22 sensor comes to play. There are three cables to connect:

  • The “+” on the sensor goes into the GPIO1 (3v3 Power)
  • The “S” or “OUT” goes into the GPIO4 (This is the one transmitting data)
  • The “-” goes into Ground.

connections

 

20161114_175250833_ios

20161114_175239525_ios

Ok good, we have our sensor installed. We also need some Python extensions installed and Adafruits_DHT Puthon libraries which accompany the DHT22 sensor, which will allow us to access the temperature data. Run the following commands:

sudo apt-get update
> sudo apt-get install build-essential python-dev
> git clone https://github.com/adafruit/Adafruit_Python_DHT.git && cd Adafruit_Python_DHT && sudo python setup.py install

Next, download this Pyhton script (uploadDHT22Data.py) and unzip the .rar file. Open the file and set the REST_API_URL to the URL you copied into Notepad earlier:

   # REST API endpoint, given to you when you create an API streaming dataset
# Will be of the format: https://api.powerbi.com/beta/<tenant id>/datasets/< dataset id>/rows?key=<key id>
REST_API_URL = ' *** Your Push API URL goes here *** '

Save the python script.

Open up a terminal windows and test your sensor by typing this command:

2016-11-14_1950

You should now see the Temprature and Humidity in the Terminal. Good, your sensor is working correctly!

Now run this command:

  > python uploadDHT22Data.py

The raspberry will start to stream data to Power BI:

Visualizing the data

With all that done head over to Power BI and create a new dashboard.

capture

Within the new dashboard add a new tile.

capture

Select Custom Streaming Data and hit Next.

5b36f783-8e46-4d69-b49d-67fc0482deec

Select the dataset you created in the first step, and click Next. We will start by creating  a card that displays the most recently received value. Select “temperature” under field:

ec7067e5-9f30-4b9c-acc8-6d98b5a4a761

Click next and select your preferred settings.

Next we will create a line chart so that we can see the data change over time. Go back and add another tile, and select “Line chart”. From there set the Axis to timestamp and value to temperature.

ae86b66c-c223-4faa-8756-e1d9054f1761

Repeat the process for the humidity field. Your dashboard should look something like this:

 

Any questions, let me know by sending me an email or use the comment section below.