GitHub • RubyGems • Documentation • History
A Ruby library that extends Tinkerforge in fun and useful ways.
Tinderfridge is available as a gem. You can simply install it with:
gem install tinderfridge
Tinderfridge has no dependencies outside Tinkerforge and the Ruby Standard Library.
Requirements:
- Tinkerforge 2.1.28 or newer.
- Ruby 2.5 or newer.
Older versions of Tinderfridge will work with Tinkerforge 2.1.27 or newer.
Add this line at the beginning of your program (or type in IRB):
require 'tinderfridge'
Tinkerforge will work as before, but with some extra powers.
For instance, you can create an IP Connection like this:
ipcon = Tinkerforge.connect 'myhost.local'
=> Tinkerforge::IPConnection (myhost.local:4223)
Access to Bricks and Bricklets is easy:
my_devices = ipcon.discover
...or combine both steps:
my_devices = Tinkerforge.connect('myhost.local').discover
Print a list of devices:
my_devices.ls
bUt RGB LED Button Bricklet
PSg GPS Bricklet 2.0
TaH HAT Brick
=> 3
Get a device's state:
my_devices['bUt'].state
=> {"uid"=>"bUt", "update_time"=>2021-07-02 10:55:51 UTC, "firmware_version"=>"2.0.2", "connected"=>{"uid"=>"TaH", "position"=>"d"}, "ipcon"=>{"host"=>"myhost.local", "port"=>4223}, "chip_temperature"=>27, "spitfp_error_count"=>[0, 1, 0, 0], "status_led_config"=>0, "color_rgb"=>[68, 9, 17], "color_calibration"=>[100, 100, 55], "pressed"=>false}
Switch off all blue status LEDs:
my_devices.set_status_led_config 0
Also see the Tinderfridge documentation.
With Tinderfridge, it is possible to automatically log certain Tinkerforge events, such as creation of new device instances. This is optional and does not happen by default.
Event logging is done using the Logger
class, which is part of the Ruby Standard Library. Logger
is simple to use, but has powerful features such as automatic log rotation and customised formatting of messages.
require 'logger'
Tinkerforge.logger = Logger.new 'my_log.txt'
# Tinkerforge will log events to my_log.txt
my_devices = Tinkerforge.connect('myhost.local').discover
You can also set up a logger for your program and tell Tinkerforge to use that:
require 'logger'
log = Logger.new 'my_log.txt'
log.debug 'My Great App is running!'
# Tell Tinkerforge to use the same log
Tinkerforge.logger = log
- Tinkerforge Ruby bindings:
Tinderfridge is licensed under the same terms as the Tinkerforge Ruby bindings.
See the included LICENSE.txt file.
“That which comes after always has a close relationship to what has gone before. For it is not like some enumeration of items separately taken and following a mere inevitable sequence, but there is a rational connection; and just as existing things have been combined into harmonious order, so also all that comes into being bears the stamp not of a mere succession but of a wonderful relationship.”
Marcus Aurelius, Meditations, Book IV §45