QNAP, Inc. - Network Attached Storage (NAS)

Language

Support

Connect Raspberry Pi to QNAP NAS via QIoT Suite Lite

Get started with Raspberry Pi (Nodejs)

In this tutorial, you will learn the basics of working with Raspberry Pi (that runs the Debian-based Raspbian). You will then learn how to connect your devices to QNAP NAS using QIoT Suite Lite.

Please ensure your Raspberry Pi and NAS are on the same LAN.

1. Connect Raspberry Pi to QNAP NAS

Please configure your Raspberry Pi device with an operating system, set up your development environment, and deploy an application to Raspberry Pi.

1.1 What will you need

  1. Raspberry Pi
  2. SD card (an 8GB class 4 SD card is recommended) with NOOBS installed.
  3. HDMI display.
  4. USB keyboard and mouse.
  5. Power Supply:  The Pi requires a USB micro power supply with at least 2A at 5V for the Model 3B, or 700mA at 5V for earlier models. 

1.2 Set up Raspbian

  • Insert the SD card containing extracted NOOBS files into the Raspberry Pi
  • Connect the keyboard, mouse, and HDMI display to the Raspberry Pi. Plug in the power adapter. The Raspberry Pi does not have a power switch, and will automatically power on once the adapter is connected.
  • A menu will ask what OS to install and what language and keyboard layout to use. Check the box next to Raspbian and click "Install".
  • The installation process may take up to 20 minutes, and will restart to the Raspbian desktop when complete.
  • Configure Wi-Fi – In the Desktop environment locate the Wireless Network icon in the top-right menu and click the icon to view a list of available Wi-Fi networks.
  • To connect to your Raspberry Pi from another device, you must know the Pi’s IP address. Using the terminal (Ctrl + Alt + t to open Terminal), enter hostname -I.

More Raspberry Pi setup guides can be found at: https://www.raspberrypi.org/learning/software-guide/

1.3 Install Nodejs and required libraries

  • Install node.js v6

    Please visit QNAP github for QIoT Suite Lite sample code

2. Create your device in QIoT Suite Lite

2.1 Install QIoT Suite Lite

  • QIoT Suite Lite can be installed from the App Center.
  • Launch and log in QIoT Suite Lite. The default username and password is "admin".

2.2 Create a new IoT application

IoT Applications are a combination of Things, Rules, and Dashboards. We recommend that you first create a “Things” in IoT Application. This IoT Application allows you to keep a record of all of the devices that are connected to your NAS.

Rules make it possible to build IoT applications that gather, process, analyze and act on data generated by connected devices. Rules can apply to data from one or many devices, and it can take one or many actions in parallel.

Dashboards turn your data into analytics and reports that provide real-time insights.

All these elements provide user a complete IoT Application environment. 

  • If this is your first time to use QIoT Suite Lite, QIoT Suite Lite provides a wizard to help you quick setup a IoT application.
  • Click “Quick Setup Wizard” to start quick setup wizard. After you read the QIoT Suite Lite introduction in pop window, click Next button.

  • Create a New IoT application
    • Enter IoT Application name, e.g., app_1.
    • Rule name and Dashboard name will be generated automatically based on the name of IoT Application you fill in.
    • Click “Next” to complete create a new IoT application
  • Click "+ Add" to add this application’s device.
  • After click "+ Add", In “Add Thing”:
    • Enter a name for your device (e.g., raspberrypi) and provide the device information (such as serial number and manufacturer) in Add attribute.
    • If your device is already supported by QIoT (Arduino Yun,Raspberry Pi, Edison, and Linkit 7688 (Duo)), choose a pre-defined Thing Type.
    • Click Add to add the device.
  • Enter the IP address, User Name, and Password of your device and click the Connect icon. QIoT Suite Lite will check the connection with the device. After the connection is verified, click Next.
  • In "Resources", Click "Add Resource".
  • After click "Add Resource", In "Add Thing Resource":
    • Enter the name and ID for the sensor in Resource Name and Resource ID. Please note that the Resource ID will be used to create a Topic in the QIoT Broker. This ID should be unique for the device and no duplicates should be allowed for the same device.
  • In "API Keys":
    • If you want to embed QIoT dashboard widgets into web pages or access QIoT APIs from third-party applications, go to the API Keys tab and click "Generate New API Key". Click "Done".
  • Your IoT application will now be created. Node.js sample codes and related files (certificate, resource information) will be uploaded to the specified path on your device.
  • A sample dashboard will be created.
  • Go to the Rule tab to define the flow or rules on how to process the data sent from the device, and how to present in a dashboard.

3. Connect your device to QIoT Suite Lite using MQTTS

3.1 Run Sample Code

  • Open Terminal application (e.g., PuTTY) on your PC.Connect to your device by SSH and enter the folder where put sample code (e.g., /home/root/bundle).
  • Install sample code dependency, enter command as following
  • Run sample code
  • Device will send message to topic "temp" or that you defined

3.2 Another protocol

  • Click "Connection a device" button
  • You can choose another protocol you would like to use
  • SSH to your device, and input command as following.

4. Integrate Power BI

4.1 Get your first Power BI account

  • Sign up for a free PowerBI account at https://powerbi.microsoft.com/en-us/
  • After registering, you will see the following page, you could click "skip for now" to start create dataset.

4.2 Setup your streaming dataset API

  • Create "Datasets"
  • Click "Create" in screen upper right corner
  • And then click "Streaming dataset"
  • Select "API" as your source of data, and click "Next".
  • Define your values from stream, and you will get a JSON result in the textbox. We will use this JSON code to push data to the IoT application. Click "Create" to finish.
  • Once you create your data stream, you get a REST API URL which IoT applications can call using POST requests to push your live data to the streaming data dataset you created.

4.3 Configure Node-RED’s nodes in IoT application

  • Create an IoT application in QIoT Suite. The following is your first Node-RED flow, and then you can start creating your own IoT flow. You can learn more about Node-RED at https://nodered.org/
  • Before you start pushing live data to Power BI. We need a "function" node to convert IoT data to a streaming data dataset. Here you can replace msg.payload to your JSON dataset.
  • Function code as following:
  • We need an "http request" node to help us to push live data to Power BI. Just drag and drop the "http request" node and connect to the tail of the "function" node.
  • Copy and paste the REST API URL that you got from the Power BI console, and set http method to POST. Click "Deploy" to save changes
  • Your Node-RED flow will look like below.

4.4 Add tiles to display real-time data

  • Create "Dashboard"
    • Click "Create" in screen upper right corner
    • And then click "Dashboard"
    • Enter dashboard’s name, and click "Create" to complete create dashboard.

  • Click "Add tile" in screen upper right corner
  • Select "CUSTOM STREAMING DATA" and click "Next".
  • Select "datasets" and then click "Next".
  • Select visualization type (e.g., gauge), and set value, min, and max value.
  • You will have a streaming dataset to work with, and you can get a real time gauge that looks as following
Release date: 2017-05-16
Was it helpful?
Thank you for your feedback.
Thank you for your feedback. If you have any question, please contact support@qnap.com