未加星标

Using Azure IoT Hub and PowerBI to Visualize Plant Floor Data

字体大小 | |
[系统(windows) 所属分类 系统(windows) | 发布者 店小二05 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏

Using Azure IoT Hub and PowerBI to Visualize Plant Floor Data

In my previous post on the Azure IoT Gateway SDK , we put together a Powershell quick start script for Modbus Gateway projects. In this post we'll continue the exploration by connecting a Modbus compatible Beckhoff BK9100 to Azure IoT Hub, shape our data with Azure Stream Analytics and then visualizing the current position of a Dynapar optical encoder with Power Bi.

We'll begin by opening up the Azure Portal, click on the plus icon in the upper right corner and search for `IoT Hub`. Once the resource is located, select `Create` in the lower left corner.


Using Azure IoT Hub and PowerBI to Visualize Plant Floor Data

Configure your IoT Hub with a unique name, select an appropriate scale tier, and make sure to put the hub into it's own resource group for easy clean-up later.


Using Azure IoT Hub and PowerBI to Visualize Plant Floor Data

Navigate to the `Shared access policies` tab of the IoT Hub and paste the `Primary key` of the `service` policy into a text file.


Using Azure IoT Hub and PowerBI to Visualize Plant Floor Data

Back in the Hub's primary blade, select the `Endpoints` tab under messaging. In the new blade select the `Events` entry under `Built-in endpoints`. Once the new blade opens, copy the `Event Hub-compatible name` value and the first segment of the `Event Hub-compatible endpoint` value (e.g. `ihsuprodbyres043dednamespace`) into your text file. We'll use these values in a moment to hook up our Azure Stream Analytics Job.


Using Azure IoT Hub and PowerBI to Visualize Plant Floor Data

Next, we'll need an Azure Stream Analytics(ASA) Job to perform some data scaling on the path toward PowerBI. While this operation could be performed in the gateway, ASA provides us an opportunity to sniff/validate our data and opens the door to easy persistence, should we so choose. Again click the plus (+) icon in the upper left corner and search for `Stream Analytics`. Once the resource is located, select `Create` in the blade's lower left corner.


Using Azure IoT Hub and PowerBI to Visualize Plant Floor Data

Configure the ASA job with a unique name and place it in the same resource group as the IoT Hub.


Using Azure IoT Hub and PowerBI to Visualize Plant Floor Data

We now need to patch the IoT Hub as the input for the ASA Job. In the overview pane, select the input section under `Job Topology`, and press add at the top of the new blade. Enter an alias that will be used to reference the input in the ASA query. Make sure that the `Source Type` is set to `Data Stream` and the `Source` is marked as `Event hub`. Unfortunately, the Event Hub input blade will not automatically recognize the IoT Hub's Event Hub endpoints, so we'll need to set the `Subscription` field to `Provide event hub settings manually`. Paste in the `Service bus namespace`, the 'Event hub name' and the `Event hub policy key` from your text file. Finish up by setting the `Event up policy name` to `service` and press `Create`. There is no need to define a non-default consumer group and the data will be JSON formatted, encoded as UTF-8


Using Azure IoT Hub and PowerBI to Visualize Plant Floor Data

Before we define our ASA query we should set up the output hook to PowerBI. Back under the ASA Job's overview tab on the main blade, Select the `Output` section under `Job Topology` and press `Add` at the top. Enter `power-bi` as your `Output alias`, set the `Sink` to `Power BI` and press authorize. You'll be asked to enter your Power BI credentials at the login. If you don't already have a Power BI account, you can sign up for one here . Once the prompt completes login, enter in a `Dataset Name` and target `Table Name`.


Using Azure IoT Hub and PowerBI to Visualize Plant Floor Data

The last bit of ASA configuration we need to handle is setting up the query. For now, we'll build the query based on values that might end up being slightly different when you wire up your device.

Navigate the the `Query` section under `Job Topology` and select it. A new blade will open up that will list the Input and Output alias previously defined and a code editor to enter the ASA query. We'll start by selecting the observation time stamp and the device type value. As I noted earlier, we need to do some maths to range our encoder value to get the data in shape for PowerBI visualization. To range the encoder value, cast the string to a float, devide by the ranges max count (in this case 65535) and multiply by 100 to push to percentage.

Once the query is entered, select `Save` at the top and back on the ASA home blade, press `Start` to kick off the job.

We can now turn our attention back to our Modbus device and complete the wiring of it to the gateway. As I noted earlier, I'm using a Beckhoff BK9100, Modbus capable, bus coupler along with a pretty standard Dynapar 2 channel optical incremental encoder (no Z full rev. channel). The Process Image for the coupler includes 8 channels of DIO in front of the mapping space for the encoder module, leaving our counter value located at the second word of the process image. For the astute, the coupler is also confiugred for IPAddres assignment using BootP via Beckhoff's TCBootP application.


Using Azure IoT Hub and PowerBI to Visualize Plant Floor Data

The next step in the process is to register our device with the IoT Hub. While there are a number of ways to accomplish this, I suggest you check out our `iot-samples` repository on GitHub. Begin by either cloning the repo, or just download the code directly. Navigate to Device Management -> csharp and open the solution file in Visual Studio (Note, you might also want to checkout my Introduction to Azure IoT with Fsharp post too!). With the solution open, set the `Create Device Identity` project as the startup project. In the config folder, copy the `config.default.yaml` file to `config.yaml`. Enter the Host Name for your IoT Hub, and the `iothubowner`'s primary key connection string, which can be found under the IoT Hub's `Shared Access policies` tab. Finish up by modifying the `Nickname` and `DeviceId` values in the config file, they can be any value you want. After you run the project, your device will be registered and a device key will be populated in the config file, we'll need that value shortly.

Open the script from myprevious blog postin an Administrative PowerShell ISE session. You'll need to set at least the following values:

rootProjectPath iotHubName deviceName - same as the "deviceId" you registered earlier deviceKey - the value from the config file in the Device Management Project deviceMac - the mac address of your modbus device modbusServerIp - the IP Address of your bus coupler/plc/IO device modbusPollingInterval - the number of milliseconds between device polls modbusDeviceType - this is the value that is plumbed to ASA modbus * - note in the sample script, I'm reading unit 0, with function code 4 (read input registers), reading starting at register 2 (1 based), and only reading 1 word of data ... you can see more about Modbus function codes on page 22 of the protocol spec . Once you fill out your data and run the script, navigate to {projectRootPat

本文系统(windows)相关术语:三级网络技术 计算机三级网络技术 网络技术基础 计算机网络技术

分页:12
转载请注明
本文标题:Using Azure IoT Hub and PowerBI to Visualize Plant Floor Data
本站链接:http://www.codesec.net/view/522278.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(windows) | 评论(0) | 阅读(30)