Class: TemperatureReadTtl
- Inherits:
-
Object
- Object
- TemperatureReadTtl
- Defined in:
- lib/temperature_read_ttl.rb
Instance Attribute Summary collapse
-
#temp ⇒ Object
readonly
Returns the value of attribute temp.
Class Method Summary collapse
- .open_url(url) ⇒ Object
-
.ttl_temperature ⇒ Object
——————————————————————— reading.
Instance Method Summary collapse
-
#initialize ⇒ TemperatureReadTtl
constructor
A new instance of TemperatureReadTtl.
Constructor Details
#initialize ⇒ TemperatureReadTtl
Returns a new instance of TemperatureReadTtl.
19 20 21 |
# File 'lib/temperature_read_ttl.rb', line 19 def initialize @temp = 0 end |
Instance Attribute Details
#temp ⇒ Object (readonly)
Returns the value of attribute temp.
17 18 19 |
# File 'lib/temperature_read_ttl.rb', line 17 def temp @temp end |
Class Method Details
.open_url(url) ⇒ Object
76 77 78 |
# File 'lib/temperature_read_ttl.rb', line 76 def self.open_url(url) Net::HTTP.get(URI.parse(url)) end |
.ttl_temperature ⇒ Object
reading
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/temperature_read_ttl.rb', line 26 def self.ttl_temperature # Subscribe example countCycles=0 MQTT::Client.connect( :host => 'staging.thethingsnetwork.org', :port => '1883', :username => '70B3D57ED00012B2', :password => 'c8iuTSccnypK1eoFzEb/OoqB2FVAiFg/aEaYesnNf4w=' ) do |c| # If you pass a block to the get method, then it will loop c.get('#') do |topic,| obj = JSON.parse("#{}") dev_eui = obj['dev_eui'] countCycles = countCycles + 1 #puts "#{topic}: #{message}" # another = JSON.parse("#{message}") # temps = another['fields'] # read_ttl_temps = temps.select {|temp| temp['temperature'] != ''} # puts read_ttl_temps # # another = JSON.parse("#{read_ttl_temps}") # temps = another['temperature'] # read_ttl_temps = temps.select {|temp| temp['temperature'] != ''} # # puts read_ttl_temps # ShowLogo.show_intro # puts "output : read from ttl".white # puts "======================\n\n".white # TemperatureOutput.show_output(TemperatureConvert.convert("#{sv1}")) # puts "-------------------------------------------------Cycle nr #{countCycles}".yellow # puts "------------------------------------dev_eui #{dev_eui}".magenta # sv1 = obj['fields']['temperature'] #client.disconnect() temp = obj['fields']['temperature'] #puts temp temp = temp.to_f @temp = temp break if [0,1] != nil end end @temp end |