當前位置:
首頁 > 最新 > Arduino Tian開發板:一個功能強大的天氣預報中心

Arduino Tian開發板:一個功能強大的天氣預報中心

每天都在出現新的連接設備。 Arduino攜手雲平台一起加入這場戰鬥,於是出現了一個新的挑戰者 - Arduino Tian!

使用python和經典Arduino框架,本教程將引導您將您的Arduino Tian開發板變成一個天氣預報中心。 但由於Lucky擴展板有那麼多感測器,所以涉及到的內容可能會更多些!

第一部分:所需的設備

● Arduino Tian開發板(https://store.arduino.cc/arduino-genuino/arduino-genuino-boards-modules/arduino-tian)

● Lucky擴展板 (https://www.amazon.com/Arduino-org-A000125-Arduino-Lucky-Shield/dp/B01F646GPW/)

● Micro-USB轉USB線纜(http://www.amazon.com/Anker-Android-Samsung-Motorola-Blackberry/dp/B00MLP6HLS)

● Micro-USB充電器(https://www.amazon.com/Motorola-Micro-USB-Charger-Discontinued-Manufacturer/dp/B004EYSKM8)

第二部分:配置Tian開發板

Tian開發板入門非常簡單。

本文的大部分內容將在Arduino操作系統中完成,但目前唯一可以與Lucky擴展板進行交互的有效方式是通過IDE實現。

我發現通過操作系統設置Tian的Arduino操作說明很容易。你可以在這裡閱讀:http://www.arduino.org/learning/ ... d-with-arduino-tian

以下是一個簡短的步驟總結:

1. 打開電源。您可以將其連接到您的計算機,或者其他設備;

2. 等待大約20秒;

3. 在您的計算機上,查找您的WiFi網路下的Arduino開發板。應該是類似於「Arduino-Tian - ******」

4. 連接到該開發板網路,然後在瀏覽器中導航到http://arduino.local

5. 應該會顯示一個要 求輸入密碼的頁面- 密碼是「arduino」;

6. 按照嚮導設置Tian的WiFi連接;

7. 一旦配置完成,連接到您給Tian設置的同一個WiFi,然後再次訪問http://arduino.local

您的Arduino操作系統現在應該可以使用了!

■ 使用Web IDE

我們在Arduino Web IDE中使用的主要工具是Terminal,可以在主菜單中的Utilities下找到。

所有我們需要做的是安裝一些工具,然後我們可以隨時從Weather Underground網站傳輸數據!

第三部分:Wunderground

溫度、露水、風塵、濕度、降水、壓力、紫外線指數、...隨時隨地都可以輕鬆的使用。 我們來學習如何使用Wunderground的超簡單API。

■如何使用Wunderground API

為了能夠使用Wunderground API,首先我們需要自己的API密鑰。獲取API密鑰可以很快實現,並且免費。

● 轉到http://www.wunderground.com/weather/api/?MR=1。

● 點擊「Sign Up for FREE」!

● 創建一個帳戶,然後單擊確認電子郵件中發送給您的鏈接來激活您的帳戶;

● 登陸

● 轉到Pricing並選擇免費的Stratus Plan(默認選擇)。您每天進行500個API調用,費用是$ 0。獲取Developer級別的API不需要信用卡。

● 點擊「Purchase Key」

● 填寫表單並提交以獲取您的API密鑰

您的密鑰看起來像這樣:0def10027afaebb7。保存。

您可以通過按照下列格式在您的瀏覽器中輸入URL,從而形成一個到Wunderground的API:

http://api.wunderground.com/api/YOUR_API_KEY/conditions/q/THE_DESIRED_STATE/THE_DESIRED_CITY.json

複製代碼

例如,要獲得加利福尼亞舊金山的天氣:

● http://api.wunderground.com/api/0def10027afaebb7/conditions/q/CA/San_Francisco.json

或者是倫敦的天氣

● http://api.wunderground.com/api/0def10027afaebb7/conditions/q/UK/London.json

或者是多倫多的天氣

● http://api.wunderground.com/api/0def10027afaebb7/conditions/q/canada/Toronto.json

我們來看看返回的內容:

{

"response": {

"version":"0.1",

"termsofService":"http://www.wunderground.com/weather/api/d/terms.html",

"features": {

"conditions": 1

}

}

, "current_observation": {

"image": {

"url":"//icons.wxug.com/graphics/wu2/logo_130x80.png",

"title":"Weather Underground",

"link":"http://www.wunderground.com"

},

"display_location": {

"full":"London, United Kingdom",

"city":"London",

"state":"",

"state_name":"United Kingdom",

"country":"UK",

"country_iso3166":"GB",

"zip":"00000",

"magic":"1",

"wmo":"03772",

"latitude":"51.47999954",

"longitude":"-0.44999999",

"elevation":"24.00000000"

},

"observation_location": {

"full":"London, ",

"city":"London",

"state":"",

"country":"UK",

"country_iso3166":"GB",

"latitude":"51.47750092",

"longitude":"-0.46138901",

"elevation":"79 ft"

},

"estimated": {

},

"station_id":"EGLL",

"observation_time":"Last Updated on October 23, 5:50 AM BST",

"observation_time_rfc822":"Fri, 23 Oct 2015 05:50:00 +0100",

"observation_epoch":"1445575800",

"local_time_rfc822":"Fri, 23 Oct 2015 06:13:53 +0100",

"local_epoch":"1445577233",

"local_tz_short":"BST",

"local_tz_long":"Europe/London",

"local_tz_offset":"+0100",

"weather":"Overcast",

"temperature_string":"50 F (10 C)",

"temp_f":50,

"temp_c":10,

"relative_humidity":"87%",

"wind_string":"From the Variable at 4 MPH",

"wind_dir":"Variable",

"wind_degrees":0,

"wind_mph":4,

"wind_gust_mph":0,

"wind_kph":6,

"wind_gust_kph":0,

"pressure_mb":"1022",

"pressure_in":"30.18",

"pressure_trend":"0",

"dewpoint_string":"46 F (8 C)",

"dewpoint_f":46,

"dewpoint_c":8,

"heat_index_string":"NA",

"heat_index_f":"NA",

"heat_index_c":"NA",

"windchill_string":"NA",

"windchill_f":"NA",

"windchill_c":"NA",

"feelslike_string":"50 F (10 C)",

"feelslike_f":"50",

"feelslike_c":"10",

"visibility_mi":"6.2",

"visibility_km":"10.0",

"solarradiation":"--",

"UV":"0","precip_1hr_string":"-9999.00 in (-9999.00 mm)",

"precip_1hr_in":"-9999.00",

"precip_1hr_metric":"--",

"precip_today_string":"0.00 in (0.0 mm)",

"precip_today_in":"0.00",

"precip_today_metric":"0.0",

"icon":"cloudy",

"icon_url":"//icons.wxug.com/i/c/k/nt_cloudy.gif",

"forecast_url":"http://www.wunderground.com/global/stations/03772.html",

"history_url":"http://www.wunderground.com/history/airport/EGLL/2015/10/23/DailyHistory.html",

"ob_url":"http://www.wunderground.com/cgi-bin/findweather/getForecast?query=51.47750092,-0.46138901",

"nowcast":""

}

}

複製代碼

看看所有這些美好的天氣數據。我們只需要編寫腳本進行解析,然後將其發送到基於Web的儀錶板上。首先,我們一起設置數據的目的地 - >Initial State。

Initial State

我們希望將我們所有的天氣數據都傳輸到雲服務,並使用這些服務將我們轉到一個可以從筆記本電腦或移動設備訪問的漂亮儀錶板。我們的數據需要一個目的地。

這裡我們要使用Initial State。

步驟1:註冊Initial State帳戶

轉到https://app.initialstate.com/#/register/,並創建一個新帳戶。

步驟2:安裝ISStreamer

將Initial State Python模塊安裝到您的Tian開發板中。為了安裝模塊,我們需要先安裝軟體包管理器pip。

在Arduino Web IDE的終端,運行以下命令:

opkg install python-openssl

opkg install distribute

easy_install pip

pip install ISStreamer

複製代碼

注意:如果安裝發行版時遇到問題,可能需要更改您的opkg軟體包列表端點。可以查看這個帖子如何做的:https://github.com/aws/aws-iot-device-sdk-arduino-yun/issues/26

步驟3:訪問密鑰

每次創建數據流時,該訪問密鑰將將該數據流引導到您的帳戶(所以不要與任何人共享您的密鑰)。

步驟4:運行示例

創建一個名為stream.py的Python腳本(可以使用vi、nano或CodeMirror),其中包含以下內容:

import time

from ISStreamer.Streamer import Streamer

streamer = Streamer(bucket_name="Stream Example Tian", bucket_key="arduinotian", access_key="Your_Access_Key")

streamer.log("My Messages", "Stream Starting")

while True:

streamer.log("My Messages","on")

time.sleep(5)

streamer.log("My Messages","off")

time.sleep(5)

複製代碼

請確保將您的Initial State訪問密鑰添加到第4行

保存並運行測試腳本,確保我們可以創建一個數據流到您的Initial State帳戶。運行以下命令:

$ python stream.py

複製代碼

步驟5:成果

在瀏覽器中返回到您的Initial State帳戶。一個名為「Stream Example Tian」的數據存儲籃應該顯示在日誌的左側(您可能需要刷新頁面)。單擊數據存儲籃,然後單擊Waves圖標查看測試數據。

您可能需要通過Waves教程來熟悉如何使用此數據可視化工具。接下來,查看Tiles中的數據,以儀錶板的形式查看相同的數據。

您現在可以開始從Wunderground獲得實時數據流。

Wunderground儀錶板

現在是最有趣的部分。我們準備開始使用Wunderground API來創建天氣儀錶板,並捕獲我們選擇的天氣歷史記錄。為此,我們將使用Python腳本:https://github.com/initialstate/ ... TianWunderground.py。該腳本只需使用您的API密鑰調用Wunderground API,並在指定的時間間隔內檢索天氣信息。它還會將該數據傳輸到您的Initial State帳戶,這將允許您創建Wunderground儀錶板。

也可以將此腳本複製到您的Tian開發板(我建議使用CodeMirror),或通過Github存儲庫來訪問。您可以通過在終端中輸入以下內容來執行此操作:

opkg install unzip

curl -l -k https://codeload.github.com/initialstate/arduino-tian-weather-hub/zip/master > archive.zip

unzip archive.zip -d .

mv arduino-tian-weather-hub-master arduino-tian-weather-hub

rm -f archive.zip

cd arduino-tian-weather-hub

複製代碼

從這裡,您將可以訪問我們運行的python文件來創建我們的天氣儀錶盤。

在運行之前,您需要設置所需的參數並插入密鑰。 使用Nano打開TianWunderground.py文件,輸入以下內容:

nano TianWunderground.py

複製代碼

然後編輯腳本頂部附近的部分:

# --------- User Settings ---------

STATE = "CA"

CITY = "San_Francisco"

WUNDERGROUND_API_KEY = "PLACE YOUR WUNDERGROUND API KEY HERE"

BUCKET_NAME = ":partly_sunny: " + CITY + " Weather"

BUCKET_KEY = "tianweatherhub"

ACCESS_KEY = "PLACE YOUR INITIAL STATE ACCESS KEY HERE"

MINUTES_BETWEEN_READS = 15

METRIC_UNITS = False

# ---------------------------------

複製代碼

您需要設置所需的狀態和城市。您還必須插入您的Wunderground API密鑰和您的Intial State帳戶訪問密鑰,否則您的數據不會去任何地方。 MINUTES_BETWEEN_READS參數將設置您的腳本輪詢Wunderground API以獲取天氣信息的頻率。 15分鐘是一個很好的間隔長期。為了短期測試,您可以將其設置為0.5分鐘。 METRIC_UNITS選項允許您選擇華氏/攝氏度、MPH / KPH等。

一旦設置好參數,就可以運行腳本了:

python TianWunderground.py

複製代碼

如果您希望長時間不間斷運行此腳本,可以使用nohup命令(不掛斷),如下所示:

opkg install coreutils-nohup

nohup python TianWunderground.py &

複製代碼

這個腳本將不僅僅是讀取天氣數據並將其發送到Initial State。該腳本將利用Initial State工具中的表情符號支持,使儀錶板更加性感。您可以看到用於從current_observation - >icon state獲取天氣狀態的邏輯,並將其轉換為weather_icon函數中的表情符號。在wind_dir_icon功能中的moon_icon功能和風向的月相相似。

轉到您的Initial State帳戶並查看您的數據。上述儀錶板的屏幕截圖是在以15分鐘間隔運行的數據收集9天後拍攝的。您可以通過使用每個圖塊右上角的cog圖標更改圖表類型並右鍵單擊圖塊來調整大小/移動圖形,來編輯儀錶板。

該項目的下一步是從我們自己的感測器開始收集天氣數據。


喜歡這篇文章嗎?立刻分享出去讓更多人知道吧!

本站內容充實豐富,博大精深,小編精選每日熱門資訊,隨時更新,點擊「搶先收到最新資訊」瀏覽吧!


請您繼續閱讀更多來自 一板網電子技術論壇 的精彩文章:

基於Arduino開發板的光學指紋識別模塊指南

TAG:一板網電子技術論壇 |