LattePanda is a powerful development board that can run a full version of Windows 10. It is equipped with an Intel Quad Core processor and has excellent connectivity, with three USB ports, integrated WiFi and Bluetooth 4.0. In this project, our home monitoring system consists of LattePanda (with Windows 10 Home x64 OS), CC2530 ZigBee devices, and Microsoft Azure services.
Let’s take a look at the architecture of the proposed system, which is depicted in Fig.1 as follows.
First of all, CC2530 ZigBee Coordinator and end devices are used to establish ZigBee home network. ZigBee Coordinator is connected with LattePanda by USB port (actually, we use CH340 as Serial to USB chipset to make it simple). ZigBee end devices are embedded with a variety of sensors for home monitoring, including DS18B20 (temperature), MQ2 (gas), PIR (motion) and photo resistor (light). The communication between ZigBee Coordinator and ZigBee end devices are implemented by ZStack-CC2530-2.5.1a, which is a Mesh Network protocol released by TI.
Secondly, LattePanda is played as a gateway in this project. On one hand, it will collect the data sent by ZigBee Coordinator and transmit these data to Azure IoTHub for further development and utilization. On the other hand, it will receive the command from Azure IoTHub and give them to the ZigBee end devices by ZigBee Coordinator.
Last but not least, Microsoft Azure services are used for data collecting, data storage, data filtering and data visualization. Azure IoTHub is responsible for collecting data sent by LattePanda, as well as streaming data to Azure Stream Analytics. Azure Stream Analytics will filter the data and send them to Azure Storage Table for data storage, as well as send them to PowerBI for data visualization. Furthermore, we can see these data anywhere by Windows Universal Apps on Windows 10 for PC or Windows 10 for Mobile device.
PrerequisitesIt will take 4-5 hours to complete the prerequisites if you don’t have Windows 10 and Visual Studio 2015 already setup but most of that time is unattended. To successfully run this project, you need following items:
- CC2530 ZigBee Modules: at least 2, one for Coordinator and one for End Device.
- Sensors: DS18B20 temperature sensor, MQ2 gas sensor, PIR motion sensor and photo resistor light sensor.
- LattePanda: both 2G/32G and 4G/64G are OK.
Time: 5 minutes
Parts: CC2530 ZigBee Modules, Sensors
Tools: N/A
MQ2 gas sensor and photo resistor will give the analog signal to the P0.7 and P0.6 of CC2530, and CC2530 will do Analog-to-Digital convert and send digital signals. DS18B20 is a one-wire temperature sensor, and we connect its signal wire to P1.1 of CC2530. PIR motion sensor is connect to P0.5 of CC2530. All the sensors are powered by 5V DC voltage on the module.
The module with all sensors are shown in figure 2.
Time: 3 minutes
Parts: CC2530 ZigBee Coordinator, LattePanda
Tools: N/A
In this project, we use CH340 as USB to Serial chipset. So, first of all we should install CH340 Windows 10 driver on lattePanda. Once we plug the USB cable as follows, the CC2530 Module is powered on.
And if we open the “Device Manger” on lattePanda, we can see the unknown USB 2.0 serial device. Then we just click right, and choose install driver automatically. Once the driver is installed successfully, we can find the Port Number under Ports (COM &LPT) item just as follows.
Here we can see that the port number of the CH340 is COM6.
Step 3: Setup ZigBee Home NetworkTime: 2 minutes
Parts: CC2530 ZigBee Coordinator, CC2530 ZigBee End Device, LattePanda
Tools: N/A
After CC2530 ZigBee Coordinator successfully connected to the LattePanda, the ZigBee network setup indicator LED will be on. Then, we can power on the CC2530 ZigBee End Devices with different sensors. Once the End Device joins the network that created by ZigBee Coordinator, the network indicator LED will be ON.
Time: 10 minutes
Parts: Azure Service
Tools: Azure Account
In this project, we will need Azure Storage Table to store the data from sensor devices. So, we can create it as follows.
- In the Azure Management Portal (https://manage.windowsazure.com), click the on the "STORAGE" icon along the left to view your existing storage accounts (if any), then click the "+NEW" button in the lower left corner.
- In the "NEW" panel, select "DATA SERVICES" | "STORAGE" | "QUICK CREATE". Complete the fields of “URL, Location/Affinity Group and Replication”, then click the "CREATE STORAGE ACCOUNT" button.
- Wait for the new storage account's status to show as "Online".
- Select the newly created Storage account, and then click MANAGE ACCESS KEYS at the bottom of the page. Copy the Storage account name and one of the access keys.
Time: 5 minutes
Parts: Azure Service
Tools: Azure Storage Explorer
We use Azure Storage Explorer (it a third party open source tool available on codeplex: https://azurestorageexplorer.codeplex.com) to create the Azure Storage Table.
- Go to add account and fill the account name and access key. Once the account established, you can access the storage that shows blob containers, queues and tables.
- Select the table and click the new button and create a new table named “LattePanda Table” as follows.
Time: 5 minutes
Parts: Azure Service
Tools: N/A
IoT Hub service is used to gather all the data that sent from the LattePanda. The new IoTHub is created as follows.
- In the Azure Portal (https://portal.azure.com), click the on the "New" icon along the left to see all the services, then click the "Internet of Things" item and choose “IoT Hub” as shown in figure 9.
- Complete the fields of “Name”, “Pricing Tier”, “IoT Hub Units”, “Device-to-Cloud Partitions”, “Resource group” and “location”, then click the "Create" button. It should be noted that “F1 Free” Pricing is enough for our project. And we’d better choose the local location of the service.
- Wait for the new IoT hub to show as "Online". When it is ready, open the blade of the new IoT hub, take note of the URI and select the key icon at the top to access to the shared access policy settings.
- Select the Shared access policy called iothubowner, and take note of the Primary key and connection string in the right blade. We may copy these into a text file for future use.
For more information, we can refer to this doc online:
Create an IoT hub using the Azure portal.
Step 7: Create Azure Stream Analytics JobTime: 5 minutes
Parts: Azure Service
Tools: N/A
Azure Stream Analytics is used in this project to filter the sensor data that gathered by IoTHub, and stream the data to PowerBI or Azure Storage Table storage.
The new Stream Analytics is created as follows.
- In the Azure Portal (https://portal.azure.com), click the on the "New" icon along the left to see all the services, then click the "Internet of Things" item and choose “Stream Analytics job” as shown in figure 11.
- Complete the fields of “Job Name”, “Resource group” and “location”, then click the "Create" button.
- Wait for the new Stream Analytics to show as "Online".
Time: 5 minutes
Parts: LattePanda
Tools: Device Explorer
Communication between Azure IoTHub and devices is secured. All the devices that connected to Azure IoTHub should be Authenticated. On Windows, we can use Device Explorer app to complete this Authentication process. A pre-built version of the Device Explorer application for Windows can be downloaded by clicking on this link: Downloads (Scroll down for SetupDeviceExplorer.msi). The default installation directory for this application is "C:\Program Files (x86)\Microsoft\DeviceExplorer".
- Open the Device Explorer app and fill the IoT Hub Connection String field with the connection string of the IoT Hub that we created in step 6 and click on Update
- Go to the Management tab and click on the Create button. The Create Device popup will be displayed. Fill the Device ID field with a new Id for your device (MyLattePanda for example) and click on Create as follows.
- When the device identity is created, it will be displayed in the grid. Right click on the identity we created, select Copy connection string for selected device and save the value by copying to clipboard, since it will be required to connect the LattePanda with the IoT Hub.
Time: 10 minutes
Parts: LattePanda
Tools: Visual Studio
The LattePanda Home App is completed with the help of “Serial UART Sample”: https://developer.microsoft.com/en-us/windows/iot/samples/serialuart
Because this application is a UWP application, you can still deploy this Project to Windows 10 IoT Core Devices (like Raspberry Pi, MinnowBoard MAX) or Windows 10 PC.
- First, download the code. Make a copy of the application on your Development PC and open the project from Visual Studio 2015 Update 3. Make sure Visual Studio Remote Tools is installed and running on your LattePanda. The tool is located in “Program Files\Microsoft Visual Studio 14.0\Common7\IDE\Remote Debugger\x64\msvsmon.exe”.
- Open MainPage.xaml.cs in Solution Explorer and locate to the “connectionstring”. Add your IoT Hub Connection String that saved in step 8.
- Locate to the “dataTransmitterTick” function. Add your storage account name and access key that saved in step 4.
- Locate to the “IoTButton_Click” function. We set the time interval (transmitting data to IoTHub) as 5 seconds. If you don’t want to send data so frequently, you can alter this parameter to 10 seconds or even larger.
- Locate to the “AzureStorageButton_Click” function. We set the time interval (transmitting data to Azure Storage Table) as 5 seconds. If you don’t want to send data so frequently, you can alter this parameter to 10 seconds or even larger.
- Right click the solution, choose the Property of the project. Then click the “Debug” tab. Choose “x64” and “Remote machine” as Platform. If you already power the LattePanda on, you can see the machine on “Find” window as follows.
Now press F5 from Visual Studio: The LattePanda home app will deploy and start, and you should see this on the device output.
Choose the USB device and click Connect button. Then we should see the data has arrived in the “Read Data” window and we have parsed the sensor data in TextBlock below.
If we click “Upload to IoTHub” Button, the sensor data will be transmitted to IoTHub that we created in step 6. If we click “Upload to Azure Storage” button, the sensor data will be transmitted to Azure Storage Table that we created in step 5. The data can be monitored by Device Explorer as follows.
Then we can see the data in “LattePanda” Table by Azure Storage Explorer as follows.
Time: 10 minutes
Parts: Azure service
Tools:N/A
Now we have sensor data on Azure IoTHub. At this moment, we may config the input, query, and output of the Stream Analytics Job that we created in step 7.
First, in the Inputs window, we choose IoT Hub, and in the IoT Hub Settings screen, we complete the following information:
- Input Alias: TelemetryHub
- Subscription: Use IoT Hub from Current Subscription
- Choose an IoT Hub: input the name used during the IoT Hub creation
- IoT Hub Shared Access Policy Name: iothubowner
- IoT Hub Consumer Group: powerbi
- Click Next, and then Complete (leave the Serialization settings as they are).
To set up the output, go to the Stream Analytics Job's OUTPUTS tab, and click the ADD AN OUTPUT link. In the Add an output to your job popup, select the POWER BI option and the click the Next button. In the following screen you will setup the credentials of your Power BI account in order to allow the job to connect and send data to it. Click the Authorize Now link. Then you will enter the following information:
- Output Alias: PowerBI
- Dataset Name: LattePandaData
- Table Name: SensorValue
- Group Name: My Workspace
To set up the Query configuration, go to the Stream Analytics Job QUERY tab and replace the query with the following statement:
SELECT
*
INTO
[PowerBI]
FROM
[TelemetryHUB]
It should be noticed that we just select all the data from IoTHub to PowerBI. Click on the SAVE button and YES in the confirmation dialog. Now that the job is configured, the START button is enabled. Click the button to start the job and then select the JOB START TIME option in the START OUTPUT popup. After clicking OK the job will be started. Once the job starts it creates the Power BI datasource associated with the given subscription.
Step 11: Config PowerBI DashboardTime: 10 minutes
Parts: Azure PowerBI service
Tools: N/A
Now that the datasource is created, go back to your Power BI session, and go to My Workspace by clicking the Power BI link. After some minutes of the job running you will see that the dataset that you configured as an output for the Job, is now displayed in the Power BI workspace Datasets section.
Please note that the Power BI dataset will only be created if the job is running and if it is receiving data from the IoT Hub input, so check that the Universal App is running and sending data to Azure to ensure that the dataset be created. To check if the Stream Analytics job is receiving and processing data you can check the Azure Management Stream Analytics monitor.
Once the datasource becomes available you can start creating reports. To create a new Report click on the lattePanda datasource:
The Report designer will be opened showing the list of fields available for the selected datasource and the different visualizations supported by the tool.
Here we choose gas, light and temperature value as Y axis, and measurement time as X axis. Now the report is almost ready. Click the SAVE button and set LattePandaEnviroment as the name for the report.
Now we will create a new Dashboard, and pin this report to it. Click the plus sign (+) next to the Dashboards section to create a new dashboard. Set LattePanda as the Title and press Enter. Now, go back to your report and click the pin icon to add the report to the recently created dashboard. Furthermore, we can create another report named HumanDetection as follows.
In this tutorial, we have achieved the design of home monitoring system based on LattePanda and CC2530 ZigBee devices. Also, the configurations of Azure Services, including Azure IoTHub, Azure Stream Analytics, Azure Storage Table and PowerBI are introduced to complete sensor data gathering, data filtering, data storage and data visualization.
Comments