easy integration between IoT devices and Rails Client: Raspberry PI Server: Rails Control devices with elegant Ruby code Rack-based Easy integration with Rails What is Tamashii
(HTML5) Two-way communication (server push) Use the same port as HTTP Support TLS (just like HTTPS) Supported by modern web servers and frameworks (Rails) What is Tamashii
on RubyConf.tw 2016 17 devices 270 attendees Access Control System Remotely control the gate for entrance Not deployed yet Projects Built with Tamashii
their badge) Bind the attendee with their RFID sticker Projects Built with Tamashii Check-in System Register Attendee Card Number Count User A 11-22-33-44 0 User B User B 55-66-77-88 0 Registrar Device
their RFID identifier Server find attendees & record to database Projects Built with Tamashii Check-in System Attendee Card Number Count User A 11-22-33-44 0 User B 55-66-77-88 0 User B 55-66-77-88 1 Check-in User B Check-in Device
Registration stage (same) Check-in stage (different) Control the behavior on Check-in devices Instead of simply recording the data Allow or deny users Projects Built with Tamashii Access Control
(I2C interface) Control using gem 6 bytes of binary command for “A” Technical Details Client Side [0x49, 0x4d, 0x49, 0x19, 0x1d, 0x19].each do |byte| i2c_write_byte(byte) end # => "A" Model: LCM 1602 I2C i2c
for different hardware model Technical Details Client Side module Lcd class Lcm1602I2C < Base def print(message) # Lots of tedious stuff end end end Lcd::Lcm1602I2C.new.print("A")
Side module RfidReader class Base def read_uid raise NotImplementedError end end end module RfidReader class Mfrc522 < Base def read_uid # code for MIFARE end end end module RfidReader class Pn532 < Base def read_uid # code for FeliCa end end end
Technical Details Client Side reader = RfidReader.new buzzer = Buzzer.new loop do if data = reader.read # non-blocking read buzzer.beep(3) # blocking operation else sleep 0.1 # save CPU end end Thread #1 New Card Beep!
program crashes! Technical Details Client Side reader = RfidReader.new buzzer = Buzzer.new # stops working loop do if data = reader.read buzzer.beep(3) # crash! else sleep 0.1 end end Thread #1 Wait for response… ? New Card
buzzer = Buzzer.new master.register(buzzer) master.register(reader) buzzer.on :rfid_data do |payload| self.beep(3) # run on another thread end loop do if data = reader.read reader.emit(Event.new(:rfid_data, data)) else sleep 0.1 end end RFID Thread Master Thread Buzzer Thread
Callback when receive messages Technical Details Server Side Redis Client #1 Client #3 Client #2 Subscribe Publish message: “Hello” subscribe('_tamashii_internal') do |on| on.message do |_, message| process_message(message) end end
client devices Params: the device data User defined Tamashii controller In Do everything that is available in Rails environment Technical Details Server Side config/routes.rb config/initializers app/tamashii/*.rb
system based on Tamashii (Rails app) Repositories tamashii tamashii-client tamashii-agent tamashii-manager tamashii-common tamashii-checkin Server module based on Rack Shared library More information at https://tamashii.io