4 weeks with Ruby

The past month brought a bunch of changes in my developer carrier. Change of job team, office, city... and technologies. One of these was to start learning a new language for developing software: Ruby!
It is quite a change from the programming languages I went through before (in short, Turbo Pascal, C, C++, Assemblers, Java, C#).

I was advised a very good Ruby book, Eloquent Ruby and some fancy "training exercises", the "Ruby Koans" to start learning about Ruby. After a few days I realized that a better exercise for me would be to re-implement my "home zwave proxy" (developer in C++, using directly the ZWay C library); and well, it was a good idea.

After 4 weeks (well, a few hours in the evenings), with some basic knowledge of Ruby, I almost managed to reach the same "level of functionality" as my native C++ application. "Almost", because there is definitively something I miss in this fancy Ruby world: real callbacks on events.
Of course, there is polling (the ZWay HTTP interface, or watching the ZWay daemon log file) to the rescue, but still, it can not be as good as a real C function callback style!

There we go, I published my very draft, beta, experimental... Ruby library on GitHub. I named it "rzwaveway" (for "Ruby ZWave Zway"). I does not do much yet, but it is a start.
A very basic example on how to use it:

require 'rzwaveway'

z_way = RZWaveWay::ZWay.new('192.168.1.123)
devices = z_way.get_devices
devices.values.each do | device |
  puts device.build_json
end

z_way.on_event(RZWaveWay::AliveEvent) {|event| puts "A device woke up" }
z_way.on_event(RZWaveWay::LevelEvent) {|event| puts "A device got triggered" }
while true do
  sleep 5
  z_way.process_events
end

Comments

Popular posts from this blog

ZWay: getting the device list.

First steps with the ZWay library

Libcurl: perform a REST HTTP PUT