FlagMaker
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    Lab 11 使用的 Ubidots 服務因為網頁上的畫面有小幅度的修改, 本文以新的畫面操作一遍, 方便大家對照操作。 :::info 實際的操作步驟和程式碼都和手冊上一樣, 只是因為網頁內容有差異, 改以新畫面操作展示。 ::: ## 註冊帳號 1. 請連線至 https://ubidots.cokm/ 後按 **TRY NOW**: ![image](https://hackmd.io/_uploads/SJrb4BaIp.png) 2. 我們使用的是它專為 STEM 教育環境提供的免費平台, 請按 **FREE platform**: ![image](https://hackmd.io/_uploads/Hk7uVHaL6.png) 3. 請按 **CREATE FREE ACCOUNT**: ![image](https://hackmd.io/_uploads/SJBhVS6Ip.png) 4. 填入你的基本資料後按 **Sign Up**: ![image](https://hackmd.io/_uploads/r10GHS6L6.png) 5. 註冊完畢, 系統會寄一封確認信給你: ![image](https://hackmd.io/_uploads/HJ4wBSaIT.png) 6. 到剛剛填寫的電子郵件信箱收信, 你會收到如下地確認信, 請按信中的按鈕啟用帳號: ![image](https://hackmd.io/_uploads/BykRBB6I6.png) 7. 接著會看到歡迎畫面, 請一直按右下角的下一頁畫面: ![image](https://hackmd.io/_uploads/HyZEUrTLa.png) 8. 最後看到這個畫面就完成註冊程序了: ![image](https://hackmd.io/_uploads/SkDuUSTIa.png) ## 查閱 API 使用方法 下一步要查看 API 的說明, 才知道如何將資料上傳到 Ubidots: 1. 請選右上方問號按鈕下的 **API docs**, 這會開啟新的頁面: ![image](https://hackmd.io/_uploads/SkM3Pr6La.png) 2. 在上方選取 **Data API**: ![image](https://hackmd.io/_uploads/ryoltHaIT.png) 3. 在左邊 API 列表中選取 HTTP 下的 **Devices/Send data to a Device** ![image](https://hackmd.io/_uploads/rkF8trp86.png) 4. 會出現 API 的說明: ![image](https://hackmd.io/_uploads/rJT9trp86.png) 這裡表示要使用 HTTP POST 連線到 ``` https://industrial.api.ubidots.com/api/v1.6/devices/<device_label>/ ``` 才能送出資料給指定名稱的裝置, Ubidots 中可以建立對應到硬體的裝置, 每個裝置可以設定多個變數, 對應到硬體上連接的感測器。 :::danger 上述 API 連結使用的加密方式資料量比較大, 不適用於像是 ESP32 這樣的小裝置, 請改用手冊上的連結: ``` https://things.ubidots.com/api/v1.6/devices/<device_label>/ ``` ::: 透過上述連結傳送感測值時, 必須在表頭中傳遞 Ubidots 派發的令牌認證身分: ![image](https://hackmd.io/_uploads/BkXaqST86.png) 上表就說明了要加上 **X-Auth-Token** 表頭帶入令牌, 另外也要註明傳送的資料是 JSON 格式, 格式如下: ![image](https://hackmd.io/_uploads/S18fsHaL6.png) 這樣就會傳送感測值 10 給裝置上的 temperature 變數。 ## 取得令牌 如同前一小節的說明, 要使用 API, 必須透過令牌認證身分, 請依照以下步驟取得令牌: 1. 回到原本註冊帳號的頁面, 按一下右上角頭像圖示後選 **API Credentials** : ![image](https://hackmd.io/_uploads/Bknoj8pLp.png) 2. 按一下令牌區的複製鈕即可複製: ![image](https://hackmd.io/_uploads/BJDXnLaUp.png) 這裡有分 API 金鑰 (key) 和令牌 (token), 請不要弄錯邊。 稍後要將複製的令牌貼到程式碼中。 ## 測試程式 :::info 有關 HTTP POST 方法請參考手冊上的說明。 ::: ```python from machine import Pin,ADC import time import network import urequests import gc adc_pin=Pin(32) adc = ADC(adc_pin) # 建立ADC物件 adc.width(ADC.WIDTH_12BIT) # 設定ADC範圍 adc.atten(ADC.ATTN_11DB) # 將最大感測電壓設定成3.6V # 連線至無線網路 sta=network.WLAN(network.STA_IF) sta.active(True) sta.connect('無線網路名稱','無線網路密碼') while not sta.isconnected() : pass print('Wi-Fi連線成功') device_label = "ESP32" # 裝置名稱 variable_label = "temperature" # 變數名稱 token = "你的令牌 (token)" url = "https://things.ubidots.com/api/v1.6/devices/"+ device_label while True: gc.collect() vol = (adc.read()/4095)*3.6 tem = (vol-0.5)*100 print('目前溫度:',tem) data = {variable_label:tem} headers = {"X-Auth-Token":token} res = urequests.post(url,json = data,headers = headers) if(res.status_code == 200): print("傳送成功") else: print("傳送失敗") print("錯誤碼:",res.status_code) res.close() time.sleep(5) ``` 執行後若正常就會看到 Thonny 的 Shell 窗格出現如下訊息: ![image](https://hackmd.io/_uploads/SyQx08pUT.png) 即可到 ubidots 查看上傳的溫度: 1. 按一下 **Devices/Devices** 鍵入裝置清單頁面: ![image](https://hackmd.io/_uploads/r1CL0IpU6.png) 2. 在裝置清單頁面中選取程式碼內指定的裝置名稱 ESP32: ![image](https://hackmd.io/_uploads/HyZ2R86Ua.png) 3. 可以看到程式碼中指定名稱的變數: ![image](https://hackmd.io/_uploads/HywmyD6Up.png) 4. 按一下變數即可查看所有資料: ![image](https://hackmd.io/_uploads/rylF1DTIa.png) 它會以折線圖顯示, 你必須自己按一下 **New data available** 才會顯示新收到的資料。 ## 建立可即時更新資料的數位儀表板 Ubidots 提供有數位儀表板功能, 可以即時顯示收到的新資料, 請依照以下步驟設計儀表板: 1. 按左上角 Ubidots 圖示回到首頁, 也就是數位儀表板頁面: ![image](https://hackmd.io/_uploads/rJeAxD6La.png) 2. 按右側的 '+' 按紐新增圖表: ![image](https://hackmd.io/_uploads/BkFZZwpIT.png) 3. 選取 **Charts/Line chart**: ![image](https://hackmd.io/_uploads/rk-dWDTUp.png) 按 **Add variables** 新增要做為資料來源的變數: ![image](https://hackmd.io/_uploads/B1pRZwTI6.png) 在交談窗中按一下裝置名稱 ESP32 後選變數名稱 temperature 後按右下角的按鈕關閉交談窗: ![image](https://hackmd.io/_uploads/SJfvMv6L6.png) 設定完成後按右下角的完成鈕: ![image](https://hackmd.io/_uploads/HyMA7vaI6.png) 4. 你會看到新增的圖表, 拖曳右下角可以變化大小: ![image](https://hackmd.io/_uploads/ryhmNv68T.png) 展開圖表右側功能表後選 **Share** 可以取得分享連結: ![image](https://hackmd.io/_uploads/SJkDEDT8T.png) 即可取得直接分享連結或室內嵌到其他網頁內的 HTML 程式碼: ![image](https://hackmd.io/_uploads/HklJBDaLp.png) 其他人即使不是 Ubidots 用戶也可以看到你的圖表: ![image](https://hackmd.io/_uploads/ryQVSvTUp.png)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully