Git Product home page Git Product logo

watch_ble_connection's Introduction

Watch BLE (Bluetooth Low Energy) Connection

Communication between Wear OS or watchOS SmartWatch and Android/iOS Device with Bluetooth Low Energy (BLE).

This will send and receive messages and/or data to the platform specific wearable communication method. It uses the wearable data layer and messaging API's on android devices and WCSession on iPhones.

Install

Android

  • add implementation 'com.google.android.gms:play-services-wearable:17.0.0' to the app level build.gradle

  • make sure that the applicationId of your WearOS app is the same as the one on your phone app

iOS

How to use

  • For information on how to access the sent data on wearable devices please see the example project
  • It is recommended to not rely on instantaneous transfer of data on IOS as applicationContext waits for a "low intensity situation" to set this value between app and watch

Sending Watchfaces

Use the static method WatchConnection.sendWatchface(String path); to send a single watch face for Apple Watch for iOS.

  • Not yet available on Android, in the future I will study the possibility of adding this capability to Android & Watch OS (@kellvembarbosa) I appreciate any contributions

  • Only iOS for Apple Watch

Example send Watchface

WatchConnection.sendWatchface("/var/.../Portrait.watchface");

Sending messages

Use the static method WatchConnection.sendMessage(Map<String, dynamic> message); to send a single shot message.

  • on android the path "/MessageChannel" will be used for all messages

Example send message

WatchConnection.sendMessage({
  "text": "Some text",
  "integerValue": 1
});

Receive message

Use the static method WatchConnection.listenForMessage; to register a message listener function.

  • (android specific) if the message data is a string then the library will assume it is JSON and try to convert it. if that operation fails the message data will be sent to the listener unchanged.

Receive message example

// msg is either a Map<String, dynamic> or a string (make sure to check for that when using the library)
WatchListener.listenForMessage((msg) {
  print(msg);
});

Set data item (datalayer/userConfig)

Use the static method WatchConnection.setData(String path, Map<String, dynamic> message); to set a data item with specified path (use wearOS compatible data layer paths)

  • (iOS specific) the path variable is used as a key within the application context dictionary
  • (iOS specific) data transfer is not instant and will wait for a "low intensity" moment. use this function only to set permanent low priority information

Example set data

WatchConnection.setData("/actor/cage",{
    "name": "Nicolas Saputra",
    "awesomeRating": 100
});

Listen to data events

Use the static method WatchConnection.listenForDataLayer; to register a data listener function.

  • (android specific) if the data is a string then the library will assume it is JSON and try to convert it. if that operation fails the data will be sent to the listener unchanged.

Example listen for data

// data should be a Map<String, dynamic> but can also be a string under exceptional circumstances
WatchListener.listenForDataLayer((data) {
  print(data);
});

Notes

  • Currently does not support nested data structures on android. Therefore it is recommended to send complex items as json strings to be parsed on the recieving end
  • Supported types in communications are
    • Strings
    • Integers
    • Floats
    • Double
    • Long
    • Boolean
    • Single type lists of strings, floats, ints or longs

Author

watch_ble_connection's People

Contributors

afriwanahda avatar harishwarrior avatar kellvembarbosa avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.