Class: LoraClient
- Inherits:
-
Object
- Object
- LoraClient
- Includes:
- LoraRb::Base, LoraRb::Call
- Defined in:
- lib/lora-rb/base.rb
Overview
An interface to Lora Service from Ruby
Instance Attribute Summary
Attributes included from LoraRb::Call
#client, #contex, #ssl_socket, #tcp_socket
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ LoraClient
constructor
Establish a secure connection to your account on the cloud.
-
#listen(options = {}, &block) ⇒ Object
Stay awaiting data from the cloud.
-
#quit ⇒ Object
Close the secure connection with the cloud.
-
#read_data(options = {}) ⇒ Object
Receive all data devices from the cloud Each device sends its data to the cloud.
-
#send_cmd(options = {}) ⇒ Object
Send the request to device.
Constructor Details
#initialize(options = {}) ⇒ LoraClient
Establish a secure connection to your account on the cloud
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/lora-rb/base.rb', line 11 def initialize( = {}) = {debug: false, token: LoraRb::Settings.token, appid: LoraRb::Settings.appid, host: LoraRb.configuration.host, port: LoraRb.configuration.port, uplink_url: LoraRb.configuration.uplink_url, downlink_url: LoraRb.configuration.downlink_url, ssl: LoraRb.configuration.ssl, ssl_file: LoraRb.configuration.ssl_file }.merge() @debug = [:debug] @token = [:token] @appid = [:appid] welcome_response = sub_initialize() raise("Lora-rb: Cannot connect to host #{options[:host]}:#{options[:port]}") unless welcome_response.key?('hello') end |
Instance Method Details
#listen(options = {}, &block) ⇒ Object
Stay awaiting data from the cloud
60 61 62 63 64 65 |
# File 'lib/lora-rb/base.rb', line 60 def listen( = {}, &block) = { debug: @debug }.merge() puts "#{Time.now} Starting Listen app #{@appid}. To exit press CTRL+C" if [:debug] sub_listen() end |
#quit ⇒ Object
Close the secure connection with the cloud
68 69 70 |
# File 'lib/lora-rb/base.rb', line 68 def quit sub_quit end |
#read_data(options = {}) ⇒ Object
Receive all data devices from the cloud Each device sends its data to the cloud
51 52 53 54 55 56 57 |
# File 'lib/lora-rb/base.rb', line 51 def read_data( = {}) = { debug: @debug }.merge() puts "#{Time.now} Waiting for #{@appid} incoming data..." if [:debug] response = sub_read_data() puts "#{Time.now} Received: #{response}" if [:debug] response end |
#send_cmd(options = {}) ⇒ Object
Send the request to device
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/lora-rb/base.rb', line 33 def send_cmd( = {}) = { debug: @debug, token: @token, appid: @appid, cmd: "tx", eui: nil, port: 40, confirmed: false, data: "0301"}.merge() raise("Eui is blank! Should i guess your device?") unless [:eui] response = sub_send_cmd() puts "#{Time.now} Cmd response: #{response}" if [:debug] response end |