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 devicesIn this lesson, you configure your Arduino Yun device with an operating system, set up your development environment, and deploy an application to Arduino Yun.
- Download and install Arduino IDE based on your host PC: https://www.arduino.cc/en/Main/Software
- More Arduino tutorials can be found here: https://www.arduino.cc/en/Tutorial/HomePage
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.
- 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.
- 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 Lite2.1 Install QIoT Suite LiteQIoT 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- 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.
- 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”
Download the SDK Sample code from: https://drive.google.com/open?id=0B5f8WeH2QCp2WWFaRzZrNG44RFU
- 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.
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
- 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 accountSign up for a free PowerBI account at https://powerbi.microsoft.com/en-us/
After registering, you will see the following page:
- 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.
- 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.
- 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.
More Information, visit https://www.qnap.com/en/how-to/tutorial/article/connect-arduino-yun-to-qnap-nas-via-qiot-suite-lite
Comments
Please log in or sign up to comment.