LinkIt Smart 7688 Duo and MCS basics

90
LinkIt Smart 7688 Duo 物物物 IoT 物物 物物物物物 CAVEDU 物物物 151229

Transcript of LinkIt Smart 7688 Duo and MCS basics

Page 1: LinkIt Smart 7688 Duo and MCS basics

LinkIt Smart 7688 Duo

物聯網 IoT 體驗夜懶人包載點

CAVEDU 曾吉弘151229

Page 2: LinkIt Smart 7688 Duo and MCS basics

硬體介紹

Page 5: LinkIt Smart 7688 Duo and MCS basics

開發環境比一比7688• Nodejs• Python• C/C++

7688 Duo• Nodejs• python• Arduino• C/C++

Page 7: LinkIt Smart 7688 Duo and MCS basics

可搭配的擴充板

Page 8: LinkIt Smart 7688 Duo and MCS basics

POWER

USB HOST

MPU / Wifi / MCU

Micro SD 卡插槽在背面WiFi 天線

Page 10: LinkIt Smart 7688 Duo and MCS basics

接上電源開始吧

Page 11: LinkIt Smart 7688 Duo and MCS basics

Arduino IDE setupWi-Fi setup

Page 12: LinkIt Smart 7688 Duo and MCS basics

Arduino IDE 下載1. 請下載 Arduino 1.6.4 以後的版本2. 從 board manager 安裝 7688 Duo3. 安裝 driver

• 網頁版教學請按我

Page 13: LinkIt Smart 7688 Duo and MCS basics

在 Arduino IDE 偏好設定中貼上這個連結• File / Preferences• http://download.labs.mediatek.com/

package_mtk_linkit_smart_7688_test_index.json

Page 14: LinkIt Smart 7688 Duo and MCS basics

在選單中看到 7688 ,按 Install

• Tools / Board / Boards Manager

Page 15: LinkIt Smart 7688 Duo and MCS basics

完成之後就可以看到 7688 了• 在很下面…

Page 16: LinkIt Smart 7688 Duo and MCS basics

如果板子在網路上也可以抓到

Page 17: LinkIt Smart 7688 Duo and MCS basics

安裝 driver ,請把 7688 接上電腦• 在 Windows 裝置管理員中會被歸類在 [ 其他裝置 ] 中。• linkit_smart_7688.inf

在懶人包裡面,指到這個位置即可

Page 18: LinkIt Smart 7688 Duo and MCS basics
Page 19: LinkIt Smart 7688 Duo and MCS basics

安裝完成後續操作上與一般 Arduino 開發板是類似的

Page 20: LinkIt Smart 7688 Duo and MCS basics

Wi-Fi LED 狀態

Page 21: LinkIt Smart 7688 Duo and MCS basics

AP mode 連到 7688 但不連外

Page 22: LinkIt Smart 7688 Duo and MCS basics

AP mode 連線• 連上

LinkIt_Smart_7688_XXXXXX 這個 AP , X 代表 MAC addr 後六碼

• 在瀏覽器輸入http://mylinkit.local即可進入主控台

• 預設帳號 root• 密碼自行設定

Page 23: LinkIt Smart 7688 Duo and MCS basics
Page 24: LinkIt Smart 7688 Duo and MCS basics

基礎組態設定

AP mode 預設 IP

改名字 , 由於 mDNS 的關係,請勿使用底線 _. EX: mylinkit_001.local <- 不行

Page 25: LinkIt Smart 7688 Duo and MCS basics

目前最新 FW 0.9.2

Page 26: LinkIt Smart 7688 Duo and MCS basics

Station mode• 切換到 Station mode 即可讓 7688 連到外部網路,之後只要在同一網路下的裝置都可連到它。

Page 27: LinkIt Smart 7688 Duo and MCS basics

再次登入後可看到 IP 位址換了

連上外網之後的 IP

Page 28: LinkIt Smart 7688 Duo and MCS basics

如果 http://mylinkit.local 連不上怎麼辦• 可能是 Windows 的 mDNS 問題• 如果有別台電腦的話,試著用別台電腦來看看是否可登入來找到 IP • 都不行的話,請用 IP 掃描工具來看看您的

7688 跑哪去了。 EX: Free IP Scanner)

Page 29: LinkIt Smart 7688 Duo and MCS basics

連上外網之後• 就不會再看到 7688 AP 了。• 一樣用 mylinkit.local 或 <IP> 來連上它• 先更新一遍

– $ opkg update– $ opkg install nano ( 好用的文字編輯器 )– $ opkg install fswebcam ( 拍照小程式 )

Page 31: LinkIt Smart 7688 Duo and MCS basics

如何回到 AP Mode

• 按住 Wi-Fi 按鈕 5 秒鐘即可從 station mode 回到 AP mode

Page 32: LinkIt Smart 7688 Duo and MCS basics

如何 Reset LinkIt Smart 7688

透過板子上的按鈕• 插上電源後請稍等約 2 分鐘等開機• 按著板子上的 Wifi 鈕 20 秒。• 放開後,就會開始看到橘色燈閃爍代表 reset 中• 靜置一段時間後,觀察是否有新的 LinkIt_Smart_7688_XXX

XXX  之 AP 出現,若有代表即完成。

透過 WebUI• 進去 WebUI 後,點選頁面最下方的 [Reset]• 稍後 2~3 min 即可完成。

Page 33: LinkIt Smart 7688 Duo and MCS basics

如果以上通通不行…• 請用 USB 隨身碟重燒吧… QQ

• https://www.gitbook.com/read/book/mediatek-labs/linkit-smart-7688?key=84149961

• 4.1 Update Firmware with USB Drive

Page 34: LinkIt Smart 7688 Duo and MCS basics

如何自定義 AP SSID

• 準備一個 USB 隨身碟與 micro USB 轉接線• 於 USB 根目錄下新增一個名為 [lks7688.cfg]

ASCII 文字檔,檔案內容:– wifi_ssid=THE_AP_SSID– wifi_key=THE_AP_PASSWORD

• 將 USB 隨身碟插入 7688 USB host 之後開機。– 按住 WiFi  鈕– 按下一次 MPU reset 鈕– 在 WiFi LED 亮起之後放開 WiFi  鈕

• 影片

Page 35: LinkIt Smart 7688 Duo and MCS basics

SSH 登入 7688

• Windows: Putty 或 TeraTerm• MAC / Linux: Terminal $ [email protected] 或 $ root@<7688IP>

Page 36: LinkIt Smart 7688 Duo and MCS basics

開始寫程式啦!

Page 37: LinkIt Smart 7688 Duo and MCS basics

First nodejs

• $ vim app.js 或 $ nano app.js ( 編輯 )• $ node app.js (執行 )

Page 38: LinkIt Smart 7688 Duo and MCS basics

First python

• $ vim test.py 或 $ nano test.py ( 編輯 )• $ python test.py (執行 )

Page 39: LinkIt Smart 7688 Duo and MCS basics

nodejs LED blinking

• $ vim led.js 或 $ nano led.js ( 編輯 )• $ node led.js (執行 )• Wifi 狀態 LED 即為

GPIO #44 pin• 0 = HIGH, 1 = LOW

Page 40: LinkIt Smart 7688 Duo and MCS basics

MediaTek Cloud SandBox

https://mcs.mediatek.com/resources/latest/tutorial/

7688_tutorial

Page 41: LinkIt Smart 7688 Duo and MCS basics

MediaTek Cloud Sandbox (MCS)

Page 42: LinkIt Smart 7688 Duo and MCS basics

MCS 主要功能• 雲端平台,執行程式• 例: Google App Engine、 Amazon Web

Services、Microsoft Azure• 提供網頁介面,讓你「點按滑鼠」就能建立雲端程式• 提供 API 程式存取介面• 提供網頁介面,觀看與控制各種資料

Page 43: LinkIt Smart 7688 Duo and MCS basics

MCS 其他功能• 通知( Notification),當某資料符合特定條件時,寄送電子郵件• 使用者權限( User Privilege),設定開發成員的存取修改權限• FOTA( Firmware Over The Air),版本控管,韌體經由無線傳輸自動更新

Page 44: LinkIt Smart 7688 Duo and MCS basics

目標• 到 MCS註冊帳號• 建立網頁應用程式( web application)• 透過MCS REST API 進行溝通• LinkIt 家族開發板、手機、瀏覽器

Page 45: LinkIt Smart 7688 Duo and MCS basics

範例• 從雲端控制板子內建的 LED• LED:想像成家裡的燈• 為什麼從雲端?不能直接連線嗎?

Page 46: LinkIt Smart 7688 Duo and MCS basics
Page 47: LinkIt Smart 7688 Duo and MCS basics

MCS 重要觀念• Prototype ,想像為程式樣板• Data Channel ,帶有時間資訊的資料串• Data Channel Id:對應的資料接口• Datapoint:每筆上傳的資料• Test Device ,想像為實際執行後的程式• DeviceId、 DeviceKey:用這個來鎖定裝置• 例: LED 控制器、溫濕度感測站

Page 48: LinkIt Smart 7688 Duo and MCS basics
Page 50: LinkIt Smart 7688 Duo and MCS basics

MCS Dashboard(儀表板)

Page 51: LinkIt Smart 7688 Duo and MCS basics

MCS 重要選項• Console:主控台• Development:建立 Prototype、新增修改 Data

channel、查詢 Data channel Id• Test Devices:查詢 DeviceId、 DeviceKey• Resources:教學文件、參考資料• Resources:常見問題、論壇、回饋

Page 52: LinkIt Smart 7688 Duo and MCS basics

範例:控制 LED並檢視狀態程式: mcsled.js

Page 53: LinkIt Smart 7688 Duo and MCS basics

流程1. 建立 Prototype2. 依照所需功能,新增 Data channel ,記下 Data channel Id3. 建立 Test device ,記下 DeviceId 與

DeviceKey

Page 54: LinkIt Smart 7688 Duo and MCS basics

建立 Prototype• Prototype name: LED

Manager ( 或自定 )• Prototype version: 1.0

• Hardware platform:LinkIt Smart 7688 (MT7688)

• Industry:自定• Application:自定

Page 55: LinkIt Smart 7688 Duo and MCS basics
Page 56: LinkIt Smart 7688 Duo and MCS basics

Data channel 資料頻道• Controller 型:可控制• Display 型:僅能顯示

Page 57: LinkIt Smart 7688 Duo and MCS basics

目前有哪些類型?Controller• ON/OFF• Category• Integer• Float• Hex• String• GPS• GPIO• PWM• Analog• GamePad

Display• ON/OFF• Category• Integer• Float• Hex• String• GPS• GPIO• PWM

Page 58: LinkIt Smart 7688 Duo and MCS basics

ON/OFF

• 控制高低電位。 LED、繼電器等• 顯示裝置的電位高低狀態

Page 59: LinkIt Smart 7688 Duo and MCS basics

Category

• 讓系統可在 2~5 個狀態之間切換

Page 60: LinkIt Smart 7688 Duo and MCS basics

Integer / Float / Hex

• 傳整數 /浮點數 /16 進位值給裝置• 顯示裝置的數值參數。各種感測器

Page 61: LinkIt Smart 7688 Duo and MCS basics

String

• 傳送字串給裝置 / 顯示裝置回傳的字串

Page 62: LinkIt Smart 7688 Duo and MCS basics

GPS (Google Map~)

• 傳送經度、緯度、標高給裝置• 顯示裝置的 GPS座標

Page 63: LinkIt Smart 7688 Duo and MCS basics

日期區間搜尋

Page 64: LinkIt Smart 7688 Duo and MCS basics

GPIO

• 控制 /顯示裝置的 GPIO 腳位高低電位

Page 65: LinkIt Smart 7688 Duo and MCS basics

PWM

• 控制 /顯示裝置的 PWM腳位,可指定範圍

Page 66: LinkIt Smart 7688 Duo and MCS basics

Analog ( 只有 Controller)

• 以滑桿方式送出指定範圍之內的數值

Page 68: LinkIt Smart 7688 Duo and MCS basics

新增 Data channel (1/2)

• 請新增一個 Controller 型• Data channel name: LED_Control• Data channel Id: LED_Control重要!將用於程式碼內• Data type: ON/OFF

• 您當然可以使用別的名稱,只要一致就好

Page 69: LinkIt Smart 7688 Duo and MCS basics
Page 70: LinkIt Smart 7688 Duo and MCS basics

建立 Test device• 一個 prototype 可有多個 Test device• Device name: LED Manager ( 或自定 )

Page 71: LinkIt Smart 7688 Duo and MCS basics

Prototype List 頁面• 這樣代表 test1229 這個 prototype 有一個 test device

Page 72: LinkIt Smart 7688 Duo and MCS basics

請到 Development/Test Devices

• 找出您剛剛建立的 test device: LED Manager

Page 73: LinkIt Smart 7688 Duo and MCS basics

DeviceId / DeviceKey

• 這兩筆資料要填在所有要與 MCS 溝通的程式中

• Data channel Id 也不能錯喔:LED_Control

Page 74: LinkIt Smart 7688 Duo and MCS basics

MCS + LED 閃爍nodejs 與 python 各自要安裝模組

請打開本日資料夾的mcsled(js).txt / mcsled(py).txt複製到 7688 的 nano 裡即可

Page 75: LinkIt Smart 7688 Duo and MCS basics

MCS 新增 channel 完成設定 nodejs 與 python 環境

Page 76: LinkIt Smart 7688 Duo and MCS basics

MCSjs modules7688 需要用到 MCSjs module ,這是一個 HTTP request library 。使用 npm 即可安裝。1. 請確認您的 7688 連上網路 (station mode) 後

SSH 登入它2. 建立一個名為 app 的資料夾: $ mkdir app 3. 切換到 app 下: $ cd app 4. npm 初始化: $ npm init5. 使用 npm 來安裝模組 (需要一點時間 ): $ npm install mcsjs

Page 77: LinkIt Smart 7688 Duo and MCS basics

安裝完成• /app 下應該會有一個 node_modules 的資料夾,稍後執行的 mcsled.js 需位於同一資料夾下才能順利執行

Page 78: LinkIt Smart 7688 Duo and MCS basics

檢查 npm 版本$ npm –v 可看到目前的版本為 2.11.3

Page 79: LinkIt Smart 7688 Duo and MCS basics

mcsled.js

• 打開下載資料夾中的 mcsled(js).txt• 然後在 7688 terminal 中,進入剛剛建立的 /app 資料夾,輸入 $ nano mcsled.js

• 在 nano 中貼入內容,並修改 deviceId / deviceKey ,如下頁

Page 80: LinkIt Smart 7688 Duo and MCS basics

程式 mcsled.js修改處var myApp = mcs.register({ deviceId: 'ABC123', deviceKey: 'XYZ123', });

以上紅字換成您 test device 的資訊

Page 81: LinkIt Smart 7688 Duo and MCS basics

Python 要先安裝 request 模組• $ pip install requests

• 然後 $nano mcsled.py 來編輯檔案

Page 82: LinkIt Smart 7688 Duo and MCS basics

程式 mcsled.py修改處DEVICE_INFO = { 'device_id' : 'YOUR_DEVICE_ID',

'device_key' : 'YOUR_DEVICE_KEY' }

以上紅字換成您 test device 的資訊

Page 83: LinkIt Smart 7688 Duo and MCS basics

執行吧!• 執行時可看到 MCS test device 名稱左邊亮起綠燈,代表裝置已與 MCS 連通• 拿起 Android 裝置打開 MCS app 來玩吧

Page 84: LinkIt Smart 7688 Duo and MCS basics

執行畫面

Page 85: LinkIt Smart 7688 Duo and MCS basics

影像串流功能

Page 86: LinkIt Smart 7688 Duo and MCS basics

好棒好棒• 7688 / 7688 Duo 已經安裝了

mjpgstreamer 套件,只要下指令就可以在瀏覽器中看到即時影像喔!• 目前可用的 UVC class webcam 請點我• 例如 Logitech C170, C310 等

Page 87: LinkIt Smart 7688 Duo and MCS basics

如何確定裝置已抓到• $ cd /dev• $ ls • 看到 /video0 就是了

Page 88: LinkIt Smart 7688 Duo and MCS basics

影像串流• 在 termninal 輸入: $ mjpg_streamer -i "input_uvc.so -d

/dev/video0 -r 640x480 -f 25" -o "output_http.so -p 8080 -w /www/webcam" &

• 如果出現 v4l2 Fatal Error 或類似訊息請重新啟動 7688

Page 89: LinkIt Smart 7688 Duo and MCS basics

看到影像了嗎?• 完成後直接開啟

– http://mylinkit.local:8080/stream.html– http://<7688IP>:8080