Hong En
    • Create new note
    • Create a note from template
      • 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
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me 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 New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
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
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me 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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Lab17 # 2024教育部計劃 實驗一 ## 版本 * rpiOS 64bit * ## 網卡設定 sudo raspi-config ![image](https://hackmd.io/_uploads/SJt3MwmnT.png) ![image](https://hackmd.io/_uploads/Sy_Rfvm2a.png) ![image](https://hackmd.io/_uploads/rk5yXDXnp.png) ![image](https://hackmd.io/_uploads/ByQl7wm3a.png) ``` sudo apt install minicom ``` ``` sudo minicom --device /dev/ttyS0 ``` ## 使用TCP連接 AT * 透過AT指令來確定設備是否已經準備好。如果沒問題的話會收到 OK。 AT+CPIN? * 首先第一個動作要解鎖 PIN 碼,要確認是否有鎖上可以透過 AT+CPIN? 來得知。 * 看到 READY 表示已經解鎖。如果看到像是 SIM PIN 則可以透過 AT+CPIN=pin指令來解鎖。 AT+CNMP * 工作模式切換 * 由於我們是使用NB-IOT SIM卡,因此要設定為38 * AT+CNMP=38 * AT+CMNB * 網路切換 * AT+CMNB=2 ,2是使用NBIOT頻段 * AT+NBSC * 打開擾碼,要跟基地台確認 * AT+NBSC=1 AT+CGDCONT=1,"IP","internet.iot" * 透過 AT+CGDCONT= 指令將 APN 給設定好。 * 中華電信 NB-IoT 使用的 APN 是 internet.iot。 * AT+CSQ * 透過 AT+CSQ 指令來了解所處地區的訊號品質 (0-31) * 回傳XX,99,如果是8以上就算可以使用,如果回傳99,99代表沒有找到基地台,要再等等,或是重開機樹莓派 AT+COPS? * 查詢註冊到的基地台,最後一位是9代表找到NB IOT網路 可以再透過以下兩個指令確認有連線成功 AT+CGATT? * 檢查GPRS狀態 AT+CPSI? AT+CGNAPN * 再次確認一下使用的APN AT+CSTT * 連線GSM/GPRS/EDGE 時的APN設定 ,再次設定為"internet.iot" * AT+CSTT="internet.iot" AT+CIICR * 啟動數據網路 * AT+CIFSR * 如果以上步驟都沒問題,就能連上數據網路,得到一組 IP。我們可以利用 AT+CIFSR 指令來查看我們的 IP。 Ping 測試 * 通常在這個步驟就能正常上網了,使用最常用的 ping 8.8.8.8 來進行測試 * AT+CIPPING="8.8.8.8" ## 與伺服器連線 ### TCP連線方式1 * 在140.116.179.18:5000有開一個 tcp socket server,會回傳傳過去的訊息 #### 使用AT連線 * AT+CIPSTART="TCP","IP","PORT" * AT+CIPSTART="TCP","140.116.179.11",8086 140.116.179.11:8086是開在實驗室虛擬機上面的一個tcp server,功能是會回傳收到的字元(echo) #### 發送資料 * 使用 AT+CIPSEND=K 來發送資料 * K代表傳訊的訊息長度 * 請傳送英文或是數字就好 * 如果沒有打到K的長度就會卡住 #### 停止連線 * AT+CIPCLOSE ### TCP連線方式2 * 連線到flask伺服器 * 連線方式一樣 * AT+CIPSTART="TCP","140.116.179.11",8087 * 傳送的訊息要符合 http 的規範 (flask是http伺服器) * 如果不知道要怎麼傳可以看flask server那邊的設定,那兩個引號中間 * flask server 端 * ![image](https://hackmd.io/_uploads/ryxRBTqCT.png) * 樹莓派 ATcommand 端,要close之後才會把訊號發出去 * ![image](https://hackmd.io/_uploads/HyjJLacAa.png) ### TCP連線方式3 * 連線到flask伺服器 * 使用AT指令中的HTTP連線方式 * 要先進行設定 #### 設定使用場景 * AT+CGREG=1 * AT+SAPBR=3,1,"Contype","GPRS" * <a>AT+SAPBR=3,1,"APN","internet.iot"</a> * ![image](https://hackmd.io/_uploads/HkaRwaq0T.png) #### 開啟GPRS * AT+SAPBR=1,1 #### 查詢GPRS狀態 * AT+SAPBR=2,1 * ![image](https://hackmd.io/_uploads/rkRavTcRp.png) * 接著就可以進行http連線了 #### 對http進行初始化 * AT+HTTPINIT #### 設定 HTTP 請求的Context ID * AT+HTTPPARA="CID",1 #### 設定連線的URL * <a>AT+HTTPPARA="URL","140.116.179.11:8087"</a> #### 進行連線 * AT+HTTPACTION=0 * 稍等一下,如果回傳是0,200代表連線成功,如果不是的話代表沒有連線成功 #### 取得http server回傳的資料 * AT+HTTPREAD #### 結束連線 * AT+HTTPTERM ![image](https://hackmd.io/_uploads/B1eSkRq06.png) ## lab 使用任何一種sensor來取得資料,並且透過SIM7000G將他發到伺服器上 參考指令: GET /upload_data?group_name=group00&key=test&value=10 HTTP/1.0 請注意發送的長度 可以到 http://140.116.179.11:8087/dashboard 查看結果 ## 指令說明 | 指令 | 功能 | 回應 |說明 | -------- | -------- | -------- |------ | | AT | AT測試指令 | OK | | | AT+CSQ | 訊號強度測試 | +CSQ: 31,99|看第一個數字,大於8就可以用 | AT+CPIN? | 解鎖 PIN 碼 | READY|READY表示已經解鎖。如果看到像是 SIM PIN 則可以透過 AT+CPIN="pin" 指令來解鎖,pin預設是0000| | AT+CGDCONT=1,"IP","APN" | 設定PDP | OK|中華電信的APN是internet.iot| | AT+CREG=1 | 啟用網路註冊,使SIM7000G開始嘗試連接網路 | OK |terminal會回傳狀態| | AT+CREG? | 查詢網路註冊狀態 |+CREG: 1,0 | | | AT+CGATT=1 | 註冊基地台 | OK | | | AT+CGATT? | 查詢基地台註冊狀態 | +CGATT: 1 | 1代表註冊成功,如果是0再等一下看看| | AT+CPSI? | 查詢網路註冊訊息 | +CPSI: LTE NB-IOT,Online,466-92,0xDBEC,156771961,37,EUTRAN-BAND8,3640,0,0,-15,-83,-68,10 |NB-IOT的SIM卡是LTE,重點是online | | AT+CSTT? | 查詢APN |+CSTT: "internet.iot","","" | | | AT+CSTT="APN" | 設定APN | OK | | | AT+CIICR | 啟用數據網路 | OK |ERROR代表沒有成功 | | AT+CIFSR | 獲得IP | 10.82.128.52 | | ### 使用python傳遞AT訊息 ``` python import time import serial ser = serial.Serial("/dev/ttyS0",115200) #SIM7000C USB port def receiving(timeout=0.25): #簡單做法, 基礎用0.25秒計時, 否則自行定義 #ser.flushInput() #清除接收緩衝區 last_received='' try: while timeout>0: time.sleep(0.2) count = ser.inWaiting() #取得當下緩衝區字元數 while count != 0: last_received += ser.read(count).decode('utf-8') #getData += bytes.decode(ch) time.sleep(0.2) # count = ser.inWaiting() #取得當下緩衝區字元數 timeout = timeout-0.25 return last_received.strip() except IOError as ex: raise RuntimeError('Failed to serial port') from ex except Exception as ex: raise ex def Send_AT(cmd, timeout=0.25, ret='OK'): ser.write((cmd+'\r\n').encode('utf-8')) #print(receiving(timeout=timeout)) data = receiving(timeout=timeout) print(data) if ret in data: return ret else: return 'ERROR' while True: try: command = input() if command =='q': break Send_AT(command) except KeyboardInterrupt: break ``` ### 參考資料 * https://frankchang.me/2018/12/18/sim7000c/ * https://www.waveshare.net/w/upload/4/49/SIM7000_Series_AT_Command_Manual_V1.02.pdf * https://www.waveshare.net/w/upload/7/7f/SIM7000C-quick-test.pdf * https://www.waveshare.net/wiki/SIM800C_GSM/GPRS_HAT#.E3.80.90HTTP_POST.E3.80.91 * https://twarm.com/commerce/product_info.php?products_id=21638

    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