Here is a tutorial about how to use remote sensor connections in ruby. I have made a tiny one-file library to simplify this. You can find it here. The syntax looks like this:
require "scratchrsc" class PrintRSC < RSCWatcher def on_broadcast(name) # when a broadcast is sent puts "broadcast #{name}" # print it to the screen end def on_sensor_update(name,value) # when a variable or sensor is updated puts "#{name} = #{value}" # print the change to the screen end def broadcast_hello # when the broadcast "hello" is sent, ignore on_broadcast and puts "Hello World" # greet the world, broadcast "foo" # and send another broadcast end end watcher = PrintRSC.new # you can provide the host as an argument watcher.sensor_update "connected", "1" loop { watcher.handle_command }
All you need to run this is ruby. Download the library file and place it in the same directory. Name the example test.rb. Make sure scratch is running and has remote sensor connections enabled, and then run it usng this command:
$ ruby -I . test.rb
I can upload a gem for this if anyone finds this useful
Last edited by logiblocs (2013-01-27 12:21:18)
Offline
That cool! It's nice to see modules coming out for other programming languages!
Offline