The Bluetooth implement for Tamashii to building IoT device with BLE (Bluetooth Low Engery) function.
Add this line to your application's Gemfile:
gem 'tamashii-bluetooth'
And then execute:
$ bundle
Or install it yourself as:
$ gem install tamashii-bluetooth
Current only support running on macOS by using iBeacon format.
require 'tamashii/bluetooth'
device = Tamashii::Bluetooth::Device.new
device.open
# Do something ...
# This is async in macOS
device.stop
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
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
- macOS support (XPC / CoreBluetooth)
- Linux support (libbluetooth)
- Advertising
- iBeacon
- iBeacon Class
- LINE Beacon Class
- EddyStone
- iBeacon
- Tests
- Events
- State Changes
- Start
- Stop
- Error Handling
We plan to add full Bluetooth support with breaking changes with MVP version.
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.
Bug reports and pull requests are welcome on GitHub at https://github.com/tamashii-io/tamashii-bluetooth.