tamashii-io / tamashii-bluetooth

Bluetooth implement for Tamashii

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tamashii Bluetooth

The Bluetooth implement for Tamashii to building IoT device with BLE (Bluetooth Low Engery) function.

Installation

Add this line to your application's Gemfile:

gem 'tamashii-bluetooth'

And then execute:

$ bundle

Or install it yourself as:

$ gem install tamashii-bluetooth

Usage

Current only support running on macOS by using iBeacon format.

Initialize Bluetooth device

require 'tamashii/bluetooth'

device = Tamashii::Bluetooth::Device.new
device.open

# Do something ...

# This is async in macOS
device.stop

Handling Event

require 'tamashii/bluetooth'

device = Tamashii::Bluetooth::Device.new
device.open

# Ensure your ruby is running otherwise the Bluetooth device will be closed
Thread.new do
  until device.events.empty?
    event = device.events.pop

    if event.type == :state_changed && device.powered_on?
      # Advertising
    end
  end

  # Free CPU
  sleep 1
end.join

Advertising (LINE Beacon)

require 'tamashii/bluetooth'
require 'tamashii/bluetooth/beacon'

device = Tamashii::Bluetooth::Device.new
device.open

# beacon = Tamashii::Bluetooth::Advertisment.new
# beacon.data = [0x02, ...]
beacon = Tamashii::Bluetooth::Beacon::LINE.new('001facddd')

# Ensure your ruby is running otherwise the Bluetooth device will be closed
Thread.new do
  until device.events.empty?
    event = device.events.pop

    if event.type == :state_changed && device.powered_on?
      device.advertising(beacon)
    end
  end

  # Free CPU
  sleep 1
end.join

Roadmap

MVP (~> 0.1)

  • macOS support (XPC / CoreBluetooth)
  • Linux support (libbluetooth)
  • Advertising
    • iBeacon
      • iBeacon Class
      • LINE Beacon Class
    • EddyStone
  • Tests
  • Events
    • State Changes
    • Start
    • Stop
  • Error Handling

Full ( >= 1.0 )

We plan to add full Bluetooth support with breaking changes with MVP version.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/tamashii-io/tamashii-bluetooth.

About

Bluetooth implement for Tamashii


Languages

Language:C 60.3%Language:Ruby 38.9%Language:Shell 0.8%