Talks

Tamashii - Create Rails IoT applications more easily

RubyKaigi2017
http://rubykaigi.org/2017/presentations/lctseng.html

There is also a short demo video to help you know more about Tamashii: https://youtu.be/hH6u4sJx_L4

Tamashii Official Website: https://tamashii.io

RubyKaigi 2017

00:00:00.030 The next speaker is here, Wheaton, and the title is Tamashii: Create Rails IoT Applications More Easily. Hello, hello!
00:00:05.549 Good morning everyone! I hope you had a wonderful party last night. I really appreciate you attending my talk.
00:00:24.180 Today, it's my honor to introduce Tamashii to you. The purpose of Tamashii is to make it easier to create IoT applications, and I will share some ideas for IoT implementation.
00:00:34.350 This is the topic of today's talk. We will first provide a general introduction about Tamashii, then we will look at some projects implemented with Tamashii, followed by demo videos. After that, I will discuss more details about the Tamashii server-side, and finally, we will conclude.
00:00:46.800 Before we start, let me introduce myself. I'm Henry Tseng, a Ruby and Rails developer based in Taipei, Taiwan. I love Ruby and iOS development, working on web applications, IoT tools, and even games. I have contributed to multiple Ruby projects and co-founded a Ruby community in Taiwan to foster growth and collaboration.
00:01:11.580 Now, let's talk about Tamashii. The word 'Tamashii' is Japanese and means 'soul or spirit.' We chose this name because we hope to give life to devices, allowing us to control them more easily. In short, Tamashii is a Ruby-based framework that facilitates easy integration between IoT devices and Rails applications. It supports both client-side and server-side development.
00:01:43.560 Currently, we have implemented Tamashii on Raspberry Pi, providing a way for you to control devices with elegant Ruby code. The server-side of Tamashii is reactive and is designed to simplify integrations with existing applications. Among the features of Tamashii, it leverages event-based data exchange within a network model based on WebSockets.
00:02:10.560 Tamashii's features include a data management component, simplified device management, and a high-level API that reduces the complexity of device control. This allows users to implement high-level logic without needing to understand the underlying device protocols.
00:02:38.109 Here are some example codes that showcase the Tamashii API. For instance, using a simple command, you can control hardware components as Ruby objects. The first example demonstrates how to play sounds using a small speaker by calling a method with the specified number of sounds as a parameter. The second example shows how to display text on an LCD screen using a straightforward print command.
00:03:14.379 The last example involves reading data from an RFID card. This is akin to the Suica or ICOCA cards used in Japan's metro systems, where you can read data from cards and send it to a server. While we can operate devices using high-level APIs, it's important to note that we usually do not interact with each component individually; instead, we combine them.
00:03:28.389 Tamashii employs an event-based approach for exchanging data among multiple components. Imagine wanting to play a song and display a message when data is received from an RFID reader. The following describes the event-based approach: when an RFID card is detected, an event is emitted and sent to the Tamashii manager, which dispatches the event to components such as speakers or LCD displays, triggering specific actions.
00:04:49.870 Networking is one of the most critical aspects of developing IoT applications. When a device reads data from an RFID reader, it needs to send that information back to the server and receive further instructions. For example, if we read an ID from the RFID card, we would check it against a database on the server.
00:05:03.789 Two-way communication is essential, and simply establishing a TCP connection may not suffice. To facilitate easier integration of devices, we decided to use WebSockets for Tamashii's networking. WebSockets enable real-time, two-way communications between clients and servers.
00:05:30.000 This technology reduces overhead compared to traditional HTTP connections while still allowing similar operations. Additionally, as WebSockets support secure transport layers, users need not worry about proxy settings in firewalls, and many modern web servers and frameworks support WebSockets.
00:05:56.000 Because we utilize WebSockets, it becomes much easier to integrate Tamashii into Rails applications. We created a WebSocket server that communicates with clients and stores device information within a Rails database.
00:06:21.000 Moreover, we defined a device management protocol that includes shared events between client and server, categorized as data events (sensor data sent from devices) and command events (action requests sent from the server to the devices). This structure facilitates smooth communication and data handling.
00:06:57.000 The Tamashii protocol also provides a simple abstraction layer for device operations, which allows users to interact with devices without delving into the underlying protocols. For example, to find a device with a specific serial number, one simply calls the method defined in Tamashii. The system handles device management and other complexities.
00:07:14.000 During this talk, I will also show a demo video illustrating device management within Tamashii. In the demo, we will toggle a device and send simultaneous commands between server and client while demonstrating the functionality of the synced devices.
00:07:56.000 I want to introduce two projects that have been built on Tamashii. The first is a check-in system for events, primarily designed to track attendees' movements. We successfully deployed this system at a Ruby conference last year with 17 devices to manage 270 attendees.
00:08:39.990 Another project we are developing is an access control system, allowing a remote administrator to control gate entries similar to the Tokyo metro system. We will divulge more details on these systems later in the discussion.
00:09:06.000 Let’s examine the check-in system closely. The check-in system helps understand which sessions attendees participate in and helps track visitor interactions with sponsors. It consists of two main stages: the registration stage and the check-in stage.
00:09:39.000 In the registration stage, attendees receive an RFID sticker that acts as an electronic ticket, allowing them to check in at different sessions. At the check-in stations, our devices read the RFID data and send this information to the server, enabling us to track behavior patterns.
00:10:10.000 We also include a short demo of this check-in system, which demonstrates how attendees are registered and how the system maintains records of which sessions they attended.
00:10:45.000 Next, let's discuss the access control system. The purpose of this system is to regulate participants' entry, similar to the check-in system. This system allows administrators to grant or deny entry based on various criteria.
00:11:18.000 The following diagram illustrates the workflow for this system. When a user checks in, the device sends an assessment request to the server, and an administrator issues a command to allow or deny entry.
00:11:58.000 A short video provides an overview of a demo for the access control system. In this video, we show how users can request access, and the system can respond by either granting or denying access.
00:12:34.000 In this demo, a user requests access, and if granted, the system notifies the user while controlling the gate mechanism, demonstrating how Tamashii operates.
00:13:00.000 Now let us look at Tamashii's architecture in a more detailed manner. I will introduce the concept of a device wrapper. The device wrapper serves to abstract the complexity of device protocols, enabling users to operate devices using simple API calls.
00:13:44.000 The wrapper stabilizes interaction with various hardware components, allowing the user to focus primarily on functionality without being burdened by the details of underlying communication protocols.
00:14:12.000 Tamashii employs an event-driven architecture. Facilitating interactions with various devices allows for elegant multi-threading without crashing the entire program. The event manager coordinates communications between devices.
00:14:50.000 With this model, we can also highlight the extensibility of Tamashii compared to earlier versions. The flexibility ensures that individual components can fail without disrupting the overall system.
00:15:25.000 In this portion of my talk, I will address the asynchronous model. In this model, requests and responses do not need to be paired. The server can process multiple requests concurrently, and clients can manage their state without waiting for a response.
00:16:00.000 The client creates request objects, which are sent to the server. In this architecture, callbacks are defined for each request, enabling the system to manage complex interactions seamlessly.
00:16:35.000 Let's take a look at an example illustrating this request object mechanism, designed to allow multiple requests to flow seamlessly. This empowers the real-time verbosity of interactions, enhancing easy monitoring and responsiveness.
00:17:05.000 Under this methodology, our API abstracts the low-level hardware manipulations, thereby simplifying the interaction layer. Users only need to provide necessary input, and the system manages the details automatically.
00:17:40.000 With its straightforward implementation, Tamashii is able to support a range of hardware such as RFID readers and LCD displays, while our development goal is to provide even broader device support.
00:18:15.000 One of our objectives is to unify interfacing among disparate devices, as different manufacturers may employ different communication protocols. By developing an interface that abstracts these differences, we allow easier management of various hardware types.
00:18:50.000 In conclusion, I want to summarize the key points about Tamashii. We have walked through important concepts and outlined several usable projects. Tamashii aims to simplify device management and integration into existing Rails applications but continues to be in active development.
00:19:30.000 We are planning to expand support to a more diverse set of devices while also refactoring the underlying code to improve performance. You can find the list of devices already supported in the system on our official website.
00:20:10.000 Tamashii is an open-source project with numerous contributions from the community. If you're interested in collaborating or learning more, please check our GitHub repository and official website.
00:20:45.000 Thank you very much for your attention. I appreciate the opportunity to share Tamashii with you.
00:21:10.000 Now, I'd like to open up the floor for questions.
00:21:46.000 One question regarding the security of IoT devices: how do the server and clients authenticate each other, and how do we mitigate risks of rogue connections? To prevent unauthorized access, we use an API key that is configured on both the server and client. This ensures that only recognized devices can connect.
00:22:12.000 Another question: how does the server know which methods are available on each device? We implement a unified interface that ensures that if one device supports a specific operation, it is made available in the server's response, while optional operations are marked accordingly.
00:22:58.000 Regarding support for different character sets like Kanji or Katakana, our current LCD module only supports ASCII characters. Supporting more complex character sets would require more specialized hardware due to cost considerations.
00:23:38.000 Lastly, are there plans for future hardware support? Yes, we actively support SPI and I2C interfaces and encourage community contributions to enhance the diversity of devices our system can support.
00:24:10.000 Thank you all for your great questions and interest in Tamashii.
00:24:15.000 We encourage everyone to reach out with further inquiries after this session.