ThingSpeak™ is an IoT analytics platform service that allows you to aggregate, visualize and analyze live data streams in the cloud. ThingSpeak provides instant visualizations of data posted by your devices to ThingSpeak. With the ability to execute MATLAB® code in ThingSpeak you can perform online analysis and processing of the data as it comes in. ThingSpeak is often used for prototyping and proof of concept IoT systems that require analytics.
申請 ThingSpeak IoT 平台免費使用帳號,建立要接收 ESP8266 上傳感測資料之 channel & fields。以瀏覽器工具,練習使用 ThingSpeak API 傳送資料至ThingSpeak IoT 平台
這裡要先到個人 email 信箱去收信,點擊信件中確認 email 的連結
email 確認完成,回到剛剛的註冊頁去
提供密碼,密碼須滿足下面條件
Between 8-50 characters
At least 1 upper and lower case letter
At least 1 number
註冊完成
提供 Channel 資料,假設這裡要記錄三種感測數據,就啟用三個 Fields
網路上查桃園市經緯度
Decimal latitude and longitude coordinates for Taoyuan City (Taiwan): 24.99368, 121.29696
建立的 Channel,都有獨特的 Channel ID。
紀錄下 Channel ID,使用 HTTP API 讀寫 Channel 會使用此參數,設計控制板程式也會使用此參數
初始預設是僅供個人有瀏覽權限。到 Private View 可以設定每個 Field 的參數。
Channel ID: 1408098
設定 Field 參數
設定 Field 2 參數
設定 Field 3 參數
要傳送數據到 ThingSpeak 或從 ThingSpeak 個人 Channel 讀取數據,需要專屬的金鑰(API Key),API Key 需紀錄保存。任何人只要有 API Key 就可以將資料寫入/讀出你的 Channel 中
紀錄下寫入資料時使用之 Write API Key 與 讀取資料時使用之 Read API Key。
NodeMCU 寫入/讀取資料時,分別會使用到 Write API Key/Read API Key。
設定共享(Public),可允許任何人瀏覽你的 Channel
設定共享(Public),允許特定人(提供 Email 帳號)瀏覽你的 Channel
設定分享後,在 Public View 就會看到分享的 Channel,Access 會由 Private 更改為 Public
修改 Public View 的 Field 參數:Public View 的 Field 參數與 Private View 是獨立的。
各 Field 設定參數與 Private View 相同
ThingSpeak REST API 使用語法,參考網站提供的 REST API 使用說明
依網頁說明 HTTP GET 更新 channel 中 field1 資料,API 語法可使用如下三種:
https://api.thingspeak.com/update?api_key=[Write API Key]&field1=xxx
回傳寫入資料第?筆數(只回傳資料點數)
https://api.thingspeak.com/update.json?api_key=[Write API Key]&field1=xxx
回傳寫入資料第?筆數( json 格式)
https://api.thingspeak.com/update.xml?api_key=[Write API Key]&field1=xxx
回傳寫入資料第?筆數( xml 格式)
這裡以第一種 API 語法實作
先找出要寫入 channel 的 Write API Key,例如:EH94XBVULOF80XTC
開瀏覽器,網址輸入 https://api.thingspeak.com/update?api_key=EH94XBVULOF80XTC&field1=666 ,按 ENTER
收到 ThingSpeak 回應 1
每隔 15 秒以上,依序
網址輸入 https://api.thingspeak.com/update?api_key=EH94XBVULOF80XTC&field2=1
收到 ThingSpeak 回應 2
網址輸入 https://api.thingspeak.com/update?api_key=EH94XBVULOF80XTC&field3=888
收到 ThingSpeak 回應 3
資料進 ThingSpeak 了
每隔 15 秒以上,依序
網址輸入 https://api.thingspeak.com/update?api_key=EH94XBVULOF80XTC&field1=888
收到 ThingSpeak 回應 4
網址輸入 https://api.thingspeak.com/update?api_key=EH94XBVULOF80XTC&field2=1
收到 ThingSpeak 回應 5
網址輸入 https://api.thingspeak.com/update?api_key=EH94XBVULOF80XTC&field3=168
收到 ThingSpeak 回應 6
一次寫入多個 Fields
https://api.thingspeak.com/update?api_key=[API_Key]&field1=???&field2=???&field3=???
每隔 15 秒以上,依序
網址輸入 https://api.thingspeak.com/update?api_key=EH94XBVULOF80XTC&field1=147&field2=1&field3=35&field4=80
網址輸入 https://api.thingspeak.com/update?api_key=EH94XBVULOF80XTC&field1=258&field2=0&field3=25&field4=50