與 IoT 相關的雲端服務為數眾多,例如:ThingSpeak、WoT.City、AWS、IBM Bluemix、MediaTek MCS 等,並在透過這些雲端服務可在對資料進行資料視覺化、資料分析與其它的應用,而本文透過 Intel Edison 將 Sensor 資料傳送到 WoT.City 。
執行步驟
前置準備作業
準備 Intel® Edison 開發板
準備 Arduino Breakout Board
準備 溫度感應器
組裝 Intel Edison 、 Arduino Breakout Board 與 溫度感應器 並連接到電腦 ( 溫度感應器接 A0 )
安裝 IDE ( Sublime Text or Visual Studio Code )
Windows 平台,請安裝 Putty 與 FileZilla
http://oranwind.org/-linkit/
Intel Edison 與 Arduino Breakout Board 連接圖
WoT.City 端
- Step 1. 到 WoT.City 網站申請帳號
Step 2. 登入 WoT.City 網站
Step 3. 點擊 DEVICE MANAGE
Step 4. 點擊 Launch New Device
Step 5. 產生 Physical Object
Intel Edison 端
- Step 1. 讀取 Sensor Data
#!/usr/bin/python
import pyupm_grove as grove
import websocket
import datetime
import time
temp = grove.GroveTemp(0)
print temp.name()
websocket.enableTrace(True)
ws = websocket.create_connection("ws://wot.city/object/57cad2809453b2446f0007de/send")
while True:
celsius = temp.value()
print "%d degrees Celsius," % (celsius)
t = time.time();
date = datetime.datetime.fromtimestamp(t).strftime('%Y%m%d%H%M%S')
vals = "{\"date\":\""+date+"\",\"temperature\":"+ str(celsius)+"}"
ws.send(vals);
time.sleep(1);
Step 2. 將 Python Code 傳送到 Intel Edison
Windows 用戶請參考 傳送檔案與登入到開發板
Step 3. 安裝相關套件於 Intel Edison
1. update opkg & install wget & disable bridge
opkg update
opkg install wget
2. install setuptools
curl https://bootstrap.pypa.io/ez_setup.py -k -o - | python
3. install six
wget --no-check-certificate https://pypi.python.org/packages/source/s/six/six-1.10.0.tar.gz
tar zxvf six-1.10.0.tar.gz
cd six-1.10.0
python setup.py install
4. install Websocket
wget --no-check-certificate https://pypi.python.org/packages/source/w/websocket-client/websocket_client-0.32.0.tar.gz
tar zxvf websocket_client-0.32.0.tar.gz
cd websocket_client-0.32.0
python setup.py install
- Step 4. 執行剛傳到 Intel Edison 中的 Python Code
python 檔名.py
Step 5. Console 執行畫面
Step 6. 從 WoT.City 取得資料
import websocket
websocket.enableTrace(True)
ws = websocket.create_connection("ws://wot.city/object/57cad2809453b2446f0007de/viewer")
while True:
result = ws.recv()
print "Received '%s'" % result
- Step 7. 執行 Python Code
python 檔名.py
- Step 8. Console 執行畫面