Tamashii Manager is a package for managing IoT devices that can handle communication between IoT devices in a way similar to Rack.
Add the following code to your
And then execute:
$ bundle install
Or install it yourself with:
$ gem install tamashii-manager
Tamashii Manager can be started directly through
Because the connection of IoT devices may need verification, we implement a simple Token authentication function, which can achieve through the configuration file.
# config.rb ::. do |config| config.env = :test config.auth_type = :token config.token = 'abc123' config.port = ENV['PORT'] || 3000 end
Then start with
$ tamashii-manager -C config.rb
To integrate with the project that use Rack through
# config.ru require 'tamashii/manager' require './config.rb' run ::.
Then start Tamashii Manager through the web server.
Rack :: URLMap to consolidate your project when collocating with Sinatra and other frameworks.
# config.ru Rack::URLMap.new( '/' => App, '/tamashii' => ::. )
To integrate with the Rails project, you can use the
mount function to plug Tamashii Manager onto Rails.
# config/routes.rb Rails.application.routes.draw do mount ::. => '/tamashii' end
In Rails, we will want to intercept information in the Tamashii Manager, processed in advance and then send to each IoT device, so it will use Tamashii Resolver function.
# config/initializer/tamashii.rb ::. do |config| config.env = Rails.env config.log_file = Rails.root.join('log', 'tamashii.log') config.auth_type = :token config.token = 'example' end ::Resolver.config do hook RailsHookForTamashii end
call method in Resolver function to handle incoming packets.
# app/tamashii/rails_hook_for_tamashii.rb class RailsHookForTamashii < ::Hook def initialize(*args) super @client = @env[:client] end def call(packet) # Handle packets here return false if packet.nil? # The processing failed and let the other Handler go on true # Finished processing end end
In this way, you can use the Hook to handle the packets sent to Tamashii Manager.
Tamashii Manager will require a
serial number as a machine ID when authenticating, and so we can use the
send_to function to send packets to a specify machine.
To get the source code
$ git clone [email protected]:tamashii-io/tamashii-manager.git
Initialize the development environment
Run the spec
Installation the version of development on localhost
$ bundle exec rake install
Please report to us on Github if there is any bug or suggested modified.
The project was developed by 5xruby Inc.