Skip to content

Instantly share code, notes, and snippets.

@shortjared
shortjared / server.rb
Last active December 21, 2015 23:58
A simple example of continuously reading from a serial based device and using websockets to send data to all registered clients on the server.
# coding: utf-8
require 'sinatra'
require 'sinatra-websocket'
require 'serialport'
set :server, 'thin'
set :sockets, []
## Setup to read from your device via serial port
ser = SerialPort.new("/dev/your_device", 9600, 8, 1, SerialPort::NONE)