2020年5月21日 星期四

在768藝術空間裡遇見百香果煉銀網


撰稿:廖清平              攝影:廖清平              日期:2020年05月20日

        原以為梅雨季的五月天,應該又是陰雨綿綿。結果老天疼惜,竟放晴了,讓參加「在768藝術空間舉辦的南開科技大學文創系學生畢業主題展」活動的我們心情格外的好。
    早上九點半,我們準時從南開科技大學出發,不用十分鐘便到達目的地768空間。768空間是一個空間不大卻是精緻的所在,在這裡,南開科技大學文創系的學生正在做最後的整理。學生們發揮巧思與創意,展出的作品風格各異,卻處處看出他們的用心。有包裝設計組的米粒mili、產品設計組的幣燃.COINRING及嵌入茶韻、影視傳播組的Ilisin及明天x再見、桌由設計組的墨陽、立體造型組的悍將等等。
    在眾多作品中,由南開科技大學展出<教育部大學社會責任實踐計畫南投百香果資源永續之煉銀網平台>之相關百香果產品和周邊商品。產品包括:本草自然面膜、百香果蜜餞、手作葉拓化妝包及工具包等等。

               計畫總主持人林正敏副校長詳細的為各位蒞臨的長官貴賓一一介紹各產品以及該計畫的執行理念,與會的貴賓均表現出高度的興趣和讚嘆。

                 一顆小小的百香果,全身都是寶,好好利用,將可以更好幫助在地果農獲取更好的收入,也能提供給消費者優質的百香果,一兼二顧。
               本次展出時間2020年05月20日至06月02日止,歡迎大家撥空前往,相信一定會有滿滿收穫。

2020年5月10日 星期日

利用Python透過氣象開放資料平台取得百香果故鄉的氣象資料



2.資料(https://opendata.cwb.gov.tw/dataset/forecast?page=1)可以分成下列幾種:

  • 預報
  • 觀測
  • 地震海嘯
  • 氣候
  • 天氣警特報
  • 數值預報
  • 天文


3.資料下載排行排,如下圖:

4.我們會發現鄉鎮天氣預報最為熱門,使用說明可以參閱https://opendata.cwb.gov.tw/devManual/insrtuction。

5.首先您必須先申請帳號,https://pweb.cwb.gov.tw/CWBMEMBER3/register/authorization。
註冊完成後,您會收到中央氣象局會員註冊確認信,點擊 成為正式會員 後,就可以登入氣象開放資料平台。

6.登入後選擇會員資訊中的API授權碼,https://opendata.cwb.gov.tw/user/authkey,您就可取得您的授權碼:



7.平台提供很好的測試介面,https://opendata.cwb.gov.tw/dist/opendata-swagger.html。

8.我們來試試看第一個例子,點一下GET按鈕,再點Try it out,填入API授權碼,選擇南投縣,最後按下Excute鍵。

9.利用網址來讀取資料,
https://opendata.cwb.gov.tw/api/v1/rest/datastore/F-C0032-001?Authorization={your key}&format=JSON&locationName=%E5%8D%97%E6%8A%95%E7%B8%A3

10.接下來我們來看看台灣百香果故鄉-埔里的天氣。

11.在鄉鎮中填入埔里鎮,記得要按下Add item鍵。

12.最後按下執行Excute鈕

13.利用網址來取得資訊,https://opendata.cwb.gov.tw/api/v1/rest/datastore/F-D0047-023?Authorization={your key}&locationName=%E5%9F%94%E9%87%8C%E9%8E%AE

14.利用程式來取得百香果故鄉的氣象資料
1
2
3
4
5
6
7
8
9
import requests

r = requests.get(
'https://opendata.cwb.gov.tw/api/v1/rest/datastore/F-D0047-023?\
Authorization={your key}\
&locationName=%E5%9F%94%E9%87%8C%E9%8E%AE'
)

print(r.text)

執行結果:

15.利用https://jsoneditoronline.org/來看JSON結構。

16.程式

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import requests
import json

r = requests.get(
'https://opendata.cwb.gov.tw/api/v1/rest/datastore/F-D0047-023?\
Authorization={your key}\
&locationName=%E5%9F%94%E9%87%8C%E9%8E%AE'
)

j = json.loads(r.text)
print(j["records"]["locations"][0]["location"][0]["locationName"])

執行結果:
延伸文章:https://passionfruittaiwan.blogspot.com/2020/05/micropythonopenweather.html

2020年5月9日 星期六

利用MicroPython透過OpenWeather取得百香果故鄉的氣象資料

俗語說看天吃飯,這是農夫生活的寫照,隨著科技進步,天氣預測已經不在是一件困難的事。
取得天氣的網站:
國際組織OpenWeather:https://openweathermap.org/

1.註冊成為會員,網址:https://home.openweathermap.org/users/sign_up



2.收到確認信,請確認。

3.收到API-KEY的信,下圖塗掉即為敏哥上網申請的KEY。

4.測試,打開網頁,輸入下列網址,記得要換上您的KEY
http://api.openweathermap.org/data/2.5/weather?q=London,uk&APPID={your key}

5.選擇網站上Maps放大查詢百香果故鄉-埔里的氣象資料


6.改用URL查詢
https://api.openweathermap.org/data/2.5/weather?q=Buli,TW&units=metric&lang=zh_tw&appid={your key}

7.把上述資料,填入https://jsoneditoronline.org/,就可以觀察JSON格式

8. 使用IDLE撰寫讀取百香果故鄉氣象資料的程式,記得KEY要換成您申請的。

1
2
3
4
5
6
7
8
9
import requests

r = requests.get(
'https://api.openweathermap.org/data/2.5/weather?\
q=Buli,TW&units=metric&lang=zh_tw&\
appid={your key}'
)

print(r.text)

9.執行結果

10.轉換成json格式進行資料操作,記得KEY要換成您申請的。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import requests
import json

r = requests.get(
'https://api.openweathermap.org/data/2.5/weather?\
q=Buli,TW&units=metric&lang=zh_tw&\
appid={your key}'
)

j = json.loads(r.text)
weatherID = j["weather"][0]["id"]       # 天氣狀況代碼
weatherDesc = j["weather"][0]["description"] # 天氣狀況

print(weatherID)
print(weatherDesc)

print(r.text)

11.執行結果

12.使用upycraft工具來編輯ESP8266的程式
boot.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Complete project details at https://RandomNerdTutorials.com

try:
  import usocket as socket
except:
  import socket

from machine import Pin
import network

import esp
esp.osdebug(None)

import gc
gc.collect()

ssid = {your ssid}
password = {your password}

station = network.WLAN(network.STA_IF)

station.active(True)
station.connect(ssid, password)

while station.isconnected() == False:
  pass

print('Connection successful')
print(station.ifconfig())

led = Pin(2, Pin.OUT)

weather.py (本程式有參考旗標出版)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import network, urequests, ujson, machine
res = urequests.get(               # API 網址
    "https://api.openweathermap.org/data/2.5/weather?" +
    "q=" + "Buli" + ",TW" +      # 指定城市與國別
    "&units=metric&lang=zh_tw&" +  # 使用攝氏單位
    "appid=" +  # 以下填入註冊後取得的 API key
    {your key})

j = ujson.loads(res.text);         # 從 JSON 轉成字典
gLED = machine.Pin(12, machine.Pin.OUT) # 控制綠燈
rLED = machine.Pin(15, machine.Pin.OUT) # 控制紅燈
weatherID = j["weather"][0]["id"]       # 天氣狀況代碼
weatherDesc = j["weather"][0]["description"] # 天氣狀況
if weatherID < 800:                # 雨天
    rLED.value(1)                  # 亮紅燈
    gLED.value(0)
else:                              # 沒下雨
    rLED.value(0)                  # 亮綠燈
    gLED.value(1)
print("目前天氣:", str(weatherID))
print("代碼意義:", weatherDesc )

13.記得存檔並下載到ESP8266,執行結果


上圖就是使用ESP8266,用MicroPython 透過OpenWeather取得百香果故鄉的氣象資料,未來加上Line Bot就能用數百元成本設計一個可以自動傳送天氣資料給農夫。

延伸文章:https://passionfruittaiwan.blogspot.com/2020/05/python.html