Permalink
Browse files

Ruby utils to set the Doorduino clock and RFIDDB

 * update_acl.rb requires 3 environment vars to be set:
   * HACKPGH_GOOGLE_USER (Google account username)
   * HACKPGH_GOOGLE_KEY (Google account password)
   * HACKPGH_GOOGLE_MEMBER_SHEET (Google spreadsheet ID with a certain layout)
     * see script for details
  • Loading branch information...
1 parent 6df6a1c commit 19a5fa108cc106ac6dee74e69395efa19bccdfa1 @martymcguire committed Dec 17, 2009
Showing with 66 additions and 0 deletions.
  1. +25 −0 utilities/set_clock.rb
  2. +41 −0 utilities/update_acl.rb
@@ -0,0 +1,25 @@
+#!/usr/bin/ruby
+
+require "rubygems"
+# From http://ruby-serialport.rubyforge.org/
+require "serialport"
+
+puts "Connecting to Arduino on #{ARGV[0]}"
+SerialPort.open(ARGV[0], 9600, 8, 1, SerialPort::NONE) do |sp|
+ sleep 5
+ puts "Connected?"
+ buf = ""; while (! /.* Ready\r\n/.match(buf)) do
+ printf("%c", t = sp.getc)
+ buf << t
+ end
+ now = Time.now
+ sp.write 'T'
+ sp.putc(now.year - 2000)
+ sp.putc(now.month)
+ sp.putc(now.day)
+ sp.putc(now.wday)
+ sp.putc(now.hour)
+ sp.putc(now.min)
+ sp.putc(now.sec)
+ t = 0; while (t != ?\n) do printf("%c", t = sp.getc) end
+end
@@ -0,0 +1,41 @@
+#!/usr/bin/ruby
+
+require "rubygems"
+# From http://github.com/gimite/google-spreadsheet-ruby
+require "google_spreadsheet"
+# From http://ruby-serialport.rubyforge.org/
+require "serialport"
+
+# Log in.
+session = GoogleSpreadsheet.login(ENV['HACKPGH_GOOGLE_USER'],
+ ENV['HACKPGH_GOOGLE_KEY'])
+
+# First worksheet of the HackPGH members list spreadsheet
+ws = session.spreadsheet_by_key(ENV['HACKPGH_GOOGLE_MEMBER_SHEET']).worksheets[0]
+
+# Gather RFID IDs for active users
+# Col 4 is Active/Not, Col -1 (8 doesn't work for some reason) is RFID out
+# Col -2 is RFID ID (don't know why 7 doesn't work)
+rfid_tags = ws.rows.select{|r| r[4] == 'Y' && r[-1] == 'Y'}.map{|r| r[-2].gsub(/"/,'')}
+
+puts "About to write #{rfid_tags.size} RFID Tags"
+puts "Connecting to Arduino on port #{ARGV[0]}"
+
+SerialPort.open(ARGV[0], 9600, 8, 1, SerialPort::NONE) do |sp|
+ sleep 5
+ puts "Connected?"
+ buf = ""; while (! /.* Ready\r\n/.match(buf)) do
+ printf("%c", t = sp.getc)
+ buf << t
+ end
+ sp.write 'U'
+ t = 0; while (t != ?\n) do printf("%c", t = sp.getc) end
+ sp.putc rfid_tags.size
+ t = 0; while (t != ?\n) do printf("%c", t = sp.getc) end
+ rfid_tags.each do |tag|
+ sp.write tag
+ t = 0; while (t != ?\n) do printf("%c", t = sp.getc) end
+ end
+ puts "Done?"
+ t = 0; while (t != ?\n) do printf("%c", t = sp.getc) end
+end

0 comments on commit 19a5fa1

Please sign in to comment.