QNAP, Inc. - Network Attached Storage (NAS)

Language

Support

Connect Arduino Yun to QNAP NAS via QIoT Suite Lite

Get started with Arduino Yun (Python)

In this tutorial, you will learn the basics of working with Arduino Yun (that runs Linux). You will then learn how to seamlessly connect your devices to QNAP NAS using QIoT Suite Lite. This example is uses the DHT11 humidity and temperature sensor.

Lesson 1: Configure your devices

In this lesson, you configure your Arduino Yun device with an operating system, set up your development environment, and deploy an application to Arduino Yun.

1.1 Download Arduino IDE

1.2 Configure and test your device

If this is your first time using Arduino Yun, you will have to follow some steps to assemble it.

  • Connect Arduino Yun to your PC with USB.
  • Open your Arduino IDE and find Blink example.
  • Configure your board:
  • Configure your port:
  • Verify and upload your Blink example to Arduino Yun
     
  • After uploading your code to Arduino Yun, check your Arduino Yun and you should see L13 blinking:
  • Connect your DHT11 sensor to “Ground”, “5V”, “Pin 2(Digital)” on Arduino Yun respectively.

1.3 Get the IP address of your Arduino Yun

  • Press and hold the Wi-Fi reset button for 5 seconds.
  • Go to your Wi-Fi settings and choose “Arduino-Yun-XXXXXXX” (where “XXXXXXX” is the MAC address of your Arduino Yun).
  • Open your browser and go to “http://192.168.240.1” or “http://arduino.local”. The default password is “arduino”.
  • Complete your Board setting and link your Arduino Yun to the router you are using. Skip “API setting” and click save.
  • On your PC, change your Wi-Fi network to your router and now your NAS and Arduino will be on the same network.

1.4 Install development tools for your Arduino Yun

  • Open a Terminal from http://arduino.local
  • Enter the login account “root” and your password. The default password is “arduino”.

Install PIP and MQTT Library by entering the following commands.

root@arduino:~# opkg update
root@arduino:~# opkg install distribute
root@arduino:~# opkg install python-openssl
root@arduino:~# easy_install pip
root@arduino:~# easy_install paho-mqtt

Lesson 2: Create your device in QIoT Suite Lite

In this lesson, you will provision your QNAP QIoT Suite Lite software, and create your first 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 to 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.

  • Click Add IoT Application, and enter a name for your IoT Application. Rule and Dashboard names will be generated automatically based on the IoT Application name.

  • Enter the related information for your IoT application.
  • Click on Add a thing. Enter a name for your device and provide the device information (such as serial number and manufacturer) in Add attribute. If your device is already supported by QIoT, choose a pre-defined Thing Type. Click Add to add the device.

  • Click the “Thing Resources Icon” and click Add Resources. 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.

  • Enter the  resource-related information.

Lesson 3: Connect your device to QIoT Suite Lite using MQTTS

In this lesson, you will generate certificate from QIoT Suite Lite, download the SDK, and connect Arduino Yun to QIoT Suite Lite.

3.1 Generate certificate and Resource information Inside QIoT Suite.

  • Click the Thing Information icon in QIoT Suite Lite, go to Connect a Device and click Generate a Device Certificate.

  • A pop up window will appear as below. Click the three links to download “Device Certificate" "CA Certificate", and "Private Key” and click OK.
  • You will then see a page with a lot of code. Click Download JSON file. The file name is “resourceinfo.json”

3.2 Download SDK sample code

Download the SDK Sample code from:
https://drive.google.com/open?id=0B5f8WeH2QCp2WWFaRzZrNG44RFU

3.3 Connect Arduino Yun to NAS

  • Open http://arduino.local/ and find “File Manager”
  • Create a new folder (for example: “123”) under Arduino Storage.
  • Create the folders “res” and “ssl” under “123”.
  • Copy and paste “QNAPIoT_Python_Test_MQTTS.py” file into “123’.
  • Upload “resourceinfo.json” file to “res” and upload the 3 certificates to “ssl”.
  • Open Arduino IDE. Find “DHT-sensor-library-master.zip” file and include it.
  • Open the “QNAPIoT_Arduino_Test.ino” by Arduino IDE and upload your Arduino sample code.

3.4 Change your connection type

QIoT supports protocols including MQTT, MQTTS and HTTP.

3.4.1 MQTT and MQTTS

  • Download and open “QNAPIoT_Python_Test_MQTT.py”. MQTT and MQTTS is different between OpenSSL.
  • To use MQTT, open QIoT Suite Lite and find “Connect a Device”. Choose MQTT and click “Next”.
  • Download the JSON file and upload it to your Arduino Yun “res” folder.
  • To run your python code, open your terminal and enter the following command:
    root@arduino:~# python QNAPIoT_Python_Test_MQTT.py or
    root@arduino:~# python QNAPIoT_Python_Test_MQTTS.py

3.4.2 HTTP

  • Find the “QNAPIoT_Python_Test_HTTP.py” sample code.
  • Run it using:
    root@arduino:~# python QNAPIoT_Python_Test_HTTP.py

Lesson 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:

4.2 Setup your streaming dataset API

  • Go to “Datasets -> Streaming datasets” on the left menu, and click “+ Add streaming dataset” in the top-right corner.
  • 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.
  • 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

  • Go to “Dashboards +” to create your first dashboard, then click “+ Add tile” to configure a widget.
  • Select “CUSTOM STREAMING DATA” and click “Next”.
  • Select datasets and click “Next”.
  • 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-12
Was it helpful?
Thank you for your feedback.
Thank you for your feedback. If you have any question, please contact support@qnap.com