Gotta 'wire em all!

@hrios10

The IoT

Connect all the things!

 

A network of every day objects that exchange data with connected devices.

How do I start?

Interface

Plan

Code

The Plan

The Plan

If you think of the connective device as a tool, how would you use it?

The Interface

The Interface

There are frameworks like Artoo, ThingSpeak, and IoT Assistant.

But you can do this all with Rails.

The Interface

Some considerations:

  • Security. Use it.
  • Do you need it to be accessible from everywhere?
  • An HTTP API is not enough, use Web-sockets or ActionCable.

The Interface

Websockets

The Code

The Code

What you'll need

WebsockerRails::EventMap.describe do
  subscribe :turn_on, 'api/v1/driveway_sensor#create'
  subscribe :check_temperature, 'api/v1/driveway_sensor#check_temperature'
  subscribe :change_temperature, 'api/v1/driveway_sensor#change_temperature'
  subscribe :turn_off, 'api/v1/driveway_sensor#destroy'
end

Websocket-Rails

The Code

What you'll need

class Api::V1::DrivewayController < WebsocketRails::BaseController
  def initialize_session
   controller_store[:sensors] = DrivewaySensorInterface.new
  end

  def create
   controller_store[:sensors].turn_on
  end

  def destroy
   controller_store[:sensors].turn_off
  end

  def check_temperature
  end

  def change_temperature
  end
end

Session Controllers

The Code

What you'll need

let dispatcher = new WebSocketRails('localhost:9001/websocket'),
  task = {
    'name': 'Check temperature for driveway',
    'completed': false
  };

...

$scope.turnSensorsOn = function () {
  dispatcher.trigger('turn_on');
};

Some Javascript

A NEW CHALLENGER APPEARS

The Code

What you'll need

require 'artoo'

connection :spark, adaptor: :spark, 
  device_id: '343_GUILTY_SPARK', 
  access_token: 'xxxThE_TRuffLE_SHUffl3'
device :led, driver: :led, pin: 'D7' # light on spark

work do
  every 1.second do
    led.toggle
  end
end

Artoo-Spark

Closing Remarks

Ruby is great for prototyping, but is a challenge for building out full-fledged IoT applications.

Connect all the things!

Things on Rails

By Hector Rios

Things on Rails

How to use Ruby to interface with the IoT.

  • 709