class LoriotClient
An interface to Loriot Service from Ruby
Public Class Methods
new(options = {})
click to toggle source
Establish a secure connection to your account on the cloud
# File lib/loriot-rb/base.rb, line 10 def initialize(options = {}) options = { debug: false, token: LoriotRb::Settings.token, appid: LoriotRb::Settings.appid, host: LoriotRb.configuration.host, port: LoriotRb.configuration.port }.merge(options) @debug = options[:debug] @token = options[:token] @appid = options[:appid] options welcome_response = sub_initialize(options) raise("Loriot-rb: Cannot connect to host #{options[:host]}:#{options[:port]}") unless welcome_response.index('hello') end
Public Instance Methods
listen(options = {}, &block)
click to toggle source
Stay awaiting data from the cloud
# File lib/loriot-rb/base.rb, line 55 def listen(options = {}, &block) options = { debug: @debug }.merge(options) puts "#{Time.now} Starting Listen #{@appid}" if options[:debug] response = nil begin response = read_data(options) block.call(response) if block end while response && !options[:test] # Return last response response end
quit()
click to toggle source
Close the secure connection with the cloud
# File lib/loriot-rb/base.rb, line 69 def quit sub_quit end
read_data(options = {})
click to toggle source
Receive all data devices from the cloud Each device sends its data to the cloud
# File lib/loriot-rb/base.rb, line 46 def read_data(options = {}) options = { debug: @debug }.merge(options) puts "#{Time.now} Waiting for #{@appid} incoming data..." if options[:debug] response = sub_read_data(options) puts "#{Time.now} Received: #{response}" if options[:debug] response end
send_cmd(options = {})
click to toggle source
Send the request to device
# File lib/loriot-rb/base.rb, line 28 def send_cmd(options = {}) options = { debug: @debug, token: @token, appid: @appid, cmd: "tx", eui: nil, port: 40, confirmed: false, data: "0301"}.merge(options) raise("Eui is blank! Should i guess your device?") unless options[:eui] response = sub_send_cmd(options) puts "#{Time.now} Cmd response: #{response}" if options[:debug] response end