呂家明
    • 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
    # **Android Studio** ## Implement Bluetooth and Mqtt protocol --- ### Classic Bluetooth #### The Information of the Smart Insole ```java public static final String SerialPortUUIDL="0000dfb1-0000-1000-8000-00805f9b34fb"; public static final String SerialPortUUIDR="0000dfb1-0000-1000-8000-00805f9b34fb"; public static final String SerialPortUUIDV="0000dfb1-0000-1000-8000-00805f9b34fb"; public static final String CommandUUIDL="0000dfb2-0000-1000-8000-00805f9b34fb"; public static final String CommandUUIDR="0000dfb2-0000-1000-8000-00805f9b34fb"; public static final String CommandUUIDV="0000dfb2-0000-1000-8000-00805f9b34fb"; public static final String ModelNumberStringUUIDL="00002a24-0000-1000-8000-00805f9b34fb"; public static final String ModelNumberStringUUIDR="00002a24-0000-1000-8000-00805f9b34fb"; public static final String ModelNumberStringUUIDV="00002a24-0000-1000-8000-00805f9b34fb"; ``` #### Bluetooth Manager :::success ```java private BluetoothManager mBluetoothManagerL; private BluetoothManager mBluetoothManagerR; ``` ::: #### Bluetooth Adapter :::success ```java private BluetoothAdapter mBluetoothAdapterL; private BluetoothAdapter mBluetoothAdapterR; ``` ::: #### What is the device using below? :::warning ```java private BluetoothManager mBluetoothManagerV; private BluetoothAdapter mBluetoothAdapterV; ``` ::: #### Initialize Bluetooth and check if the phone supports Bluetooth ```java public boolean initializeR() { // For API level 18 and above, get a reference to BluetoothAdapter through // BluetoothManager. System.out.println("BluetoothLeService initialize"+mBluetoothManagerR); if (mBluetoothManagerR == null) { mBluetoothManagerR = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); if (mBluetoothManagerR == null) { Log.e(TAG, "Unable to initialize BluetoothManager."); return false; } } mBluetoothAdapterR = mBluetoothManagerR.getAdapter(); if (mBluetoothAdapterR == null) { Log.e(TAG, "Unable to obtain a BluetoothAdapter."); return false; } return true; } ``` #### Get Instance of BluetoothDevice ```java final BluetoothDevice deviceL = mBluetoothAdapterL.getRemoteDevice(addressL); if (deviceL == null) { Log.w(TAG, "Device not found. Unable to connect."); return false; } ``` #### The Smart Insole communicates with classic Bluetooth, why does it use BLE connection? :::warning ```java synchronized(this) { mBluetoothGattR = deviceR.connectGatt(this, false, mGattCallbackR); } ``` ::: #### Protocol of SmartInsole ![image](https://hackmd.io/_uploads/r1NuEb4Lp.png) ##### Reference project ```java private String start_bytes = "0 254 128"; private int max_data_len = 114; private int ns_list[] = {58, 76, 77, 78, 79, 80, 81, 82, 83, 84, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 112, 113, 114};//不要的資料 ``` :::warning 1.此專案為何有其他藍芽裝置進行連線 2.為何使用BLE Protocol,而非Classic Bt ::: #### Implement Scheme #### Classic Bluetooth ![image](https://hackmd.io/_uploads/Syt1YWEIa.png) ##### 從第三方藍芽APP得知,此SmartInsole運行在Classic Bt protocol #### 檢查手機端是否支援藍芽協議 ```java public void CheckPhoneBt(Activity activity){ Context context = activity.getApplicationContext(); // bluetoothManager = context.getSystemService(BluetoothManager.class); // bluetoothAdapter = bluetoothManager.getAdapter(); if (bluetoothAdapter == null) { Toast.makeText(context, "The Device don't support bt", Toast.LENGTH_SHORT).show(); }//determine that device is support bluetooth if (!bluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); activity.startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } } ``` #### 以BluetoothAdapter 取得 遠端藍芽裝置 之 BluetoothDevice類資訊 ```java public BluetoothDevice getBtDevice(String mac){ bluetoothDeviceL = bluetoothAdapter.getRemoteDevice(mac); //取得遠端藍芽裝置 BluetoothDeviceL 類資料。 // Log.d(TAG, bluetoothDeviceL.getName()); // Log.d(TAG, bluetoothDeviceL.getAddress()); return bluetoothDeviceL; } ``` #### Create socket between app and remote devices. ```java private BluetoothSocket CreatSocket(BluetoothDevice device){ BluetoothSocket tmp = null; try{ tmp = device.createRfcommSocketToServiceRecord(SerialPortUUID_L); }catch (IOException e){ Log.e("Connect_socket", "Socket's create() method failed",e); } return tmp; }//CreatSocket() ``` #### Connecting socket with remote device ```java private boolean btConnectSocket(BluetoothSocket mmSocket){ bluetoothAdapter.cancelDiscovery(); try { // Connect to the remote device through the socket. This call blocks // until it succeeds or throws an exception. mmSocket.connect(); Log.d(TAG, "client socket connected"); } catch (IOException connectException) { // Unable to connect; close the socket and return. try { mmSocket.close(); } catch (IOException closeException) { Log.e(TAG, "Could not close the client socket", closeException); } return false; } if(mmSocket.isConnected() == true){ Log.d(TAG, "build socket sucess"); return true; // BtSerialThread btSerialThread = new BtSerialThread(mmSocket, "SmartInsole_L"); // // btSerialThread.write(end_cmd_byte); // btSerialThread.write(start_cmd_byte); // btSerialThread.run(); } return false; }//btConnectSocket() ``` #### Finally, generator a thread to handle bt communication #### Android Studio Bluetooth 進度 1. Creating and building socket between app and smart insole through classic bluetooth. 完成 2. Read and collect data through the socket. ![image](https://hackmd.io/_uploads/rkJ7gQNLp.png) ![image](https://hackmd.io/_uploads/rJ-el7EIp.png) #### Android Studio and FastAPI MQTT進度 1. transmit data through Topic between app and server. 已完成. 2. 將手機讀取到的足底壓力資料透過MQTT傳輸資料至FastAPI Server做處理.進行中 #### Android GUI 移植 (0%) ![image](https://hackmd.io/_uploads/B1DdGQELT.png) #### 與組員討論如何部署Model至FastAPI or App --- #### 壓力值的分布

    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