[ Intel Edison ] 傳送 Sensor Data 到 WoT.City

與 IoT 相關的雲端服務為數眾多,例如:ThingSpeakWoT.CityAWSIBM BluemixMediaTek MCS 等,並在透過這些雲端服務可在對資料進行資料視覺化、資料分析與其它的應用,而本文透過 Intel Edison 將 Sensor 資料傳送到 WoT.City 。

Imgur

執行步驟

Imgur

前置準備作業

  1. 準備 Intel® Edison 開發板

  2. 準備 Arduino Breakout Board

  3. 準備 溫度感應器

  4. 組裝 Intel Edison 、 Arduino Breakout Board 與 溫度感應器 並連接到電腦 ( 溫度感應器接 A0 )

  5. 安裝 IDE ( Sublime Text or Visual Studio Code )

  6. Windows 平台,請安裝 Putty 與 FileZilla
    http://oranwind.org/-linkit/

Intel Edison 與 Arduino Breakout Board 連接圖

Imgur

WoT.City 端

  • Step 1. 到 WoT.City 網站申請帳號

https://wotcity.com/

  • Step 2. 登入 WoT.City 網站 Imgur

  • Step 3. 點擊 DEVICE MANAGE

  • Step 4. 點擊 Launch New Device Imgur

  • Step 5. 產生 Physical Object Imgur

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);

Imgur

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 執行畫面 Imgur

  • 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 執行畫面 Imgur

GitHub

IoT Cloud

List of blogs

Archer

Having being a full stack engineer. Experience with C, Python, Go, Swift, JavaScript, Node.js, Linkit 7697, Linkit Smart 7688, Raspberry Pi, ARM mbed, IoT solutions. Contact us : [email protected]

ALL RIGHTS RESERVED. COPYRIGHT © 2016. Designed and Coded by Makee.io