PowerBI with Raspberry PLC

Visualize your sensor data in realtime with the help of PowerBi
January 31, 2022 by
PowerBI with Raspberry PLC
Boot & Work Corp. S.L., Amil Shrivastava


This blog post is only a demonstration of Raspberry PLC's versatility and flexibility. It is compatible with a plethora of services out there in the market and for this blog, we are gathering data from the PLC's inputs and displaying it in real-time on PowerBI's dashboard. 

PowerBI is Microsoft's licensed data visualization software which is majorly focused on business intelligence. It has quite a lot of features and a broad spectrum of business intelligence services. 

For demonstration, we will be connecting a sensor to the Raspberry PLC and the data that it collects will be streamed on PowerBI's dashboard in realtime.

PowereBI's Real-time Datasets

PowerBI has three real-time dataset types, they are:

  • Push dataset
    In this, when the data is pushed in the PowerBI service, a database is created automatically and therefore reports can be generated. Visuals can be generated with this database in PowerBI's dashboard.
  • Streaming dataset
    In this case, the data, when pushed in the PowerBI service, it is only stored in the temporary cache of it, which expires quickly. This means that with this stored data only display visuals can be made and no reports or reports based visuals can be generated.
  • PubNub streaming dataset
    With this, you have to use a PubNub SDK to read an existing PubNub data stream. Here, No data is stored by the PowerBI service. PubNub is a real-time communication platform that provides infrastructure over which real-time chat applications can be built.

We will be using the Streaming dataset to stream our temperature and humidity sensor's output.

The steps to the process are as follows:

1) Register yourself on PowerBi

2) Go to "My Workspace"; Click on new to add a streaming dataset.

Register yourself on PowerBimy workspace - PowerBI with RaspberryPLCStreaming datashit - PowerBI with RaspberryPLC

3) On clicking the streaming dataset, you will have to choose the API option in the pop up window that appears.

streaming dataset - PowerBI with RaspberryPLC

4) Fill in the parameters and their datatypes. 
Paramaters and datatypes - PowerBI with Raspberry PLC

Make sure that you add the timestamp variable as that is important for streaming datatypes and very importantly turn on the Historic data analysis toggle switch.

5) In the next window, you will obtain the API link which will be used to connect your script to the database, therefore copy it and the structure of the key:value pair of the variables you inserted in the previous steps.

6) Your streaming dataset is ready, now we will prepare a dashboard with tiles that will stream your data. To do that, click on "+new" again from step 2 and select "Dashboard" this time.

Dashboard - PowerBI with RaspberryPLC

7) In the Dashboard page, click on edit and add a tile

Add a title - PowerBI with RaspberryPLC

8) Fill all the required data

Real-time data - PowerBI with RaspberryPLC

9) Choose your streaming dataset

Custom streaming data title - PowerBI with Raspberry PLC

10) You now have to select visualization type and add values to it from the drop down menu. Please repeate this step till all the values from your previously created datasets are fed in.

Add the required details in the following steps and you are good to go.

The next steps are only to code the program and add the API link obtained in step 5.


Python sample for Raspberry Pi which reads temperature and humidity values from
a DHT22 sensor, and sends that data to Power BI for use in a streaming dataset.
import urllib3, time
from datetime import datetime
from rpiplc_lib import rpiplc

while True:
  humidity,temp = dht.read_retry(SENSOR, PIN)
        now=datetime.strftime(datetime.now(), "%Y-%m-%dT%H:%M:%S%Z")
    # data that we're sending to Power BI REST API
        data = '[{{ "timestamp": "{0}", "temperature": {1:0.1f}, "humidity": {2:0.1f} }}]'.format(now, temp, humidity)
        print (data)
    # make HTTP POST request to Power BI REST API
        http = urllib3.PoolManager()
        req = http.request(url=REST_API_URL,method='POST', body=data, headers={'Content-Type':'application/json'})
        response = req.read()
        print("POST request to Power BI with data:{0}".format(data))
        print("Response: HTTP {0} {1}\n".format(response, response))
       # rpiplc.delay(1000)
    except urllib3.exceptions.HTTPError as e:
        print("HTTP Error: {0} - {1}".format(e.code, e.reason))
    except urllib3.exceptions.RequestError as e:
        print("Request Error: {0}".format(e.reason))
    except Exception as e:
        print("General Exception: {0}".format(e)) except Exception as e: print("General Exception: {0}".format(e))

Some Useful Links

1) Big Data Analytics in the Industry 4.0

2) Best 5 Opensource IIOT Databases

3) How to learn Industrial Automation

Search in our Blog

PowerBI with Raspberry PLC
Boot & Work Corp. S.L., Amil Shrivastava January 31, 2022
Share this post

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.

Industrial PLC comparison >>>