Class: LoraClient
Overview
An interface to Lora Service from Ruby
Instance Attribute Summary collapse
-
#protocol ⇒ Object
readonly
Returns the value of attribute protocol.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
Instance Method Summary collapse
-
#delete_enqueued_messages(eui:, id: nil, debug: false) ⇒ Object
It returns enqueued message ready to delivery to node [‘topic’, [ {‘reply’ => { … }, ‘status’ => 200 ] ].
-
#get_enqueued_messages(eui:, request_id: nil, debug: false) ⇒ Object
It returns enqueued message ready to delivery to node [‘topic’, {‘reply’ => [ { … } ], ‘status’ => 200}].
-
#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.
Methods included from LoraRb::Base
#lora_decode, #lora_encode, #merge_tags_to_url
Constructor Details
#initialize(options = {}) ⇒ LoraClient
Establish a secure connection to your account on the cloud
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/lora-rb/base.rb', line 13 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, enqueued_downlinks_url: LoraRb.configuration.enqueued_downlinks_url, downlink_response_urls: LoraRb.configuration.downlink_response_urls, delete_enqueued_downlink_url: LoraRb.configuration.delete_enqueued_downlink_url, username: LoraRb::Settings.username, password: LoraRb::Settings.password, ssl: LoraRb.configuration.ssl, ssl_file: LoraRb.configuration.ssl_file, timeout: LoraRb.configuration.timeout, encoding: false}.merge() @debug = [:debug] @token = [:token] @appid = [:appid] @provider = LoraRb.configuration.provider @protocol = LoraRb.configuration.protocol @encoding = [:encoding] require 'base64' if @encoding require 'philter' require 'securerandom' raise "Specify your provider in the configuration file!" unless LoraRb.configuration.provider raise "Specify the protocol in the configuration file!" unless LoraRb.configuration.protocol raise "Provider #{LoraRb.configuration.provider} not defined!" unless LoraRb::Protocol.provider_is_valid? raise "Connection protocol #{LoraRb.configuration.protocol} not supported by the provider #{LoraRb.configuration.provider}!" unless LoraRb::Protocol.supported? require_relative "#{@provider}/#{@protocol}/call" self.extend LoraRb::Call welcome_response = sub_initialize() raise("Lora-rb: Cannot connect to host #{[:host]}:#{[:port]}") unless welcome_response.key?('hello') end |
Instance Attribute Details
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
10 11 12 |
# File 'lib/lora-rb/base.rb', line 10 def protocol @protocol end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
10 11 12 |
# File 'lib/lora-rb/base.rb', line 10 def provider @provider end |
Instance Method Details
#delete_enqueued_messages(eui:, id: nil, debug: false) ⇒ Object
It returns enqueued message ready to delivery to node
- ‘topic’, [ {‘reply’ => { … }, ‘status’ => 200
-
]
102 103 104 105 106 107 108 |
# File 'lib/lora-rb/base.rb', line 102 def (eui:, id: nil, debug: false) res = (eui: eui, id: id, debug: debug) puts "delete_enqueued_message #{res}" if @debug res end |
#get_enqueued_messages(eui:, request_id: nil, debug: false) ⇒ Object
It returns enqueued message ready to delivery to node
- ‘topic’, {‘reply’ => [ { … } ], ‘status’ => 200}
92 93 94 95 96 97 98 |
# File 'lib/lora-rb/base.rb', line 92 def (eui:, request_id: nil, debug: false) res = (eui: eui, request_id: request_id, debug: debug) puts "get_enqueued_message #{res}" if @debug res end |
#listen(options = {}, &block) ⇒ Object
Stay awaiting data from the cloud
83 84 85 86 87 88 |
# File 'lib/lora-rb/base.rb', line 83 def listen( = {}, &block) = { debug: @debug }.merge() puts "#{Time.now} Starting Listen app #{@appid}. To exit press CTRL+C" if [:debug] sub_listen(, &block) end |
#quit ⇒ Object
Close the secure connection with the cloud
110 111 112 |
# File 'lib/lora-rb/base.rb', line 110 def quit sub_quit end |
#read_data(options = {}) ⇒ Object
Receive all data devices from the cloud Each device sends its data to the cloud
74 75 76 77 78 79 80 |
# File 'lib/lora-rb/base.rb', line 74 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
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/lora-rb/base.rb', line 56 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 |