[ Linkit Smart 7688 ] 傳送 Sensor Data 到 WoT.City

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

Imgur

執行步驟

Imgur

前置準備作業

  1. 準備 Linkit Smart 7688 Duo 開發板

  2. 準備 Arduino Breakout for LinkIt Smart 7688 Duo

  3. 準備 Grove - Temperature & Humidity Sensor

  4. 將 Linkit Smart 7688 Duo 與 Arduino Breakout for LinkIt Smart 7688 Duo 組裝、Grove - Temperature & Humidity Sensor 裝到 A0 的位置並將 Linkit Smart 7688 Duo 連接至電腦

  5. 安裝 Arduino IDE (version: 1.6.6)
    https://www.arduino.cc/en/Main/OldSoftwareReleases

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

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

Linkit Smart 7688 Duo 與 Grove - Temperature & Humidity Sensor 連接圖

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

Linkit Smart 7688 Duo - MCU ( Arduino ) 端

  • Step 1. 透過 MCU 讀取 Sensor Data
// MCU To MPU
#include <Bridge.h>

// DHT
#include "DHT.h"
#define DHTPIN A0
#define DHTTYPE DHT11 
DHT dht(DHTPIN, DHTTYPE);

void setup() {  
  Serial.begin(9600); 
  dht.begin();
  Bridge.begin();
}

void loop() {  
  // Get Temperature and Humidity
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  // Display Temperature and Humidity Value
  Serial.print("DHT-Humidity: "); 
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("DHT-Temperature: "); 
  Serial.print(t);
  Serial.println(" *C\t");

  // MCU To MPU
  Bridge.put("Humidity", String(h));
  Bridge.put("Temperature", String(t));

  delay(1000); //每秒回傳一次資料
}

Imgur

Linkit Smart 7688 Duo - MPU ( Python ) 端

  • Step 1. 透過 Python 讀取 MCU Sensor Data
import time  
import sys  
import websocket  
import datetime

sys.path.insert(0, '/usr/lib/python2.7/bridge/')  
from bridgeclient import BridgeClient as bridgeclient

value = bridgeclient()

websocket.enableTrace(True)  
ws = websocket.create_connection("ws://wot.city/object/57cad2809453b2446f0007de/send")

while True:  
    h0 = value.get("Humidity")
    t0 = value.get("Temperature")
    print "Humi: " + h0
    print "Temp: " + t0

    t = time.time();
    date = datetime.datetime.fromtimestamp(t).strftime('%Y%m%d%H%M%S')

    vals = "{\"date\":\""+date+"\",\"temperature\":"+t0+",\"h\":"+h0+"}"

    time.sleep(1);
    ws.send(vals);
    print vals;

Imgur

  • Step 2. 將 Python Code 傳送到 Linkit Smart 7688 Duo

  • Step 3. 安裝相關套件於 Linkit Smart 7688 Duo

1. update opkg & install wget & disable bridge  
opkg update  
opkg install wget  
uci set yunbridge.config.disabled=0  
uci commit  
reboot

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. 執行剛傳到 Linkit Smart 7688 Duo 中的 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
List of blogs

Archer

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

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