close

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.


1. Configure your devices


1.1 Download Arduino IDE



1.2 Configure and test your devices


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

  • Log in with the username "root" and your password. The default password is "arduino".

  • Install PIP and MQTT Library by entering the following commands.


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 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.

All these elements provide user a complete IoT Application environment.



If this is your first time using QIoT Suite Lite, click "Quick Setup Wizard" to start the quick setup wizard. After reading the introduction, click "Next".



 



  • Create a New IoT application

    • Enter the IoT Application name (for example: "app_1").

    • The Rule name and Dashboard name will be automatically generated based on the IoT Application Name.

    • Click "Next".



  • Click "+ Add" to add this application’s device.

  • Click "+Add", In "Add Things":

    • Enter a name for your device (for example: "arduino") and enter 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.



  • 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".

  • 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 (such as: PuTTY) on your PC. Connect to your device using SSH and enter the folder where the smaple code is stored (for example: /home/root/bundle).

  • To install sample code dependencies, enter the following commands:

  • Run the sample code

  • The device will send a message to topic "temp" (or the topic you defined).


3.2 Another protocol



  • Click "Connect a Device".

  • You can select another protocol.

  • Connect to your device using SSH, and enter the following commands:


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 a sequence of registration, the page will lead you to below page, you can press "My workspace", and "skip for now" button appear. You could click "skip for now "to start create dataset.


4.2 Setup your streaming dataset API



  • Create "Datasets"

    • Click "Create" in the top-right corner

    • Click "Streaming dataset"



  • Select "API", the source of your data, and click "Next".

  • Define your values from stream (e.g., temp, max, min), and you will get a JSON result in the textbox. We will use this JSON code to push data to the QIoT Suite Lite 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 NodeRED’s nodes in IoT application



  • Create 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 drop and drag "http request" node and connect to tail of "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 tile 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 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.


Please visit QNAP github for QIoT Suite Lite sample code "QNAP-Github"
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 tttt 的頭像
    tttt

    觀察筆記

    tttt 發表在 痞客邦 留言(0) 人氣()