Giter VIP home page Giter VIP logo

faketooth's Introduction

Faketooth

Faketooth is a library that allows you to simulate a Bluetooth Low Energy (BLE) interface on iOS/macOS/watchOS/tvOS platforms. It leverages swizzling techniques to emulate a BLE device, enabling you to create virtual peripherals with custom services, characteristics, descriptors, and advertisement data.

Installation

You can integrate Faketooth into your project using Swift Package Manager. Simply add the following dependency to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/rozd/faketooth.git", from: "0.5.0")
]

Usage

To start using Faketooth, follow the steps below:

  1. Import the Faketooth module in your code:
import Faketooth
  1. Set up the simulated peripherals by assigning an array of FaketoothPeripheral instances to CBCentralManager.simulatedPeripherals. Each FaketoothPeripheral represents a virtual BLE device with its own unique identifier, name, services, advertisement data, and more.

Here's an example that demonstrates the basic usage:

CBCentralManager.simulatedPeripherals = [
    FaketoothPeripheral(
        identifier: UUID(),
        name: "Test",
        services: [
            FaketoothService(
                uuid: CBUUID(),
                isPrimary: true,
                characteristics: [
                    FaketoothCharacteristic(
                        uuid: CBUUID(),
                        properties: [.read, .notify, .write],
                        descriptors: [
                            FaketoothDescriptor(
                                uuid: CBUUID(string: "2902"),
                                valueProducer: { () -> Any? in
                                    return Data(capacity: 2)
                                }
                            )
                        ],
                        valueProducer: { "Hello".data(using: .utf8) },
                        valueHandler: { data in
                            print("\(String(data: data!, encoding: .utf8)!)")
                        }
                    )
                ]
            )
        ],
        advertisementData: [
            CBAdvertisementDataLocalNameKey: "Name for Advertisement"
        ]
    )
]

In this example, we create a single virtual peripheral named "Test" with a primary service. The service contains one characteristic with read, notify, and write properties. Additionally, the characteristic has a descriptor with a UUID of "2902". We also specify an advertisement name for the peripheral.

  1. Build and run your project. Faketooth will now simulate the BLE interface, allowing you to interact with your virtual peripherals as if they were real devices.

Examples

To help you get started, the Faketooth repository provides examples that demonstrate different use cases and configurations. You can find these examples in the Demo directory.

Contributions and Support

Contributions to Faketooth are welcome! If you encounter any issues, have questions, or would like to suggest improvements, please open an issue on the GitHub repository.

License

Faketooth is available under the MIT license. See the LICENSE file for more information.


Thank you for using Faketooth! I hope this library simplifies your BLE testing and development workflows. If you find it helpful, please consider giving it a star on GitHub.

faketooth's People

Contributors

rozd avatar

Stargazers

William Parker avatar

Watchers

 avatar James Cloos avatar  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.