Ruby bindings to libhelium.
require 'rbhelium'
require 'base64'
require 'msgpack'
Thread.abort_on_exception = true
token = Base64.decode64("HNWl6+nTEHVBXqTVkwPO4w==")
conn = Helium::Connection.new("r01.sjc.helium.io") do |mac, datums|
puts "Got data #{datums} from mac #{mac}"
end
puts "subscribing..."
status = conn.subscribe(0x00212effff003d92, token)
msg = ("hello from ruby #{Process.pid}").to_msgpack
conn.write(0x00212effff003d92, token, msg)
puts "status: #{status}"
sleep 15
rbhelium requires Ruby >= 2.0. You'll also need libhelium, pthreads, Bundler, and ruby-devel.
git clone https://github.com/helium/rbhelium.git ; cd rbhelium
bundle install
If you want to install the gem globally:
gem build rbhelium.gemspec
gem install rbhelium-0.2.1.gem
We host our gems on packagecloud.io. To install those gems, you can see the Gem section of the installation page.
If you don't have libhelium installed, you will get this error when building/installing the gem:
[ERROR]: missing `helium`. Aborting.
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Be aware that the callback block runs in a different thread, so for debugging you should set Thread.abort_on_exception=true